Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Deprecate addTracingExtensions #11579

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ We've removed the following packages:
`@sentry/tracing` has been removed and will no longer be published. See
[below](./MIGRATION.md/#3-removal-of-deprecated-apis) for more details.

For Browser SDKs you can import `BrowserTracing` from the SDK directly:
For Browser SDKs you can import `browserTracingIntegration` from the SDK directly:

```js
// v7
Expand All @@ -86,12 +86,13 @@ import * as Sentry from '@sentry/browser';
Sentry.init({
dsn: '__DSN__',
tracesSampleRate: 1.0,
integrations: [new Sentry.BrowserTracing()],
integrations: [Sentry.browserTracingIntegration()],
});
```

If you were importing `@sentry/tracing` for the side effect, you can now use `Sentry.addTracingExtensions()` to add the
tracing extensions to the SDK. `addTracingExtensions` replaces the `addExtensionMethods` method from `@sentry/tracing`.
If you don't want to use `browserTracingIntegration` but still manually start spans, you can now use
`Sentry.registerSpanErrorInstrumentation()` to setup handlers for span instrumentation.
`registerSpanErrorInstrumentation` replaces the `addExtensionMethods` method from `@sentry/tracing`.

```js
// v7
Expand All @@ -108,7 +109,7 @@ Sentry.init({
// v8
import * as Sentry from '@sentry/browser';

Sentry.addTracingExtensions();
Sentry.registerSpanErrorInstrumentation();

Sentry.init({
dsn: '__DSN__',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;

Sentry.addTracingExtensions();

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
tracesSampleRate: 1.0,
Expand Down
11 changes: 1 addition & 10 deletions packages/browser-utils/test/browser/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import {
SentrySpan,
addTracingExtensions,
getCurrentScope,
getIsolationScope,
setCurrentClient,
spanToJSON,
} from '@sentry/core';
import { SentrySpan, getCurrentScope, getIsolationScope, setCurrentClient, spanToJSON } from '@sentry/core';
import { startAndEndSpan } from '../../src/metrics/utils';
import { TestClient, getDefaultClientOptions } from '../utils/TestClient';

describe('startAndEndSpan()', () => {
beforeEach(() => {
addTracingExtensions();

getCurrentScope().clear();
getIsolationScope().clear();

Expand Down
13 changes: 2 additions & 11 deletions packages/browser/src/index.bundle.feedback.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
// This is exported so the loader does not fail when switching off Replay/Tracing
import {
addTracingExtensionsShim,
browserTracingIntegrationShim,
replayIntegrationShim,
} from '@sentry-internal/integration-shims';
import { browserTracingIntegrationShim, replayIntegrationShim } from '@sentry-internal/integration-shims';

export * from './index.bundle.base';

Expand All @@ -14,8 +9,4 @@ export {
getFeedback,
} from '@sentry-internal/feedback';

export {
browserTracingIntegrationShim as browserTracingIntegration,
addTracingExtensionsShim as addTracingExtensions,
replayIntegrationShim as replayIntegration,
};
export { browserTracingIntegrationShim as browserTracingIntegration, replayIntegrationShim as replayIntegration };
3 changes: 0 additions & 3 deletions packages/browser/src/index.bundle.replay.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// This is exported so the loader does not fail when switching off Replay/Tracing
import {
addTracingExtensionsShim,
browserTracingIntegrationShim,
feedbackIntegrationShim,
feedbackModalIntegrationShim,
Expand All @@ -13,7 +11,6 @@ export { replayIntegration } from '@sentry-internal/replay';

export {
browserTracingIntegrationShim as browserTracingIntegration,
addTracingExtensionsShim as addTracingExtensions,
feedbackIntegrationShim as feedbackIntegration,
feedbackModalIntegrationShim as feedbackModalIntegration,
feedbackScreenshotIntegrationShim as feedbackScreenshotIntegration,
Expand Down
6 changes: 2 additions & 4 deletions packages/browser/src/index.bundle.tracing.replay.feedback.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { addTracingExtensions } from '@sentry/core';
import { registerSpanErrorInstrumentation } from '@sentry/core';

// We are patching the global object with our hub extension methods
addTracingExtensions();
registerSpanErrorInstrumentation();

export * from './index.bundle.base';

Expand All @@ -14,7 +13,6 @@ export {
withActiveSpan,
getSpanDescendants,
setMeasurement,
addTracingExtensions,
} from '@sentry/core';

export {
Expand Down
6 changes: 2 additions & 4 deletions packages/browser/src/index.bundle.tracing.replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import {
feedbackModalIntegrationShim,
feedbackScreenshotIntegrationShim,
} from '@sentry-internal/integration-shims';
import { addTracingExtensions } from '@sentry/core';
import { registerSpanErrorInstrumentation } from '@sentry/core';

// We are patching the global object with our hub extension methods
addTracingExtensions();
registerSpanErrorInstrumentation();

export * from './index.bundle.base';

Expand All @@ -19,7 +18,6 @@ export {
withActiveSpan,
getSpanDescendants,
setMeasurement,
addTracingExtensions,
} from '@sentry/core';

export {
Expand Down
7 changes: 2 additions & 5 deletions packages/browser/src/index.bundle.tracing.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// This is exported so the loader does not fail when switching off Replay
import {
feedbackIntegrationShim,
feedbackModalIntegrationShim,
feedbackScreenshotIntegrationShim,
replayIntegrationShim,
} from '@sentry-internal/integration-shims';
import { addTracingExtensions } from '@sentry/core';
import { registerSpanErrorInstrumentation } from '@sentry/core';

// We are patching the global object with our hub extension methods
addTracingExtensions();
registerSpanErrorInstrumentation();

export * from './index.bundle.base';

Expand All @@ -21,7 +19,6 @@ export {
withActiveSpan,
getSpanDescendants,
setMeasurement,
addTracingExtensions,
} from '@sentry/core';

export {
Expand Down
3 changes: 0 additions & 3 deletions packages/browser/src/index.bundle.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// This is exported so the loader does not fail when switching off Replay/Tracing
import {
addTracingExtensionsShim,
browserTracingIntegrationShim,
feedbackIntegrationShim,
feedbackModalIntegrationShim,
Expand All @@ -11,7 +9,6 @@ import {
export * from './index.bundle.base';

export {
addTracingExtensionsShim as addTracingExtensions,
browserTracingIntegrationShim as browserTracingIntegration,
feedbackIntegrationShim as feedbackIntegration,
feedbackModalIntegrationShim as feedbackModalIntegration,
Expand Down
2 changes: 2 additions & 0 deletions packages/browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export {
} from './tracing/browserTracingIntegration';
export type { RequestInstrumentationOptions } from './tracing/request';
export {
// eslint-disable-next-line deprecation/deprecation
addTracingExtensions,
registerSpanErrorInstrumentation,
getActiveSpan,
getRootSpan,
startSpan,
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/tracing/browserTracingIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import {
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
TRACING_DEFAULTS,
addTracingExtensions,
continueTrace,
getActiveSpan,
getClient,
getCurrentScope,
getIsolationScope,
getRootSpan,
registerSpanErrorInstrumentation,
spanToJSON,
startIdleSpan,
withScope,
Expand Down Expand Up @@ -153,7 +153,7 @@ const DEFAULT_BROWSER_TRACING_OPTIONS: BrowserTracingOptions = {
* We explicitly export the proper type here, as this has to be extended in some cases.
*/
export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptions> = {}) => {
addTracingExtensions();
registerSpanErrorInstrumentation();

const options = {
...DEFAULT_BROWSER_TRACING_OPTIONS,
Expand Down
4 changes: 1 addition & 3 deletions packages/browser/test/unit/tracing/backgroundtab.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addTracingExtensions, getCurrentScope } from '@sentry/core';
import { getCurrentScope } from '@sentry/core';
import { setCurrentClient } from '@sentry/core';

import { TextDecoder, TextEncoder } from 'util';
Expand Down Expand Up @@ -30,8 +30,6 @@ describe('registerBackgroundTabDetection', () => {
setCurrentClient(client);
client.init();

addTracingExtensions();

global.document.addEventListener = jest.fn((event, callback) => {
events[event] = callback;
});
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/server-runtime-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import { DEBUG_BUILD } from './debug-build';
import type { Scope } from './scope';
import { SessionFlusher } from './sessionflusher';
import {
addTracingExtensions,
getDynamicSamplingContextFromClient,
getDynamicSamplingContextFromSpan,
registerSpanErrorInstrumentation,
} from './tracing';
import { _getSpanForScope } from './utils/spanOnScope';
import { getRootSpan, spanToTraceContext } from './utils/spanUtils';
Expand All @@ -47,7 +47,7 @@ export class ServerRuntimeClient<
*/
public constructor(options: O) {
// Server clients always support tracing
addTracingExtensions();
registerSpanErrorInstrumentation();

super(options);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/tracing/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export function _resetErrorsInstrumented(): void {
}

/**
* Configures global error listeners
* Ensure that global errors automatically set the active span status.
*/
export function registerErrorInstrumentation(): void {
export function registerSpanErrorInstrumentation(): void {
if (errorsInstrumented) {
return;
}
Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/tracing/hubextensions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { registerErrorInstrumentation } from './errors';
import { registerSpanErrorInstrumentation } from './errors';

/**
* Adds tracing extensions.
* TODO (v8): Do we still need this?? Can we solve this differently?
* @deprecated Use `registerSpanErrorInstrumentation()` instead. In v9, this function will be removed. Note that you don't need to call this in Node-based SDKs or when using `browserTracingIntegration`.
*/
export function addTracingExtensions(): void {
registerErrorInstrumentation();
registerSpanErrorInstrumentation();
}
2 changes: 2 additions & 0 deletions packages/core/src/tracing/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export { registerSpanErrorInstrumentation } from './errors';
export { setCapturedScopesOnSpan, getCapturedScopesOnSpan } from './utils';
// eslint-disable-next-line deprecation/deprecation
export { addTracingExtensions } from './hubextensions';
export { startIdleSpan, TRACING_DEFAULTS } from './idleSpan';
export { SentrySpan } from './sentrySpan';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ import {
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
setCurrentClient,
} from '../../../src';
import {
SentrySpan,
addTracingExtensions,
getDynamicSamplingContextFromSpan,
startInactiveSpan,
} from '../../../src/tracing';
import { SentrySpan, getDynamicSamplingContextFromSpan, startInactiveSpan } from '../../../src/tracing';
import { freezeDscOnSpan } from '../../../src/tracing/dynamicSamplingContext';
import { TestClient, getDefaultTestClientOptions } from '../../mocks/client';

Expand All @@ -19,7 +14,6 @@ describe('getDynamicSamplingContextFromSpan', () => {
const client = new TestClient(options);
setCurrentClient(client);
client.init();
addTracingExtensions();
});

afterEach(() => {
Expand Down
16 changes: 6 additions & 10 deletions packages/core/test/lib/tracing/errors.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { HandlerDataError, HandlerDataUnhandledRejection } from '@sentry/types';
import { addTracingExtensions, setCurrentClient, spanToJSON, startInactiveSpan, startSpan } from '../../../src';
import { setCurrentClient, spanToJSON, startInactiveSpan, startSpan } from '../../../src';

import { _resetErrorsInstrumented, registerErrorInstrumentation } from '../../../src/tracing/errors';
import { _resetErrorsInstrumented, registerSpanErrorInstrumentation } from '../../../src/tracing/errors';
import { TestClient, getDefaultTestClientOptions } from '../../mocks/client';

const mockAddGlobalErrorInstrumentationHandler = jest.fn();
Expand All @@ -25,10 +25,6 @@ jest.mock('@sentry/utils', () => {
};
});

beforeAll(() => {
addTracingExtensions();
});

describe('registerErrorHandlers()', () => {
beforeEach(() => {
mockAddGlobalErrorInstrumentationHandler.mockClear();
Expand All @@ -41,15 +37,15 @@ describe('registerErrorHandlers()', () => {
});

it('registers error instrumentation', () => {
registerErrorInstrumentation();
registerSpanErrorInstrumentation();
expect(mockAddGlobalErrorInstrumentationHandler).toHaveBeenCalledTimes(1);
expect(mockAddGlobalUnhandledRejectionInstrumentationHandler).toHaveBeenCalledTimes(1);
expect(mockAddGlobalErrorInstrumentationHandler).toHaveBeenCalledWith(expect.any(Function));
expect(mockAddGlobalUnhandledRejectionInstrumentationHandler).toHaveBeenCalledWith(expect.any(Function));
});

it('does not set status if transaction is not on scope', () => {
registerErrorInstrumentation();
registerSpanErrorInstrumentation();

const transaction = startInactiveSpan({ name: 'test' })!;
expect(spanToJSON(transaction).status).toBe(undefined);
Expand All @@ -64,7 +60,7 @@ describe('registerErrorHandlers()', () => {
});

it('sets status for transaction on scope on error', () => {
registerErrorInstrumentation();
registerSpanErrorInstrumentation();

startSpan({ name: 'test' }, span => {
mockErrorCallback({} as HandlerDataError);
Expand All @@ -73,7 +69,7 @@ describe('registerErrorHandlers()', () => {
});

it('sets status for transaction on scope on unhandledrejection', () => {
registerErrorInstrumentation();
registerSpanErrorInstrumentation();

startSpan({ name: 'test' }, span => {
mockUnhandledRejectionCallback({});
Expand Down
2 changes: 0 additions & 2 deletions packages/core/test/lib/tracing/idleSpan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON,
SentryNonRecordingSpan,
SentrySpan,
addTracingExtensions,
getActiveSpan,
getClient,
getCurrentScope,
Expand All @@ -24,7 +23,6 @@ const dsn = 'https://123@sentry.io/42';
describe('startIdleSpan', () => {
beforeEach(() => {
jest.useFakeTimers();
addTracingExtensions();

getCurrentScope().clear();
getIsolationScope().clear();
Expand Down
Loading
Loading