Skip to content

Commit

Permalink
Change the default instrument name from "ServiceLevelIndicator" to "o…
Browse files Browse the repository at this point in the history
…peration.duration" (#45)
  • Loading branch information
xavierjohn authored Nov 22, 2024
1 parent 83358bf commit 9818762
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ By tracking SLIs over time, service providers can identify trends and make impro
**ServiceLevelIndicators** library will help emit latency metrics for each API operation to help monitor the service performance over time.
The metrics is emitted via standard [.NET Meter Class](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.metrics.meter?view=net-7.0).

By default, an instrument named `ServiceLevelIndicator` is added to the service metrics and the metrics are emitted. The metrics are emitted with the following [attributes](https://opentelemetry.io/docs/specs/otel/common/#attribute).
By default, a meter named `ServiceLevelIndicator` with instrument name `operation.duration` is added to the service metrics. The metrics are emitted with the following [attributes](https://opentelemetry.io/docs/specs/otel/common/#attribute).

- CustomerResourceId - A value that helps identity the customer, customer group or calling service.
- LocationId - The location where the service running. eg. Public cloud, West US 3 region. [Azure Core](https://learn.microsoft.com/en-us/dotnet/api/azure.core.azurelocation?view=azure-dotnet)
Expand Down Expand Up @@ -308,7 +308,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 `ServiceLevelIndicator_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 `operation_duration_milliseconds_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 @@ -262,7 +262,7 @@ private void OnMeasurementRecorded(Instrument instrument, long measurement, Read
_callbackCalled = true;

_output.WriteLine($"Measurement {measurement}");
instrument.Name.Should().Be("ServiceLevelIndicator");
instrument.Name.Should().Be("operation.duration");
instrument.Unit.Should().Be("ms");
measurement.Should().BeInRange(MillisecondsDelay - 10, MillisecondsDelay + 400);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ public void Dispose()
private void ValidateMetrics(Instrument instrument, long measurement, ReadOnlySpan<KeyValuePair<string, object?>> tags, KeyValuePair<string, object?>[] expectedTags)
{
_callbackCalled = true;
instrument.Name.Should().Be("ServiceLevelIndicator");
instrument.Name.Should().Be("operation.duration");
instrument.Unit.Should().Be("ms");
measurement.Should().BeInRange(TestHostBuilder.MillisecondsDelay - 10, TestHostBuilder.MillisecondsDelay + 400);
_output.WriteLine($"Measurement {measurement}");
Expand Down
2 changes: 1 addition & 1 deletion ServiceLevelIndicators/src/ServiceLevelIndicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public ServiceLevelIndicator(IOptions<ServiceLevelIndicatorOptions> options)
ServiceLevelIndicatorOptions.Meter = new(DefaultMeterName, InstrumentationVersion);
}

_responseLatencyHistogram = ServiceLevelIndicatorOptions.Meter.CreateHistogram<long>(ServiceLevelIndicatorOptions.InstrumentName, "ms", "Duration of the operation.");
_responseLatencyHistogram = ServiceLevelIndicatorOptions.Meter.CreateHistogram<long>(ServiceLevelIndicatorOptions.DurationInstrumentName, "ms", "Duration of the operation.");
}

public void Record(string operation, long elapsedTime, params KeyValuePair<string, object?>[] attributes) =>
Expand Down
2 changes: 1 addition & 1 deletion ServiceLevelIndicators/src/ServiceLevelIndicatorOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Meter Meter
/// <summary>
/// The instrument name created on the given meter. Cannot be null.
/// </summary>
public string InstrumentName { get; set; } = "ServiceLevelIndicator";
public string DurationInstrumentName { get; set; } = "operation.duration";

/// <summary>
/// Activity Status Code attribute name.
Expand Down
4 changes: 2 additions & 2 deletions ServiceLevelIndicators/tests/ServiceLevelIndicatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void Customize_instrument_name()
CustomerResourceId = customerResourceId,
LocationId = locationId,
Meter = _meter,
InstrumentName = InstrumentName
DurationInstrumentName = InstrumentName
};
var serviceLevelIndicator = new ServiceLevelIndicator(Options.Create(options));

Expand All @@ -152,7 +152,7 @@ public void Customize_instrument_name()
ValidateMetrics(elapsedTime, InstrumentName);
}

private void ValidateMetrics(int elapsedTime, string instrumentName = "ServiceLevelIndicator", int? approx = null)
private void ValidateMetrics(int elapsedTime, string instrumentName = "operation.duration", int? approx = null)
{
_callbackCalled.Should().BeTrue();
_actualTags.Should().BeEquivalentTo(_expectedTags);
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 9818762

Please sign in to comment.