getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.68k stars 1.49k forks source link

Sentry syntheticException should not capture it's own stack trace #11812

Open krystofwoldrich opened 3 weeks ago

krystofwoldrich commented 3 weeks ago

When object without stack trace is captured by captureException, syntheticException is created to capture where was the captureException called.

Currently the top of the stack trace is the syntheticException line and not the captureException call site.

Actual: In ErrorsScreen.tsx called captureException('string')

npm:@sentry/core/cjs/hub.js in Hub#captureException at line 272:40
npm:@sentry/core/cjs/exports.js in captureException at line 23:45
/samples/react-native/src/Screens/ErrorsScreen.tsx in Button.props.onPress at line 78:35
npm:react-native/Libraries/Pressability/Pressability.js in _performTransitionSideEffects at line 789:17
npm:react-native/Libraries/Pressability/Pressability.js in _receiveSignal at line 726:40
npm:react-native/Libraries/Pressability/Pressability.js in responderEventHandlers.onResponderRelease at line 543:27

Expected: In ErrorsScreen.tsx called captureException('string')

/samples/react-native/src/Screens/ErrorsScreen.tsx in Button.props.onPress at line 78:35
npm:react-native/Libraries/Pressability/Pressability.js in _performTransitionSideEffects at line 789:17
npm:react-native/Libraries/Pressability/Pressability.js in _receiveSignal at line 726:40
npm:react-native/Libraries/Pressability/Pressability.js in responderEventHandlers.onResponderRelease at line 543:27

Solution: port https://github.com/getsentry/sentry-react-native/blob/6227788926d3c82f6a1a50e410f63038cbd644d7/src/js/utils/error.ts#L11-L18 to JS Core

AbhiPrasad commented 3 weeks ago

@krystofwoldrich would you like to open up a PR? 😄