Repository navigation
chore: Ensure Sentry traces for messenger action calls include action in name - #47517
Conversation
|
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. |
✨ Files requiring CODEOWNER review ✨👨🔧 @MetaMask/extension-platform (1 files, +20 -13)
|
Builds ready [3220ae7]
⚡ Performance Benchmarks (Total: 🟢 9 pass · 🟡 1 warn · 🔴 3 fail)
Bundle Size Diffs
|
When `submitRequestToBackground` is passed a root messenger action type string, it correct includes a trace context in the request so that the handler on the background side can use it to create a Sentry span. However, the name assigned to the span does not reflect the action type string but rather `messengerCall` (which is the name of the RPC method in the background API that all messenger calls are routed through). This commit fixes this issue, and adds an e2e test to ensure it isn't introduced again.
3220ae7 to
8923a41
Compare
Builds ready [8923a41]
⚡ Performance Benchmarks (Total: 🟢 7 pass · 🟡 2 warn · 🔴 4 fail)
Bundle Size Diffs
|
| const { cleanParams, traceContext } = extractTraceContext(data.params); | ||
| let messengerAction; | ||
| let spanName: `Background RPC: ${string}`; | ||
|
|
||
| if (data.method === 'messengerCall') { | ||
| messengerAction = | ||
| Array.isArray(cleanParams) && typeof cleanParams[0] === 'string' | ||
| ? cleanParams[0] | ||
| : undefined; | ||
|
|
||
| if (messengerAction) { | ||
| spanName = `Background RPC: ${messengerAction}`; | ||
| } else { | ||
| outStream.write({ | ||
| jsonrpc: '2.0', | ||
| error: rpcErrors.invalidRequest({ | ||
| message: 'messengerCall must be given an action type string', | ||
| }), | ||
| id: data.id, | ||
| }); | ||
| return; | ||
| } | ||
| } else if (controller) { | ||
| spanName = `Background RPC: ${controller}.${data.method}`; | ||
| } else { | ||
| spanName = `Background RPC: ${data.method}`; | ||
| } |
There was a problem hiding this comment.
is there a solution that doesn't leak the messenger call abstraction into this unrelated module? 🤔
There was a problem hiding this comment.
I guess we were already allowing lots of leakage here, which I fought against originally as well :-).
There was a problem hiding this comment.
Yeah, good point. I was just expanding on the code that was already here around assigning names to traces. But considering that the trace context always come from the submitRequestToBackground call, maybe we could move a lot of this logic there instead. I'll take a closer look at it.
There was a problem hiding this comment.
@davidmurdoch Okay, I've extracted the messengerCall-specific logic to submitRequestToBackground: https://github.com/MetaMask/metamask-extension/pull/47517/changes/8923a414d0e0af71d41a385fefdc80966082cdab..eea9a69f420a0dca5a93ac0f749e0e710190230d. How does that look?
…g as trace metadata
Builds ready [eea9a69]
⚡ Performance Benchmarks (Total: 🟢 6 pass · 🟡 3 warn · 🔴 4 fail)
Bundle Size Diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [f3fdda9]
⚡ Performance Benchmarks (Total: 🟢 5 pass · 🟡 5 warn · 🔴 3 fail)
Bundle Size Diffs
|
Builds ready [c7890ec]
⚡ Performance Benchmarks (Total: 🟢 10 pass · 🟡 1 warn · 🔴 2 fail)
Bundle Size Diffs
|
Builds ready [d7f62d5]
⚡ Performance Benchmarks (Total: 🟢 10 pass · 🟡 0 warn · 🔴 3 fail)
Bundle Size Diffs
|
|
|
Since distributed tracing with backend spans is in the works, one requested change for OTel propagation: Let's replace export type SerializedTraceMetadata = {
/**
- * The originating UI span's serialized context.
+ * W3C `traceparent` of the originating UI span.
*/
- context: SerializedTraceContext;
+ traceparent: string;Why
|
|
@MajorLift Okay. Is it possible to make the change you requested in a future PR? I have a PR #47254 which this PR is blocking. |



Description
When
submitRequestToBackgroundis passed a root messenger action type string, it correct includes a trace context in the request so that the handler on the background side can use it to create a Sentry span. However, the name assigned to the span does not reflect the action type string but rathermessengerCall(which is the name of the RPC method in the background API that all messenger calls are routed through).This commit fixes this issue, and adds an end-to-end test to ensure it isn't introduced again.
Changelog
CHANGELOG entry: null
Related issues
See #47254 (comment).
Manual testing steps
It's a bit difficult to test this manually, but you can try this:
SENTRY_DSN_DEVis set in.metamaskrc. (You can find a value forSENTRY_DSN_DEVfrom.metamaskrc.dist.)shared/lib/wrapper-sampling.tsand changeshouldSampleWrapperslike this:export function shouldSampleWrappers(traceId: string | undefined): boolean { if (!traceId || traceId.length < 8) { return false; } - const rate = getRemoteWrapperSampleRate() ?? WRAPPER_SAMPLE_RATE; - const hashBucket = parseInt(traceId.slice(0, 8), 16) % 10000; - return hashBucket < rate * 10000; + return true; }yarn start --sentry.transactionwhich starts with "Background RPC:"Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Low Risk
Observability-only RPC metadata and span naming; no auth or user-data paths, with backward-safe handling when
_traceis missing or invalid.Overview
Replaces the trailing
_traceContextRPC payload with a structured_traceobject (serialized UI context,spanName, and optionalmessengerAction) and renames extraction toextractTraceMetadata, with stricter validation so legitimate params are not stripped.On the UI,
submitRequestToBackgroundalways attaches this metadata and sets span names likeBackground RPC: AppStateController:getStateinstead of genericmessengerCall. The backgroundcreateMetaRPCHandlerconsumes that metadata for Sentryrpc.handlerspans (includingactionin span data) and no longer infers names from the RPC method or arguments.Tests cover metadata extraction, handler behavior, UI wiring, and a new e2e check that Sentry envelopes include messenger-action-named background RPC spans.
.metamaskrc.distdocuments the kill switch appending_trace.Reviewed by Cursor Bugbot for commit d7f62d5. Bugbot is set up for automated code reviews on this repo. Configure here.