---
title: "OpenTelemetry Support"
description: "Using OpenTelemetry with Sentry Performance."
url: https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/tracing/instrumentation/opentelemetry/
---

# OpenTelemetry Support | Sentry for ASP.NET Core

You can configure your [OpenTelemetry SDK](https://opentelemetry.io/) to send traces and spans to Sentry.

## [Install](https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/tracing/instrumentation/opentelemetry.md#install)

The `Sentry.OpenTelemetry` package requires `OpenTelemetry` package `1.5.0` or higher.

To install, add the `Sentry` and `Sentry.OpenTelemetry` **NuGet** packages to your project:

```shell
dotnet add package Sentry -v 6.3.2
dotnet add package Sentry.OpenTelemetry -v 6.3.2
```

If you're building an ASP.NET or ASP.NET Core application, add their respective packages (`Sentry.AspNet` or `Sentry.AspNetCore`) as well.

To instrument outgoing HTTP requests using OpenTelemetry, also install [`OpenTelemetry.Instrumentation.Http`](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.Http):

```shell
dotnet add package OpenTelemetry.Instrumentation.Http
```

## [Usage](https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/tracing/instrumentation/opentelemetry.md#usage)

To start tracing in an ASP.NET Core app, add OpenTelemetry with tracing and add Sentry to the tracer provider.

```csharp
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOpenTelemetry()
    .WithTracing(tracerProviderBuilder =>
        tracerProviderBuilder
            .AddAspNetCoreInstrumentation() // <-- Adds ASP.NET Core telemetry sources
            .AddHttpClientInstrumentation() // <-- Adds HttpClient telemetry sources
            .AddSentry() // <-- Configure OpenTelemetry to send trace information to Sentry
    );
```

Next, initialize Sentry and opt into the use of OpenTelemetry. This allows the SDK to send OpenTelemetry spans to Sentry.

```csharp
builder.WebHost.UseSentry(options =>
{
    options.Dsn = "...Your DSN...";
    options.SendDefaultPii = true;
    options.TracesSampleRate = 1.0;
    options.UseOpenTelemetry(); // <-- Configure Sentry to use OpenTelemetry trace information
    options.DisableSentryHttpMessageHandler = true; // <-- Disable Sentry's HttpClient instrumentation to avoid duplicate spans
});
```

##### Important Note

When using OpenTelemetry to instrument HttpClient spans via `AddHttpClientInstrumentation`, you **must** set `DisableSentryHttpMessageHandler = true` in the Sentry options to disable Sentry's built-in HttpClient instrumentation. This prevents the creation of duplicate spans for HTTP requests.

## [OpenTelemetry and Sentry](https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/tracing/instrumentation/opentelemetry.md#opentelemetry-and-sentry)

With Sentry’s OpenTelemetry SDK, an OpenTelemetry `Span` becomes a Sentry `Transaction` or `Span`. The first `Span` sent through the Sentry `SpanProcessor` is a `Transaction`, and any child `Span` gets attached to the first `Transaction` upon checking the parent `Span` context. This is true for the OpenTelemetry root `Span` and any top level `Span` in the system. For example, a request sent from frontend to backend will create an OpenTelemetry root `Span` with a corresponding Sentry `Transaction`. The backend request will create a new Sentry `Transaction` for the OpenTelemetry `Span`. The Sentry `Transaction` and `Span` are linked as a trace for navigation and error tracking purposes.

### [Capturing exceptions](https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/tracing/instrumentation/opentelemetry.md#capturing-exceptions)

OpenTelemetry in .NET is implemented via the System.Diagnostics.Activity namespace. However, not all of the functionality in that namespace is supported by OpenTelemetry. In particular, it is [not recommended](https://github.com/open-telemetry/opentelemetry-specification/pull/4333) that you use the `Activity.RecordException` or `Activity.AddException` methods. Using either of these methods will result in valuable **information being removed from exceptions** before these get captured by Sentry.

Instead you should either log the exceptions (using `ILogger`) or capture the exceptions directly using `SentrySdk.CaptureException`.

## [Additional Configuration](https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/tracing/instrumentation/opentelemetry.md#additional-configuration)

If you need more fine grained control over Sentry, take a look at the [Configuration page](https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/configuration.md). In case you'd like to filter out transactions before sending them to Sentry (to get rid of health checks, for example), you may find the [Filtering page](https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/configuration/filtering.md#filtering-transaction-events) helpful.
