diff --git a/packages/tracing-internal/src/errors.ts b/packages/core/src/tracing/errors.ts similarity index 77% rename from packages/tracing-internal/src/errors.ts rename to packages/core/src/tracing/errors.ts index 3d41e43830f0..3351f428fecf 100644 --- a/packages/tracing-internal/src/errors.ts +++ b/packages/core/src/tracing/errors.ts @@ -1,11 +1,19 @@ -import type { SpanStatusType } from '@sentry/core'; -import { getActiveTransaction } from '@sentry/core'; 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); } diff --git a/packages/core/src/tracing/hubextensions.ts b/packages/core/src/tracing/hubextensions.ts index 9624df4b709e..b5518f95e04b 100644 --- a/packages/core/src/tracing/hubextensions.ts +++ b/packages/core/src/tracing/hubextensions.ts @@ -4,6 +4,7 @@ import { isNaN, logger } from '@sentry/utils'; import type { Hub } from '../hub'; import { getMainCarrier } from '../hub'; import { hasTracingEnabled } from '../utils/hasTracingEnabled'; +import { registerErrorInstrumentation } from './errors'; import { IdleTransaction } from './idletransaction'; import { Transaction } from './transaction'; @@ -237,4 +238,6 @@ export function addTracingExtensions(): void { if (!carrier.__SENTRY__.extensions.traceHeaders) { carrier.__SENTRY__.extensions.traceHeaders = traceHeaders; } + + registerErrorInstrumentation(); } diff --git a/packages/tracing-internal/test/errors.test.ts b/packages/core/test/lib/tracing/errors.test.ts similarity index 94% rename from packages/tracing-internal/test/errors.test.ts rename to packages/core/test/lib/tracing/errors.test.ts index 1dba00b825b1..8bf12f675032 100644 --- a/packages/tracing-internal/test/errors.test.ts +++ b/packages/core/test/lib/tracing/errors.test.ts @@ -2,8 +2,8 @@ import { BrowserClient } from '@sentry/browser'; import { addTracingExtensions, Hub, makeMain } from '@sentry/core'; import type { InstrumentHandlerCallback, InstrumentHandlerType } from '@sentry/utils'; -import { getDefaultBrowserClientOptions } from '../../tracing/test/testutils'; -import { registerErrorInstrumentation } from '../src/errors'; +import { getDefaultBrowserClientOptions } from '../../../../tracing/test/testutils'; +import { registerErrorInstrumentation } from '../../../src/tracing/errors'; const mockAddInstrumentationHandler = jest.fn(); let mockErrorCallback: InstrumentHandlerCallback = () => undefined; diff --git a/packages/tracing-internal/src/extensions.ts b/packages/tracing-internal/src/extensions.ts index e3c2ab511804..555a1451b55e 100644 --- a/packages/tracing-internal/src/extensions.ts +++ b/packages/tracing-internal/src/extensions.ts @@ -2,8 +2,6 @@ import { addTracingExtensions, getMainCarrier } from '@sentry/core'; import type { Integration, IntegrationClass } from '@sentry/types'; import { dynamicRequire, isNodeEnv, loadModule } from '@sentry/utils'; -import { registerErrorInstrumentation } from './errors'; - /** * @private */ @@ -66,7 +64,4 @@ export function addExtensionMethods(): void { if (isNodeEnv()) { _autoloadDatabaseIntegrations(); } - - // If an error happens globally, we should make sure transaction status is set to error. - registerErrorInstrumentation(); }