Commit cabe3dc
feat(opentelemetry)!: Simplify propagation and remove custom OTel tracing utils (#22702)
Simplifies the OpenTelemetry `SentryPropagator` down to a thin
`TextMapPropagator` that delegates all trace-data serialization to
core's `getTraceData()`, and removes the custom OTel-specific
tracing/propagation overrides (`continueTrace`, `startNewTrace`,
`getTraceData`, `getTraceContextForScope`) in favor of core's
implementations. The net effect is that OTel-powered SDKs (Node,
Next.js, SvelteKit, etc.) now share the same propagation and
trace-continuation code paths as the rest of the SDK instead of
maintaining a parallel OTel-only variant.
### What changed
- **`SentryPropagator`** no longer extends `W3CBaggagePropagator`. It
now implements `TextMapPropagator` directly. `inject()` reads headers
from `getTraceData()` and only operates on the active context — if
called with a non-active context it warns and skips.
- Injecting with a non-active context _was_ supported before, but we
intentionally drop it. The main remaining consumers of this propagator
(Next.js and SvelteKit) don't need it, so rather than carry the
complexity of handling arbitrary non-active contexts, we focus the
propagator on the main use case and skip the edge cases that would
drastically increase its complexity.
- **URL / `tracePropagationTargets` filtering and
`propagateTraceparent`** are no longer the propagator's concern —
outgoing-request filtering already lives in the Node HTTP layer
(`inject-trace-propagation-headers.ts`), so the duplicated logic, the
`_urlMatchesTargetsMap` LRU cache, and the `sentry.url` trace-state
(`SENTRY_TRACE_STATE_URL`) are removed.
- **Removed the OTel-specific `getTraceData`, `continueTrace`, and
`startNewTrace`** overrides from the async context strategy. Core's
implementations are now used directly. To make this work,
`continueTrace`/`startNewTrace` in core were reworked to route through
`withActiveSpan(null, …)`, and OTel's non-recording (TwP) spans fall
back to the scope's propagation-context trace id.
- **Removed `getTraceContextForScope`** (and
`NodeClient._getTraceInfoFromScope`); scope→trace-context resolution now
goes through the shared core path.
- `_startSpan` now runs the callback with the started span set active on
the unsuppressed context, fixing event trace-context attaching to a
stale ancestor span across `startNewTrace`/`continueTrace` boundaries.
### Aligning Node and Browser behavior
Previously, the OTel/Node path and the browser (core) path had subtly
diverging propagation behavior because they ran through _different_
implementations of `getTraceData`, `continueTrace`, and `startNewTrace`.
The OTel variants derived trace data from the OTel context/span graph,
while the browser used core's scope- and span-based logic — so edge
cases (TwP sampling, DSC freezing, which trace id a fresh root span
lands on) could resolve differently between the two.
By deleting the OTel-specific overrides and routing everything through
core, Node and Browser now produce trace headers and continue/start
traces via a single common code path. There is one source of truth for
how a `sentry-trace`/`baggage` pair is derived from the current scope
and span, which removes a class of Node-vs-Browser discrepancies and
makes future changes apply uniformly to both.
### Test adjustments
Because this aligns Node's propagation/trace-continuation behavior with
the common core path, a number of Node integration tests had to be
updated to match the new (now shared) behavior — primarily expectations
around trace ids for parallel/root spans and outgoing-request
propagation (`parallel-root-spans`, `parallel-spans-in-scope`,
`fetch-sampled-no-active-span`, etc.). These changes reflect the
corrected/unified behavior, not regressions.
### Breaking changes
- `getTraceContextForScope` is no longer exported from
`@sentry/opentelemetry`.
- The `sentry.url` trace-state and the `getInjectionData` /
OTel-specific `getTraceData` internals of the propagator are removed.
- The `SentryPropagator` no longer injects when called with a non-active
context.
Closes #22281
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: isaacs <i@izs.me>
Co-authored-by: Andrei Borza <andrei.borza@sentry.io>
Co-authored-by: Andrei <168741329+andreiborza@users.noreply.github.com>
Co-authored-by: Sigrid <32902192+s1gr1d@users.noreply.github.com>1 parent 33725cd commit cabe3dc
26 files changed
Lines changed: 249 additions & 1624 deletions
File tree
- dev-packages/node-integration-tests/suites
- pino
- public-api
- bindScopeToEmitter
- startSpan
- parallel-root-spans-streamed
- parallel-root-spans
- parallel-spans-in-scope-streamed
- parallel-spans-in-scope-with-parentSpanId-streamed
- parallel-spans-in-scope-with-parentSpanId
- parallel-spans-in-scope
- tracing/requests/fetch-sampled-no-active-span
- packages
- core/src/tracing
- node/src/sdk
- opentelemetry
- src
- utils
- test
- integration
- utils
- vercel-edge
- src
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
479 | 479 | | |
480 | 480 | | |
481 | 481 | | |
482 | | - | |
| 482 | + | |
483 | 483 | | |
484 | 484 | | |
485 | 485 | | |
| |||
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | | - | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
38 | 40 | | |
39 | | - | |
| 41 | + | |
40 | 42 | | |
Lines changed: 10 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
16 | | - | |
17 | | - | |
18 | 15 | | |
19 | | - | |
20 | | - | |
21 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
22 | 20 | | |
23 | | - | |
24 | | - | |
25 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
26 | 24 | | |
27 | | - | |
| 25 | + | |
| 26 | + | |
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
| |||
Lines changed: 7 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | 17 | | |
19 | | - | |
20 | | - | |
21 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
22 | 21 | | |
23 | | - | |
| 22 | + | |
24 | 23 | | |
25 | | - | |
26 | | - | |
| 24 | + | |
| 25 | + | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
| |||
Lines changed: 9 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | 15 | | |
20 | | - | |
21 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
22 | 20 | | |
23 | | - | |
24 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
Lines changed: 11 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | 15 | | |
20 | | - | |
21 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
22 | 20 | | |
23 | | - | |
24 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
25 | 28 | | |
26 | 29 | | |
27 | 30 | | |
| |||
Lines changed: 7 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | 15 | | |
18 | | - | |
19 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
20 | 20 | | |
21 | | - | |
22 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
| 23 | + | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
| 13 | + | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
| 18 | + | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
0 commit comments