OpenTelemetry.Instrumentation.Owin
1.13.0-beta.1
Prefix Reserved
dotnet add package OpenTelemetry.Instrumentation.Owin --version 1.13.0-beta.1
NuGet\Install-Package OpenTelemetry.Instrumentation.Owin -Version 1.13.0-beta.1
<PackageReference Include="OpenTelemetry.Instrumentation.Owin" Version="1.13.0-beta.1" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Owin" Version="1.13.0-beta.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Owin" />
paket add OpenTelemetry.Instrumentation.Owin --version 1.13.0-beta.1
#r "nuget: OpenTelemetry.Instrumentation.Owin, 1.13.0-beta.1"
#:package OpenTelemetry.Instrumentation.Owin@1.13.0-beta.1
#addin nuget:?package=OpenTelemetry.Instrumentation.Owin&version=1.13.0-beta.1&prerelease
#tool nuget:?package=OpenTelemetry.Instrumentation.Owin&version=1.13.0-beta.1&prerelease
OWIN Instrumentation for OpenTelemetry .NET
| Status | |
|---|---|
| Stability | Beta |
| Code Owners | @open-telemetry/dotnet-contrib-maintainers |
This is an Instrumentation Library, which instruments OWIN/Katana and collects telemetry about incoming requests.
Steps to enable OpenTelemetry.Instrumentation.Owin
An example project is available in the examples/owin folder.
Step 1: Install Package
Add a reference to the
OpenTelemetry.Instrumentation.Owin
package. Also, add any other instrumentations & exporters you will need.
dotnet add package OpenTelemetry.Instrumentation.Owin
Step 2: Configure OWIN middleware
Call the UseOpenTelemetry IAppBuilder extension to register OpenTelemetry
middleware which emits diagnostic events from th OWIN pipeline. This should be
done before any other middleware registrations.
using var host = WebApp.Start(
"http://localhost:9000",
appBuilder =>
{
appBuilder.UseOpenTelemetry();
});
Step 3: Enable OWIN Instrumentation at application startup
Configure OpenTelemetry TracerProvider
Call the AddOwinInstrumentation TracerProviderBuilder extension to register
OpenTelemetry instrumentation which listens to the OWIN diagnostic events.
using var openTelemetry = Sdk.CreateTracerProviderBuilder()
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("Owin-Example"))
.AddOwinInstrumentation()
.AddConsoleExporter()
.Build();
Following list of attributes are added by default on activity. See http-spans for more details about each individual attribute:
http.request.methodhttp.request.method_originalhttp.response.status_codenetwork.protocol.versionuser_agent.originalserver.addressserver.porturl.pathurl.query- By default, the values in the query component are replaced with the textRedacted. For example,?key1=value1&key2=value2becomes?key1=Redacted&key2=Redacted. You can disable this redaction by setting the environment variableOTEL_DOTNET_EXPERIMENTAL_OWIN_DISABLE_URL_QUERY_REDACTIONtotrue.url.scheme
Configure OpenTelemetry MeterProvider
Call the AddOwinInstrumentation MeterProviderBuilder extension to register
OpenTelemetry instrumentation which generates request duration metrics for OWIN requests.
The metric implemention does not rely on tracing, and will generate metrics even if tracing is disabled.
using var openTelemetry = Sdk.CreateMeterProviderBuilder()
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("Owin-Example"))
.AddOwinInstrumentation()
.AddConsoleExporter()
.Build();
The instrumentation is implemented based on metrics semantic conventions. Currently, the instrumentation supports the following metric.
| Name | Instrument Type | Unit | Description |
|---|---|---|---|
http.server.request.duration |
Histogram | s |
Duration of HTTP server requests. |
Customize OWIN span names
The OpenTelemetry OWIN instrumentation will create spans with very generic names
based on the http method of the request. For example: HTTP GET or HTTP POST.
The reason for this is the OpenTelemetry Specification http semantic
conventions
call specifically for low cardinality values and OWIN does not expose any kind
of route template.
To change the span name set Activity.Current.DisplayName to the value you want
to display once a route has been resolved. Here is how this can be done using WebAPI:
using var host = WebApp.Start(
"http://localhost:9000",
appBuilder =>
{
appBuilder.UseOpenTelemetry();
HttpConfiguration config = new HttpConfiguration();
config.MessageHandlers.Add(new ActivityDisplayNameRouteEnrichingHandler());
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional });
appBuilder.UseWebApi(config);
});
private class ActivityDisplayNameRouteEnrichingHandler : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request,
CancellationToken cancellationToken)
{
try
{
return await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
}
finally
{
var activity = Activity.Current;
if (activity != null)
{
var routeData = request.GetRouteData();
if (routeData != null)
{
activity.DisplayName = routeData.Route.RouteTemplate;
}
}
}
}
}
References
| Product | Versions 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. |
-
.NETFramework 4.6.2
- Microsoft.Extensions.Configuration (>= 9.0.0)
- Microsoft.Extensions.Options (>= 9.0.0)
- Microsoft.Owin (>= 4.2.2)
- OpenTelemetry.Api.ProviderBuilderExtensions (>= 1.13.1 && < 2.0.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on OpenTelemetry.Instrumentation.Owin:
| Package | Downloads |
|---|---|
|
Grafana.OpenTelemetry
Full Grafana distribution of OpenTelemetry .NET |
|
|
Honeycomb.OpenTelemetry.CommonInstrumentations
Honeycomb's OpenTelemetry common instrumentations package. Adds support for many common instrumentation libraries for you. |
|
|
Honeycomb.OpenTelemetry.AutoInstrumentations
Honeycomb's OpenTelemetry autoinstrumentations package. Adds support for many common instrumentation libraries for you. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 1.13.0-beta.1 | 133 | 10/23/2025 | |
| 1.12.0-beta.1 | 16,694 | 5/5/2025 | |
| 1.11.0-beta.1 | 7,448 | 3/5/2025 | |
| 1.10.0-beta.1 | 3,345 | 12/20/2024 | |
| 1.0.0-rc.6 | 94,974 | 4/19/2024 | |
| 1.0.0-rc.5 | 170 | 4/17/2024 | |
| 1.0.0-rc.4 | 5,759 | 3/20/2024 | |
| 1.0.0-rc.3 | 107,519 | 9/20/2022 | |
| 1.0.0-rc.2 | 1,761 | 3/18/2022 |