Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Rethrow caught promise rejections in startSpan, startSpanManual, trace #9958

Merged
merged 11 commits into from Dec 22, 2023

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Dec 21, 2023

This severely messed with my brain today..

Seems like our previous implementation of startSpan et.al. assumed that because we were "cloning" the original promise, unhandled promise rejections would still bubble up to the global onunhandledrejection handler so that Sentry would catch the error.

However, we tried investigating this and found out that our "cloning" mechanism didn't work correctly and because we already added a rejection handler, the promise rejection would not always make it to the global handler.

After adding multiple integration tests, I further narrowed the buggy behaviour down to a rather special case:

async function run() {
  // `await` missing on purpose
  Sentry.startSpan({ name: 'parent_span', op: 'test' }, async () => {
    throw new Error('test error');
  });
 }

 const button = document.getElementById('button1');
 button.addEventListener('click', async () => {
    await run();
});

As we can see in the example, the startSpan call is not awaited which for some reason will lead to the SDK not catching the error. Unless, we apply the fix in this PR.

This PR removes this cloning mechanism in favour of directly attaching a rejection handler to the promise. In this handler, we rethrow the error which should trigger the global handlers.

Copy link
Contributor

github-actions bot commented Dec 21, 2023

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) - Webpack (gzipped) 75.89 KB (0%)
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 67.25 KB (0%)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 60.87 KB (0%)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 31.83 KB (0%)
@sentry/browser (incl. Feedback) - Webpack (gzipped) 30.39 KB (0%)
@sentry/browser - Webpack (gzipped) 22.09 KB (0%)
@sentry/browser (incl. Tracing, Replay, Feedback) - ES6 CDN Bundle (gzipped) 73.3 KB (-0.02% 🔽)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 64.97 KB (-0.02% 🔽)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 31.12 KB (-0.03% 🔽)
@sentry/browser - ES6 CDN Bundle (gzipped) 23.12 KB (-0.05% 🔽)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 203.77 KB (-0.01% 🔽)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 93.66 KB (-0.02% 🔽)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 68.58 KB (-0.03% 🔽)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 34.07 KB (-0.04% 🔽)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 67.66 KB (0%)
@sentry/react - Webpack (gzipped) 22.12 KB (0%)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 84.31 KB (0%)
@sentry/nextjs Client - Webpack (gzipped) 48.95 KB (0%)
@sentry-internal/feedback - Webpack (gzipped) 16.6 KB (0%)

@Lms24 Lms24 marked this pull request as ready for review December 21, 2023 20:33
Copy link
Member

@mydea mydea left a comment

Choose a reason for hiding this comment

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

Very good find & fix! I think this should be good.

@Lms24 Lms24 merged commit cf412d9 into develop Dec 22, 2023
97 checks passed
@Lms24 Lms24 deleted the lms/fix-startspan-throws branch December 22, 2023 10:23
mydea added a commit that referenced this pull request Dec 22, 2023
… callbacks (#9974)

Oops, I noticed that our current `withScope` implementation does not
actually wait for async callbacks for setting the current scope 😬
Related to #9958,
which I copied there now!
anonrig pushed a commit that referenced this pull request Jan 3, 2024
… callbacks (#9974)

Oops, I noticed that our current `withScope` implementation does not
actually wait for async callbacks for setting the current scope 😬
Related to #9958,
which I copied there now!
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.

None yet

3 participants