Skip to content

feat(opentelemetry)!: Simplify propagation and remove custom OTel tracing utils - #22702

Merged
andreiborza merged 16 commits into
developfrom
fn/propagator
Aug 3, 2026
Merged

feat(opentelemetry)!: Simplify propagation and remove custom OTel tracing utils#22702
andreiborza merged 16 commits into
developfrom
fn/propagator

Conversation

@mydea

@mydea mydea commented Jul 27, 2026

Copy link
Copy Markdown
Member

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

@github-actions

github-actions Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 29.91 kB - -
@sentry/browser - with treeshaking flags 28.11 kB - -
@sentry/browser (incl. Tracing) 47.35 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.36 kB - -
@sentry/browser (incl. Tracing, Profiling) 52.13 kB - -
@sentry/browser (incl. Tracing, Replay) 86.69 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 76.13 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 91.41 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 104.05 kB - -
@sentry/browser (incl. Feedback) 47.22 kB - -
@sentry/browser (incl. sendFeedback) 34.76 kB - -
@sentry/browser (incl. FeedbackAsync) 39.86 kB - -
@sentry/browser (incl. Metrics) 30.99 kB - -
@sentry/browser (incl. Logs) 31.22 kB - -
@sentry/browser (incl. Metrics & Logs) 31.89 kB - -
@sentry/react 31.73 kB - -
@sentry/react (incl. Tracing) 49.61 kB - -
@sentry/vue 34.98 kB - -
@sentry/vue (incl. Tracing) 49.34 kB - -
@sentry/svelte 29.94 kB - -
CDN Bundle 32 kB +0.06% +16 B 🔺
CDN Bundle (incl. Tracing) 47.72 kB - -
CDN Bundle (incl. Logs, Metrics) 33.55 kB +0.02% +4 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 49.08 kB +0.01% +3 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 72.89 kB -0.01% -5 B 🔽
CDN Bundle (incl. Tracing, Replay) 85.35 kB +0.01% +3 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.65 kB +0.01% +2 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 91.14 kB +0.01% +4 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.45 kB +0.01% +4 B 🔺
CDN Bundle - uncompressed 95.5 kB +0.01% +5 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 143.08 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 100.21 kB +0.01% +5 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 147.06 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 224.97 kB +0.01% +5 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 262.34 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 266.3 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 276.04 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 280 kB - -
@sentry/nextjs (client) 52.2 kB - -
@sentry/sveltekit (client) 47.8 kB - -
@sentry/core/server 80 kB +0.01% +5 B 🔺
@sentry/core/browser 51.96 kB +0.01% +3 B 🔺
@sentry/node 120.88 kB -0.83% -1 kB 🔽
@sentry/node/import (ESM hook with diagnostics-channel injection) 0 B added added
@sentry/node - without tracing 84.26 kB -1.3% -1.11 kB 🔽
@sentry/aws-serverless 92.92 kB -1.16% -1.09 kB 🔽
@sentry/cloudflare (withSentry) - minified 199.28 kB - -
@sentry/cloudflare (withSentry) 490.8 kB +0.01% +23 B 🔺

View base workflow run

Comment thread packages/opentelemetry/src/propagator.ts
Comment thread packages/node/src/sdk/initOtel.ts
Comment thread packages/nextjs/src/server/index.ts Outdated
Comment thread packages/opentelemetry/src/propagator.ts
Comment thread packages/opentelemetry/src/propagator.ts
Comment thread packages/opentelemetry/src/propagator.ts
Comment thread packages/opentelemetry/src/propagator.ts
Comment thread packages/opentelemetry/src/propagator.ts
Comment thread packages/opentelemetry/src/asyncContextStrategy.ts
@mydea
mydea force-pushed the fn/propagator branch 2 times, most recently from c4a4b13 to 93d6542 Compare July 29, 2026 11:15
@mydea
mydea changed the base branch from develop to fn/continue-start-trace-tests July 29, 2026 11:15
Comment thread packages/opentelemetry/src/index.ts
@mydea
mydea force-pushed the fn/propagator branch 2 times, most recently from afdbe2c to 7aa618c Compare July 29, 2026 14:13
scope.setPropagationContext({
traceId: generateTraceId(),
sampleRand: safeMathRandom(),
return withActiveSpan(null, () => {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just switching this up, it should not make concrete difference but seems more resilient, as it makes us more independent of what withActiveSpan does under the hood!

}

/** Custom implementation for OTEL, so we can handle scope-span linking. */
protected _getTraceInfoFromScope(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems this was not used anywhere anymore!

Base automatically changed from fn/continue-start-trace-tests to develop July 30, 2026 07:49
@mydea mydea changed the title feat(opentelemetry)!: Remove SentryPropagator feat(opentelemetry)!: Simplify propagation and remove custom OTel tracing utils Jul 30, 2026
@mydea
mydea marked this pull request as ready for review July 30, 2026 07:54
Comment thread packages/opentelemetry/src/propagator.ts
@mydea
mydea requested review from a team as code owners July 30, 2026 07:54
@mydea
mydea requested a review from a team as a code owner July 31, 2026 10:19
@mydea
mydea requested review from logaretm and msonnb and removed request for a team July 31, 2026 10:19
@mydea
mydea changed the base branch from fn/bun-http-integration to fn/streamline-acs-isolation-scope July 31, 2026 10:20
mydea added 2 commits July 31, 2026 13:25
remove getTraceData & fixes

fix traceparent propagation
@mydea
mydea force-pushed the fn/propagator branch 2 times, most recently from cf12656 to 5d24bc4 Compare July 31, 2026 11:26
Comment thread packages/opentelemetry/src/propagator.ts
Comment thread packages/opentelemetry/src/propagator.ts
Base automatically changed from fn/streamline-acs-isolation-scope to develop August 3, 2026 09:35
andreiborza and others added 2 commits August 3, 2026 11:49
# Conflicts:
#	packages/core/src/monitor.ts
#	packages/core/test/integrations/redis/redis-common.test.ts
#	packages/node/test/integrations/tracing/redis/redis-common.test.ts
#	packages/opentelemetry/src/asyncContextStrategy.ts
#	packages/server-utils/src/async-context.ts
#	packages/server-utils/test/async-context.test.ts
#	packages/server-utils/test/redis/redis-common.test.ts
#	packages/vercel-edge/test/middlewareTraceIsolation.test.ts
Co-authored-by: Sigrid <32902192+s1gr1d@users.noreply.github.com>
Comment thread packages/opentelemetry/src/propagator.ts

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 61517d1. Configure here.

Comment thread packages/server-utils/src/index.ts
Comment thread packages/opentelemetry/src/propagator.ts
Comment thread packages/core/src/tracing/trace.ts
@andreiborza
andreiborza merged commit cabe3dc into develop Aug 3, 2026
266 checks passed
@andreiborza
andreiborza deleted the fn/propagator branch August 3, 2026 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove W3CBaggagePropagator from @opentelemetry/core

3 participants