99[ ![ NuGet download count badge] ( https://img.shields.io/nuget/dt/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule )] ( https://www.nuget.org/packages/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule/ )
1010[ ![ codecov.io] ( https://codecov.io/gh/open-telemetry/opentelemetry-dotnet-contrib/branch/main/graphs/badge.svg?flag=unittests-Instrumentation.AspNet )] ( https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet-contrib?flags[0]=unittests-Instrumentation.AspNet )
1111
12- The ASP.NET Telemetry HttpModule enables distributed tracing of incoming ASP.NET
13- requests using the OpenTelemetry API.
12+ The ASP.NET Telemetry HttpModule is a skeleton to enable distributed tracing
13+ and metrics of incoming ASP.NET requests using the OpenTelemetry API.
14+
15+ > [ !NOTE]
16+ > This package is a [ pre-release] ( https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/VERSIONING.md#pre-releases ) .
17+ Until a [ stable version] ( https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/telemetry-stability.md )
18+ is released, there can be breaking changes.
1419
1520## Usage
1621
@@ -19,7 +24,7 @@ requests using the OpenTelemetry API.
1924If you are using the traditional ` packages.config ` reference style, a
2025` web.config ` transform should run automatically and configure the
2126` TelemetryHttpModule ` for you. If you are using the more modern PackageReference
22- style, this may be needed to be done manually. For more information, see:
27+ style, this may need to be done manually. For more information, see:
2328[ Migrate from packages.config to
2429PackageReference] ( https://docs.microsoft.com/nuget/consume-packages/migrate-packages-config-to-package-reference ) .
2530
@@ -37,65 +42,14 @@ To configure your `web.config` manually, add this:
3742</system .webServer>
3843```
3944
40- ### Step 2: Register a listener
45+ ### Step 2: Register hooks
4146
42- ` TelemetryHttpModule ` registers an
43- [ ActivitySource] ( https://docs.microsoft.com/dotnet/api/system.diagnostics.activitysource )
44- with the name ` OpenTelemetry.Instrumentation.AspNet ` . By default, .NET
45- ` ActivitySource ` will not generate any ` Activity ` objects unless there is
46- a registered listener.
47+ ` TelemetryHttpModule ` provides hooks to create and manage activities and metrics.
4748
48- To register a listener automatically using OpenTelemetry, please use the
49- [ OpenTelemetry.Instrumentation.AspNet] ( https://www.nuget.org/packages/OpenTelemetry.Instrumentation.AspNet/ )
49+ To automatically register the entire infrastructure using OpenTelemetry, please
50+ use the [ OpenTelemetry.Instrumentation.AspNet] ( https://www.nuget.org/packages/OpenTelemetry.Instrumentation.AspNet/ )
5051NuGet package.
5152
52- To register a listener manually, use code such as the following:
53-
54- ``` csharp
55- using System .Diagnostics ;
56- using System .Web ;
57- using System .Web .Http ;
58- using System .Web .Mvc ;
59- using System .Web .Routing ;
60- using OpenTelemetry .Instrumentation .AspNet ;
61-
62- namespace Examples .AspNet ;
63-
64- public class WebApiApplication : HttpApplication
65- {
66- private ActivityListener aspNetActivityListener ;
67-
68- protected void Application_Start ()
69- {
70- this .aspNetActivityListener = new ActivityListener
71- {
72- ShouldListenTo = (activitySource ) =>
73- {
74- // Only listen to TelemetryHttpModule's ActivitySource.
75- return activitySource .Name == " OpenTelemetry.Instrumentation.AspNet" ;
76- },
77- Sample = (ref ActivityCreationOptions <ActivityContext > options ) =>
78- {
79- // Sample everything created by TelemetryHttpModule's ActivitySource.
80- return ActivitySamplingResult .AllDataAndRecorded ;
81- },
82- };
83-
84- ActivitySource .AddActivityListener (this .aspNetActivityListener );
85-
86- GlobalConfiguration .Configure (WebApiConfig .Register );
87-
88- AreaRegistration .RegisterAllAreas ();
89- RouteConfig .RegisterRoutes (RouteTable .Routes );
90- }
91-
92- protected void Application_End ()
93- {
94- this .aspNetActivityListener ? .Dispose ();
95- }
96- }
97- ```
98-
9953## Options
10054
10155` TelemetryHttpModule ` provides a static options property
@@ -105,7 +59,7 @@ public class WebApiApplication : HttpApplication
10559### TextMapPropagator
10660
10761` TextMapPropagator ` controls how trace context will be extracted from incoming
108- Http request messages. By default, [ W3C Trace
62+ HTTP request messages. By default, [ W3C Trace
10963Context] ( https://www.w3.org/TR/trace-context/ ) is enabled.
11064
11165The OpenTelemetry API ships with a handful of [ standard
@@ -134,10 +88,13 @@ default supports W3C Trace Context & Baggage.
13488
13589### Events
13690
137- ` OnRequestStartedCallback ` , ` OnRequestStoppedCallback ` , & ` OnExceptionCallback `
91+ ` OnRequestStartedCallback ` , ` OnRequestStoppedCallback ` , and ` OnExceptionCallback `
13892are provided on ` TelemetryHttpModuleOptions ` and will be fired by the
13993` TelemetryHttpModule ` as requests are processed.
14094
141- A typical use case for these events is to add information (tags, events, and/or
142- links) to the created ` Activity ` based on the request, response, and/or
143- exception event being fired.
95+ A typical use case for the ` OnRequestStartedCallback ` event is to create an activity
96+ based on the ` HttpContextBase ` and ` ActivityContext ` .
97+
98+ ` OnRequestStoppedCallback ` and ` OnExceptionCallback ` are needed to add
99+ information (tags, events, and/or links) to the created ` Activity ` based on the
100+ request, response, and/or exception event being fired.
0 commit comments