Skip to content

Commit 9818762

Browse files
authored
Change the default instrument name from "ServiceLevelIndicator" to "operation.duration" (#45)
1 parent 83358bf commit 9818762

File tree

8 files changed

+8
-8
lines changed

8 files changed

+8
-8
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ By tracking SLIs over time, service providers can identify trends and make impro
2929
**ServiceLevelIndicators** library will help emit latency metrics for each API operation to help monitor the service performance over time.
3030
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).
3131

32-
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).
32+
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).
3333

3434
- CustomerResourceId - A value that helps identity the customer, customer group or calling service.
3535
- 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.
308308
1. Run Docker Desktop
309309
2. Run [sample\DockerOpenTelemetry\run.cmd](sample\DockerOpenTelemetry\run.cmd) to download and run zipkin and prometheus.
310310
3. Run the sample web API project and call the `GET WeatherForecast` using the Open API UI.
311-
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`
311+
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`
312312
![SLI](assets/prometheus.jpg)
313313
5. If you run the sample with API Versioning, you will see something similar to the following.
314314
![SLI](assets/versioned.jpg)

ServiceLevelIndicators.Asp.ApiVersioning/tests/ServiceLevelIndicatorVersionedAspTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ private void OnMeasurementRecorded(Instrument instrument, long measurement, Read
262262
_callbackCalled = true;
263263

264264
_output.WriteLine($"Measurement {measurement}");
265-
instrument.Name.Should().Be("ServiceLevelIndicator");
265+
instrument.Name.Should().Be("operation.duration");
266266
instrument.Unit.Should().Be("ms");
267267
measurement.Should().BeInRange(MillisecondsDelay - 10, MillisecondsDelay + 400);
268268
}

ServiceLevelIndicators.Asp/tests/ServiceLevelIndicatorAspTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ public void Dispose()
404404
private void ValidateMetrics(Instrument instrument, long measurement, ReadOnlySpan<KeyValuePair<string, object?>> tags, KeyValuePair<string, object?>[] expectedTags)
405405
{
406406
_callbackCalled = true;
407-
instrument.Name.Should().Be("ServiceLevelIndicator");
407+
instrument.Name.Should().Be("operation.duration");
408408
instrument.Unit.Should().Be("ms");
409409
measurement.Should().BeInRange(TestHostBuilder.MillisecondsDelay - 10, TestHostBuilder.MillisecondsDelay + 400);
410410
_output.WriteLine($"Measurement {measurement}");

ServiceLevelIndicators/src/ServiceLevelIndicator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public ServiceLevelIndicator(IOptions<ServiceLevelIndicatorOptions> options)
2323
ServiceLevelIndicatorOptions.Meter = new(DefaultMeterName, InstrumentationVersion);
2424
}
2525

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

2929
public void Record(string operation, long elapsedTime, params KeyValuePair<string, object?>[] attributes) =>

ServiceLevelIndicators/src/ServiceLevelIndicatorOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public Meter Meter
4242
/// <summary>
4343
/// The instrument name created on the given meter. Cannot be null.
4444
/// </summary>
45-
public string InstrumentName { get; set; } = "ServiceLevelIndicator";
45+
public string DurationInstrumentName { get; set; } = "operation.duration";
4646

4747
/// <summary>
4848
/// Activity Status Code attribute name.

ServiceLevelIndicators/tests/ServiceLevelIndicatorTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public void Customize_instrument_name()
131131
CustomerResourceId = customerResourceId,
132132
LocationId = locationId,
133133
Meter = _meter,
134-
InstrumentName = InstrumentName
134+
DurationInstrumentName = InstrumentName
135135
};
136136
var serviceLevelIndicator = new ServiceLevelIndicator(Options.Create(options));
137137

@@ -152,7 +152,7 @@ public void Customize_instrument_name()
152152
ValidateMetrics(elapsedTime, InstrumentName);
153153
}
154154

155-
private void ValidateMetrics(int elapsedTime, string instrumentName = "ServiceLevelIndicator", int? approx = null)
155+
private void ValidateMetrics(int elapsedTime, string instrumentName = "operation.duration", int? approx = null)
156156
{
157157
_callbackCalled.Should().BeTrue();
158158
_actualTags.Should().BeEquivalentTo(_expectedTags);

assets/prometheus.jpg

127 KB
Loading

assets/versioned.jpg

119 KB
Loading

0 commit comments

Comments
 (0)