OpenTelemetry (OTLP)

Learn about using OTLP to automatically send OpenTelemetry Traces to Sentry.

The OTLP exporter configures the Sentry SDK to automatically send trace data instrumented by an OpenTelemetry SDK to Sentry's OpenTelemetry Protocol ingestion endpoint.

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

Copied
dotnet add package Sentry.OpenTelemetry.Exporter -v 6.6.0

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

To instrument outgoing HTTP requests using OpenTelemetry, also install OpenTelemetry.Instrumentation.Http:

Copied
dotnet add package OpenTelemetry.Instrumentation.Http

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

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

Copied
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
    .AddSource("MyApp") // the name of your ActivitySource
    .AddHttpClientInstrumentation()
    .AddSentryOtlpExporter("___PUBLIC_DSN___")
    .Build();

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

Copied
SentrySdk.Init(options =>
{
    options.Dsn = "___PUBLIC_DSN___";
    options.UseOtlp();
});

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. Note: Do not also set up tracing via the Sentry SDK (i.e. do not set TracesSampleRate).
  • A SentryPropagator that injects sentry-trace and baggage headers alongside the standard W3C traceparent for compatibility with services using Sentry's native tracing
  • Trace/Span linking for all other Sentry events such as Errors, Logs, and Metrics

Cross-service trace propagation uses OTel's default W3C traceparent headers and does not require additional configuration. See Exporters, Event Linking, and Propagation for details.

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

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.

  • defaultTextMapPropagator (TextMapPropagator, optional):

    Override the default propagator. Defaults to SentryPropagator, which propagates sentry-trace, baggage, and W3C traceparent headers. This option will be removed alongside the automatic propagator setup in the next major version.

  • .NET: 8.0+ / .NET Standard 2.0+ / .NET Framework 4.6.2+
  • Sentry: 6.5.0+
  • OpenTelemetry: 1.10.0+
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").