ServiceLevelIndicators.Asp
10.0.0-preview.6
dotnet add package ServiceLevelIndicators.Asp --version 10.0.0-preview.6
NuGet\Install-Package ServiceLevelIndicators.Asp -Version 10.0.0-preview.6
<PackageReference Include="ServiceLevelIndicators.Asp" Version="10.0.0-preview.6" />
<PackageVersion Include="ServiceLevelIndicators.Asp" Version="10.0.0-preview.6" />
<PackageReference Include="ServiceLevelIndicators.Asp" />
paket add ServiceLevelIndicators.Asp --version 10.0.0-preview.6
#r "nuget: ServiceLevelIndicators.Asp, 10.0.0-preview.6"
#:package ServiceLevelIndicators.Asp@10.0.0-preview.6
#addin nuget:?package=ServiceLevelIndicators.Asp&version=10.0.0-preview.6&prerelease
#tool nuget:?package=ServiceLevelIndicators.Asp&version=10.0.0-preview.6&prerelease
ServiceLevelIndicators.Asp
ASP.NET Core middleware that automatically emits Service Level Indicator (SLI) latency metrics in milliseconds for every API operation. Built on the ServiceLevelIndicators core library, it helps teams move from generic request timing to service-specific latency metrics with dimensions such as operation, customer, location, and status.
For API versioning support, add ServiceLevelIndicators.Asp.ApiVersioning.
When To Use This Package
Choose ServiceLevelIndicators.Asp when you are building an ASP.NET Core application and want SLI metrics emitted automatically for MVC controllers or Minimal API endpoints.
Use ServiceLevelIndicators if you only need manual measurement in non-HTTP code. Add ServiceLevelIndicators.Asp.ApiVersioning when your ASP.NET Core app uses Asp.Versioning and you want the resolved API version emitted as a metric dimension.
Installation
dotnet add package ServiceLevelIndicators.Asp
Quick Start — MVC Controllers
// 1. Register with OpenTelemetry
builder.Services.AddOpenTelemetry()
.WithMetrics(metrics =>
{
metrics.AddServiceLevelIndicatorInstrumentation();
metrics.AddOtlpExporter();
});
// 2. Configure SLI — AddMvc() enables attribute-based overrides
builder.Services.AddServiceLevelIndicator(options =>
{
options.LocationId = ServiceLevelIndicator.CreateLocationId("public", "westus3");
})
.AddMvc();
// 3. Add the middleware
app.UseServiceLevelIndicator();
Quick Start — Minimal APIs
builder.Services.AddServiceLevelIndicator(options =>
{
options.LocationId = ServiceLevelIndicator.CreateLocationId("public", "westus3");
});
app.UseServiceLevelIndicator();
// Mark individual endpoints
app.MapGet("/hello", () => "Hello World!")
.AddServiceLevelIndicator();
If you configure a custom Meter in ServiceLevelIndicatorOptions, register that same meter with OpenTelemetry by calling AddServiceLevelIndicatorInstrumentation(meter).
Emitted Metrics
A meter named ServiceLevelIndicator with instrument operation.duration (milliseconds) is emitted with the following attributes:
| Attribute | Description |
|---|---|
Operation |
Defaults to the route template, e.g. GET WeatherForecast |
CustomerResourceId |
Identifies the customer or caller |
LocationId |
Where the service is running |
activity.status.code |
Ok (2xx), Error (5xx), or Unset (other) |
http.response.status.code |
The HTTP response status code |
http.request.method |
(Optional) The HTTP method — enabled via AddHttpMethod() |
Customizations
Add HTTP method as a dimension
builder.Services.AddServiceLevelIndicator(options => { /* ... */ })
.AddMvc()
.AddHttpMethod();
Enrich with custom data
Use Enrich (or EnrichAsync) to set CustomerResourceId or add custom attributes:
builder.Services.AddServiceLevelIndicator(options => { /* ... */ })
.AddMvc()
.Enrich(context =>
{
var upn = context.HttpContext.User.Claims
.FirstOrDefault(c => c.Type == "upn")?.Value ?? "Unknown";
context.SetCustomerResourceId(upn);
context.AddAttribute("UserPrincipalName", upn);
});
Override the operation name
[HttpGet("MyAction")]
[ServiceLevelIndicator(Operation = "MyCustomName")]
public IActionResult Get() => Ok();
Set CustomerResourceId from a route parameter
[HttpGet("get-by-zip-code/{zipCode}")]
public IActionResult GetByZipcode([CustomerResourceId] string zipCode) => Ok();
Or imperatively:
HttpContext.GetMeasuredOperation().CustomerResourceId = customerResourceId;
Add custom attributes from route parameters
Parameters decorated with [Measure] are automatically added as metric dimensions:
[HttpGet("name/{first}/{surname}")]
public IActionResult Get([Measure] string first, [CustomerResourceId] string surname) => Ok();
Add custom attributes manually
HttpContext.GetMeasuredOperation().AddAttribute("CustomKey", value);
// Safe version for middleware (won't throw if SLI is not configured for the route)
if (HttpContext.TryGetMeasuredOperation(out var op))
op.AddAttribute("CustomKey", value);
Cardinality Guidance
Use CustomerResourceId, [Measure], and custom attributes for stable service dimensions such as tenant, subscription, region, or API flavor. Avoid unbounded values like request IDs, email addresses, timestamps, or arbitrary user input unless you explicitly want high-cardinality metrics and your backend can absorb the cost.
Opt-in mode
To disable automatic SLI emission on all controllers:
options.AutomaticallyEmitted = false;
Then add [ServiceLevelIndicator] only to the controllers you want measured.
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
- ServiceLevelIndicators (>= 10.0.0-preview.6)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ServiceLevelIndicators.Asp:
| Package | Downloads |
|---|---|
|
ServiceLevelIndicators.Asp.ApiVersioning
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.0.0-preview.6 | 43 | 3/14/2026 |
| 10.0.0-preview.2 | 67 | 3/5/2026 |
| 8.0.1 | 346 | 2/11/2025 |
| 8.0.0-alpha.25 | 123 | 11/22/2024 |
| 8.0.0-alpha.24 | 100 | 11/20/2024 |
| 8.0.0-alpha.17 | 161 | 5/21/2024 |
| 8.0.0-alpha.12 | 167 | 3/29/2024 |
| 8.0.0-alpha.7 | 131 | 1/24/2024 |
| 8.0.0-alpha.6 | 133 | 1/23/2024 |
| 1.1.2 | 341 | 12/14/2023 |
| 1.1.1 | 301 | 11/10/2023 |
| 1.0.1 | 304 | 10/3/2023 |
| 0.1.0-alpha.20 | 172 | 9/27/2023 |
| 0.1.0-alpha.19 | 134 | 9/27/2023 |
| 0.1.0-alpha.18 | 195 | 9/14/2023 |
| 0.1.0-alpha.10 | 235 | 8/23/2023 |