Skip to content

fix(browser): Fix missing traces for user feedback#19660

Open
andreiborza wants to merge 4 commits intodevelopfrom
ab/user-feedback-traces
Open

fix(browser): Fix missing traces for user feedback#19660
andreiborza wants to merge 4 commits intodevelopfrom
ab/user-feedback-traces

Conversation

@andreiborza
Copy link
Member

@andreiborza andreiborza commented Mar 5, 2026

Closes #19681 (added automatically)

@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.64 kB +0.05% +12 B 🔺
@sentry/browser - with treeshaking flags 24.14 kB +0.03% +7 B 🔺
@sentry/browser (incl. Tracing) 42.44 kB +0.02% +8 B 🔺
@sentry/browser (incl. Tracing, Profiling) 47.1 kB +0.02% +8 B 🔺
@sentry/browser (incl. Tracing, Replay) 81.26 kB +0.02% +9 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 70.88 kB +0.02% +8 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 85.95 kB +0.02% +9 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 98.21 kB +0.01% +7 B 🔺
@sentry/browser (incl. Feedback) 42.44 kB +0.02% +7 B 🔺
@sentry/browser (incl. sendFeedback) 30.31 kB +0.04% +11 B 🔺
@sentry/browser (incl. FeedbackAsync) 35.36 kB +0.04% +11 B 🔺
@sentry/browser (incl. Metrics) 26.8 kB +0.04% +9 B 🔺
@sentry/browser (incl. Logs) 26.95 kB +0.03% +8 B 🔺
@sentry/browser (incl. Metrics & Logs) 27.62 kB +0.04% +9 B 🔺
@sentry/react 27.39 kB +0.04% +9 B 🔺
@sentry/react (incl. Tracing) 44.78 kB +0.02% +8 B 🔺
@sentry/vue 30.09 kB +0.04% +10 B 🔺
@sentry/vue (incl. Tracing) 44.31 kB +0.03% +9 B 🔺
@sentry/svelte 25.66 kB +0.04% +9 B 🔺
CDN Bundle 28.18 kB +0.04% +9 B 🔺
CDN Bundle (incl. Tracing) 43.27 kB +0.03% +11 B 🔺
CDN Bundle (incl. Logs, Metrics) 29.02 kB +0.04% +9 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 44.11 kB +0.03% +10 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 68.1 kB +0.02% +8 B 🔺
CDN Bundle (incl. Tracing, Replay) 80.15 kB +0.02% +12 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 81.01 kB +0.02% +10 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 85.66 kB +0.02% +9 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 86.54 kB +0.02% +10 B 🔺
CDN Bundle - uncompressed 82.38 kB +0.04% +26 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 128.09 kB +0.03% +26 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 85.21 kB +0.04% +26 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 130.93 kB +0.02% +26 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 208.88 kB +0.02% +26 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 244.98 kB +0.02% +26 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 247.8 kB +0.02% +26 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 257.89 kB +0.02% +26 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 260.7 kB +0.01% +26 B 🔺
@sentry/nextjs (client) 47.19 kB +0.02% +9 B 🔺
@sentry/sveltekit (client) 42.9 kB +0.02% +8 B 🔺
@sentry/node-core 52.25 kB +0.03% +14 B 🔺
@sentry/node 174.73 kB +0.01% +9 B 🔺
@sentry/node - without tracing 97.4 kB +0.02% +16 B 🔺
@sentry/aws-serverless 113.2 kB +0.02% +14 B 🔺

View base workflow run

@s1gr1d s1gr1d force-pushed the ab/user-feedback-traces branch from 5e4c528 to a2cb952 Compare March 6, 2026 13:31
@s1gr1d s1gr1d force-pushed the ab/user-feedback-traces branch from 2fb3a76 to a5c830b Compare March 6, 2026 13:33
@s1gr1d s1gr1d self-assigned this Mar 6, 2026
@s1gr1d s1gr1d marked this pull request as ready for review March 6, 2026 13:33
Copy link
Member Author

@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, I can't approve since it's my pr 😅

const feedbackEvent = envelopeRequestParser((await feedbackRequestPromise).request());

expect(feedbackEvent.contexts?.trace?.trace_id).toMatch(/\w{32}/);
expect(feedbackEvent.contexts?.trace?.span_id).toMatch(/\w{16}/);
Copy link

Choose a reason for hiding this comment

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

Test uses weak unanchored regex for trace assertions

Low Severity

The assertions for trace_id and span_id use /\w{32}/ and /\w{16}/ — unanchored regexes with \w (which matches underscores and uppercase letters). This is inconsistent with the stricter /^[a-f\d]{32}$/ used on line 62 in the same test. Since these are the core assertions validating the fix (that feedback events get proper trace context), they don't thoroughly verify the newly added behavior. A string longer than 32 characters or containing non-hex characters would still pass.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

@s1gr1d s1gr1d enabled auto-merge (squash) March 6, 2026 13:39
Comment on lines 1224 to 1227
evt.contexts = {
trace: getTraceContextFromScope(currentScope),
trace: { ...evt.contexts?.trace, ...getTraceContextFromScope(currentScope) },
...evt.contexts,
};
Copy link

Choose a reason for hiding this comment

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

Bug: The trace property in evt.contexts is overwritten by the object spread that follows it, preventing the scope's trace context from being correctly merged.
Severity: CRITICAL

Suggested Fix

To ensure the merged trace context is preserved, move the trace property definition after the spread of evt.contexts. The correct implementation should be: evt.contexts = { ...evt.contexts, trace: { ...evt.contexts?.trace, ...getTraceContextFromScope(currentScope) } };

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: packages/core/src/client.ts#L1224-L1227

Potential issue: In `_prepareEvent`, the code attempts to merge trace context from the
scope into an event's contexts. However, due to the property order in the object
literal, the `trace` property is defined and then immediately overwritten by the spread
of the original `evt.contexts`. The line `...evt.contexts` comes after the new `trace`
property, causing the original `evt.contexts.trace` to replace the newly merged one.
This negates the intended merge, preventing trace information from the scope from being
added to events that already have a trace context, such as user feedback events.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link

@cursor cursor bot left a comment

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.

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


evt.contexts = {
trace: getTraceContextFromScope(currentScope),
trace: { ...evt.contexts?.trace, ...getTraceContextFromScope(currentScope) },
Copy link

Choose a reason for hiding this comment

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

Trace context merge is overwritten by spread order

Medium Severity

The computed merge { ...evt.contexts?.trace, ...getTraceContextFromScope(currentScope) } on line 1225 is immediately overwritten by ...evt.contexts on line 1226, because later properties in an object literal override earlier ones with the same key. When evt.contexts has a trace property, the spread replaces the merged trace with the original unmerged value, making this change a no-op compared to the old code. If the intent was to ensure scope trace data supplements existing trace context, trace needs to appear after ...evt.contexts in the object literal.

Fix in Cursor Fix in Web

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 9,296 - 9,030 +3%
GET With Sentry 1,698 18% 1,692 +0%
GET With Sentry (error only) 5,923 64% 5,999 -1%
POST Baseline 1,194 - 1,198 -0%
POST With Sentry 574 48% 581 -1%
POST With Sentry (error only) 1,046 88% 1,057 -1%
MYSQL Baseline 3,247 - 3,233 +0%
MYSQL With Sentry 409 13% 461 -11%
MYSQL With Sentry (error only) 2,639 81% 2,637 +0%

View base workflow run

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.

fix(browser): Fix missing traces for user feedback

2 participants