@@ -8,6 +8,10 @@ import { logAndExitProcess } from './utils/errorhandling';
8
8
9
9
type OnFatalErrorHandler = ( firstError : Error , secondError ?: Error ) => void ;
10
10
11
+ type TaggedListener = NodeJS . UncaughtExceptionListener & {
12
+ tag ?: string ;
13
+ } ;
14
+
11
15
// CAREFUL: Please think twice before updating the way _options looks because the Next.js SDK depends on it in `index.server.ts`
12
16
interface OnUncaughtExceptionOptions {
13
17
// TODO(v8): Evaluate whether we should switch the default behaviour here.
@@ -95,18 +99,21 @@ export class OnUncaughtException implements Integration {
95
99
// exit behaviour of the SDK accordingly:
96
100
// - If other listeners are attached, do not exit.
97
101
// - If the only listener attached is ours, exit.
98
- const userProvidedListenersCount = global . process
99
- . listeners ( 'uncaughtException' )
100
- . reduce < number > ( ( acc , listener ) => {
101
- if (
102
- listener . name === 'domainUncaughtExceptionClear' || // as soon as we're using domains this listener is attached by node itself
103
- listener === this . handler // filter the handler we registered ourselves)
104
- ) {
105
- return acc ;
106
- } else {
107
- return acc + 1 ;
108
- }
109
- } , 0 ) ;
102
+ const userProvidedListenersCount = (
103
+ global . process . listeners ( 'uncaughtException' ) as TaggedListener [ ]
104
+ ) . reduce < number > ( ( acc , listener ) => {
105
+ if (
106
+ // There are 3 listeners we ignore:
107
+ listener . name === 'domainUncaughtExceptionClear' || // as soon as we're using domains this listener is attached by node itself
108
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
109
+ ( listener . tag && listener . tag === 'sentry_tracingErrorCallback' ) || // the handler we register for tracing
110
+ listener === this . handler // the handler we register in this integration
111
+ ) {
112
+ return acc ;
113
+ } else {
114
+ return acc + 1 ;
115
+ }
116
+ } , 0 ) ;
110
117
111
118
const processWouldExit = userProvidedListenersCount === 0 ;
112
119
const shouldApplyFatalHandlingLogic = this . _options . exitEvenIfOtherHandlersAreRegistered || processWouldExit ;
0 commit comments