OpenTelemetry (OTLP)
Learn about using OTLP to automatically send OpenTelemetry Traces to Sentry.
The OTLP integration configures the Sentry SDK to automatically send trace data instrumented by an OpenTelemetry SDK to Sentry's OpenTelemetry Protocol ingestion endpoint.
Install sentry-sdk from PyPI with the opentelemetry-otlp extra.
pip install "sentry-sdk[opentelemetry-otlp]"
pip install "sentry-sdk[opentelemetry-otlp]"
uv add "sentry-sdk[opentelemetry-otlp]"
You need to configure both the OpenTelemetry and Sentry SDKs to get trace data.
For the OpenTelemetry SDK, you need to configure instrumentation you want to capture.
For the Sentry SDK, add the OTLPIntegration to your existing configuration.
import sentry_sdk
from sentry_sdk.integrations.otlp import OTLPIntegration
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
# Add data like request headers and IP for users, if applicable;
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
send_default_pii=True,
# ___PRODUCT_OPTION_START___ logs
# Enable logs to be sent to Sentry
enable_logs=True,
# ___PRODUCT_OPTION_END___ logs
integrations=[
OTLPIntegration(),
],
)
import sentry_sdk
from sentry_sdk.integrations.otlp import OTLPIntegration
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
# Add data like request headers and IP for users, if applicable;
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
send_default_pii=True,
# ___PRODUCT_OPTION_START___ logs
# Enable logs to be sent to Sentry
enable_logs=True,
# ___PRODUCT_OPTION_END___ logs
integrations=[
OTLPIntegration(),
],
)
Under the hood, the OTLPIntegration sets up the following parts:
- A
SpanExporterthat automatically configures the OTLP ingestion endpoint from your Sentry DSN. This enables tracing in Sentry. Note: Do not also set up tracing via the Python SDK (i.e. do not settraces_sample_rateortraces_sampler). - A Sentry
Propagatorfor compatibility with services using Sentry's native tracing (see note below) - 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.
You can pass the following keyword arguments to OTLPIntegration():
setup_otlp_traces_exporter:Automatically configure an Exporter to send OTLP traces to the right project from the DSN or
collector_url, defaults toTrue.Set to
Falseto set up the TracerProvider manually.collector_url: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.
setup_propagator:Automatically configure the Sentry propagator for distributed tracing, defaults to
True.Set to
Falseto configure propagators manually or to disable propagation.Planned Removal
The automatic propagator setup will be removed in the next major version. Configure propagators manually using the OpenTelemetry propagation API instead.
capture_exceptions:Set to
Trueto intercept and capture exceptions on the OpenTelemetry Span recorded withSpan.record_exceptionin Sentry as well, defaults toFalse.Caveat: Since Sentry already captures most exceptions, duplicate exceptions might be dropped by
DedupeIntegrationbut that should not affect your overall product experience on the Issues page.
- Python: 3.7+
- opentelemetry-distro: 0.35b0+
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").