Skip to content

ref(opentelemetry): Vendor minimal TraceState implementation#21192

Open
mydea wants to merge 2 commits into
developfrom
fn/vendor-trace-state
Open

ref(opentelemetry): Vendor minimal TraceState implementation#21192
mydea wants to merge 2 commits into
developfrom
fn/vendor-trace-state

Conversation

@mydea
Copy link
Copy Markdown
Member

@mydea mydea commented May 27, 2026

Summary

  • Adds a small in-tree TraceState class under packages/opentelemetry/src/utils/TraceState.ts implementing api.TraceState from @opentelemetry/api.
  • Swaps the four import { TraceState } from '@opentelemetry/core' sites (sampler.ts, makeTraceState.ts, and three test files) to use the vendored version.

Why

The SDK only ever calls new TraceState() and chains .set(), .get(), .unset(), and .serialize() on the result — none of the upstream class's heavier behavior (raw tracestate header parsing, key/value validation, W3C length/item caps) ever runs against our inputs. Inlining the ~40 lines we actually use lets us drop one consumer of @opentelemetry/core from a heavily-imported file without behavior change.

Deliberately dropped from upstream

  • Raw-string parsing in the constructor — the W3C tracestate header is parsed by OTel's own W3CTraceContextPropagator, which uses its own TraceState. Our class is never constructed from a raw header.
  • Key/value validation — we only set known SENTRY_TRACE_STATE_* constants.
  • MAX_TRACE_STATE_ITEMS / MAX_TRACE_STATE_LEN truncation — only relevant when parsing input.

@opentelemetry/core remains a dependency because propagator.ts, resource.ts, trace.ts, and utils/suppressTracing.ts still use isTracingSuppressed, W3CBaggagePropagator, SDK_INFO, and suppressTracing.

🤖 Generated with Claude Code

mydea and others added 2 commits May 27, 2026 14:13
Getting rid of this usage from `@opentelemetry/core`.
Replaces the `TraceState` import from `@opentelemetry/core` with a small
in-tree implementation under `packages/opentelemetry/src/utils/`. The
SDK only ever calls `new TraceState()` and chains `.set()`/`.get()`/
`.serialize()` on it, so the vendored version drops raw-string parsing,
key/value validation, and the W3C length/item caps — none of which apply
to keys we control.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mydea mydea self-assigned this May 27, 2026
@github-actions
Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.27 kB - -
@sentry/browser - with treeshaking flags 25.69 kB - -
@sentry/browser (incl. Tracing) 45.27 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.51 kB - -
@sentry/browser (incl. Tracing, Profiling) 50.25 kB - -
@sentry/browser (incl. Tracing, Replay) 84.87 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.38 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.59 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.2 kB - -
@sentry/browser (incl. Feedback) 44.46 kB - -
@sentry/browser (incl. sendFeedback) 32.09 kB - -
@sentry/browser (incl. FeedbackAsync) 37.21 kB - -
@sentry/browser (incl. Metrics) 28.37 kB - -
@sentry/browser (incl. Logs) 28.59 kB - -
@sentry/browser (incl. Metrics & Logs) 29.29 kB - -
@sentry/react 29.01 kB - -
@sentry/react (incl. Tracing) 47.5 kB - -
@sentry/vue 32.19 kB - -
@sentry/vue (incl. Tracing) 47.13 kB - -
@sentry/svelte 27.3 kB - -
CDN Bundle 29.68 kB - -
CDN Bundle (incl. Tracing) 47.8 kB - -
CDN Bundle (incl. Logs, Metrics) 31.17 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.05 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.48 kB - -
CDN Bundle (incl. Tracing, Replay) 85.3 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.45 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.17 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.33 kB - -
CDN Bundle - uncompressed 87.69 kB - -
CDN Bundle (incl. Tracing) - uncompressed 144.18 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 92.18 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 147.94 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 216.91 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 262.96 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 266.7 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 276.66 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 280.39 kB - -
@sentry/nextjs (client) 49.99 kB - -
@sentry/sveltekit (client) 45.75 kB - -
@sentry/core/server 76.44 kB - -
@sentry/core/browser 63.19 kB - -
@sentry/node-core 62.28 kB -0.43% -264 B 🔽
@sentry/node 131.09 kB +0.02% +25 B 🔺
@sentry/node - without tracing 74.71 kB -0.36% -265 B 🔽
@sentry/aws-serverless 86.92 kB -0.33% -281 B 🔽
@sentry/cloudflare (withSentry) - minified 173.4 kB - -
@sentry/cloudflare (withSentry) 433.33 kB - -

View base workflow run

@mydea mydea marked this pull request as ready for review May 27, 2026 14:25
@mydea mydea requested a review from a team as a code owner May 27, 2026 14:26
@mydea mydea requested review from JPeer264 and andreiborza and removed request for a team May 27, 2026 14:26
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.

1 participant