---
title: "OpenTelemetry (OTLP)"
description: "Learn about using OTLP to automatically send OpenTelemetry Traces to Sentry using the .NET SDK."
url: https://docs.sentry.io/platforms/dotnet/guides/extensions-hosting/tracing/instrumentation/opentelemetry-otlp/
---

# OpenTelemetry (OTLP) for Generic Host

The OTLP exporter configures the Sentry SDK to automatically send trace data instrumented by an OpenTelemetry SDK to Sentry's [OpenTelemetry Protocol](https://opentelemetry.io/docs/specs/otel/protocol/) [ingestion endpoint](https://docs.sentry.io/concepts/otlp.md).

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

Add the `Sentry.OpenTelemetry.Exporter` NuGet package to your project:

```shell
dotnet add package Sentry.OpenTelemetry.Exporter -v 7.0.0
```

*Other available variations of the above snippet: Package Manager, Paket CLI*

This package includes the standard OpenTelemetry OTLP exporter as a transitive dependency.

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
```

*Other available variations of the above snippet: Package Manager*

## [Configure](https://docs.sentry.io/platforms/dotnet/guides/extensions-hosting/tracing/instrumentation/opentelemetry-otlp.md#configure)

You need to configure both the OpenTelemetry and Sentry SDKs to get trace data.

### [OpenTelemetry](https://docs.sentry.io/platforms/dotnet/guides/extensions-hosting/tracing/instrumentation/opentelemetry-otlp.md#opentelemetry)

Set up a `TracerProvider` using `AddSentryOtlpExporter` with your DSN. This automatically configures the OTLP endpoint and authentication headers derived from the DSN.

```csharp
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
    .AddSource("MyApp") // the name of your ActivitySource
    .AddHttpClientInstrumentation()
    .AddSentryOtlpExporter("https://<key>@o<orgId>.ingest.sentry.io/<projectId>")
    .Build();
```

### [Sentry](https://docs.sentry.io/platforms/dotnet/guides/extensions-hosting/tracing/instrumentation/opentelemetry-otlp.md#sentry)

Initialize Sentry and call `UseOtlp()` to disable Sentry's built-in span creation in favor of OpenTelemetry tracing.

```csharp
SentrySdk.Init(options =>
{
    options.Dsn = "https://<key>@o<orgId>.ingest.sentry.io/<projectId>";
    options.UseOtlp();
});
```

## [Behavior](https://docs.sentry.io/platforms/dotnet/guides/extensions-hosting/tracing/instrumentation/opentelemetry-otlp.md#behavior)

Under the hood, the OTLP exporter sets up the following parts:

* An OTLP exporter that automatically configures the ingestion endpoint from your Sentry DSN. This enables tracing in Sentry.
* Trace/Span linking for all other Sentry events such as Errors, Logs, and Metrics

Calling `UseOtlp()` on `SentryOptions` turns off Sentry's automatic span creation from `SentryHttpMessageHandler`, `DiagnosticSource` listener, and Entity Framework interception to avoid duplicate spans.

## [Sampling](https://docs.sentry.io/platforms/dotnet/guides/extensions-hosting/tracing/instrumentation/opentelemetry-otlp.md#sampling)

Because Sentry doesn't create transactions of its own when you call `UseOtlp()`, `TracesSampleRate` and `TracesSampler` have no effect. OpenTelemetry decides which spans are exported, so configure sampling on the `TracerProvider` instead:

```csharp
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
    .AddSource("MyApp")
    .SetSampler(new ParentBasedSampler(new TraceIdRatioBasedSampler(0.25)))
    .AddSentryOtlpExporter("https://<key>@o<orgId>.ingest.sentry.io/<projectId>")
    .Build();
