forked from getsentry/sentry-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.ts
23 lines (21 loc) · 795 Bytes
/
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
import type { SpanStatusType } from '@sentry/core';
import { getActiveTransaction } from '@sentry/core';
import { addInstrumentationHandler, logger } from '@sentry/utils';
/**
* Configures global error listeners
*/
export function registerErrorInstrumentation(): void {
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);
}
}