From 68af4f96f0d226497aec31f61a2f7a0ca298c89a Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Thu, 10 Jul 2025 13:27:37 +0200 Subject: [PATCH 1/3] fix: Remove side-effect from `tracing/errors.ts` --- packages/core/src/tracing/errors.ts | 32 +++++++++++++++-------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/packages/core/src/tracing/errors.ts b/packages/core/src/tracing/errors.ts index 28f582f32309..5dea629d2b79 100644 --- a/packages/core/src/tracing/errors.ts +++ b/packages/core/src/tracing/errors.ts @@ -20,24 +20,26 @@ export function registerSpanErrorInstrumentation(): void { return; } + /** + * If an error or unhandled promise occurs, we mark the active root span as failed + */ + function errorCallback(): void { + const activeSpan = getActiveSpan(); + const rootSpan = activeSpan && getRootSpan(activeSpan); + if (rootSpan) { + const message = 'internal_error'; + DEBUG_BUILD && logger.log(`[Tracing] Root span: ${message} -> Global error occurred`); + rootSpan.setStatus({ code: SPAN_STATUS_ERROR, message }); + } + } + + // 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'; + errorsInstrumented = true; addGlobalErrorInstrumentationHandler(errorCallback); addGlobalUnhandledRejectionInstrumentationHandler(errorCallback); } -/** - * If an error or unhandled promise occurs, we mark the active root span as failed - */ -function errorCallback(): void { - const activeSpan = getActiveSpan(); - const rootSpan = activeSpan && getRootSpan(activeSpan); - if (rootSpan) { - const message = 'internal_error'; - DEBUG_BUILD && logger.log(`[Tracing] Root span: ${message} -> Global error occurred`); - rootSpan.setStatus({ code: SPAN_STATUS_ERROR, message }); - } -} -// 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'; From 9184779192efd884509b30c394aebb0c74175fbc Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Thu, 10 Jul 2025 13:32:04 +0200 Subject: [PATCH 2/3] Lint --- .../linked-traces/consistent-sampling/meta-precedence/test.ts | 3 --- packages/core/src/tracing/errors.ts | 2 -- 2 files changed, 5 deletions(-) diff --git a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/linked-traces/consistent-sampling/meta-precedence/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/linked-traces/consistent-sampling/meta-precedence/test.ts index f48aebbca9e3..1b55f5235088 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/linked-traces/consistent-sampling/meta-precedence/test.ts +++ b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/linked-traces/consistent-sampling/meta-precedence/test.ts @@ -25,9 +25,6 @@ sentryTest.describe('When `consistentTraceSampling` is `true` and page contains sentryTest.skip(); } - - - const url = await getLocalTestUrl({ testDir: __dirname }); const clientReportPromise = waitForClientReportRequest(page); diff --git a/packages/core/src/tracing/errors.ts b/packages/core/src/tracing/errors.ts index 5dea629d2b79..d6b43adb7ddf 100644 --- a/packages/core/src/tracing/errors.ts +++ b/packages/core/src/tracing/errors.ts @@ -41,5 +41,3 @@ export function registerSpanErrorInstrumentation(): void { addGlobalErrorInstrumentationHandler(errorCallback); addGlobalUnhandledRejectionInstrumentationHandler(errorCallback); } - - From 490ba54964359de1e8f238bf9c4b583c5f96d82b Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Fri, 11 Jul 2025 13:13:16 +0200 Subject: [PATCH 3/3] Fix dodgy merge --- packages/core/src/tracing/errors.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/tracing/errors.ts b/packages/core/src/tracing/errors.ts index d6b43adb7ddf..a2d5af2560c5 100644 --- a/packages/core/src/tracing/errors.ts +++ b/packages/core/src/tracing/errors.ts @@ -1,7 +1,7 @@ import { DEBUG_BUILD } from '../debug-build'; import { addGlobalErrorInstrumentationHandler } from '../instrument/globalError'; import { addGlobalUnhandledRejectionInstrumentationHandler } from '../instrument/globalUnhandledRejection'; -import { logger } from '../utils/logger'; +import { debug } from '../utils/logger'; import { getActiveSpan, getRootSpan } from '../utils/spanUtils'; import { SPAN_STATUS_ERROR } from './spanstatus'; @@ -28,7 +28,7 @@ export function registerSpanErrorInstrumentation(): void { const rootSpan = activeSpan && getRootSpan(activeSpan); if (rootSpan) { const message = 'internal_error'; - DEBUG_BUILD && logger.log(`[Tracing] Root span: ${message} -> Global error occurred`); + DEBUG_BUILD && debug.log(`[Tracing] Root span: ${message} -> Global error occurred`); rootSpan.setStatus({ code: SPAN_STATUS_ERROR, message }); } }