ServiceLevelIndicators 10.0.0-preview.6

This is a prerelease version of ServiceLevelIndicators.
dotnet add package ServiceLevelIndicators --version 10.0.0-preview.6
                    
NuGet\Install-Package ServiceLevelIndicators -Version 10.0.0-preview.6
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ServiceLevelIndicators" Version="10.0.0-preview.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ServiceLevelIndicators" Version="10.0.0-preview.6" />
                    
Directory.Packages.props
<PackageReference Include="ServiceLevelIndicators" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ServiceLevelIndicators --version 10.0.0-preview.6
                    
#r "nuget: ServiceLevelIndicators, 10.0.0-preview.6"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ServiceLevelIndicators@10.0.0-preview.6
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ServiceLevelIndicators&version=10.0.0-preview.6&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=ServiceLevelIndicators&version=10.0.0-preview.6&prerelease
                    
Install as a Cake Tool

ServiceLevelIndicators

NuGet Package

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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