Skip to content

fix(core): Record client outcomes when beforeSend callbacks return invalid values - #25049

Draft
Lms24 wants to merge 2 commits into
lms/fix-core-span-outcomesfrom
lms/fix-core-before-send-reject-outcomes
Draft

Lms24 wants to merge 2 commits into
lms/fix-core-span-outcomesfrom
lms/fix-core-before-send-reject-outcomes

Conversation

@Lms24

@Lms24 Lms24 commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

When beforeSend or beforeSendTransaction returns something other than an event or null (often undefined from a forgotten return), the event is dropped but no client outcome is recorded. It now records before_send outcomes for the event's category and, for transactions, the root span plus all child spans that weren't already recorded as ignored. I picked before_send over invalid because the event itself is valid and the user's callback is what dropped it. In the spec, invalid is for telemetry items that fail validation themselves.

The validation now lives in the existing drop branch, so _validateBeforeSendResult goes away. Its rejection branch was dead code because safeCallback (from #25006) already turns a rejected callback into a callback_error drop. New tests cover that for beforeSendTransaction with ignored child spans.

🤖 Generated with Claude Code

@Lms24
Lms24 added this pull request to stack #25050 October 5, 2026 11:40
@Lms24 Lms24 changed the title fix(core): Record client outcomes when beforeSend callbacks return invalid values fix(core): Record client outcomes when beforeSend callbacks reject or return invalid values Oct 5, 2026
@Lms24 Lms24 changed the title fix(core): Record client outcomes when beforeSend callbacks reject or return invalid values fix(core): Record client outcomes when beforeSend callbacks return invalid values Oct 5, 2026
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 29.44 kB -0.03% -6 B 🔽
@sentry/browser - with treeshaking flags 27.57 kB -0.05% -13 B 🔽
@sentry/browser - with treeshaking flags tracing without tracing 27.47 kB -0.02% -5 B 🔽
@sentry/browser (incl. Tracing) 51.33 kB +0.02% +10 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 51.34 kB +0.02% +9 B 🔺
@sentry/browser (incl. Tracing, Profiling) 54.32 kB +0.02% +6 B 🔺
@sentry/browser (incl. Tracing, Replay) 90.95 kB +0.01% +6 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 79.92 kB -0.02% -10 B 🔽
@sentry/browser (incl. Tracing, Replay with Canvas) 95.66 kB +0.01% +6 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 108.64 kB -0.01% -2 B 🔽
@sentry/browser (incl. Feedback) 46.94 kB -0.03% -14 B 🔽
@sentry/browser (incl. sendFeedback) 34.49 kB -0.03% -8 B 🔽
@sentry/browser (incl. FeedbackAsync) 39.6 kB -0.02% -6 B 🔽
@sentry/browser (incl. Metrics) 30.44 kB -0.03% -9 B 🔽
@sentry/browser (incl. Logs) 30.73 kB -0.04% -10 B 🔽
@sentry/browser (incl. Metrics & Logs) 31.38 kB -0.05% -13 B 🔽
@sentry/react 31.27 kB -0.04% -12 B 🔽
@sentry/react (incl. Tracing) 53.7 kB +0.02% +7 B 🔺
@sentry/vue 37.4 kB -0.03% -8 B 🔽
@sentry/vue (incl. Tracing) 54.23 kB -0.01% -2 B 🔽
@sentry/svelte 29.46 kB -0.04% -9 B 🔽
@sentry/remix (Remix 3 client bundle) 55.66 kB +0.01% +4 B 🔺
CDN Bundle 31.12 kB -0.02% -6 B 🔽
CDN Bundle (incl. Tracing) 51.88 kB +0.03% +14 B 🔺
CDN Bundle (incl. Logs, Metrics) 33.35 kB -0.06% -18 B 🔽
CDN Bundle (incl. Tracing, Logs, Metrics) 53.82 kB +0.02% +10 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 74.11 kB +0.02% +9 B 🔺
CDN Bundle (incl. Tracing, Replay) 89.45 kB +0.01% +7 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 91.41 kB -0.01% -5 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) 95.63 kB +0.01% +2 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 97.59 kB -0.01% -2 B 🔽
CDN Bundle - uncompressed 91.81 kB -0.16% -139 B 🔽
CDN Bundle (incl. Tracing) - uncompressed 154.15 kB -0.07% -104 B 🔽
CDN Bundle (incl. Logs, Metrics) - uncompressed 98.39 kB -0.15% -139 B 🔽
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 160.11 kB -0.07% -104 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 228.01 kB -0.07% -139 B 🔽
CDN Bundle (incl. Tracing, Replay) - uncompressed 273.96 kB -0.04% -104 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 279.9 kB -0.04% -104 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 287.66 kB -0.04% -104 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 293.59 kB -0.04% -104 B 🔽
@sentry/nextjs (client) 56.18 kB - -
@sentry/sveltekit (client) 51.73 kB -0.02% -8 B 🔽
@sentry/core/server 40.5 kB +0.02% +6 B 🔺
@sentry/core/browser 13.52 kB +0.08% +10 B 🔺
@sentry/node 144.63 kB +0.01% +4 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 83.22 kB - -
@sentry/node - without tracing 93.22 kB +0.03% +21 B 🔺
@sentry/node - without channel injection 122.85 kB +0.01% +9 B 🔺
@sentry/aws-serverless 101.45 kB - -
@sentry/cloudflare (withSentry) - minified 208.33 kB -0.07% -134 B 🔽
@sentry/cloudflare (withSentry) 516.5 kB -0.05% -255 B 🔽

View base workflow run

/**
* Verifies that return value of configured `beforeSend` or `beforeSendTransaction` is of expected type, and returns the value if so.
*/
function _validateBeforeSendResult(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this function can conveniently be removed because the invalidValueError is now directly thrown in line 1569 and the ${beforeSendLabel} rejected with ${e} wasn't reached already because of safeCallback handling throws now. So this was mostly just dead code that could be simplified.

Lms24 and others added 2 commits October 5, 2026 19:51
…valid values

When `beforeSend` or `beforeSendTransaction` returned something other than
an event or `null` (e.g. `undefined` from a forgotten `return`), the event
was dropped without recording any outcome. It now records `before_send`
outcomes for the event category and, for transactions, the root span plus
all child spans that were not already recorded as `ignored`.

Validation moves into the existing drop branch, which removes
`_validateBeforeSendResult`. Its rejection branch was dead code because
`safeCallback` already turns a rejected callback into a `callback_error`
drop; a test now covers that for `beforeSendTransaction` as well.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Lms24
Lms24 force-pushed the lms/fix-core-before-send-reject-outcomes branch from 535f0b3 to 8064da8 Compare October 5, 2026 17:51

This branch has not been deployed

No deployments
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