```

## [Trace Propagation](https://docs.sentry.io/platforms/dotnet/guides/extensions-hosting/tracing/instrumentation/opentelemetry-otlp.md#trace-propagation)

The OTLP exporter doesn't configure an OpenTelemetry propagator, so OpenTelemetry's default applies: it sends and reads W3C `traceparent`, `tracestate`, and `baggage` headers. Traces connect across services that use OpenTelemetry without additional configuration. See [Exporters, Event Linking, and Propagation](https://docs.sentry.io/concepts/otlp/sentry-with-otel.md#exporters-event-linking-and-propagation) for details.

##### Changed in Version 7.0.0

Earlier versions of `AddSentryOtlpExporter` set `SentryPropagator` as OpenTelemetry's default propagator, and accepted a `defaultTextMapPropagator` parameter (as did `UseOtlp`) to use a different one. Version 7.0.0 removed the automatic setup and the parameter. To keep propagating `sentry-trace` headers, set the propagator yourself as shown below.

Requests sent through `SentryHttpMessageHandler` also get a `sentry-trace` header. `UseOtlp()` stops the handler from creating spans, but not from adding headers. Sentry adds this handler to `IHttpClientFactory` clients automatically when you initialize Sentry through dependency injection, for example with `UseSentry()` in ASP.NET Core.

### [Services That Use Sentry's Tracing](https://docs.sentry.io/platforms/dotnet/guides/extensions-hosting/tracing/instrumentation/opentelemetry-otlp.md#services-that-use-sentrys-tracing)

Services that use a Sentry SDK's own tracing, rather than OpenTelemetry, continue traces from `sentry-trace` and `baggage` headers. When they receive a request that didn't go through `SentryHttpMessageHandler`, they start a new trace.

To send a `sentry-trace` header on every request OpenTelemetry instruments, and to continue traces from incoming `sentry-trace` headers, add `SentryPropagator` (included in `Sentry.OpenTelemetry.Exporter`) next to the W3C propagator when configuring the OpenTelemetry SDK at startup:

```csharp
using OpenTelemetry;
using OpenTelemetry.Context.Propagation;
using Sentry.OpenTelemetry;

Sdk.SetDefaultTextMapPropagator(new CompositeTextMapPropagator(new TextMapPropagator[]
{
    new TraceContextPropagator(),
    new SentryPropagator(),
}));
```

If you only need to continue traces from services that call this one, enable [`propagateTraceparent`](https://docs.sentry.io/concepts/otlp/sentry-with-otel.md#linking-sentry-and-otlp-traces) in their Sentry SDKs instead. They then also send a `traceparent` header, which OpenTelemetry reads by default. In .NET, that's the [`PropagateTraceparent`](https://docs.sentry.io/platforms/dotnet/guides/extensions-hosting/configuration/options.md#PropagateTraceparent) option. You don't need it in the service that uses the OTLP exporter, because OpenTelemetry already sends `traceparent` from there.

If the calling service hasn't made a sampling decision, for example because tracing is turned off there, its `traceparent` header is marked as not sampled (`-00`), since W3C trace context can't express an undecided state. OpenTelemetry's parent-based sampler then doesn't record this service's spans for those requests.

## [Options](https://docs.sentry.io/platforms/dotnet/guides/extensions-hosting/tracing/instrumentation/opentelemetry-otlp.md#options)

`AddSentryOtlpExporter` accepts the following parameters:

* `dsnString` (string):

  Your Sentry DSN. The OTLP endpoint and authentication headers are derived from this automatically.

* `collectorUrl` (Uri, optional):

  URL of your own OpenTelemetry collector. When set, the exporter will send traces to this URL instead of the Sentry OTLP endpoint derived from the DSN.

## [Supported Versions](https://docs.sentry.io/platforms/dotnet/guides/extensions-hosting/tracing/instrumentation/opentelemetry-otlp.md#supported-versions)

* .NET: 8.0+ / .NET Standard 2.0+ / .NET Framework 4.6.2+
* Sentry: 6.5.0+
* OpenTelemetry: 1.12.0+
