Skip to content

Commit 029ed99

Browse files
committed
ref: Set internal error on transaction
1 parent 08738b0 commit 029ed99

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

packages/apm/src/integrations/tracing.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,27 @@ export class Tracing implements Integration {
211211
});
212212
}
213213

214+
/**
215+
* If an error or unhandled promise occurs, we mark the active transaction as failed
216+
*/
217+
// tslint:disable-next-line: completed-docs
218+
function errorCallback(): void {
219+
if (Tracing._activeTransaction) {
220+
logger.log(`[Tracing] Global error occured, setting status in transaction: ${SpanStatus.InternalError}`);
221+
(Tracing._activeTransaction as SpanClass).setStatus(SpanStatus.InternalError);
222+
}
223+
}
224+
225+
addInstrumentationHandler({
226+
callback: errorCallback,
227+
type: 'error',
228+
});
229+
230+
addInstrumentationHandler({
231+
callback: errorCallback,
232+
type: 'unhandledrejection',
233+
});
234+
214235
if (Tracing.options.discardBackgroundSpans && global.document) {
215236
document.addEventListener('visibilitychange', () => {
216237
if (document.hidden && Tracing._activeTransaction) {

0 commit comments

Comments
 (0)