Skip to content

Commit 128f7bc

Browse files
authored
feat(tracing): Move registerErrorInstrumentation to @sentry/core (#7494)
1 parent 3045390 commit 128f7bc

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

packages/tracing-internal/src/errors.ts renamed to packages/core/src/tracing/errors.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
import type { SpanStatusType } from '@sentry/core';
2-
import { getActiveTransaction } from '@sentry/core';
31
import { addInstrumentationHandler, logger } from '@sentry/utils';
42

3+
import type { SpanStatusType } from './span';
4+
import { getActiveTransaction } from './utils';
5+
6+
let errorsInstrumented = false;
7+
58
/**
69
* Configures global error listeners
710
*/
811
export function registerErrorInstrumentation(): void {
12+
if (errorsInstrumented) {
13+
return;
14+
}
15+
16+
errorsInstrumented = true;
917
addInstrumentationHandler('error', errorCallback);
1018
addInstrumentationHandler('unhandledrejection', errorCallback);
1119
}

packages/core/src/tracing/hubextensions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { isNaN, logger } from '@sentry/utils';
44
import type { Hub } from '../hub';
55
import { getMainCarrier } from '../hub';
66
import { hasTracingEnabled } from '../utils/hasTracingEnabled';
7+
import { registerErrorInstrumentation } from './errors';
78
import { IdleTransaction } from './idletransaction';
89
import { Transaction } from './transaction';
910

@@ -237,4 +238,6 @@ export function addTracingExtensions(): void {
237238
if (!carrier.__SENTRY__.extensions.traceHeaders) {
238239
carrier.__SENTRY__.extensions.traceHeaders = traceHeaders;
239240
}
241+
242+
registerErrorInstrumentation();
240243
}

packages/tracing-internal/test/errors.test.ts renamed to packages/core/test/lib/tracing/errors.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { BrowserClient } from '@sentry/browser';
22
import { addTracingExtensions, Hub, makeMain } from '@sentry/core';
33
import type { InstrumentHandlerCallback, InstrumentHandlerType } from '@sentry/utils';
44

5-
import { getDefaultBrowserClientOptions } from '../../tracing/test/testutils';
6-
import { registerErrorInstrumentation } from '../src/errors';
5+
import { getDefaultBrowserClientOptions } from '../../../../tracing/test/testutils';
6+
import { registerErrorInstrumentation } from '../../../src/tracing/errors';
77

88
const mockAddInstrumentationHandler = jest.fn();
99
let mockErrorCallback: InstrumentHandlerCallback = () => undefined;

packages/tracing-internal/src/extensions.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { addTracingExtensions, getMainCarrier } from '@sentry/core';
22
import type { Integration, IntegrationClass } from '@sentry/types';
33
import { dynamicRequire, isNodeEnv, loadModule } from '@sentry/utils';
44

5-
import { registerErrorInstrumentation } from './errors';
6-
75
/**
86
* @private
97
*/
@@ -66,7 +64,4 @@ export function addExtensionMethods(): void {
6664
if (isNodeEnv()) {
6765
_autoloadDatabaseIntegrations();
6866
}
69-
70-
// If an error happens globally, we should make sure transaction status is set to error.
71-
registerErrorInstrumentation();
7267
}

0 commit comments

Comments
 (0)