Repository navigation
Conversation
Swap the bespoke `{_traceId, _spanId}` envelope appended to cross-boundary
JSON-RPC calls for a W3C `traceparent` string, so extension-emitted client
spans (Sentry) and OTel-instrumented backend spans (o11y/Tempo) can share
trace IDs end-to-end. Both producer and consumer ship in lockstep within the
extension binary, so no receive-side backwards compatibility is required.
- `getSerializedTraceContext()` emits `00-{traceId}-{spanId}-{flags}` from the
active span context instead of a `{_traceId, _spanId}` object.
- `extractTraceContext()` validates and unpacks the `traceparent` last-param
via `@sentry/utils` `extractTraceparentData`, after a mechanical W3C ->
sentry-trace normalization (extractTraceparentData parses the sentry-trace
shape, not W3C directly).
- `continueTraceContext()` and the cross-process `startSpan` branch consume the
parsed `TraceparentData`.
- `SerializedTraceContext` drops `_traceId`/`_spanId`; keeps `_name`/`_id` for
same-process map lookup, plus a `traceparent` field.
The propagation wrappers are unchanged except for a one-token field read in
`createMetaRPCHandler` (`traceContext._traceId` -> `.traceId`), since the
extracted context is now Sentry's canonical `TraceparentData`.
Closes MetaMask/MetaMask-planning#7234
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
Builds ready [5418fdf]
⚡ Performance Benchmarks (Total: 🟢 19 pass · 🟡 5 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
|
@metamaskbot update-policies |
The W3C `traceparent` envelope migration pulls in `@sentry/utils`, which requests the `process` builtin. Regenerating all four browserify build-type policies (`main`, `beta`, `flask`, `experimental`) adds the missing allowlist entry, fixing the `Validate LavaMoat webapp policy` check and the cascading browserify e2e `SES_UNCAUGHT_EXCEPTION` failures.
✨ Files requiring CODEOWNER review ✨🫰 @MetaMask/core-platform (1 files, +10 -5)
👨🔧 @MetaMask/extension-platform (2 files, +38 -44)
|
Builds ready [cf9a264]
⚡ Performance Benchmarks (Total: 🟢 19 pass · 🟡 6 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
There was a problem hiding this comment.
Pull request overview
Migrates cross-boundary distributed tracing propagation (UI ↔ background JSON-RPC seam) from a bespoke { _traceId, _spanId } envelope to a W3C traceparent string, enabling end-to-end trace ID continuity between extension-emitted Sentry spans and OTel-instrumented backend spans.
Changes:
- Emit W3C
traceparentfrom the active span and parse/continue traces from a validatedtraceparentstring viaextractTraceparentData. - Update background RPC handler to sample/continue using parsed
TraceparentData(traceContext.traceId). - Expand unit test coverage for valid/invalid trace context envelopes and update LavaMoat policies to allow
@sentry/utils.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| shared/lib/trace.ts | Switches propagation helpers to emit/parse W3C traceparent and continue traces using TraceparentData. |
| shared/lib/trace.test.ts | Adds/updates tests for W3C traceparent serialization, extraction, and trace continuation behavior. |
| app/scripts/lib/createMetaRPCHandler.ts | Updates wrapper sampling to use traceContext.traceId from the parsed context. |
| app/scripts/lib/createMetaRPCHandler.test.ts | Updates RPC handler tests to pass/expect W3C traceparent and parsed TraceparentData. |
| lavamoat/browserify/main/policy.json | Allows required globals/packages for @sentry/utils under LavaMoat. |
| lavamoat/browserify/flask/policy.json | Allows required globals/packages for @sentry/utils under LavaMoat. |
| lavamoat/browserify/experimental/policy.json | Allows required globals/packages for @sentry/utils under LavaMoat. |
| lavamoat/browserify/beta/policy.json | Allows required globals/packages for @sentry/utils under LavaMoat. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The W3C `traceparent` second field is the `parent-id` (parent span id), not the current span id — align the local variable with the field semantics and JSDoc.
Builds ready [b3ca722]
⚡ Performance Benchmarks (Total: 🟢 19 pass · 🟡 6 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
…ry/w3c-traceparent-envelope
…ry/w3c-traceparent-envelope
Builds ready [9e33ed8]
⚡ Performance Benchmarks (Total: 🟢 6 pass · 🟡 3 warn · 🔴 4 fail)
Bundle Size Diffs [🚨 Warning! Bundle size has increased!]
|
…ry/w3c-traceparent-envelope
Builds ready [a6f50a6]
⚡ Performance Benchmarks (Total: 🟢 9 pass · 🟡 1 warn · 🔴 3 fail)
Bundle Size Diffs [🚨 Warning! Bundle size has increased!]
|
…ry/w3c-traceparent-envelope
Builds ready [5ff7c73] [reused from a6f50a6]
⚡ Performance Benchmarks (Total: 🟢 9 pass · 🟡 1 warn · 🔴 3 fail)
Bundle Size Diffs [🚨 Warning! Bundle size has increased!]
|
| const paramsWithTrace = | ||
| globalThis.sentry?.startSpan && | ||
| !process.env.SENTRY_DISTRIBUTED_TRACING_DISABLED && | ||
| (traceparent || messengerAction) |
There was a problem hiding this comment.
Messenger calls attach _trace even with no traceparent, so without these checks a build with Sentry tracing off would still send trace metadata to the background.
| // No local parent: continue from parsed `TraceparentData`, or from the | ||
| // `traceparent` a snap's `SerializedTraceContext` keeps after its parent ended. | ||
| if (!parentSpan) { |
There was a problem hiding this comment.
Removing the hasInProcessIdentity skip from b8cfbbf (Stop billing spans that declared a parent as segments) is safe: serializeTraceContext is the only producer of a context carrying both _name and trace ids, and on base the snap context carried no _name, so it always continued the trace. Snap contexts now nest under their parent while its trace is pending, and continue from traceparent only after it ends.
…ry/w3c-traceparent-envelope
Builds ready [3a2a47c]
⚡ Performance Benchmarks (Total: 🟢 8 pass · 🟡 2 warn · 🔴 3 fail)
Bundle Size Diffs [🚨 Warning! Bundle size has increased!]
|
…ry/w3c-traceparent-envelope
Builds ready [2ed184b]
⚡ Performance Benchmarks (Total: 🟢 9 pass · 🟡 2 warn · 🔴 2 fail)
Bundle Size Diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [7014304]
⚡ Performance Benchmarks (Total: 🟢 7 pass · 🟡 3 warn · 🔴 3 fail)
Bundle Size Diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [9d85fc2] [reused from 7014304]
⚡ Performance Benchmarks (Total: 🟢 7 pass · 🟡 3 warn · 🔴 3 fail)
Bundle Size Diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [7014304]
⚡ Performance Benchmarks (Total: 🟢 7 pass · 🟡 3 warn · 🔴 3 fail)
Bundle Size Diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [2455276] [reused from 7014304]
⚡ Performance Benchmarks (Total: 🟢 7 pass · 🟡 3 warn · 🔴 3 fail)
Bundle Size Diffs [🚨 Warning! Bundle size has increased!]
|
|
| // and the `TraceparentData` it unpacks to once extracted. | ||
| const TRACE_ID_MOCK = '4bf92f3577b34da6a3ce929d0e0e4736'; | ||
| const SPAN_ID_MOCK = '00f067aa0ba902b7'; | ||
| const TRACEPARENT_MOCK = `00-${TRACE_ID_MOCK}-${SPAN_ID_MOCK}-01`; |
There was a problem hiding this comment.
open suggestion: we could call this SAMPLED_TRACEPARENT_MOCK, and add:
const UNSAMPLED_TRACEPARENT_MOCK = `00-${TRACE_ID_MOCK}-${SPAN_ID_MOCK}-00`;



+157 −73 lines (excluding tests, comments, whitespace)
Description
Continued UI traces sent backends a sampled
traceparentwithout thesentry-sampledbaggage they route on, and the background treated unsampled UI spans as sampled.Breaking changes
sentry-sampledsend their spans for sampled UI traces to Sentry (not measured, because backend ingestion is outside the captures).SerializedTraceContextreplaces_traceId/_spanIdwithtraceparent.snap_startTracereturns{ _name, _id?, traceparent }. Preinstalled snaps passnameonly, and none of their bundles reads the removed fields.Changes
traceparentcarrying the UI's sampled flag.sentry-sampledbaggage in continued traces, mirroring that flag.traceparentin snap trace contexts.Changelog
CHANGELOG entry: null
Related issues
Closes MWPE-437 (Migrate cross-boundary trace envelope to W3C
traceparent)Parent epic: MWPE-222 (L3 Maturity: Sentry Attribution)
Stack: #45527 (misparented spans) → #43931 (
/service-worker.jsmega-trace) → #43199 (backend spans in continued UI traces). Merge all three together: each builds on the one below, and the evidence covers only the merged stack.Manual testing steps
SENTRY_DSN_DEV,tracesSampleRate: 1.0and MetaMetrics enabled.submitRequestToBackgroundcall inside atrace()callback, like a Swaps quote fetch: the last RPC param is{ _trace: { traceparent: "00-<32hex>-<16hex>-01", spanName } }.Screenshots/Recordings
Before
Stack base
1fbe8e3d90f, shown in each exhibit under After.After
Stack top
a6f50a65bff, live ingest totest-metamask(figures).A
/home.htmltransaction and its continuedBackground RPC:spans share one trace (trace):At
tracesSampleRate0, background transactions go from 76 to 0, and every top-run backend request sendssentry-sampled=false(base log, top log).At rate 1, all 14 requests continuing a
/home.htmlspan sendsentry-sampled=true. Base's one such request carried nosentry-sampled(top log, base log).Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Changes cross-boundary tracing contracts and sampling behavior (large Sentry volume impact per PR notes); observability-critical but well-tested with integration tests.
Overview
Migrates UI → background distributed tracing from
_traceId/_spanIdenvelopes to W3Ctraceparent, and threads the parent’s sampled flag through parsing, RPC handling, and Sentry continuation.Propagation:
getSerializedTraceContext()returns atraceparentstring;submitRequestToBackgroundsends{ _trace: { traceparent?, messengerAction?, spanName } }(metadata withouttraceparentwhen no active UI span). SnapstartTracenow usesserializeTraceContext()(_name,_id?,traceparent).Background RPC:
createMetaRPCHandlerkeys off parsedtraceContext.parentSampledinstead ofshouldSampleWrappers: sampled parents get anrpc.handlerchild span (so downstreamhttp.clientspans nest correctly); unsampled parents usecontinueTraceContextwith no wrapper span.Sentry:
continueTracenow includessentry-sampledbaggage derived from the parent’s sampling decision;trace()can resume from serializedtraceparentwhen in-process map lookup misses.Tests are updated for the new shape, plus integration coverage for outbound baggage and real
http.clientinstrumentation.Reviewed by Cursor Bugbot for commit 2455276. Bugbot is set up for automated code reviews on this repo. Configure here.