Skip to content

Commit

Permalink
Update doc (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierjohn committed May 21, 2024
1 parent 61bf8a4 commit b0e199a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,14 @@ eg GET WeatherForecast/Action1

```

Or use `GetMeasuredOperationLatency` extension method.
Or use `GetMeasuredOperation` extension method.

``` csharp

[HttpGet("{customerResourceId}")]
public IEnumerable<WeatherForecast> Get(string customerResourceId)
{
HttpContext.GetMeasuredOperationLatency().CustomerResourceId = customerResourceId;
HttpContext.GetMeasuredOperation().CustomerResourceId = customerResourceId;
return GetWeather();
}

Expand All @@ -277,18 +277,18 @@ eg GET WeatherForecast/Action1

``` csharp

HttpContext.GetMeasuredOperationLatency().AddAttribute(attribute, value);
HttpContext.GetMeasuredOperation().AddAttribute(attribute, value);

```

GetMeasuredOperationLatency will **throw** if the route is not configured to emit SLI.
GetMeasuredOperation will **throw** if the route is not configured to emit SLI.

When used in a middleware or scenarios where a route may not be configured to emit SLI.

``` csharp

if (HttpContext.TryGetMeasuredOperationLatency(out var measuredOperationLatency))
measuredOperationLatency.AddAttribute("CustomAttribute", value);
if (HttpContext.TryGetMeasuredOperation(out var measuredOperation))
measuredOperation.AddAttribute("CustomAttribute", value);

```

Expand All @@ -314,7 +314,7 @@ eg GET WeatherForecast/Action1

In this case, add the attribute `[ServiceLevelIndicator]` on the controllers that should emit SLI.

- To measure a process, run it within a `using StartLatencyMeasureOperation` block.
- To measure a process, run it within a `using StartMeasuring` block.

Example.

Expand All @@ -323,7 +323,7 @@ eg GET WeatherForecast/Action1
public void StoreItem(MyDomainEvent domainEvent)
{
var attribute = new KeyValuePair<string, object?>("Event", domainEvent.GetType().Name);
using var measuredOperation = _serviceLevelIndicator.StartLatencyMeasureOperation("StoreItem", attribute);
using var measuredOperation = _serviceLevelIndicator.StartMeasuring("StoreItem", attribute);
DoTheWork();
)

Expand All @@ -338,7 +338,7 @@ To view the metrics locally.
1. Run Docker Desktop
2. Run [sample\DockerOpenTelemetry\run.cmd](sample\DockerOpenTelemetry\run.cmd) to download and run zipkin and prometheus.
3. Run the sample web API project and call the `GET WeatherForecast` using the Open API UI.
4. You should see the SLI metrics in prometheus under the meter `LatencySLI_bucket` where the `Operation = "GET WeatherForeCase"`, `http.response.status.code = 200`, `LocationId = "ms-loc://az/public/westus2"`, `activity.status_code = Ok`
4. You should see the SLI metrics in prometheus under the meter `ServiceLevelIndicator_bucket` where the `Operation = "GET WeatherForeCase"`, `http.response.status_code = 200`, `LocationId = "ms-loc://az/public/westus2"`, `activity.status_code = Ok`
![SLI](assets/prometheus.jpg)
5. If you run the sample with API Versioning, you will see something similar to the following.
![SLI](assets/versioned.jpg)
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public async Task TryGetMeasuredOperation_will_return_false_if_route_does_not_em
{
using var host = await TestHostBuilder.CreateHostWithoutSli();

var response = await host.GetTestClient().GetAsync("test/try_get_measured_operation_latency/Donald");
var response = await host.GetTestClient().GetAsync("test/try_get_measured_operation/Donald");
response.StatusCode.Should().Be(HttpStatusCode.OK);
var content = await response.Content.ReadAsStringAsync();

Expand All @@ -317,7 +317,7 @@ public async Task TryGetMeasuredOperation_will_return_true_if_route_emits_SLI()

using var host = await TestHostBuilder.CreateHostWithSli(_meter);

var response = await host.GetTestClient().GetAsync("test/try_get_measured_operation_latency/Goofy");
var response = await host.GetTestClient().GetAsync("test/try_get_measured_operation/Goofy");
response.StatusCode.Should().Be(HttpStatusCode.OK);
var content = await response.Content.ReadAsStringAsync();

Expand All @@ -329,7 +329,7 @@ void OnMeasurementRecorded(Instrument instrument, long measurement, ReadOnlySpan
{
new("CustomerResourceId", "TestCustomerResourceId"),
new("LocationId", "ms-loc://az/public/West US 3"),
new("Operation", "GET Test/try_get_measured_operation_latency/{value}"),
new("Operation", "GET Test/try_get_measured_operation/{value}"),
new("activity.status.code", "Ok"),
new("http.response.status.code", 200),
new("CustomAttribute", "Goofy"),
Expand Down
4 changes: 2 additions & 2 deletions ServiceLevelIndicators.Asp/tests/TestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public IActionResult AddCustomAttribute(string value)
return Ok(value);
}

[HttpGet("try_get_measured_operation_latency/{value}")]
public IActionResult TryGetMeasuredOperationLatency(string value)
[HttpGet("try_get_measured_operation/{value}")]
public IActionResult TryGetMeasuredOperation(string value)
{
if (HttpContext.TryGetMeasuredOperation(out var measuredOperation))
{
Expand Down
Binary file modified assets/prometheus.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/versioned.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b0e199a

Please sign in to comment.