ServiceLevelIndicators 10.0.0-preview.2

This is a prerelease version of ServiceLevelIndicators.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package ServiceLevelIndicators --version 10.0.0-preview.2
                    
NuGet\Install-Package ServiceLevelIndicators -Version 10.0.0-preview.2
                    
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.2" />
                    
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.2" />
                    
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.2
                    
#r "nuget: ServiceLevelIndicators, 10.0.0-preview.2"
                    
#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.2
                    
#: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.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=ServiceLevelIndicators&version=10.0.0-preview.2&prerelease
                    
Install as a Cake Tool

ServiceLevelIndicators

NuGet Package

A .NET library for emitting Service Level Indicator (SLI) latency metrics via the standard System.Diagnostics.Metrics API. Use it to measure operation duration across any .NET application — console apps, background services, worker processes, and more.

For ASP.NET Core applications, see ServiceLevelIndicators.Asp.

Installation

dotnet add package ServiceLevelIndicators

Quick Start

1. Register with OpenTelemetry

builder.Services.AddOpenTelemetry()
    .WithMetrics(metrics =>
    {
        metrics.AddServiceLevelIndicatorInstrumentation();
        metrics.AddOtlpExporter();
    });

2. Configure options

builder.Services.AddServiceLevelIndicator(options =>
{
    options.LocationId = ServiceLevelIndicator.CreateLocationId("public", "westus3");
    options.CustomerResourceId = "my-customer";
});

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

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 68 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