diff --git a/README.md b/README.md index e2b87d1..78560ac 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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) \ No newline at end of file diff --git a/ServiceLevelIndicators.Asp.ApiVersioning/tests/ServiceLevelIndicatorVersionedAspTests.cs b/ServiceLevelIndicators.Asp.ApiVersioning/tests/ServiceLevelIndicatorVersionedAspTests.cs index 2dc492a..f0ed212 100644 --- a/ServiceLevelIndicators.Asp.ApiVersioning/tests/ServiceLevelIndicatorVersionedAspTests.cs +++ b/ServiceLevelIndicators.Asp.ApiVersioning/tests/ServiceLevelIndicatorVersionedAspTests.cs @@ -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); } diff --git a/ServiceLevelIndicators.Asp/tests/ServiceLevelIndicatorAspTests.cs b/ServiceLevelIndicators.Asp/tests/ServiceLevelIndicatorAspTests.cs index ebbc7dd..4cda279 100644 --- a/ServiceLevelIndicators.Asp/tests/ServiceLevelIndicatorAspTests.cs +++ b/ServiceLevelIndicators.Asp/tests/ServiceLevelIndicatorAspTests.cs @@ -404,7 +404,7 @@ public void Dispose() private void ValidateMetrics(Instrument instrument, long measurement, ReadOnlySpan> tags, KeyValuePair[] 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}"); diff --git a/ServiceLevelIndicators/src/ServiceLevelIndicator.cs b/ServiceLevelIndicators/src/ServiceLevelIndicator.cs index b242ada..0a70fd0 100644 --- a/ServiceLevelIndicators/src/ServiceLevelIndicator.cs +++ b/ServiceLevelIndicators/src/ServiceLevelIndicator.cs @@ -23,7 +23,7 @@ public ServiceLevelIndicator(IOptions options) ServiceLevelIndicatorOptions.Meter = new(DefaultMeterName, InstrumentationVersion); } - _responseLatencyHistogram = ServiceLevelIndicatorOptions.Meter.CreateHistogram(ServiceLevelIndicatorOptions.InstrumentName, "ms", "Duration of the operation."); + _responseLatencyHistogram = ServiceLevelIndicatorOptions.Meter.CreateHistogram(ServiceLevelIndicatorOptions.DurationInstrumentName, "ms", "Duration of the operation."); } public void Record(string operation, long elapsedTime, params KeyValuePair[] attributes) => diff --git a/ServiceLevelIndicators/src/ServiceLevelIndicatorOptions.cs b/ServiceLevelIndicators/src/ServiceLevelIndicatorOptions.cs index d681d0d..e44405b 100644 --- a/ServiceLevelIndicators/src/ServiceLevelIndicatorOptions.cs +++ b/ServiceLevelIndicators/src/ServiceLevelIndicatorOptions.cs @@ -42,7 +42,7 @@ public Meter Meter /// /// The instrument name created on the given meter. Cannot be null. /// - public string InstrumentName { get; set; } = "ServiceLevelIndicator"; + public string DurationInstrumentName { get; set; } = "operation.duration"; /// /// Activity Status Code attribute name. diff --git a/ServiceLevelIndicators/tests/ServiceLevelIndicatorTests.cs b/ServiceLevelIndicators/tests/ServiceLevelIndicatorTests.cs index c0c3bf2..8d92f53 100644 --- a/ServiceLevelIndicators/tests/ServiceLevelIndicatorTests.cs +++ b/ServiceLevelIndicators/tests/ServiceLevelIndicatorTests.cs @@ -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)); @@ -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); diff --git a/assets/prometheus.jpg b/assets/prometheus.jpg index c209dc1..1b36bee 100644 Binary files a/assets/prometheus.jpg and b/assets/prometheus.jpg differ diff --git a/assets/versioned.jpg b/assets/versioned.jpg index b32a9ca..6809fe5 100644 Binary files a/assets/versioned.jpg and b/assets/versioned.jpg differ