Skip to content

Commit baef982

Browse files
authored
fix(core): Remove side-effect from tracing/errors.ts (#16888)
- Ref #16846
1 parent 9ec2bff commit baef982

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

packages/core/src/tracing/errors.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@ export function registerSpanErrorInstrumentation(): void {
2020
return;
2121
}
2222

23+
/**
24+
* If an error or unhandled promise occurs, we mark the active root span as failed
25+
*/
26+
function errorCallback(): void {
27+
const activeSpan = getActiveSpan();
28+
const rootSpan = activeSpan && getRootSpan(activeSpan);
29+
if (rootSpan) {
30+
const message = 'internal_error';
31+
DEBUG_BUILD && debug.log(`[Tracing] Root span: ${message} -> Global error occurred`);
32+
rootSpan.setStatus({ code: SPAN_STATUS_ERROR, message });
33+
}
34+
}
35+
36+
// The function name will be lost when bundling but we need to be able to identify this listener later to maintain the
37+
// node.js default exit behaviour
38+
errorCallback.tag = 'sentry_tracingErrorCallback';
39+
2340
errorsInstrumented = true;
2441
addGlobalErrorInstrumentationHandler(errorCallback);
2542
addGlobalUnhandledRejectionInstrumentationHandler(errorCallback);
2643
}
27-
28-
/**
29-
* If an error or unhandled promise occurs, we mark the active root span as failed
30-
*/
31-
function errorCallback(): void {
32-
const activeSpan = getActiveSpan();
33-
const rootSpan = activeSpan && getRootSpan(activeSpan);
34-
if (rootSpan) {
35-
const message = 'internal_error';
36-
DEBUG_BUILD && debug.log(`[Tracing] Root span: ${message} -> Global error occurred`);
37-
rootSpan.setStatus({ code: SPAN_STATUS_ERROR, message });
38-
}
39-
}
40-
41-
// The function name will be lost when bundling but we need to be able to identify this listener later to maintain the
42-
// node.js default exit behaviour
43-
errorCallback.tag = 'sentry_tracingErrorCallback';

0 commit comments

Comments
 (0)