From 30ca8b878fad609a811bbf7bb3bd44c778ce2821 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Tue, 23 Jan 2024 14:43:37 -0500 Subject: [PATCH 1/2] feat(browser): Deprecate `BrowserTracing` in favor of `browserTracingIntegration` --- packages/astro/src/client/sdk.ts | 4 +-- packages/astro/test/client/sdk.test.ts | 7 ++--- packages/browser/src/index.bundle.feedback.ts | 11 +++++++- packages/browser/src/index.bundle.replay.ts | 4 +++ .../index.bundle.tracing.replay.feedback.ts | 5 +++- .../src/index.bundle.tracing.replay.ts | 5 +++- packages/browser/src/index.bundle.tracing.ts | 5 +++- packages/browser/src/index.bundle.ts | 4 +++ packages/browser/src/index.ts | 2 ++ .../test/unit/profiling/integration.test.ts | 2 +- .../sentry-performance.ts | 4 +-- packages/ember/addon/types.ts | 4 +-- packages/gatsby/src/utils/integrations.ts | 6 ++--- packages/gatsby/test/gatsby-browser.test.ts | 4 +-- packages/gatsby/test/sdk.test.ts | 10 +++---- .../integration-shims/src/BrowserTracing.ts | 19 ++++++++++++- packages/integration-shims/src/index.ts | 9 ++++++- .../src/client/browserTracingIntegration.ts | 13 +++++++++ packages/nextjs/src/client/index.ts | 15 ++++++++--- packages/nextjs/test/clientSdk.test.ts | 27 ++++++++++++------- .../src/client/browserTracingIntegration.ts | 13 +++++++++ packages/sveltekit/src/client/sdk.ts | 8 +++--- packages/sveltekit/test/client/sdk.test.ts | 6 +++-- .../src/browser/browsertracing.ts | 8 ++++++ .../tracing-internal/src/browser/index.ts | 7 ++++- packages/tracing-internal/src/index.ts | 2 ++ packages/tracing/src/index.ts | 2 ++ 27 files changed, 161 insertions(+), 45 deletions(-) diff --git a/packages/astro/src/client/sdk.ts b/packages/astro/src/client/sdk.ts index 8d2b70ee6751..a289296c2ab2 100644 --- a/packages/astro/src/client/sdk.ts +++ b/packages/astro/src/client/sdk.ts @@ -1,6 +1,6 @@ import type { BrowserOptions } from '@sentry/browser'; import { - BrowserTracing, + browserTracingIntegration, getDefaultIntegrations as getBrowserDefaultIntegrations, init as initBrowserSdk, setTag, @@ -34,7 +34,7 @@ function getDefaultIntegrations(options: BrowserOptions): Integration[] | undefi // in which case everything inside will get treeshaken away if (typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__) { if (hasTracingEnabled(options)) { - return [...getBrowserDefaultIntegrations(options), new BrowserTracing()]; + return [...getBrowserDefaultIntegrations(options), browserTracingIntegration()]; } } diff --git a/packages/astro/test/client/sdk.test.ts b/packages/astro/test/client/sdk.test.ts index 2e10d4210953..4996df46ca39 100644 --- a/packages/astro/test/client/sdk.test.ts +++ b/packages/astro/test/client/sdk.test.ts @@ -1,7 +1,7 @@ -import type { BrowserClient } from '@sentry/browser'; +import type { BrowserClient, BrowserTracing } from '@sentry/browser'; import { getCurrentScope } from '@sentry/browser'; import * as SentryBrowser from '@sentry/browser'; -import { BrowserTracing, SDK_VERSION, WINDOW, getClient } from '@sentry/browser'; +import { SDK_VERSION, WINDOW, browserTracingIntegration, getClient } from '@sentry/browser'; import { vi } from 'vitest'; import { init } from '../../../astro/src/client/sdk'; @@ -103,12 +103,13 @@ describe('Sentry client SDK', () => { it('Overrides the automatically default BrowserTracing instance with a a user-provided instance', () => { init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [new BrowserTracing({ finalTimeout: 10, startTransactionOnLocationChange: false })], + integrations: [browserTracingIntegration({ finalTimeout: 10, startTransactionOnLocationChange: false })], enableTracing: true, }); const integrationsToInit = browserInit.mock.calls[0][0]?.defaultIntegrations; + // eslint-disable-next-line deprecation/deprecation const browserTracing = getClient()?.getIntegrationByName('BrowserTracing') as BrowserTracing; const options = browserTracing.options; diff --git a/packages/browser/src/index.bundle.feedback.ts b/packages/browser/src/index.bundle.feedback.ts index 5d3612106286..8e653c2d4757 100644 --- a/packages/browser/src/index.bundle.feedback.ts +++ b/packages/browser/src/index.bundle.feedback.ts @@ -1,6 +1,12 @@ // This is exported so the loader does not fail when switching off Replay/Tracing import { Feedback, feedbackIntegration } from '@sentry-internal/feedback'; -import { BrowserTracing, Replay, addTracingExtensions, replayIntegration } from '@sentry-internal/integration-shims'; +import { + BrowserTracing, + Replay, + addTracingExtensions, + browserTracingIntegration, + replayIntegration, +} from '@sentry-internal/integration-shims'; import * as Sentry from './index.bundle.base'; @@ -8,11 +14,14 @@ import * as Sentry from './index.bundle.base'; // eslint-disable-next-line deprecation/deprecation Sentry.Integrations.Replay = Replay; +// eslint-disable-next-line deprecation/deprecation Sentry.Integrations.BrowserTracing = BrowserTracing; export * from './index.bundle.base'; export { + // eslint-disable-next-line deprecation/deprecation BrowserTracing, + browserTracingIntegration, addTracingExtensions, // eslint-disable-next-line deprecation/deprecation Replay, diff --git a/packages/browser/src/index.bundle.replay.ts b/packages/browser/src/index.bundle.replay.ts index 2609e7d9b48c..2e4619ab49ea 100644 --- a/packages/browser/src/index.bundle.replay.ts +++ b/packages/browser/src/index.bundle.replay.ts @@ -3,6 +3,7 @@ import { BrowserTracing, Feedback, addTracingExtensions, + browserTracingIntegration, feedbackIntegration, } from '@sentry-internal/integration-shims'; import { Replay, replayIntegration } from '@sentry/replay'; @@ -13,11 +14,14 @@ import * as Sentry from './index.bundle.base'; // eslint-disable-next-line deprecation/deprecation Sentry.Integrations.Replay = Replay; +// eslint-disable-next-line deprecation/deprecation Sentry.Integrations.BrowserTracing = BrowserTracing; export * from './index.bundle.base'; export { + // eslint-disable-next-line deprecation/deprecation BrowserTracing, + browserTracingIntegration, addTracingExtensions, // eslint-disable-next-line deprecation/deprecation Replay, diff --git a/packages/browser/src/index.bundle.tracing.replay.feedback.ts b/packages/browser/src/index.bundle.tracing.replay.feedback.ts index e17c7de4159a..5822a2379cc4 100644 --- a/packages/browser/src/index.bundle.tracing.replay.feedback.ts +++ b/packages/browser/src/index.bundle.tracing.replay.feedback.ts @@ -1,5 +1,5 @@ import { Feedback, feedbackIntegration } from '@sentry-internal/feedback'; -import { BrowserTracing, Span, addExtensionMethods } from '@sentry-internal/tracing'; +import { BrowserTracing, Span, addExtensionMethods, browserTracingIntegration } from '@sentry-internal/tracing'; import { Replay, replayIntegration } from '@sentry/replay'; import * as Sentry from './index.bundle.base'; @@ -10,6 +10,7 @@ import * as Sentry from './index.bundle.base'; // eslint-disable-next-line deprecation/deprecation Sentry.Integrations.Replay = Replay; +// eslint-disable-next-line deprecation/deprecation Sentry.Integrations.BrowserTracing = BrowserTracing; // We are patching the global object with our hub extension methods @@ -22,7 +23,9 @@ export { Replay, feedbackIntegration, replayIntegration, + // eslint-disable-next-line deprecation/deprecation BrowserTracing, + browserTracingIntegration, Span, addExtensionMethods, }; diff --git a/packages/browser/src/index.bundle.tracing.replay.ts b/packages/browser/src/index.bundle.tracing.replay.ts index 5dc0537be064..41ea77b8d982 100644 --- a/packages/browser/src/index.bundle.tracing.replay.ts +++ b/packages/browser/src/index.bundle.tracing.replay.ts @@ -1,5 +1,5 @@ import { Feedback, feedbackIntegration } from '@sentry-internal/integration-shims'; -import { BrowserTracing, Span, addExtensionMethods } from '@sentry-internal/tracing'; +import { BrowserTracing, Span, addExtensionMethods, browserTracingIntegration } from '@sentry-internal/tracing'; import { Replay, replayIntegration } from '@sentry/replay'; import * as Sentry from './index.bundle.base'; @@ -10,6 +10,7 @@ import * as Sentry from './index.bundle.base'; // eslint-disable-next-line deprecation/deprecation Sentry.Integrations.Replay = Replay; +// eslint-disable-next-line deprecation/deprecation Sentry.Integrations.BrowserTracing = BrowserTracing; // We are patching the global object with our hub extension methods @@ -22,7 +23,9 @@ export { Replay, replayIntegration, feedbackIntegration, + // eslint-disable-next-line deprecation/deprecation BrowserTracing, + browserTracingIntegration, Span, addExtensionMethods, }; diff --git a/packages/browser/src/index.bundle.tracing.ts b/packages/browser/src/index.bundle.tracing.ts index f810b61b92a7..6607dacf992c 100644 --- a/packages/browser/src/index.bundle.tracing.ts +++ b/packages/browser/src/index.bundle.tracing.ts @@ -1,6 +1,6 @@ // This is exported so the loader does not fail when switching off Replay import { Feedback, Replay, feedbackIntegration, replayIntegration } from '@sentry-internal/integration-shims'; -import { BrowserTracing, Span, addExtensionMethods } from '@sentry-internal/tracing'; +import { BrowserTracing, Span, addExtensionMethods, browserTracingIntegration } from '@sentry-internal/tracing'; import * as Sentry from './index.bundle.base'; @@ -10,6 +10,7 @@ import * as Sentry from './index.bundle.base'; // eslint-disable-next-line deprecation/deprecation Sentry.Integrations.Replay = Replay; +// eslint-disable-next-line deprecation/deprecation Sentry.Integrations.BrowserTracing = BrowserTracing; // We are patching the global object with our hub extension methods @@ -22,7 +23,9 @@ export { Replay, feedbackIntegration, replayIntegration, + // eslint-disable-next-line deprecation/deprecation BrowserTracing, + browserTracingIntegration, Span, addExtensionMethods, }; diff --git a/packages/browser/src/index.bundle.ts b/packages/browser/src/index.bundle.ts index a92ff6bf66ec..3087d7d317ca 100644 --- a/packages/browser/src/index.bundle.ts +++ b/packages/browser/src/index.bundle.ts @@ -4,6 +4,7 @@ import { Feedback, Replay, addTracingExtensions, + browserTracingIntegration, feedbackIntegration, replayIntegration, } from '@sentry-internal/integration-shims'; @@ -14,16 +15,19 @@ import * as Sentry from './index.bundle.base'; // eslint-disable-next-line deprecation/deprecation Sentry.Integrations.Replay = Replay; +// eslint-disable-next-line deprecation/deprecation Sentry.Integrations.BrowserTracing = BrowserTracing; export * from './index.bundle.base'; export { + // eslint-disable-next-line deprecation/deprecation BrowserTracing, addTracingExtensions, // eslint-disable-next-line deprecation/deprecation Replay, // eslint-disable-next-line deprecation/deprecation Feedback, + browserTracingIntegration, feedbackIntegration, replayIntegration, }; diff --git a/packages/browser/src/index.ts b/packages/browser/src/index.ts index 19c377fc5931..8fbf60bf1bd7 100644 --- a/packages/browser/src/index.ts +++ b/packages/browser/src/index.ts @@ -54,7 +54,9 @@ export { } from '@sentry-internal/feedback'; export { + // eslint-disable-next-line deprecation/deprecation BrowserTracing, + browserTracingIntegration, defaultRequestInstrumentationOptions, instrumentOutgoingRequests, } from '@sentry-internal/tracing'; diff --git a/packages/browser/test/unit/profiling/integration.test.ts b/packages/browser/test/unit/profiling/integration.test.ts index b69d3a52d655..d7f13a3848f6 100644 --- a/packages/browser/test/unit/profiling/integration.test.ts +++ b/packages/browser/test/unit/profiling/integration.test.ts @@ -44,7 +44,7 @@ describe('BrowserProfilingIntegration', () => { send, }; }, - integrations: [new Sentry.BrowserTracing(), new BrowserProfilingIntegration()], + integrations: [Sentry.browserTracingIntegration(), new BrowserProfilingIntegration()], }); const client = Sentry.getClient(); diff --git a/packages/ember/addon/instance-initializers/sentry-performance.ts b/packages/ember/addon/instance-initializers/sentry-performance.ts index b25125b28da6..d6f5bf61a053 100644 --- a/packages/ember/addon/instance-initializers/sentry-performance.ts +++ b/packages/ember/addon/instance-initializers/sentry-performance.ts @@ -404,11 +404,11 @@ export async function instrumentForPerformance(appInstance: ApplicationInstance) // Maintaining backwards compatibility with config.browserTracingOptions, but passing it with Sentry options is preferred. const browserTracingOptions = config.browserTracingOptions || config.sentry.browserTracingOptions || {}; - const { BrowserTracing } = await import('@sentry/browser'); + const { browserTracingIntegration } = await import('@sentry/browser'); const idleTimeout = config.transitionTimeout || 5000; - const browserTracing = new BrowserTracing({ + const browserTracing = browserTracingIntegration({ routingInstrumentation: (customStartTransaction, startTransactionOnPageLoad) => { // eslint-disable-next-line ember/no-private-routing-service const routerMain = appInstance.lookup('router:main') as EmberRouterMain; diff --git a/packages/ember/addon/types.ts b/packages/ember/addon/types.ts index 787eecc7e4cf..dbd14ff96f70 100644 --- a/packages/ember/addon/types.ts +++ b/packages/ember/addon/types.ts @@ -1,7 +1,7 @@ -import type { BrowserOptions, BrowserTracing } from '@sentry/browser'; +import type { BrowserOptions, browserTracingIntegration } from '@sentry/browser'; import type { Transaction, TransactionContext } from '@sentry/types'; -type BrowserTracingOptions = ConstructorParameters[0]; +type BrowserTracingOptions = Parameters[0]; export type EmberSentryConfig = { sentry: BrowserOptions & { browserTracingOptions?: BrowserTracingOptions }; diff --git a/packages/gatsby/src/utils/integrations.ts b/packages/gatsby/src/utils/integrations.ts index 94ef28f21272..7c61adee1d50 100644 --- a/packages/gatsby/src/utils/integrations.ts +++ b/packages/gatsby/src/utils/integrations.ts @@ -1,5 +1,5 @@ import { hasTracingEnabled } from '@sentry/core'; -import { BrowserTracing } from '@sentry/react'; +import { browserTracingIntegration } from '@sentry/react'; import type { Integration } from '@sentry/types'; import type { GatsbyOptions } from './types'; @@ -31,8 +31,8 @@ export function getIntegrationsFromOptions(options: GatsbyOptions): UserIntegrat * @param isTracingEnabled Whether the user has enabled tracing. */ function getIntegrationsFromArray(userIntegrations: Integration[], isTracingEnabled: boolean): Integration[] { - if (isTracingEnabled && !userIntegrations.some(integration => integration.name === BrowserTracing.name)) { - userIntegrations.push(new BrowserTracing()); + if (isTracingEnabled && !userIntegrations.some(integration => integration.name === 'BrowserTracing')) { + userIntegrations.push(browserTracingIntegration()); } return userIntegrations; } diff --git a/packages/gatsby/test/gatsby-browser.test.ts b/packages/gatsby/test/gatsby-browser.test.ts index b67305042c71..cf456a9d3e9d 100644 --- a/packages/gatsby/test/gatsby-browser.test.ts +++ b/packages/gatsby/test/gatsby-browser.test.ts @@ -2,7 +2,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { onClientEntry } from '../gatsby-browser'; -import { BrowserTracing } from '../src/index'; +import { browserTracingIntegration } from '../src/index'; (global as any).__SENTRY_RELEASE__ = '683f3a6ab819d47d23abfca9a914c81f0524d35b'; (global as any).__SENTRY_DSN__ = 'https://examplePublicKey@o0.ingest.sentry.io/0'; @@ -141,7 +141,7 @@ describe('onClientEntry', () => { }); it('only defines a single `BrowserTracing` integration', () => { - const integrations = [new BrowserTracing()]; + const integrations = [browserTracingIntegration()]; onClientEntry(undefined, { tracesSampleRate: 0.5, integrations }); expect(sentryInit).toHaveBeenLastCalledWith( diff --git a/packages/gatsby/test/sdk.test.ts b/packages/gatsby/test/sdk.test.ts index c3c95cdabc1f..28206d1ef6c5 100644 --- a/packages/gatsby/test/sdk.test.ts +++ b/packages/gatsby/test/sdk.test.ts @@ -1,4 +1,4 @@ -import { BrowserTracing, SDK_VERSION, init } from '@sentry/react'; +import { SDK_VERSION, browserTracingIntegration, init } from '@sentry/react'; import type { Integration } from '@sentry/types'; import { init as gatsbyInit } from '../src/sdk'; @@ -68,27 +68,27 @@ describe('Integrations from options', () => { [ 'tracing disabled, with BrowserTracing as an array', [], - { integrations: [new BrowserTracing()] }, + { integrations: [browserTracingIntegration()] }, ['BrowserTracing'], ], [ 'tracing disabled, with BrowserTracing as a function', [], { - integrations: () => [new BrowserTracing()], + integrations: () => [browserTracingIntegration()], }, ['BrowserTracing'], ], [ 'tracing enabled, with BrowserTracing as an array', [], - { tracesSampleRate: 1, integrations: [new BrowserTracing()] }, + { tracesSampleRate: 1, integrations: [browserTracingIntegration()] }, ['BrowserTracing'], ], [ 'tracing enabled, with BrowserTracing as a function', [], - { tracesSampleRate: 1, integrations: () => [new BrowserTracing()] }, + { tracesSampleRate: 1, integrations: () => [browserTracingIntegration()] }, ['BrowserTracing'], ], ] as TestArgs[])( diff --git a/packages/integration-shims/src/BrowserTracing.ts b/packages/integration-shims/src/BrowserTracing.ts index 310dc589afe9..94936b004903 100644 --- a/packages/integration-shims/src/BrowserTracing.ts +++ b/packages/integration-shims/src/BrowserTracing.ts @@ -5,6 +5,8 @@ import { consoleSandbox } from '@sentry/utils'; * This is a shim for the BrowserTracing integration. * It is needed in order for the CDN bundles to continue working when users add/remove tracing * from it, without changing their config. This is necessary for the loader mechanism. + * + * @deprecated Use `browserTracingIntegration()` instead. */ class BrowserTracingShim implements Integration { /** @@ -19,6 +21,7 @@ class BrowserTracingShim implements Integration { // eslint-disable-next-line @typescript-eslint/no-explicit-any public constructor(_options: any) { + // eslint-disable-next-line deprecation/deprecation this.name = BrowserTracingShim.id; consoleSandbox(() => { @@ -33,7 +36,21 @@ class BrowserTracingShim implements Integration { } } -export { BrowserTracingShim as BrowserTracing }; +/** + * This is a shim for the BrowserTracing integration. + * It is needed in order for the CDN bundles to continue working when users add/remove tracing + * from it, without changing their config. This is necessary for the loader mechanism. + */ +function browserTracingIntegrationShim(): Integration { + // eslint-disable-next-line deprecation/deprecation + return new BrowserTracingShim({}); +} + +export { + // eslint-disable-next-line deprecation/deprecation + BrowserTracingShim as BrowserTracing, + browserTracingIntegrationShim as browserTracingIntegration, +}; /** Shim function */ export function addTracingExtensions(): void { diff --git a/packages/integration-shims/src/index.ts b/packages/integration-shims/src/index.ts index 43243f69a194..bffdf82c99f7 100644 --- a/packages/integration-shims/src/index.ts +++ b/packages/integration-shims/src/index.ts @@ -3,9 +3,16 @@ export { Feedback, feedbackIntegration, } from './Feedback'; + export { // eslint-disable-next-line deprecation/deprecation Replay, replayIntegration, } from './Replay'; -export { BrowserTracing, addTracingExtensions } from './BrowserTracing'; + +export { + // eslint-disable-next-line deprecation/deprecation + BrowserTracing, + browserTracingIntegration, + addTracingExtensions, +} from './BrowserTracing'; diff --git a/packages/nextjs/src/client/browserTracingIntegration.ts b/packages/nextjs/src/client/browserTracingIntegration.ts index c3eb18887301..b7c6f33159eb 100644 --- a/packages/nextjs/src/client/browserTracingIntegration.ts +++ b/packages/nextjs/src/client/browserTracingIntegration.ts @@ -1,10 +1,14 @@ import { BrowserTracing as OriginalBrowserTracing, defaultRequestInstrumentationOptions } from '@sentry/react'; +import type { Integration } from '@sentry/types'; import { nextRouterInstrumentation } from '../index.client'; /** * A custom BrowserTracing integration for Next.js. + * @deprecated Use `browserTracingIntegration()` instead. */ +// eslint-disable-next-line deprecation/deprecation export class BrowserTracing extends OriginalBrowserTracing { + // eslint-disable-next-line deprecation/deprecation public constructor(options?: ConstructorParameters[0]) { super({ // eslint-disable-next-line deprecation/deprecation @@ -24,3 +28,12 @@ export class BrowserTracing extends OriginalBrowserTracing { }); } } + +/** + * A custom BrowserTracing integration for Next.js. + */ +// eslint-disable-next-line deprecation/deprecation +export function browserTracingIntegration(options?: ConstructorParameters[0]): Integration { + // eslint-disable-next-line deprecation/deprecation + return new BrowserTracing(options); +} diff --git a/packages/nextjs/src/client/index.ts b/packages/nextjs/src/client/index.ts index d1d5e1db7ff5..60c1c5d2a7f8 100644 --- a/packages/nextjs/src/client/index.ts +++ b/packages/nextjs/src/client/index.ts @@ -10,7 +10,7 @@ import type { EventProcessor, Integration } from '@sentry/types'; import { devErrorSymbolicationEventProcessor } from '../common/devErrorSymbolicationEventProcessor'; import { getVercelEnv } from '../common/getVercelEnv'; -import { BrowserTracing } from './browserTracingIntegration'; +import { BrowserTracing, browserTracingIntegration } from './browserTracingIntegration'; import { rewriteFramesIntegration } from './rewriteFramesIntegration'; import { applyTunnelRouteOption } from './tunnelRoute'; @@ -35,7 +35,12 @@ export const Integrations = { // // import { BrowserTracing } from '@sentry/nextjs'; // const instance = new BrowserTracing(); -export { BrowserTracing, rewriteFramesIntegration }; +export { + // eslint-disable-next-line deprecation/deprecation + BrowserTracing, + browserTracingIntegration, + rewriteFramesIntegration, +}; // Treeshakable guard to remove all code related to tracing declare const __SENTRY_TRACING__: boolean; @@ -90,13 +95,15 @@ function maybeUpdateBrowserTracingIntegration(integrations: Integration[]): Inte const browserTracing = integrations.find(integration => integration.name === 'BrowserTracing'); // If BrowserTracing was added, but it is not our forked version, // replace it with our forked version with the same options + // eslint-disable-next-line deprecation/deprecation if (browserTracing && !(browserTracing instanceof BrowserTracing)) { + // eslint-disable-next-line deprecation/deprecation const options: ConstructorParameters[0] = (browserTracing as BrowserTracing).options; // These two options are overwritten by the custom integration delete options.routingInstrumentation; // eslint-disable-next-line deprecation/deprecation delete options.tracingOrigins; - integrations[integrations.indexOf(browserTracing)] = new BrowserTracing(options); + integrations[integrations.indexOf(browserTracing)] = browserTracingIntegration(options); } return integrations; @@ -109,7 +116,7 @@ function getDefaultIntegrations(options: BrowserOptions): Integration[] { // will get treeshaken away if (typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__) { if (hasTracingEnabled(options)) { - customDefaultIntegrations.push(new BrowserTracing()); + customDefaultIntegrations.push(browserTracingIntegration()); } } diff --git a/packages/nextjs/test/clientSdk.test.ts b/packages/nextjs/test/clientSdk.test.ts index 464b7db14dc7..6de340dfc3e1 100644 --- a/packages/nextjs/test/clientSdk.test.ts +++ b/packages/nextjs/test/clientSdk.test.ts @@ -6,7 +6,8 @@ import type { Integration } from '@sentry/types'; import { logger } from '@sentry/utils'; import { JSDOM } from 'jsdom'; -import { BrowserTracing, breadcrumbsIntegration, init, nextRouterInstrumentation } from '../src/client'; +import type { BrowserTracing } from '../src/client'; +import { breadcrumbsIntegration, browserTracingIntegration, init, nextRouterInstrumentation } from '../src/client'; const reactInit = jest.spyOn(SentryReact, 'init'); const captureEvent = jest.spyOn(BaseClient.prototype, 'captureEvent'); @@ -124,6 +125,7 @@ describe('Client init()', () => { }); const client = getClient()!; + // eslint-disable-next-line deprecation/deprecation const browserTracingIntegration = client.getIntegrationByName('BrowserTracing'); expect(browserTracingIntegration).toBeDefined(); @@ -141,6 +143,7 @@ describe('Client init()', () => { }); const client = getClient()!; + // eslint-disable-next-line deprecation/deprecation const browserTracingIntegration = client.getIntegrationByName('BrowserTracing'); expect(browserTracingIntegration).toBeDefined(); @@ -157,6 +160,7 @@ describe('Client init()', () => { }); const client = getClient()!; + // eslint-disable-next-line deprecation/deprecation const browserTracingIntegration = client.getIntegrationByName('BrowserTracing'); expect(browserTracingIntegration).toBeUndefined(); @@ -166,14 +170,15 @@ describe('Client init()', () => { init({ dsn: TEST_DSN, tracesSampleRate: 1.0, - integrations: [new BrowserTracing({ startTransactionOnLocationChange: false })], + integrations: [browserTracingIntegration({ startTransactionOnLocationChange: false })], }); const client = getClient()!; - const browserTracingIntegration = client.getIntegrationByName('BrowserTracing'); + // eslint-disable-next-line deprecation/deprecation + const integration = client.getIntegrationByName('BrowserTracing'); - expect(browserTracingIntegration).toBeDefined(); - expect(browserTracingIntegration?.options).toEqual( + expect(integration).toBeDefined(); + expect(integration?.options).toEqual( expect.objectContaining({ routingInstrumentation: nextRouterInstrumentation, // This proves it's still the user's copy @@ -186,15 +191,19 @@ describe('Client init()', () => { init({ dsn: TEST_DSN, tracesSampleRate: 1.0, - integrations: defaults => [...defaults, new BrowserTracing({ startTransactionOnLocationChange: false })], + integrations: defaults => [ + ...defaults, + browserTracingIntegration({ startTransactionOnLocationChange: false }), + ], }); const client = getClient()!; - const browserTracingIntegration = client.getIntegrationByName('BrowserTracing'); + // eslint-disable-next-line deprecation/deprecation + const integration = client.getIntegrationByName('BrowserTracing'); - expect(browserTracingIntegration).toBeDefined(); - expect(browserTracingIntegration?.options).toEqual( + expect(integration).toBeDefined(); + expect(integration?.options).toEqual( expect.objectContaining({ routingInstrumentation: nextRouterInstrumentation, // This proves it's still the user's copy diff --git a/packages/sveltekit/src/client/browserTracingIntegration.ts b/packages/sveltekit/src/client/browserTracingIntegration.ts index 9968f8b6de5f..d6b5e0bde95f 100644 --- a/packages/sveltekit/src/client/browserTracingIntegration.ts +++ b/packages/sveltekit/src/client/browserTracingIntegration.ts @@ -1,10 +1,14 @@ import { BrowserTracing as OriginalBrowserTracing } from '@sentry/svelte'; +import type { Integration } from '@sentry/types'; import { svelteKitRoutingInstrumentation } from './router'; /** * A custom BrowserTracing integration for Sveltekit. + * @deprecated Use `browserTracingIntegration()` instead. */ +// eslint-disable-next-line deprecation/deprecation export class BrowserTracing extends OriginalBrowserTracing { + // eslint-disable-next-line deprecation/deprecation public constructor(options?: ConstructorParameters[0]) { super({ routingInstrumentation: svelteKitRoutingInstrumentation, @@ -12,3 +16,12 @@ export class BrowserTracing extends OriginalBrowserTracing { }); } } + +/** + * A custom BrowserTracing integration for Sveltekit. + */ +// eslint-disable-next-line deprecation/deprecation +export function browserTracingIntegration(options?: ConstructorParameters[0]): Integration { + // eslint-disable-next-line deprecation/deprecation + return new BrowserTracing(options); +} diff --git a/packages/sveltekit/src/client/sdk.ts b/packages/sveltekit/src/client/sdk.ts index 7b9c608a862d..c8894605f53d 100644 --- a/packages/sveltekit/src/client/sdk.ts +++ b/packages/sveltekit/src/client/sdk.ts @@ -4,7 +4,7 @@ import { getDefaultIntegrations as getDefaultSvelteIntegrations } from '@sentry/ import { WINDOW, getCurrentScope, init as initSvelteSdk } from '@sentry/svelte'; import type { Integration } from '@sentry/types'; -import { BrowserTracing } from './browserTracingIntegration'; +import { BrowserTracing, browserTracingIntegration } from './browserTracingIntegration'; type WindowWithSentryFetchProxy = typeof WINDOW & { _sentryFetchProxy?: typeof fetch; @@ -65,11 +65,13 @@ function maybeUpdateBrowserTracingIntegration(integrations: Integration[]): Inte const browserTracing = integrations.find(integration => integration.name === 'BrowserTracing'); // If BrowserTracing was added, but it is not our forked version, // replace it with our forked version with the same options + // eslint-disable-next-line deprecation/deprecation if (browserTracing && !(browserTracing instanceof BrowserTracing)) { + // eslint-disable-next-line deprecation/deprecation const options: ConstructorParameters[0] = (browserTracing as BrowserTracing).options; // This option is overwritten by the custom integration delete options.routingInstrumentation; - integrations[integrations.indexOf(browserTracing)] = new BrowserTracing(options); + integrations[integrations.indexOf(browserTracing)] = browserTracingIntegration(options); } return integrations; @@ -80,7 +82,7 @@ function getDefaultIntegrations(options: BrowserOptions): Integration[] | undefi // will get treeshaken away if (typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__) { if (hasTracingEnabled(options)) { - return [...getDefaultSvelteIntegrations(options), new BrowserTracing()]; + return [...getDefaultSvelteIntegrations(options), browserTracingIntegration()]; } } diff --git a/packages/sveltekit/test/client/sdk.test.ts b/packages/sveltekit/test/client/sdk.test.ts index 10292658bc54..0f643c9e9b14 100644 --- a/packages/sveltekit/test/client/sdk.test.ts +++ b/packages/sveltekit/test/client/sdk.test.ts @@ -4,7 +4,8 @@ import * as SentrySvelte from '@sentry/svelte'; import { SDK_VERSION, WINDOW } from '@sentry/svelte'; import { vi } from 'vitest'; -import { BrowserTracing, init } from '../../src/client'; +import type { BrowserTracing } from '../../src/client'; +import { browserTracingIntegration, init } from '../../src/client'; import { svelteKitRoutingInstrumentation } from '../../src/client/router'; const svelteInit = vi.spyOn(SentrySvelte, 'init'); @@ -100,10 +101,11 @@ describe('Sentry client SDK', () => { it('Merges a user-provided BrowserTracing integration with the automatically added one', () => { init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [new BrowserTracing({ finalTimeout: 10, startTransactionOnLocationChange: false })], + integrations: [browserTracingIntegration({ finalTimeout: 10, startTransactionOnLocationChange: false })], enableTracing: true, }); + // eslint-disable-next-line deprecation/deprecation const browserTracing = getClient()?.getIntegrationByName('BrowserTracing') as BrowserTracing; const options = browserTracing.options; diff --git a/packages/tracing-internal/src/browser/browsertracing.ts b/packages/tracing-internal/src/browser/browsertracing.ts index e9f61c73c0f3..5ba73743be3d 100644 --- a/packages/tracing-internal/src/browser/browsertracing.ts +++ b/packages/tracing-internal/src/browser/browsertracing.ts @@ -159,6 +159,14 @@ const DEFAULT_BROWSER_TRACING_OPTIONS: BrowserTracingOptions = { * The integration can be configured with a variety of options, and can be extended to use * any routing library. This integration uses {@see IdleTransaction} to create transactions. */ +export function browserTracingIntegration(options?: Partial): Integration { + // eslint-disable-next-line deprecation/deprecation + return new BrowserTracing(options); +} + +/** + * @deprecated Use `browserTracingIntegration()` instead. + */ export class BrowserTracing implements Integration { // This class currently doesn't have a static `id` field like the other integration classes, because it prevented // @sentry/tracing from being treeshaken. Tree shakers do not like static fields, because they behave like side effects. diff --git a/packages/tracing-internal/src/browser/index.ts b/packages/tracing-internal/src/browser/index.ts index 5b30bc519404..d9a17641b2b4 100644 --- a/packages/tracing-internal/src/browser/index.ts +++ b/packages/tracing-internal/src/browser/index.ts @@ -2,7 +2,12 @@ export * from '../exports'; export type { RequestInstrumentationOptions } from './request'; -export { BrowserTracing, BROWSER_TRACING_INTEGRATION_ID } from './browsertracing'; +export { + // eslint-disable-next-line deprecation/deprecation + BrowserTracing, + browserTracingIntegration, + BROWSER_TRACING_INTEGRATION_ID, +} from './browsertracing'; export { instrumentOutgoingRequests, defaultRequestInstrumentationOptions } from './request'; export { diff --git a/packages/tracing-internal/src/index.ts b/packages/tracing-internal/src/index.ts index 495d8dbb26b9..5e8791018c6f 100644 --- a/packages/tracing-internal/src/index.ts +++ b/packages/tracing-internal/src/index.ts @@ -13,7 +13,9 @@ export { export type { LazyLoadedIntegration } from './node'; export { + // eslint-disable-next-line deprecation/deprecation BrowserTracing, + browserTracingIntegration, BROWSER_TRACING_INTEGRATION_ID, instrumentOutgoingRequests, defaultRequestInstrumentationOptions, diff --git a/packages/tracing/src/index.ts b/packages/tracing/src/index.ts index 8559188884d7..b0a5b47554ae 100644 --- a/packages/tracing/src/index.ts +++ b/packages/tracing/src/index.ts @@ -38,6 +38,7 @@ import { * import { BrowserTracing } from '@sentry/browser'; * new BrowserTracing() */ +// eslint-disable-next-line deprecation/deprecation export const BrowserTracing = BrowserTracingT; // BrowserTracing is already exported as part of `Integrations` below (and for the moment will remain so for @@ -50,6 +51,7 @@ export const BrowserTracing = BrowserTracingT; * import { BrowserTracing } from '@sentry/browser'; * new BrowserTracing() */ +// eslint-disable-next-line deprecation/deprecation export type BrowserTracing = BrowserTracingT; /** From 243bdda7c3b3a6371be2e378d4de292cd618b671 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Wed, 24 Jan 2024 08:35:44 -0500 Subject: [PATCH 2/2] add migration docs --- MIGRATION.md | 1 + 1 file changed, 1 insertion(+) diff --git a/MIGRATION.md b/MIGRATION.md index 4c0ea3eddc91..cf5fb0bef004 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -36,6 +36,7 @@ The following list shows how integrations should be migrated: | Old | New | Packages | | ------------------------- | -------------------------------- | ------------------------------------------------------------------------------------------------------- | +| `new BrowserTracing()` | `browserTracingIntegration()` | `@sentry/browser` | | `new InboundFilters()` | `inboundFiltersIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` | | `new FunctionToString()` | `functionToStringIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` | | `new LinkedErrors()` | `linkedErrorsIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |