-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy patherrors.ts
35 lines (29 loc) · 1.07 KB
/
errors.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { addInstrumentationHandler, logger } from '@sentry/utils';
import type { SpanStatusType } from './span';
import { getActiveTransaction } from './utils';
let errorsInstrumented = false;
/**
* Configures global error listeners
*/
export function registerErrorInstrumentation(): void {
if (errorsInstrumented) {
return;
}
errorsInstrumented = true;
addInstrumentationHandler('error', errorCallback);
addInstrumentationHandler('unhandledrejection', errorCallback);
}
/**
* If an error or unhandled promise occurs, we mark the active transaction as failed
*/
function errorCallback(): void {
const activeTransaction = getActiveTransaction();
if (activeTransaction) {
const status: SpanStatusType = 'internal_error';
__DEBUG_BUILD__ && logger.log(`[Tracing] Transaction: ${status} -> Global error occured`);
activeTransaction.setStatus(status);
}
}
// The function name will be lost when bundling but we need to be able to identify this listener later to maintain the
// node.js default exit behaviour
errorCallback.tag = 'sentry_tracingErrorCallback';