|
| 1 | +--- |
| 2 | +title: OpenTelemetry (OTLP) |
| 3 | +description: "Learn about using OTLP to automatically send OpenTelemetry Traces to Sentry." |
| 4 | +keywords: ["otlp", "otel", "opentelemetry"] |
| 5 | +--- |
| 6 | + |
| 7 | +The OTLP integration configures the Sentry SDK to automatically send trace data instrumented by an [OpenTelemetry](https://opentelemetry.io) SDK to Sentry's [OpenTelemetry Protocol](https://opentelemetry.io/docs/specs/otel/protocol/) [ingestion endpoint](/concepts/otlp). |
| 8 | + |
| 9 | +## Install |
| 10 | + |
| 11 | +Install `sentry-sdk` from PyPI with the `opentelemetry-otlp` extra. |
| 12 | + |
| 13 | +```bash {tabTitle:pip} |
| 14 | +pip install "sentry-sdk[opentelemetry-otlp]" |
| 15 | +``` |
| 16 | +```bash {tabTitle:uv} |
| 17 | +uv add "sentry-sdk[opentelemetry-otlp]" |
| 18 | +``` |
| 19 | + |
| 20 | +## Configure |
| 21 | + |
| 22 | +You need to configure both the OpenTelemetry and Sentry SDKs to get trace data. |
| 23 | + |
| 24 | +### OpenTelemetry |
| 25 | + |
| 26 | +For the OpenTelemetry SDK, you need to [configure instrumentation](https://opentelemetry.io/docs/languages/python/getting-started/#instrumentation) as per your needs. |
| 27 | + |
| 28 | +### Sentry |
| 29 | + |
| 30 | +For the Sentry SDK, you simply need to enable our `OTLPIntegration` along with your existing configuration. |
| 31 | + |
| 32 | +<OnboardingOptionButtons |
| 33 | + options={["error-monitoring", "logs"]} |
| 34 | +/> |
| 35 | + |
| 36 | +```python |
| 37 | +import sentry_sdk |
| 38 | +from sentry_sdk.integrations.otlp import OTLPIntegration |
| 39 | + |
| 40 | +sentry_sdk.init( |
| 41 | + dsn="___PUBLIC_DSN___", |
| 42 | + # Add data like request headers and IP for users, if applicable; |
| 43 | + # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info |
| 44 | + send_default_pii=True, |
| 45 | + # ___PRODUCT_OPTION_START___ logs |
| 46 | + # Enable logs to be sent to Sentry |
| 47 | + enable_logs=True, |
| 48 | + # ___PRODUCT_OPTION_END___ logs |
| 49 | + integrations=[ |
| 50 | + OTLPIntegration(), |
| 51 | + ], |
| 52 | +) |
| 53 | +``` |
| 54 | + |
| 55 | +## Behavior |
| 56 | + |
| 57 | +Under the hood, the `OTLPIntegration` will setup the following parts: |
| 58 | + |
| 59 | +* A [`SpanExporter`](https://opentelemetry.io/docs/concepts/components/#exporters) that will automatically setup the OTLP ingestion endpoint from your Sentry DSN |
| 60 | +* A [`Propagator`](https://opentelemetry.io/docs/concepts/context-propagation/#propagation) that ensures [distributed tracing](concepts/key-terms/tracing/distributed-tracing/) works |
| 61 | +* Trace/Span linking for all other Sentry events such as Errors, Logs, Crons and Metrics |
| 62 | + |
| 63 | +## Supported Versions |
| 64 | + |
| 65 | +- Python: 3.7+ |
| 66 | +- opentelemetry-distro: 0.35b0+ |
0 commit comments