Skip to content

fix(core): Don't let a throwing beforeSendSpan callback escape into user code - #22836

Draft
Lms24 wants to merge 1 commit into
feat/span-streaming-tree-shakingfrom
fix/before-send-span-throw
Draft

fix(core): Don't let a throwing beforeSendSpan callback escape into user code#22836
Lms24 wants to merge 1 commit into
feat/span-streaming-tree-shakingfrom
fix/before-send-span-throw

Conversation

@Lms24

@Lms24 Lms24 commented Jul 29, 2026

Copy link
Copy Markdown
Member

Wraps the beforeSendSpan callback application in captureSpan in a try/catch, logging the error and sending the span unmodified instead of letting the throw escape.

Spans are captured synchronously from the afterSpanEnd hook, so a throwing callback propagates straight out of whatever user code called span.end(). That turns a faulty Sentry option into an exception in unrelated application code — a failure mode the SDK should never introduce.

This is particularly relevant now that beforeSendSpan receives StreamedSpanJSON by default: a v10 callback that wasn't migrated and reaches into span.data throws on the first ended span, which would otherwise break the instrumented app rather than just degrading span processing. Falling back to the unmodified span keeps data flowing and surfaces the problem through a debug-build error log.

@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 30.07 kB +0.86% +256 B 🔺
@sentry/browser - with treeshaking flags 28.2 kB +0.65% +180 B 🔺
@sentry/browser (incl. Tracing) 47.32 kB +0.47% +221 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 47.34 kB +0.51% +236 B 🔺
@sentry/browser (incl. Tracing, Profiling) 52.03 kB +0.44% +225 B 🔺
@sentry/browser (incl. Tracing, Replay) 86.63 kB +0.28% +234 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 76.03 kB +0.26% +192 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 91.34 kB +0.24% +214 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 104 kB +0.23% +238 B 🔺
@sentry/browser (incl. Feedback) 47.41 kB +0.59% +276 B 🔺
@sentry/browser (incl. sendFeedback) 34.91 kB +0.72% +247 B 🔺
@sentry/browser (incl. FeedbackAsync) 40.02 kB +0.65% +258 B 🔺
@sentry/browser (incl. Metrics) 31.14 kB +0.79% +241 B 🔺
@sentry/browser (incl. Logs) 31.37 kB +0.8% +247 B 🔺
@sentry/browser (incl. Metrics & Logs) 32.03 kB +0.76% +240 B 🔺
@sentry/react 31.85 kB +0.81% +253 B 🔺
@sentry/react (incl. Tracing) 49.56 kB +0.48% +233 B 🔺
@sentry/vue 34.98 kB +0.7% +240 B 🔺
@sentry/vue (incl. Tracing) 49.28 kB +0.47% +229 B 🔺
@sentry/svelte 30.1 kB +0.85% +251 B 🔺
CDN Bundle 32.05 kB +0.57% +179 B 🔺
CDN Bundle (incl. Tracing) 47.58 kB +0.28% +130 B 🔺
CDN Bundle (incl. Logs, Metrics) 33.61 kB +0.58% +192 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 48.97 kB +0.29% +139 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 72.94 kB +0.22% +160 B 🔺
CDN Bundle (incl. Tracing, Replay) 85.21 kB +0.15% +121 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.54 kB +0.18% +150 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 91 kB +0.16% +144 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.31 kB +0.15% +136 B 🔺
CDN Bundle - uncompressed 95.52 kB +0.51% +481 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 142.74 kB +0.34% +481 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 100.23 kB +0.49% +481 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 146.72 kB +0.33% +481 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 224.99 kB +0.22% +481 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 261.99 kB +0.19% +481 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 265.96 kB +0.19% +481 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 275.7 kB +0.18% +481 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 279.65 kB +0.18% +481 B 🔺
@sentry/nextjs (client) 52.15 kB +0.44% +224 B 🔺
@sentry/sveltekit (client) 47.74 kB +0.49% +229 B 🔺
@sentry/core/server 79.81 kB +0.26% +206 B 🔺
@sentry/core/browser 51.83 kB +0.46% +234 B 🔺
@sentry/node 121.52 kB +0.19% +225 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 166 B - -
@sentry/node - without tracing 84.15 kB -0.74% -620 B 🔽
@sentry/aws-serverless 93.24 kB +0.24% +219 B 🔺
@sentry/cloudflare (withSentry) - minified 198.35 kB +0.39% +757 B 🔺
@sentry/cloudflare (withSentry) 487.41 kB +0.34% +1.63 kB 🔺

View base workflow run

… user code

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Lms24
Lms24 force-pushed the fix/before-send-span-throw branch from 2b3d3e2 to 192e001 Compare July 29, 2026 15:37
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