OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule 1.12.0-beta.2

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

ASP.NET Telemetry HttpModule for OpenTelemetry

Status
Stability Beta
Code Owners @open-telemetry/dotnet-contrib-maintainers

NuGet version badge NuGet download count badge codecov.io

The ASP.NET Telemetry HttpModule enables distributed tracing of incoming ASP.NET requests using the OpenTelemetry API.

Usage

Step 1: Install NuGet package

If you are using the traditional packages.config reference style, a web.config transform should run automatically and configure the TelemetryHttpModule for you. If you are using the more modern PackageReference style, this may be needed to be done manually. For more information, see: Migrate from packages.config to PackageReference.

To configure your web.config manually, add this:

<system.webServer>
    <modules>
        <add
            name="TelemetryHttpModule"
            type="OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule,
                OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule"
            preCondition="integratedMode,managedHandler" />
    </modules>
</system.webServer>

Step 2: Register a listener

TelemetryHttpModule registers an ActivitySource with the name OpenTelemetry.Instrumentation.AspNet. By default, .NET ActivitySource will not generate any Activity objects unless there is a registered listener.

To register a listener automatically using OpenTelemetry, please use the OpenTelemetry.Instrumentation.AspNet NuGet package.

To register a listener manually, use code such as the following:

using System.Diagnostics;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;
using OpenTelemetry.Instrumentation.AspNet;

namespace Examples.AspNet;

public class WebApiApplication : HttpApplication
{
    private ActivityListener aspNetActivityListener;

    protected void Application_Start()
    {
        this.aspNetActivityListener = new ActivityListener
        {
            ShouldListenTo = (activitySource) =>
            {
                // Only listen to TelemetryHttpModule's ActivitySource.
                return activitySource.Name == "OpenTelemetry.Instrumentation.AspNet";
            },
            Sample = (ref ActivityCreationOptions<ActivityContext> options) =>
            {
                // Sample everything created by TelemetryHttpModule's ActivitySource.
                return ActivitySamplingResult.AllDataAndRecorded;
            },
        };

        ActivitySource.AddActivityListener(this.aspNetActivityListener);

        GlobalConfiguration.Configure(WebApiConfig.Register);

        AreaRegistration.RegisterAllAreas();
        RouteConfig.RegisterRoutes(RouteTable.Routes);
    }

    protected void Application_End()
    {
        this.aspNetActivityListener?.Dispose();
    }
}

Options

TelemetryHttpModule provides a static options property (TelemetryHttpModule.Options) which can be used to configure the TelemetryHttpModule and listen to events it fires.

TextMapPropagator

TextMapPropagator controls how trace context will be extracted from incoming Http request messages. By default, W3C Trace Context is enabled.

The OpenTelemetry API ships with a handful of standard implementations which may be used, or you can write your own by deriving from the TextMapPropagator class.

To add support for Baggage propagation in addition to W3C Trace Context, use:

TelemetryHttpModuleOptions.TextMapPropagator = new CompositeTextMapPropagator(
    new TextMapPropagator[]
    {
        new TraceContextPropagator(),
        new BaggagePropagator(),
    });

When using the OpenTelemetry.Instrumentation.AspNet TelemetryHttpModuleOptions.TextMapPropagator is automatically initialized to the SDK default propagator (Propagators.DefaultTextMapPropagator) which by default supports W3C Trace Context & Baggage.

Events

OnRequestStartedCallback, OnRequestStoppedCallback, & OnExceptionCallback are provided on TelemetryHttpModuleOptions and will be fired by the TelemetryHttpModule as requests are processed.

A typical use case for these events is to add information (tags, events, and/or links) to the created Activity based on the request, response, and/or exception event being fired.

Product Compatible and additional computed target framework versions.
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule:

Package Downloads
OpenTelemetry.Instrumentation.AspNet

ASP.NET instrumentation for OpenTelemetry .NET.

C3D.Extensions.SystemWeb.OpenTelemetry.Application

Assembly Version: 0.1.0.0 File Version: 0.1.122.35648 Informational Version: 0.1.122+408be8c6f1 Build Configuration: Release

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule:

Repository Stars
getsentry/examples
Collection of all different kinds of Sentry SDKs and integrations
Version Downloads Last Updated
1.12.0-beta.2 1,038 9/18/2025
1.12.0-beta.1 54,665 5/5/2025
1.11.0-beta.2 56,258 3/5/2025
1.11.0-beta.1 38,735 1/27/2025
1.10.0-beta.1 59,341 12/9/2024
1.9.0-beta.1 471,738 6/18/2024
1.8.0-beta.3 149,790 5/23/2024
1.8.0-beta.2 138,735 4/17/2024
1.8.0-beta.1 34,304 4/5/2024
1.7.0-beta.2 120,764 2/7/2024
1.7.0-beta.1 66,493 12/20/2023
1.6.0-beta.2 134,623 11/6/2023
1.6.0-beta.1 28,419 10/12/2023
1.0.0-rc9.9 217,530 6/9/2023
1.0.0-rc9.8 276,167 2/28/2023
1.0.0-rc9.7 135,050 11/28/2022
1.0.0-rc9.6 63,502 9/28/2022
1.0.0-rc9.5 111,535 6/21/2022
1.0.0-rc9.4 63,393 6/3/2022
1.0.0-rc9.3 9,445 4/20/2022
1.0.0-rc9.2 28,209 4/13/2022
1.0.0-rc9.1 82,605 3/30/2022
1.0.0-rc9 94,937 2/3/2022
1.0.0-rc8 97,510 10/8/2021