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.
implementation 'io.sentry:sentry-opentelemetry-otlp-spring:8.34.0'
This includes sentry-opentelemetry-otlp and the OpenTelemetry Spring Boot starter as transitive dependencies.
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).
Add the following to your application.properties:
sentry.dsn=___PUBLIC_DSN___
otel.propagators=sentry
otel.traces.exporter=otlp
otel.exporter.otlp.traces.endpoint=___OTLP_TRACES_URL___
otel.exporter.otlp.traces.protocol=http/protobuf
otel.exporter.otlp.traces.headers=x-sentry-auth=sentry sentry_key=___PUBLIC_KEY___
otel.logs.exporter=none
otel.metrics.exporter=none
Register the OpenTelemetryOtlpEventProcessor as a Spring bean to link Sentry events to OpenTelemetry traces:
import io.sentry.opentelemetry.otlp.OpenTelemetryOtlpEventProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SentryConfig {
@Bean
public OpenTelemetryOtlpEventProcessor openTelemetryOtlpEventProcessor() {
return 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.
Deferred Sampling
If you need to control sampling for deferred traces, you have to implement a custom OpenTelemetry Sampler.
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").