OpenTelemetry.Instrumentation.Owin 1.13.0-beta.1

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

OWIN Instrumentation for OpenTelemetry .NET

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

NuGet version badge NuGet download count badge codecov.io

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.method
  • http.request.method_original
  • http.response.status_code
  • network.protocol.version
  • user_agent.original
  • server.address
  • server.port
  • url.path
  • url.query - By default, the values in the query component are replaced with the text Redacted. For example, ?key1=value1&key2=value2 becomes ?key1=Redacted&key2=Redacted. You can disable this redaction by setting the environment variable OTEL_DOTNET_EXPERIMENTAL_OWIN_DISABLE_URL_QUERY_REDACTION to true.
  • 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 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 (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.4 is deprecated.
1.0.0-rc.3 107,519 9/20/2022 1.0.0-rc.3 is deprecated.
1.0.0-rc.2 1,761 3/18/2022 1.0.0-rc.2 is deprecated.