OpenTelemetry.Extensions.Enrichment.AspNetCore 1.19.1-beta.1

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

OpenTelemetry .NET SDK ASP.NET Core telemetry enrichment

Status
Stability Development
Code Owners @evgenyfedorov2, @dariusclay

NuGet version badge NuGet download count badge codecov.io

Contains OpenTelemetry .NET SDK ASP.NET Core telemetry enrichment extensions which are used for enrichment of logs, metrics, and traces in inbound HTTP requests.

Introduction

ASP.NET Core Telemetry enrichment attaches various types of information to traces generated for incoming HTTP requests. You can use the ASP.NET Core Telemetry enrichment framework to attach any custom information that you would like to be present in traces for incoming HTTP requests.

With the ASP.NET Core Telemetry enrichment framework, you don't need to worry about attaching the information carefully to each telemetry object you touch. Instead, if you implement your enricher class inherited from AspNetCoreTraceEnricher, it takes care of the details automatically. You simply register your class with the enrichment framework and the enrichment framework will make sure to call the enrichment methods of your class for every incoming HTTP request in your app.

Traces

Currently this package supports trace enrichment only.

Steps to enable OpenTelemetry.Extensions.Enrichment.AspNetCore

Step 1: Install package

Download the OpenTelemetry.Extensions.Enrichment.AspNetCore package:

dotnet add package OpenTelemetry.Extensions.Enrichment.AspNetCore --prerelease

Step 2: Create enricher class

Create your custom enricher class that inherits from the AspNetCoreTraceEnricher class and override one or more of the following virtual methods, as needed:

  • EnrichWithHttpRequest(in TraceEnrichmentBag bag, HttpRequest request)
  • EnrichWithHttpResponse(in TraceEnrichmentBag bag, HttpResponse response)
  • EnrichWithException(in TraceEnrichmentBag bag, Exception exception)

Each method receives a TraceEnrichmentBag, the same lightweight readonly struct used by OpenTelemetry.Extensions.Enrichment, which exposes a single Add(string key, object? value) method for adding tags.

internal sealed class MyAspNetCoreTraceEnricher : AspNetCoreTraceEnricher
{
    public override void EnrichWithHttpRequest(in TraceEnrichmentBag bag, HttpRequest request)
    {
        bag.Add("http.request.header.x-my-custom-header", request.Headers["x-my-custom-header"].ToString());
    }

    public override void EnrichWithHttpResponse(in TraceEnrichmentBag bag, HttpResponse response)
    {
        bag.Add("http.response.content-length", response.ContentLength);
    }

    public override void EnrichWithException(in TraceEnrichmentBag bag, Exception exception)
    {
        bag.Add("exception.source", exception.Source);
    }
}

Optionally, inject other services your enricher class depends on via its constructor, the same way you would with TraceEnricher (see the OpenTelemetry.Extensions.Enrichment README for an example).

Step 3: Register enricher class

Add your custom enricher class to the TracerProviderBuilder by calling the TryAddAspNetCoreTraceEnricher<T>() method:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOpenTelemetry()
    .WithTracing(tracing => tracing
        .AddAspNetCoreInstrumentation()
        .TryAddAspNetCoreTraceEnricher<MyAspNetCoreTraceEnricher>()
        .AddConsoleExporter());

var app = builder.Build();

app.MapGet("/", () => "Hello OpenTelemetry!");

app.Run();

Alternatively, you can add your custom enricher to the IServiceCollection directly:

var builder = WebApplication.CreateBuilder(args);

builder.Services.TryAddAspNetCoreTraceEnricher<MyAspNetCoreTraceEnricher>();

builder.Services.AddOpenTelemetry()
    .WithTracing(tracing => tracing
        .AddAspNetCoreInstrumentation()
        .AddConsoleExporter());

var app = builder.Build();

app.MapGet("/", () => "Hello OpenTelemetry!");

app.Run();

The TryAddAspNetCoreTraceEnricher() call should be done before exporter related Activity processors are added.

Step 4: Usage

Once registered, the enrichment methods of your class are called automatically for every incoming HTTP request handled by ASP.NET Core - no additional code is required at the request-handling site. Run your application and issue a request; the tags added in your enricher will appear on the resulting Activity.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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 OpenTelemetry.Extensions.Enrichment.AspNetCore:

Package Downloads
xSdk.Extensions.Telemetry

xSdk.Extensions.Telemetry - Telemetry extensions for the xSdk project.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.19.1-beta.1 67 9/21/2026
1.19.0-beta.1 90 9/18/2026
1.18.0-beta.1 218 8/21/2026
1.17.0-beta.1 285 7/17/2026
1.16.0-beta.1 101 7/9/2026
1.15.1-beta.2 591 4/23/2026
1.15.1-beta.1 86 4/21/2026
1.15.0-beta.1 3,737 1/21/2026
1.14.0-alpha.1 296 11/14/2025