Skip to content

Commit 5db1e94

Browse files
committed
feat(otlp): Add develop docs for OTLPIntegration
1 parent 5d923b2 commit 5db1e94

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
title: OTLP Integration
3+
---
4+
5+
This document outlines how to build a dedicated `OTLPIntegration` in SDKs that makes it easier for users using [OpenTelemetry](https://opentelemetry.io/) for instrumentation to send their spans and traces to Sentry's new [OTLP ingestion endpoint](https://docs.sentry.io/concepts/otlp/).
6+
7+
## Background
8+
9+
### Existing OpenTelemetry Support
10+
11+
Some of our SDKs (Node, Java) already shipped a complete Performance powered by OpenTelemetry (POTEL) system following the [OpenTelemetry Support spec](../opentelemetry).
12+
13+
Some other SDKs (Python, Ruby, Elixir) implement a simpler system with **only** the `SpanProcessor` and `Propagator` components.
14+
15+
While building the POTEL prototype for Python, we questioned if the complexity we were adding was justified and the architecture was scalable and decided to stop with POTEL for other backend SDKs.
16+
17+
### OTLP Ingestion Endpoint
18+
19+
Concurrently to the above SDK work, we also shipped first-class support for ingesting OTLP Traces and Logs. This opened up the possibility of a much cleaner system that allows users to setup OpenTelemetry with Sentry seamlessly while preserving behavior - **Trace Connectedness** that makes Sentry valuable.
20+
21+
## Integration Spec
22+
23+
The new integration MUST be called `OTLPIntegration` with the following signature:
24+
25+
```python
26+
OTLPIntegration(setup_otlp_traces_exporter=True, setup_propagator=True)
27+
```
28+
29+
The arguments `setup_otlp_traces_exporter` and `setup_propagator` MUST be booleans that default to `True` and can be turned off if needed by the user.
30+
31+
It MUST consist of and setup the following components:
32+
33+
* A `SpanExporter` that automatically configures the OTLP ingestion endpoint from the DSN
34+
* A `Propagator` that ensures Distributed Tracing works with other upstream and downstream services using Sentry SDKs
35+
* Note that we use the `sentry-trace` (NOT `traceparent`) and `baggage` headers here
36+
* An `external_propagation_context` that extracts the active `trace_id` and `span_id` from the OpenTelemetry SDK
37+
38+
### SpanExporter
39+
40+
IF `setup_otlp_traces_exporter` is `True`, the integration MUST do the following:
41+
42+
* Take the existing `TracerProvider` from OpenTelemetry if it exists, otherwise create a new one
43+
* Construct the OTLP Traces `endpoint` from the DSN
44+
* The `endpoint` has the format - `https://o0.ingest.sentry.io/api/{project_id}/integration/otlp/v1/traces/`
45+
* It is RECOMMENDED to centralize API endpoint generation from the DSN if your SDK doesn't already have that
46+
* Add the `X-Sentry-Auth` header to a `headers` dictionary
47+
* Instantiate a `OTLPSpanExporter` from OpenTelemetry with the `endpoint` and `headers`
48+
* Instantiate a `BatchSpanProcessor` with the above `OTLPSpanExporter`
49+
* Add the `BatchSpanProcessor` to the `TracerProvider`
50+
51+
IF `setup_otlp_traces_exporter` is `False`, the integration MUST skip this entire step so users can configure their exporters OR collectors manually if they wish to do so.
52+
53+
See the reference Python implementation:
54+
<GitHubCodePreview url="https://github.com/getsentry/sentry-python/blob/c68c3d6b5152b879bc107f76d9a9c78e95792235/sentry_sdk/integrations/otlp.py#L36-L55" />
55+
56+
### Propagator
57+
58+
The `Propagator` implementation is the same as in the earlier [OpenTelemetry Spec](../opentelemetry/#step-2-implement-the-sentrypropagator-on-your-sdk-add-sentrypropagator).
59+
60+
IF `setup_propagator` is `True`, the integration MUST setup the `Propagator`.
61+
62+
The way to setup the propagator is dependent on the language ecosystem. The Python implementation uses `set_global_textmap`.
63+
64+
IF `setup_propagator` is `False`, the integration MUST skip setting up the `Propagator` and leave it to user to configure manually if they wish to do so.
65+
66+
### External Propagation Context
67+
68+
This specification introduces a new `external_propagation_context` concept that is a global function that adds a new source of `trace_id` and `span_id` to be used in other Sentry event payloads.
69+
70+
This is to ensure that all other Sentry events such as Errors, Check-Ins, Logs and Metrics have the correct `TraceContext` (for Errors and Check-Ins) or `trace_id, span_id` attributes (for Logs and Metrics) and can be linked correctly to the relevant Trace and Span originating from OpenTelemetry.
71+
72+
#### Scope
73+
74+
The `Scope` implementation MUST add two new methods:
75+
76+
* `register_external_propagation_context(fn)` that takes a function and stores it as a global
77+
* `get_external_propagation_context` that when called calls the above stored global function and returns a `(trace_id, span_id)` tuple or `None`
78+
79+
Further, the scope's `get_trace_context` method should use this `get_external_propagation_context` in preference to the local `propagation_context` on the scope to fill in the `trace_id` and `span_id` in the respective event payloads.
80+
81+
It is RECOMMENDED to centralize this logic for fetching the active `trace_id` and `span_id` for Logs and Metrics if that is not already the case in your SDK.
82+
83+
See the reference Python implementation:
84+
<GitHubCodePreview url="https://github.com/getsentry/sentry-python/blob/c68c3d6b5152b879bc107f76d9a9c78e95792235/sentry_sdk/scope.py#L149-L165" />
85+
86+
<GitHubCodePreview url="https://github.com/getsentry/sentry-python/blob/c68c3d6b5152b879bc107f76d9a9c78e95792235/sentry_sdk/scope.py#L587-L610" />
87+
88+
#### Integration
89+
90+
The Integration then MUST call `register_external_propagation_context` with a function that fetches the `(trace_id, span_id)` tuple from OpenTelemetry.
91+
92+
See the reference Python implementation:
93+
<GitHubCodePreview url="https://github.com/getsentry/sentry-python/blob/c68c3d6b5152b879bc107f76d9a9c78e95792235/sentry_sdk/integrations/otlp.py#L23-L33" />
94+
<GitHubCodePreview url="https://github.com/getsentry/sentry-python/blob/c68c3d6b5152b879bc107f76d9a9c78e95792235/sentry_sdk/integrations/otlp.py#L70" />
95+
96+
## Comparison to POTEL
97+
98+
Note the difference in components above to the components in the POTEL implementation:
99+
100+
* A `SpanProcessor` for processing and packaging the Spans that OpenTelemetry emits
101+
* A `Propagator` that ensures Distributed Tracing works with other upstream and downstream services using Sentry SDKs
102+
* A `Sampler` that works with Sentry's `traces_sample_rate` and `traces_sampler`
103+
* Note that this implies users **need** to use OpenTelemetry sampling themselves for now if they need. We might revisit the sampling DX with OTLP later.
104+
* Bidirectional syncing between Sentry's `Scope`s and OpenTelemetry's `Context` so that spans can be started in either API and interleaved freely while preserving the span tree

src/components/codeTabs.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ const Container = styled('div')`
140140
border-radius: 0 0 6px 6px;
141141
border: 1px solid var(--accent-11);
142142
border-top: none;
143+
margin-bottom: 1.5rem;
143144
}
144145
145146
@media (max-width: 768px) {

0 commit comments

Comments
 (0)