ServiceLevelIndicators 10.0.0-preview.6
dotnet add package ServiceLevelIndicators --version 10.0.0-preview.6
NuGet\Install-Package ServiceLevelIndicators -Version 10.0.0-preview.6
<PackageReference Include="ServiceLevelIndicators" Version="10.0.0-preview.6" />
<PackageVersion Include="ServiceLevelIndicators" Version="10.0.0-preview.6" />
<PackageReference Include="ServiceLevelIndicators" />
paket add ServiceLevelIndicators --version 10.0.0-preview.6
#r "nuget: ServiceLevelIndicators, 10.0.0-preview.6"
#:package ServiceLevelIndicators@10.0.0-preview.6
#addin nuget:?package=ServiceLevelIndicators&version=10.0.0-preview.6&prerelease
#tool nuget:?package=ServiceLevelIndicators&version=10.0.0-preview.6&prerelease
ServiceLevelIndicators
A .NET library for emitting Service Level Indicator (SLI) latency metrics in milliseconds via the standard System.Diagnostics.Metrics API. Use it to measure operation duration across any .NET application and attach dimensions such as operation name, customer, location, and outcome so the data is useful for SLO dashboards and alerts.
For ASP.NET Core applications, see ServiceLevelIndicators.Asp.
When To Use This Package
Choose ServiceLevelIndicators when you want to measure operations directly in application code, especially in console apps, worker services, background jobs, libraries, or shared business logic that should stay independent from ASP.NET Core.
If you want automatic measurement of ASP.NET Core endpoints, use ServiceLevelIndicators.Asp instead.
Installation
dotnet add package ServiceLevelIndicators
Quick Start
1. Register with OpenTelemetry
builder.Services.AddOpenTelemetry()
.WithMetrics(metrics =>
{
metrics.AddServiceLevelIndicatorInstrumentation();
metrics.AddOtlpExporter();
});
If you supply a custom Meter in ServiceLevelIndicatorOptions, register that same meter with OpenTelemetry:
var sliMeter = new Meter("MyCompany.ServiceLevelIndicator");
builder.Services.AddOpenTelemetry()
.WithMetrics(metrics =>
{
metrics.AddServiceLevelIndicatorInstrumentation(sliMeter);
metrics.AddOtlpExporter();
});
builder.Services.Configure<ServiceLevelIndicatorOptions>(options =>
{
options.Meter = sliMeter;
options.LocationId = ServiceLevelIndicator.CreateLocationId("public", "westus3");
options.CustomerResourceId = "my-customer";
});
builder.Services.AddSingleton<ServiceLevelIndicator>();
2. Configure options
builder.Services.Configure<ServiceLevelIndicatorOptions>(options =>
{
options.LocationId = ServiceLevelIndicator.CreateLocationId("public", "westus3");
options.CustomerResourceId = "my-customer";
});
builder.Services.AddSingleton<ServiceLevelIndicator>();
3. Measure operations
Wrap any block of code in a using StartMeasuring scope:
async Task DoWork(ServiceLevelIndicator sli)
{
using var op = sli.StartMeasuring("ProcessOrder");
// Do work...
op.SetActivityStatusCode(ActivityStatusCode.Ok);
}
You can also pass custom attributes:
var attribute = new KeyValuePair<string, object?>("Event", "OrderCreated");
using var op = sli.StartMeasuring("ProcessOrder", attribute);
Emitted Metrics
A meter named ServiceLevelIndicator with instrument operation.duration (milliseconds) is emitted with the following attributes:
| Attribute | Description |
|---|---|
Operation |
The name of the measured operation |
CustomerResourceId |
Identifies the customer, customer group, or calling service |
LocationId |
Where the service is running (e.g. ms-loc://az/public/westus3) |
activity.status.code |
Ok, Error, or Unset based on the operation outcome |
Cardinality Guidance
Use stable, bounded values for CustomerResourceId and custom attributes. Good dimensions include tenant, subscription, environment, region, or product tier. Avoid highly variable values such as request IDs, email addresses, timestamps, or arbitrary user input unless high-cardinality metrics are intentional and supported by your backend.
Key APIs
| Type / Method | Description |
|---|---|
ServiceLevelIndicator.StartMeasuring(operation, attributes) |
Start a measured operation scope |
MeasuredOperation.SetActivityStatusCode(code) |
Set the outcome status |
MeasuredOperation.AddAttribute(name, value) |
Add a custom metric attribute |
MeasuredOperation.CustomerResourceId |
Get/set the customer resource ID |
ServiceLevelIndicator.CreateLocationId(cloud, region?, zone?) |
Helper to build a location ID string |
ServiceLevelIndicator.CreateCustomerResourceId(guid) |
Helper to build a customer resource ID from a service tree GUID |
Further Reading
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.3)
- Microsoft.Extensions.Options (>= 10.0.3)
- OpenTelemetry (>= 1.15.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ServiceLevelIndicators:
| Package | Downloads |
|---|---|
|
ServiceLevelIndicators.Asp
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.0.0-preview.6 | 42 | 3/14/2026 |
| 10.0.0-preview.2 | 67 | 3/5/2026 |
| 8.0.1 | 387 | 2/11/2025 |
| 8.0.0-alpha.25 | 121 | 11/22/2024 |
| 8.0.0-alpha.24 | 113 | 11/20/2024 |
| 8.0.0-alpha.17 | 173 | 5/21/2024 |
| 8.0.0-alpha.12 | 165 | 3/29/2024 |
| 8.0.0-alpha.7 | 128 | 1/24/2024 |
| 8.0.0-alpha.6 | 112 | 1/23/2024 |
| 1.1.2 | 390 | 12/14/2023 |
| 1.1.1 | 320 | 11/10/2023 |
| 1.0.1 | 333 | 10/3/2023 |
| 0.1.0-alpha.20 | 166 | 9/27/2023 |
| 0.1.0-alpha.19 | 137 | 9/27/2023 |
| 0.1.0-alpha.18 | 196 | 9/14/2023 |
| 0.1.0-alpha.10 | 190 | 8/23/2023 |