OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule 1.13.0-beta.2
ASP.NET Telemetry HttpModule for OpenTelemetry
| Status | |
|---|---|
| Stability | Beta |
| Code Owners | @open-telemetry/dotnet-contrib-maintainers |
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(),
});
[!NOTE] When using the
OpenTelemetry.Instrumentation.AspNetTelemetryHttpModuleOptions.TextMapPropagatoris 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.
Showing the top 20 packages that depend on OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.
| Packages | Downloads |
|---|---|
|
OpenTelemetry.Instrumentation.AspNet
ASP.NET instrumentation for OpenTelemetry .NET
|
20 |
|
OpenTelemetry.Instrumentation.AspNet
ASP.NET instrumentation for OpenTelemetry .NET
|
22 |
|
OpenTelemetry.Instrumentation.AspNet
ASP.NET instrumentation for OpenTelemetry .NET
|
24 |
|
OpenTelemetry.Instrumentation.AspNet
ASP.NET instrumentation for OpenTelemetry .NET
|
26 |
|
OpenTelemetry.Instrumentation.AspNet
ASP.NET instrumentation for OpenTelemetry .NET
|
27 |
|
OpenTelemetry.Instrumentation.AspNet
ASP.NET instrumentation for OpenTelemetry .NET
|
28 |
|
OpenTelemetry.Instrumentation.AspNet
ASP.NET instrumentation for OpenTelemetry .NET
|
29 |
|
OpenTelemetry.Instrumentation.AspNet
ASP.NET instrumentation for OpenTelemetry .NET
|
30 |
|
OpenTelemetry.Instrumentation.AspNet
ASP.NET instrumentation for OpenTelemetry .NET
|
31 |
|
OpenTelemetry.Instrumentation.AspNet
ASP.NET instrumentation for OpenTelemetry .NET.
|
24 |
.NET Framework 4.6.2
- OpenTelemetry.Api (>= 1.13.1 && < 2.0.0)
| Version | Downloads | Last updated |
|---|---|---|
| 1.13.0-beta.2 | 3 | 10/24/2025 |
| 1.13.0-beta.1 | 4 | 10/20/2025 |
| 1.12.0-beta.2 | 5 | 09/19/2025 |
| 1.12.0-beta.1 | 12 | 05/09/2025 |
| 1.11.0-beta.2 | 20 | 03/06/2025 |
| 1.11.0-beta.1 | 19 | 02/02/2025 |
| 1.10.0-beta.1 | 24 | 01/04/2025 |
| 1.9.0-beta.1 | 20 | 11/29/2024 |
| 1.8.0-beta.3 | 23 | 05/25/2024 |
| 1.8.0-beta.2 | 21 | 05/25/2024 |
| 1.8.0-beta.1 | 27 | 05/25/2024 |
| 1.7.0-beta.2 | 24 | 05/25/2024 |
| 1.7.0-beta.1 | 20 | 05/25/2024 |
| 1.6.0-beta.2 | 27 | 05/25/2024 |
| 1.6.0-beta.1 | 19 | 05/25/2024 |
| 1.0.0-rc9.9 | 24 | 05/25/2024 |
| 1.0.0-rc9.8 | 21 | 05/25/2024 |
| 1.0.0-rc9.7 | 22 | 05/25/2024 |
| 1.0.0-rc9.6 | 22 | 05/25/2024 |
| 1.0.0-rc9.5 | 26 | 05/25/2024 |
| 1.0.0-rc9.4 | 24 | 05/25/2024 |
| 1.0.0-rc9.3 | 26 | 05/25/2024 |
| 1.0.0-rc9.2 | 20 | 05/25/2024 |
| 1.0.0-rc9.1 | 33 | 05/25/2024 |
| 1.0.0-rc9 | 19 | 05/25/2024 |
| 1.0.0-rc8 | 24 | 05/25/2024 |