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:
dotnet add package Sentry.OpenTelemetry.Exporter -v 6.7.0
dotnet add package Sentry.OpenTelemetry.Exporter -v 6.7.0
Install-Package Sentry.OpenTelemetry.Exporter -Version 6.7.0
paket add Sentry.OpenTelemetry.Exporter --version 6.7.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:
dotnet add package OpenTelemetry.Instrumentation.Http
dotnet add package OpenTelemetry.Instrumentation.Http
Install-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.
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddSource("MyApp") // the name of your ActivitySource
.AddHttpClientInstrumentation()
.AddSentryOtlpExporter("___PUBLIC_DSN___")
.Build();
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.
SentrySdk.Init(options =>
{
options.Dsn = "___PUBLIC_DSN___";
options.UseOtlp();
});
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
SentryPropagatorthat injectssentry-traceandbaggageheaders alongside the standard W3Ctraceparentfor compatibility with services using Sentry's native tracing - Trace/Span linking for all other Sentry events such as Errors, Logs, and Metrics
Planned Removal
The automatic propagator setup will be removed in the next major version. Configure propagators manually using the OpenTelemetry propagation API instead.
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 propagatessentry-trace,baggage, and W3Ctraceparentheaders. 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+
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").