A module that instruments incoming request with System.Diagnostics.Activity and notifies listeners with DiagnosticsSource.
$ dotnet add package OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule| Status | |
|---|---|
| Stability | Stable |
| Code Owners | @open-telemetry/dotnet-contrib-maintainers |
The ASP.NET Telemetry HttpModule is a skeleton to enable distributed tracing and metrics of incoming ASP.NET requests using the OpenTelemetry API.
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 need 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>
TelemetryHttpModule provides hooks to create and manage activities and metrics.
To automatically register the entire infrastructure using OpenTelemetry, please use the OpenTelemetry.Instrumentation.AspNet NuGet package.
TelemetryHttpModule provides a static options property
(TelemetryHttpModule.Options) which can be used to configure the
TelemetryHttpModule and listen to events it fires.
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.
OnRequestStartedCallback, OnRequestStoppedCallback, and OnExceptionCallback
are provided on TelemetryHttpModuleOptions and will be fired by the
TelemetryHttpModule as requests are processed.
A typical use case for the OnRequestStartedCallback event is to create an activity
based on the HttpContextBase and ActivityContext.
OnRequestStoppedCallback and OnExceptionCallback are needed to add
information (tags, events, and/or links) to the created Activity based on the
request, response, and/or exception event being fired.