Skip to content

ref(opentelemetry): Vendor minimal TraceState implementation#21192

Merged
mydea merged 1 commit into
developfrom
fn/vendor-trace-state
May 29, 2026
Merged

ref(opentelemetry): Vendor minimal TraceState implementation#21192
mydea merged 1 commit 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 mydea self-assigned this May 27, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 27, 2026

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 27.17 kB - -
@sentry/browser - with treeshaking flags 25.62 kB - -
@sentry/browser (incl. Tracing) 45.25 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.47 kB - -
@sentry/browser (incl. Tracing, Profiling) 50.22 kB - -
@sentry/browser (incl. Tracing, Replay) 84.83 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.39 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.53 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.15 kB - -
@sentry/browser (incl. Feedback) 44.34 kB - -
@sentry/browser (incl. sendFeedback) 31.98 kB - -
@sentry/browser (incl. FeedbackAsync) 37.08 kB - -
@sentry/browser (incl. Metrics) 28.25 kB - -
@sentry/browser (incl. Logs) 28.48 kB - -
@sentry/browser (incl. Metrics & Logs) 29.19 kB - -
@sentry/react 28.99 kB - -
@sentry/react (incl. Tracing) 47.51 kB - -
@sentry/vue 32.2 kB - -
@sentry/vue (incl. Tracing) 47.16 kB - -
@sentry/svelte 27.19 kB - -
CDN Bundle 29.55 kB - -
CDN Bundle (incl. Tracing) 47.81 kB - -
CDN Bundle (incl. Logs, Metrics) 31.05 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.04 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.31 kB - -
CDN Bundle (incl. Tracing, Replay) 85.18 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.35 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.05 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.21 kB - -
CDN Bundle - uncompressed 87.59 kB - -
CDN Bundle (incl. Tracing) - uncompressed 144.09 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 92.08 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 147.85 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 216.81 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 262.87 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 266.61 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 276.57 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 280.3 kB - -
@sentry/nextjs (client) 50.03 kB - -
@sentry/sveltekit (client) 45.68 kB - -
@sentry/core/server 75.93 kB - -
@sentry/core/browser 63.09 kB - -
@sentry/node-core 61.69 kB -0.42% -259 B 🔽
@sentry/node 130.46 kB +0.1% +128 B 🔺
@sentry/node - without tracing 74.13 kB -0.32% -235 B 🔽
@sentry/aws-serverless 86.33 kB -0.27% -227 B 🔽
@sentry/cloudflare (withSentry) - minified 171.5 kB - -
@sentry/cloudflare (withSentry) 429.29 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
Copy link
Copy Markdown
Member

@JPeer264 JPeer264 left a comment

Choose a reason for hiding this comment

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

LGTM.

Just on a note, this PR contains more than just TraceState changes, they also include time changes to our @sentry/core helpers (they have a different type signature, but should be alright as these functions are only internal

Edit: I just saw that these are anyways 2 separate commits, maybe they went in by accident

@mydea
Copy link
Copy Markdown
Member Author

mydea commented May 28, 2026

LGTM.

Just on a note, this PR contains more than just TraceState changes, they also include time changes to our @sentry/core helpers (they have a different type signature, but should be alright as these functions are only internal

Edit: I just saw that these are anyways 2 separate commits, maybe they went in by accident

oops, yeah that was on accident, will rebase/remote the other stuff!

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 force-pushed the fn/vendor-trace-state branch from c15ac25 to 6c4a3e5 Compare May 29, 2026 06:40
Copy link
Copy Markdown
Member

@andreiborza andreiborza left a comment

Choose a reason for hiding this comment

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

LGTM

@mydea mydea merged commit 7e2443e into develop May 29, 2026
213 of 214 checks passed
@mydea mydea deleted the fn/vendor-trace-state branch May 29, 2026 06:58
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.

3 participants