Trellis.ServiceLevelIndicators 10.0.0-preview.21

This is a prerelease version of Trellis.ServiceLevelIndicators.
dotnet add package Trellis.ServiceLevelIndicators --version 10.0.0-preview.21
                    
NuGet\Install-Package Trellis.ServiceLevelIndicators -Version 10.0.0-preview.21
                    
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="Trellis.ServiceLevelIndicators" Version="10.0.0-preview.21" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Trellis.ServiceLevelIndicators" Version="10.0.0-preview.21" />
                    
Directory.Packages.props
<PackageReference Include="Trellis.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 Trellis.ServiceLevelIndicators --version 10.0.0-preview.21
                    
#r "nuget: Trellis.ServiceLevelIndicators, 10.0.0-preview.21"
                    
#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 Trellis.ServiceLevelIndicators@10.0.0-preview.21
                    
#: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=Trellis.ServiceLevelIndicators&version=10.0.0-preview.21&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Trellis.ServiceLevelIndicators&version=10.0.0-preview.21&prerelease
                    
Install as a Cake Tool

Trellis.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 Trellis.ServiceLevelIndicators.Asp.

When To Use This Package

Choose Trellis.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 Trellis.ServiceLevelIndicators.Asp instead.

Installation

dotnet add package Trellis.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.AddServiceLevelIndicator(options =>
{
    options.Meter = sliMeter;
    options.LocationId = ServiceLevelIndicator.CreateLocationId("public", "westus3");
    options.CustomerResourceId = "my-customer";
});

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:

void DoWork(ServiceLevelIndicator sli)
{
    using var op = sli.StartMeasuring("ProcessOrder");
    // Do work...
    op.SetOutcome(SliOutcome.Success);
}

You can also pass custom attributes:

var attribute = new KeyValuePair<string, object?>("Event", "OrderCreated");
using var op = sli.StartMeasuring("ProcessOrder", attribute);

Custom attribute names must be unique and must not reuse SLI-reserved tags such as CustomerResourceId, LocationId, Operation, Outcome, activity.status.code, http.request.method, or http.response.status.code.

Emitted Metrics

By default, a meter named Trellis.SLI emits the operation.duration histogram in milliseconds. If you configure ServiceLevelIndicatorOptions.Meter, metrics are emitted from that meter instead.

StartMeasuring(...) emits the following attributes when the returned MeasuredOperation is disposed:

Attribute Description
Operation The name of the measured operation
CustomerResourceId A stable identifier for the entity the operation is acting on (tenant, subscription, account, work item, etc.). NOT the caller, NOT a per-request ID, NOT a user/email.
LocationId Where the service is running (e.g. ms-loc://az/public/westus3)
Outcome Success, Failure, ClientError, or Ignored

Direct Record(...) calls emit CustomerResourceId, LocationId, Operation, Outcome, and any custom attributes supplied to the call. Without an explicit outcome, manual/background measurements default to Ignored.

Cardinality Guidance

Required tags must be stable and meaningful. Good values: tenant, subscription, environment, region, product tier, work-item type. Bad values: per-request GUIDs, timestamps, free-form user input, or raw emails when a stable object ID is available. The same rule applies to any custom attributes you add via MeasuredOperation.AddAttribute(...).

Disposal

ServiceLevelIndicator is a sealed IDisposable and is meant to be registered as a singleton — the DI container disposes it (and the Meter it created) at host shutdown, so applications never need to call Dispose() manually. If you supply your own Meter via ServiceLevelIndicatorOptions.Meter, you own its lifetime; SLI will not dispose it.

Key APIs

Type / Method Description
ServiceLevelIndicator.StartMeasuring(operation, attributes) Start a measured operation scope
MeasuredOperation.SetOutcome(outcome) Set the SLI outcome
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 Trellis.ServiceLevelIndicators:

Package Downloads
Trellis.ServiceLevelIndicators.Asp

ASP.NET Core middleware and MVC filter that auto-emit Service Level Indicator (SLI) latency metrics for HTTP requests. Adds attributes (ServiceLevelIndicator, RemoveServiceLevelIndicator, EnrichServiceLevelIndicator, CustomerResourceId, Measure) for opt-in/opt-out and dimension enrichment. Built on Trellis.ServiceLevelIndicators.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.0.0-preview.21 36 5/19/2026
10.0.0-preview.10 69 4/24/2026
10.0.0-preview.9 54 4/23/2026