Skip to content

fix(core): Apply capture mechanism to originally captured exception - #23320

Open
s1gr1d wants to merge 4 commits into
developfrom
sig/error-metadata-ordering
Open

fix(core): Apply capture mechanism to originally captured exception#23320
s1gr1d wants to merge 4 commits into
developfrom
sig/error-metadata-ordering

Conversation

@s1gr1d

@s1gr1d s1gr1d commented Aug 12, 2026

Copy link
Copy Markdown
Member

Fix custom exception mechanisms being applied to the deepest linked cause instead of the originally captured error.

LinkedErrors prepends causes before capture hints are applied, so the mechanism could overwrite a cause's chained metadata and incorrectly mark it as unhandled. Capture mechanisms now target the captured exception (identified by exception_id === 0 for exception groups) while preserving existing behavior for ordinary events.

Previous Behavior

In this scenario:

  const cause1 = new Error('Failure 1');
  const cause2 = new Error('Failure 2', { cause: cause1 });
  const error = new Error('Failure 3', { cause: cause2 });

  Sentry.captureException(error, {
    mechanism: { handled: false, type: 'auto.http.example' },
  });

...the mechanism of would be applied not to "Failure 3" but "Failure 1":

image

References

Also came up in this comment from 2025:

Related to this PR (added tests to showcase problem):

@s1gr1d
s1gr1d requested a review from a team as a code owner August 12, 2026 08:41
@s1gr1d
s1gr1d requested review from Lms24, logaretm and msonnb and removed request for a team August 12, 2026 08:41
@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 30.34 kB +0.15% +43 B 🔺
@sentry/browser - with treeshaking flags 28.51 kB +0.15% +41 B 🔺
@sentry/browser - with treeshaking flags tracing without tracing 26.85 kB +0.16% +41 B 🔺
@sentry/browser (incl. Tracing) 48.56 kB +0.08% +35 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 48.57 kB +0.06% +27 B 🔺
@sentry/browser (incl. Tracing, Profiling) 51.45 kB +0.05% +22 B 🔺
@sentry/browser (incl. Tracing, Replay) 87.97 kB +0.06% +50 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.35 kB +0.01% +7 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 92.69 kB +0.06% +54 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 105.37 kB +0.03% +30 B 🔺
@sentry/browser (incl. Feedback) 47.66 kB +0.08% +38 B 🔺
@sentry/browser (incl. sendFeedback) 35.16 kB +0.13% +45 B 🔺
@sentry/browser (incl. FeedbackAsync) 40.31 kB +0.12% +47 B 🔺
@sentry/browser (incl. Metrics) 31.31 kB +0.09% +26 B 🔺
@sentry/browser (incl. Logs) 31.58 kB +0.13% +38 B 🔺
@sentry/browser (incl. Metrics & Logs) 32.25 kB +0.14% +43 B 🔺
@sentry/react 32.13 kB +0.15% +45 B 🔺
@sentry/react (incl. Tracing) 50.77 kB +0.1% +49 B 🔺
@sentry/vue 35.35 kB +0.14% +48 B 🔺
@sentry/vue (incl. Tracing) 50.51 kB +0.07% +34 B 🔺
@sentry/svelte 30.37 kB +0.2% +58 B 🔺
CDN Bundle 31.64 kB +0.13% +40 B 🔺
CDN Bundle (incl. Tracing) 48.89 kB +0.09% +42 B 🔺
CDN Bundle (incl. Logs, Metrics) 33.86 kB +0.14% +45 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 50.85 kB +0.09% +43 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 74.38 kB +0.04% +26 B 🔺
CDN Bundle (incl. Tracing, Replay) 86.48 kB +0.04% +34 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 88.34 kB +0.04% +33 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 92.19 kB +0.05% +42 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 94.16 kB +0.04% +34 B 🔺
CDN Bundle - uncompressed 93.94 kB +0.12% +106 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 146.76 kB +0.08% +106 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 100.34 kB +0.11% +106 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 152.56 kB +0.07% +106 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 229.28 kB +0.05% +106 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 266.02 kB +0.04% +106 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 271.81 kB +0.04% +106 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 279.72 kB +0.04% +106 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 285.49 kB +0.04% +106 B 🔺
@sentry/nextjs (client) 53.29 kB +0.03% +14 B 🔺
@sentry/sveltekit (client) 48.98 kB +0.08% +39 B 🔺
@sentry/core/server 65.44 kB +0.04% +23 B 🔺
@sentry/core/browser 51.8 kB +0.04% +18 B 🔺
@sentry/node 117.97 kB +0.03% +24 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 0 B added added
@sentry/node - without tracing 82.09 kB +0.05% +37 B 🔺
@sentry/aws-serverless 91.5 kB +0.06% +46 B 🔺
@sentry/cloudflare (withSentry) - minified 214.07 kB +0.09% +192 B 🔺
@sentry/cloudflare (withSentry) 528.89 kB +0.12% +588 B 🔺

View base workflow run

@s1gr1d
s1gr1d requested a review from a team as a code owner August 12, 2026 09:23
@s1gr1d
s1gr1d requested review from JPeer264 and mydea and removed request for a team August 12, 2026 09:23
@s1gr1d

s1gr1d commented Aug 12, 2026

Copy link
Copy Markdown
Member Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit dad2fdc. Configure here.

@Lms24 Lms24 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a really nice fix! Thanks for taking this on!

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.

3 participants