OpenTelemetry OTLP

Using OpenTelemetry OTLP export with Sentry.

Use the sentry-opentelemetry-otlp module when you want OpenTelemetry to handle tracing (with spans exported via OTLP to Sentry) while Sentry handles errors, logs, and metrics. Sentry reads trace and span IDs from the OpenTelemetry Context so that all Sentry events are correlated with your OpenTelemetry traces.

Unlike the Agent and Agentless integrations, this module does not use OpenTelemetry for scope storage or span creation within the Sentry SDK.

Copied
implementation 'io.sentry:sentry-opentelemetry-otlp:8.34.1'

This includes the OpenTelemetry SDK autoconfiguration and OTLP exporter as transitive dependencies. If you configure the OpenTelemetry SDK manually without autoconfiguration, you can exclude opentelemetry-sdk-extension-autoconfigure to prevent it from discovering and activating components via SPI.

You need to configure both OpenTelemetry (to export spans via OTLP to Sentry) and Sentry (to read trace/span IDs from OpenTelemetry).

The OTLP endpoint and authentication details are shown in the code examples below. You can also find the OTLP Traces Endpoint and OTLP Traces Endpoint Headers in your Sentry project under Settings > Projects > [Project] > Client Keys (DSN).

Initialize OpenTelemetry using AutoConfiguredOpenTelemetrySdk, then initialize Sentry with the OpenTelemetryOtlpEventProcessor:

Copied
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
import io.sentry.Sentry;
import io.sentry.opentelemetry.otlp.OpenTelemetryOtlpEventProcessor;

// 1. Configure OpenTelemetry
AutoConfiguredOpenTelemetrySdk.builder()
    .setResultAsGlobal()
    .addPropertiesSupplier(() -> {
        Map<String, String> properties = new HashMap<>();
        properties.put("otel.traces.exporter", "otlp");
        properties.put("otel.exporter.otlp.traces.endpoint", "___OTLP_TRACES_URL___");
        properties.put("otel.exporter.otlp.traces.protocol", "http/protobuf");
        properties.put("otel.exporter.otlp.traces.headers", "x-sentry-auth=sentry sentry_key=___PUBLIC_KEY___");
        properties.put("otel.propagators", "sentry");
        properties.put("otel.logs.exporter", "none");
        properties.put("otel.metrics.exporter", "none");
        return properties;
    })
    .build();

// 2. Initialize Sentry
Sentry.init(options -> {
    options.setDsn("___PUBLIC_DSN___");
    // Link Sentry events to OpenTelemetry traces
    options.addEventProcessor(new OpenTelemetryOtlpEventProcessor());
});

The Sentry propagator inherits the sampling decision from the incoming sentry-trace header. When no sampling flag is present (deferred decision), it defaults to sampled.

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").