diff --git a/MIGRATION.md b/MIGRATION.md index 063788881242..4c0ea3eddc91 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -10,16 +10,6 @@ npx @sentry/migr8@latest This will let you select which updates to run, and automatically update your code. Make sure to still review all code changes! -## Deprecate transaction-related options to `BrowserTracing` - -When configuring the `BrowserTracing` integration, some options have been renamed: - -- `startTransactionOnPageLoad` --> `spanOnPageLoad` -- `startTransactionOnLocationChange` --> `spanOnLocationChange` -- `markBackgroundTransactions` --> `markBackgroundSpan` - -Also, `beforeNavigate` is replaced with a `beforeStartSpan` callback, which receives `StartSpanOptions`. - ## Deprecate using `getClient()` to check if the SDK was initialized In v8, `getClient()` will stop returning `undefined` if `Sentry.init()` was not called. For cases where this may be used @@ -46,7 +36,6 @@ 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` | diff --git a/packages/astro/src/client/sdk.ts b/packages/astro/src/client/sdk.ts index a289296c2ab2..8d2b70ee6751 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 { - browserTracingIntegration, + BrowserTracing, 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), browserTracingIntegration()]; + return [...getBrowserDefaultIntegrations(options), new BrowserTracing()]; } } diff --git a/packages/astro/test/client/sdk.test.ts b/packages/astro/test/client/sdk.test.ts index 4996df46ca39..2e10d4210953 100644 --- a/packages/astro/test/client/sdk.test.ts +++ b/packages/astro/test/client/sdk.test.ts @@ -1,7 +1,7 @@ -import type { BrowserClient, BrowserTracing } from '@sentry/browser'; +import type { BrowserClient } from '@sentry/browser'; import { getCurrentScope } from '@sentry/browser'; import * as SentryBrowser from '@sentry/browser'; -import { SDK_VERSION, WINDOW, browserTracingIntegration, getClient } from '@sentry/browser'; +import { BrowserTracing, SDK_VERSION, WINDOW, getClient } from '@sentry/browser'; import { vi } from 'vitest'; import { init } from '../../../astro/src/client/sdk'; @@ -103,13 +103,12 @@ 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: [browserTracingIntegration({ finalTimeout: 10, startTransactionOnLocationChange: false })], + integrations: [new BrowserTracing({ 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 8e653c2d4757..5d3612106286 100644 --- a/packages/browser/src/index.bundle.feedback.ts +++ b/packages/browser/src/index.bundle.feedback.ts @@ -1,12 +1,6 @@ // 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, - browserTracingIntegration, - replayIntegration, -} from '@sentry-internal/integration-shims'; +import { BrowserTracing, Replay, addTracingExtensions, replayIntegration } from '@sentry-internal/integration-shims'; import * as Sentry from './index.bundle.base'; @@ -14,14 +8,11 @@ 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 2e4619ab49ea..2609e7d9b48c 100644 --- a/packages/browser/src/index.bundle.replay.ts +++ b/packages/browser/src/index.bundle.replay.ts @@ -3,7 +3,6 @@ import { BrowserTracing, Feedback, addTracingExtensions, - browserTracingIntegration, feedbackIntegration, } from '@sentry-internal/integration-shims'; import { Replay, replayIntegration } from '@sentry/replay'; @@ -14,14 +13,11 @@ 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 5822a2379cc4..e17c7de4159a 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, browserTracingIntegration } from '@sentry-internal/tracing'; +import { BrowserTracing, Span, addExtensionMethods } from '@sentry-internal/tracing'; import { Replay, replayIntegration } from '@sentry/replay'; import * as Sentry from './index.bundle.base'; @@ -10,7 +10,6 @@ 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 @@ -23,9 +22,7 @@ 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 41ea77b8d982..5dc0537be064 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, browserTracingIntegration } from '@sentry-internal/tracing'; +import { BrowserTracing, Span, addExtensionMethods } from '@sentry-internal/tracing'; import { Replay, replayIntegration } from '@sentry/replay'; import * as Sentry from './index.bundle.base'; @@ -10,7 +10,6 @@ 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 @@ -23,9 +22,7 @@ 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 6607dacf992c..f810b61b92a7 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, browserTracingIntegration } from '@sentry-internal/tracing'; +import { BrowserTracing, Span, addExtensionMethods } from '@sentry-internal/tracing'; import * as Sentry from './index.bundle.base'; @@ -10,7 +10,6 @@ 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 @@ -23,9 +22,7 @@ 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 3087d7d317ca..a92ff6bf66ec 100644 --- a/packages/browser/src/index.bundle.ts +++ b/packages/browser/src/index.bundle.ts @@ -4,7 +4,6 @@ import { Feedback, Replay, addTracingExtensions, - browserTracingIntegration, feedbackIntegration, replayIntegration, } from '@sentry-internal/integration-shims'; @@ -15,19 +14,16 @@ 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 8fbf60bf1bd7..19c377fc5931 100644 --- a/packages/browser/src/index.ts +++ b/packages/browser/src/index.ts @@ -54,9 +54,7 @@ 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 d7f13a3848f6..b69d3a52d655 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: [Sentry.browserTracingIntegration(), new BrowserProfilingIntegration()], + integrations: [new Sentry.BrowserTracing(), new BrowserProfilingIntegration()], }); const client = Sentry.getClient(); diff --git a/packages/core/src/tracing/trace.ts b/packages/core/src/tracing/trace.ts index 885cbd7c9d08..eb070510a3b7 100644 --- a/packages/core/src/tracing/trace.ts +++ b/packages/core/src/tracing/trace.ts @@ -1,5 +1,15 @@ -import type { Span, SpanTimeInput, StartSpanOptions, TransactionContext } from '@sentry/types'; - +import type { + Instrumenter, + Primitive, + Scope, + Span, + SpanTimeInput, + TransactionContext, + TransactionMetadata, +} from '@sentry/types'; +import type { SpanAttributes } from '@sentry/types'; +import type { SpanOrigin } from '@sentry/types'; +import type { TransactionSource } from '@sentry/types'; import { dropUndefinedKeys, logger, tracingContextFromHeaders } from '@sentry/utils'; import { DEBUG_BUILD } from '../debug-build'; @@ -10,6 +20,105 @@ import { handleCallbackErrors } from '../utils/handleCallbackErrors'; import { hasTracingEnabled } from '../utils/hasTracingEnabled'; import { spanTimeInputToSeconds, spanToJSON } from '../utils/spanUtils'; +interface StartSpanOptions extends TransactionContext { + /** A manually specified start time for the created `Span` object. */ + startTime?: SpanTimeInput; + + /** If defined, start this span off this scope instead off the current scope. */ + scope?: Scope; + + /** The name of the span. */ + name: string; + + /** An op for the span. This is a categorization for spans. */ + op?: string; + + /** The origin of the span - if it comes from auto instrumenation or manual instrumentation. */ + origin?: SpanOrigin; + + /** Attributes for the span. */ + attributes?: SpanAttributes; + + // All remaining fields are deprecated + + /** + * @deprecated Manually set the end timestamp instead. + */ + trimEnd?: boolean; + + /** + * @deprecated This cannot be set manually anymore. + */ + parentSampled?: boolean; + + /** + * @deprecated Use attributes or set data on scopes instead. + */ + metadata?: Partial; + + /** + * The name thingy. + * @deprecated Use `name` instead. + */ + description?: string; + + /** + * @deprecated Use `span.setStatus()` instead. + */ + status?: string; + + /** + * @deprecated Use `scope` instead. + */ + parentSpanId?: string; + + /** + * @deprecated You cannot manually set the span to sampled anymore. + */ + sampled?: boolean; + + /** + * @deprecated You cannot manually set the spanId anymore. + */ + spanId?: string; + + /** + * @deprecated You cannot manually set the traceId anymore. + */ + traceId?: string; + + /** + * @deprecated Use an attribute instead. + */ + source?: TransactionSource; + + /** + * @deprecated Use attributes or set tags on the scope instead. + */ + tags?: { [key: string]: Primitive }; + + /** + * @deprecated Use attributes instead. + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + data?: { [key: string]: any }; + + /** + * @deprecated Use `startTime` instead. + */ + startTimestamp?: number; + + /** + * @deprecated Use `span.end()` instead. + */ + endTimestamp?: number; + + /** + * @deprecated You cannot set the instrumenter manually anymore. + */ + instrumenter?: Instrumenter; +} + /** * Wraps a function with a transaction/span and finishes the span after the function is done. * diff --git a/packages/ember/addon/instance-initializers/sentry-performance.ts b/packages/ember/addon/instance-initializers/sentry-performance.ts index d6f5bf61a053..b25125b28da6 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 { browserTracingIntegration } = await import('@sentry/browser'); + const { BrowserTracing } = await import('@sentry/browser'); const idleTimeout = config.transitionTimeout || 5000; - const browserTracing = browserTracingIntegration({ + const browserTracing = new BrowserTracing({ 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 dbd14ff96f70..787eecc7e4cf 100644 --- a/packages/ember/addon/types.ts +++ b/packages/ember/addon/types.ts @@ -1,7 +1,7 @@ -import type { BrowserOptions, browserTracingIntegration } from '@sentry/browser'; +import type { BrowserOptions, BrowserTracing } from '@sentry/browser'; import type { Transaction, TransactionContext } from '@sentry/types'; -type BrowserTracingOptions = Parameters[0]; +type BrowserTracingOptions = ConstructorParameters[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 7c61adee1d50..94ef28f21272 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 { browserTracingIntegration } from '@sentry/react'; +import { BrowserTracing } 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')) { - userIntegrations.push(browserTracingIntegration()); + if (isTracingEnabled && !userIntegrations.some(integration => integration.name === BrowserTracing.name)) { + userIntegrations.push(new BrowserTracing()); } return userIntegrations; } diff --git a/packages/gatsby/test/gatsby-browser.test.ts b/packages/gatsby/test/gatsby-browser.test.ts index cf456a9d3e9d..b67305042c71 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 { browserTracingIntegration } from '../src/index'; +import { BrowserTracing } 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 = [browserTracingIntegration()]; + const integrations = [new BrowserTracing()]; 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 28206d1ef6c5..c3c95cdabc1f 100644 --- a/packages/gatsby/test/sdk.test.ts +++ b/packages/gatsby/test/sdk.test.ts @@ -1,4 +1,4 @@ -import { SDK_VERSION, browserTracingIntegration, init } from '@sentry/react'; +import { BrowserTracing, SDK_VERSION, 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: [browserTracingIntegration()] }, + { integrations: [new BrowserTracing()] }, ['BrowserTracing'], ], [ 'tracing disabled, with BrowserTracing as a function', [], { - integrations: () => [browserTracingIntegration()], + integrations: () => [new BrowserTracing()], }, ['BrowserTracing'], ], [ 'tracing enabled, with BrowserTracing as an array', [], - { tracesSampleRate: 1, integrations: [browserTracingIntegration()] }, + { tracesSampleRate: 1, integrations: [new BrowserTracing()] }, ['BrowserTracing'], ], [ 'tracing enabled, with BrowserTracing as a function', [], - { tracesSampleRate: 1, integrations: () => [browserTracingIntegration()] }, + { tracesSampleRate: 1, integrations: () => [new BrowserTracing()] }, ['BrowserTracing'], ], ] as TestArgs[])( diff --git a/packages/integration-shims/src/BrowserTracing.ts b/packages/integration-shims/src/BrowserTracing.ts index 94936b004903..310dc589afe9 100644 --- a/packages/integration-shims/src/BrowserTracing.ts +++ b/packages/integration-shims/src/BrowserTracing.ts @@ -5,8 +5,6 @@ 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 { /** @@ -21,7 +19,6 @@ 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(() => { @@ -36,21 +33,7 @@ class BrowserTracingShim implements Integration { } } -/** - * 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, -}; +export { BrowserTracingShim as BrowserTracing }; /** Shim function */ export function addTracingExtensions(): void { diff --git a/packages/integration-shims/src/index.ts b/packages/integration-shims/src/index.ts index bffdf82c99f7..43243f69a194 100644 --- a/packages/integration-shims/src/index.ts +++ b/packages/integration-shims/src/index.ts @@ -3,16 +3,9 @@ export { Feedback, feedbackIntegration, } from './Feedback'; - export { // eslint-disable-next-line deprecation/deprecation Replay, replayIntegration, } from './Replay'; - -export { - // eslint-disable-next-line deprecation/deprecation - BrowserTracing, - browserTracingIntegration, - addTracingExtensions, -} from './BrowserTracing'; +export { BrowserTracing, addTracingExtensions } from './BrowserTracing'; diff --git a/packages/nextjs/src/client/browserTracingIntegration.ts b/packages/nextjs/src/client/browserTracingIntegration.ts index b7c6f33159eb..c3eb18887301 100644 --- a/packages/nextjs/src/client/browserTracingIntegration.ts +++ b/packages/nextjs/src/client/browserTracingIntegration.ts @@ -1,14 +1,10 @@ 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 @@ -28,12 +24,3 @@ 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 60c1c5d2a7f8..d1d5e1db7ff5 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, browserTracingIntegration } from './browserTracingIntegration'; +import { BrowserTracing } from './browserTracingIntegration'; import { rewriteFramesIntegration } from './rewriteFramesIntegration'; import { applyTunnelRouteOption } from './tunnelRoute'; @@ -35,12 +35,7 @@ export const Integrations = { // // import { BrowserTracing } from '@sentry/nextjs'; // const instance = new BrowserTracing(); -export { - // eslint-disable-next-line deprecation/deprecation - BrowserTracing, - browserTracingIntegration, - rewriteFramesIntegration, -}; +export { BrowserTracing, rewriteFramesIntegration }; // Treeshakable guard to remove all code related to tracing declare const __SENTRY_TRACING__: boolean; @@ -95,15 +90,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; // 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)] = browserTracingIntegration(options); + integrations[integrations.indexOf(browserTracing)] = new BrowserTracing(options); } return integrations; @@ -116,7 +109,7 @@ function getDefaultIntegrations(options: BrowserOptions): Integration[] { // will get treeshaken away if (typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__) { if (hasTracingEnabled(options)) { - customDefaultIntegrations.push(browserTracingIntegration()); + customDefaultIntegrations.push(new BrowserTracing()); } } diff --git a/packages/nextjs/test/clientSdk.test.ts b/packages/nextjs/test/clientSdk.test.ts index 6de340dfc3e1..464b7db14dc7 100644 --- a/packages/nextjs/test/clientSdk.test.ts +++ b/packages/nextjs/test/clientSdk.test.ts @@ -6,8 +6,7 @@ import type { Integration } from '@sentry/types'; import { logger } from '@sentry/utils'; import { JSDOM } from 'jsdom'; -import type { BrowserTracing } from '../src/client'; -import { breadcrumbsIntegration, browserTracingIntegration, init, nextRouterInstrumentation } from '../src/client'; +import { BrowserTracing, breadcrumbsIntegration, init, nextRouterInstrumentation } from '../src/client'; const reactInit = jest.spyOn(SentryReact, 'init'); const captureEvent = jest.spyOn(BaseClient.prototype, 'captureEvent'); @@ -125,7 +124,6 @@ describe('Client init()', () => { }); const client = getClient()!; - // eslint-disable-next-line deprecation/deprecation const browserTracingIntegration = client.getIntegrationByName('BrowserTracing'); expect(browserTracingIntegration).toBeDefined(); @@ -143,7 +141,6 @@ describe('Client init()', () => { }); const client = getClient()!; - // eslint-disable-next-line deprecation/deprecation const browserTracingIntegration = client.getIntegrationByName('BrowserTracing'); expect(browserTracingIntegration).toBeDefined(); @@ -160,7 +157,6 @@ describe('Client init()', () => { }); const client = getClient()!; - // eslint-disable-next-line deprecation/deprecation const browserTracingIntegration = client.getIntegrationByName('BrowserTracing'); expect(browserTracingIntegration).toBeUndefined(); @@ -170,15 +166,14 @@ describe('Client init()', () => { init({ dsn: TEST_DSN, tracesSampleRate: 1.0, - integrations: [browserTracingIntegration({ startTransactionOnLocationChange: false })], + integrations: [new BrowserTracing({ startTransactionOnLocationChange: false })], }); const client = getClient()!; - // eslint-disable-next-line deprecation/deprecation - const integration = client.getIntegrationByName('BrowserTracing'); + const browserTracingIntegration = client.getIntegrationByName('BrowserTracing'); - expect(integration).toBeDefined(); - expect(integration?.options).toEqual( + expect(browserTracingIntegration).toBeDefined(); + expect(browserTracingIntegration?.options).toEqual( expect.objectContaining({ routingInstrumentation: nextRouterInstrumentation, // This proves it's still the user's copy @@ -191,19 +186,15 @@ describe('Client init()', () => { init({ dsn: TEST_DSN, tracesSampleRate: 1.0, - integrations: defaults => [ - ...defaults, - browserTracingIntegration({ startTransactionOnLocationChange: false }), - ], + integrations: defaults => [...defaults, new BrowserTracing({ startTransactionOnLocationChange: false })], }); const client = getClient()!; - // eslint-disable-next-line deprecation/deprecation - const integration = client.getIntegrationByName('BrowserTracing'); + const browserTracingIntegration = client.getIntegrationByName('BrowserTracing'); - expect(integration).toBeDefined(); - expect(integration?.options).toEqual( + expect(browserTracingIntegration).toBeDefined(); + expect(browserTracingIntegration?.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 d6b5e0bde95f..9968f8b6de5f 100644 --- a/packages/sveltekit/src/client/browserTracingIntegration.ts +++ b/packages/sveltekit/src/client/browserTracingIntegration.ts @@ -1,14 +1,10 @@ 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, @@ -16,12 +12,3 @@ 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 c8894605f53d..7b9c608a862d 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, browserTracingIntegration } from './browserTracingIntegration'; +import { BrowserTracing } from './browserTracingIntegration'; type WindowWithSentryFetchProxy = typeof WINDOW & { _sentryFetchProxy?: typeof fetch; @@ -65,13 +65,11 @@ 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)] = browserTracingIntegration(options); + integrations[integrations.indexOf(browserTracing)] = new BrowserTracing(options); } return integrations; @@ -82,7 +80,7 @@ function getDefaultIntegrations(options: BrowserOptions): Integration[] | undefi // will get treeshaken away if (typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__) { if (hasTracingEnabled(options)) { - return [...getDefaultSvelteIntegrations(options), browserTracingIntegration()]; + return [...getDefaultSvelteIntegrations(options), new BrowserTracing()]; } } diff --git a/packages/sveltekit/test/client/sdk.test.ts b/packages/sveltekit/test/client/sdk.test.ts index 0f643c9e9b14..10292658bc54 100644 --- a/packages/sveltekit/test/client/sdk.test.ts +++ b/packages/sveltekit/test/client/sdk.test.ts @@ -4,8 +4,7 @@ import * as SentrySvelte from '@sentry/svelte'; import { SDK_VERSION, WINDOW } from '@sentry/svelte'; import { vi } from 'vitest'; -import type { BrowserTracing } from '../../src/client'; -import { browserTracingIntegration, init } from '../../src/client'; +import { BrowserTracing, init } from '../../src/client'; import { svelteKitRoutingInstrumentation } from '../../src/client/router'; const svelteInit = vi.spyOn(SentrySvelte, 'init'); @@ -101,11 +100,10 @@ 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: [browserTracingIntegration({ finalTimeout: 10, startTransactionOnLocationChange: false })], + integrations: [new BrowserTracing({ 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 28c10215118d..e9f61c73c0f3 100644 --- a/packages/tracing-internal/src/browser/browsertracing.ts +++ b/packages/tracing-internal/src/browser/browsertracing.ts @@ -1,4 +1,4 @@ -/* eslint-disable max-lines, complexity */ +/* eslint-disable max-lines */ import type { Hub, IdleTransaction } from '@sentry/core'; import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, @@ -9,14 +9,7 @@ import { spanToJSON, startIdleTransaction, } from '@sentry/core'; -import type { - EventProcessor, - Integration, - StartSpanOptions, - Transaction, - TransactionContext, - TransactionSource, -} from '@sentry/types'; +import type { EventProcessor, Integration, Transaction, TransactionContext, TransactionSource } from '@sentry/types'; import { getDomElement, logger, tracingContextFromHeaders } from '@sentry/utils'; import { DEBUG_BUILD } from '../common/debug-build'; @@ -66,49 +59,28 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions { */ heartbeatInterval: number; - /** - * If a span should be created on location (history) changes. - * Default: true - */ - spanOnLocationChange: boolean; - - /** - * If a span should be created on pageload. - * Default: true - */ - spanOnPageLoad: boolean; - - /** - * Flag spans where tabs moved to background with "cancelled". Browser background tab timing is - * not suited towards doing precise measurements of operations. By default, we recommend that this option - * be enabled as background transactions can mess up your statistics in nondeterministic ways. - * - * Default: true - */ - markBackgroundSpan: boolean; - /** * Flag to enable/disable creation of `navigation` transaction on history changes. + * * Default: true - * @deprecated Configure `spanOnLocationChange` instead. */ - startTransactionOnLocationChange?: boolean; + startTransactionOnLocationChange: boolean; /** * Flag to enable/disable creation of `pageload` transaction on first pageload. + * * Default: true - * @deprecated Configure `spanOnPageLoad` instead. */ - startTransactionOnPageLoad?: boolean; + startTransactionOnPageLoad: boolean; /** * Flag Transactions where tabs moved to background with "cancelled". Browser background tab timing is * not suited towards doing precise measurements of operations. By default, we recommend that this option * be enabled as background transactions can mess up your statistics in nondeterministic ways. + * * Default: true - * @deprecated Configure `markBackgroundSpan` instead. */ - markBackgroundTransactions?: boolean; + markBackgroundTransactions: boolean; /** * If true, Sentry will capture long tasks and add them to the corresponding transaction. @@ -145,12 +117,6 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions { onStartRouteTransaction: (t: Transaction | undefined, ctx: TransactionContext, getCurrentHub: () => Hub) => void; }>; - /** - * A callback which is called before a span for a pageload or navigation is started. - * It receives the options passed to `startSpan`, and expects to return an updated options object. - */ - beforeStartSpan?: (options: StartSpanOptions) => StartSpanOptions; - /** * beforeNavigate is called before a pageload/navigation transaction is created and allows users to modify transaction * context data, or drop the transaction entirely (by setting `sampled = false` in the context). @@ -160,8 +126,6 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions { * @param context: The context data which will be passed to `startTransaction` by default * * @returns A (potentially) modified context object, with `sampled = false` if the transaction should be dropped. - * - * @deprecated Use `beforeStartSpan` instead. */ beforeNavigate?(this: void, context: TransactionContext): TransactionContext | undefined; @@ -179,10 +143,10 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions { const DEFAULT_BROWSER_TRACING_OPTIONS: BrowserTracingOptions = { ...TRACING_DEFAULTS, + markBackgroundTransactions: true, routingInstrumentation: instrumentRoutingWithDefaults, - spanOnLocationChange: true, - spanOnPageLoad: true, - markBackgroundSpan: true, + startTransactionOnLocationChange: true, + startTransactionOnPageLoad: true, enableLongTask: true, _experiments: {}, ...defaultRequestInstrumentationOptions, @@ -195,14 +159,6 @@ 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. @@ -226,7 +182,7 @@ export class BrowserTracing implements Integration { private _hasSetTracePropagationTargets: boolean; - public constructor(_options: Partial = {}) { + public constructor(_options?: Partial) { this.name = BROWSER_TRACING_INTEGRATION_ID; this._hasSetTracePropagationTargets = false; @@ -234,34 +190,12 @@ export class BrowserTracing implements Integration { if (DEBUG_BUILD) { this._hasSetTracePropagationTargets = !!( + _options && // eslint-disable-next-line deprecation/deprecation (_options.tracePropagationTargets || _options.tracingOrigins) ); } - // Migrate legacy options - // TODO v8: Remove this - /* eslint-disable deprecation/deprecation */ - if (typeof _options.startTransactionOnPageLoad === 'boolean') { - _options.spanOnPageLoad = _options.startTransactionOnPageLoad; - } - if (typeof _options.startTransactionOnLocationChange === 'boolean') { - _options.spanOnLocationChange = _options.startTransactionOnLocationChange; - } - if (typeof _options.markBackgroundTransactions === 'boolean') { - _options.markBackgroundSpan = _options.markBackgroundTransactions; - } - /* eslint-enable deprecation/deprecation */ - - // TODO (v8): remove this block after tracingOrigins is removed - // Set tracePropagationTargets to tracingOrigins if specified by the user - // In case both are specified, tracePropagationTargets takes precedence - // eslint-disable-next-line deprecation/deprecation - if (!_options.tracePropagationTargets && _options.tracingOrigins) { - // eslint-disable-next-line deprecation/deprecation - _options.tracePropagationTargets = _options.tracingOrigins; - } - this.options = { ...DEFAULT_BROWSER_TRACING_OPTIONS, ..._options, @@ -273,6 +207,15 @@ export class BrowserTracing implements Integration { this.options.enableLongTask = this.options._experiments.enableLongTask; } + // TODO (v8): remove this block after tracingOrigins is removed + // Set tracePropagationTargets to tracingOrigins if specified by the user + // In case both are specified, tracePropagationTargets takes precedence + // eslint-disable-next-line deprecation/deprecation + if (_options && !_options.tracePropagationTargets && _options.tracingOrigins) { + // eslint-disable-next-line deprecation/deprecation + this.options.tracePropagationTargets = _options.tracingOrigins; + } + this._collectWebVitals = startTrackingWebVitals(); if (this.options.enableLongTask) { startTrackingLongTasks(); @@ -294,9 +237,9 @@ export class BrowserTracing implements Integration { const { routingInstrumentation: instrumentRouting, - spanOnPageLoad, - spanOnLocationChange, - markBackgroundSpan, + startTransactionOnLocationChange, + startTransactionOnPageLoad, + markBackgroundTransactions, traceFetch, traceXHR, shouldCreateSpanForRequest, @@ -332,11 +275,11 @@ export class BrowserTracing implements Integration { return transaction; }, - spanOnPageLoad, - spanOnLocationChange, + startTransactionOnPageLoad, + startTransactionOnLocationChange, ); - if (markBackgroundSpan) { + if (markBackgroundTransactions) { registerBackgroundTabDetection(); } @@ -363,14 +306,7 @@ export class BrowserTracing implements Integration { const hub = this._getCurrentHub(); - const { - // eslint-disable-next-line deprecation/deprecation - beforeNavigate, - beforeStartSpan, - idleTimeout, - finalTimeout, - heartbeatInterval, - } = this.options; + const { beforeNavigate, idleTimeout, finalTimeout, heartbeatInterval } = this.options; const isPageloadTransaction = context.op === 'pageload'; @@ -392,11 +328,7 @@ export class BrowserTracing implements Integration { trimEnd: true, }; - const contextAfterProcessing = beforeStartSpan ? beforeStartSpan(expandedContext) : expandedContext; - - const modifiedContext = - // eslint-disable-next-line deprecation/deprecation - typeof beforeNavigate === 'function' ? beforeNavigate(contextAfterProcessing) : contextAfterProcessing; + const modifiedContext = typeof beforeNavigate === 'function' ? beforeNavigate(expandedContext) : expandedContext; // For backwards compatibility reasons, beforeNavigate can return undefined to "drop" the transaction (prevent it // from being sent to Sentry). diff --git a/packages/tracing-internal/src/browser/index.ts b/packages/tracing-internal/src/browser/index.ts index d9a17641b2b4..5b30bc519404 100644 --- a/packages/tracing-internal/src/browser/index.ts +++ b/packages/tracing-internal/src/browser/index.ts @@ -2,12 +2,7 @@ export * from '../exports'; export type { RequestInstrumentationOptions } from './request'; -export { - // eslint-disable-next-line deprecation/deprecation - BrowserTracing, - browserTracingIntegration, - BROWSER_TRACING_INTEGRATION_ID, -} from './browsertracing'; +export { BrowserTracing, 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 5e8791018c6f..495d8dbb26b9 100644 --- a/packages/tracing-internal/src/index.ts +++ b/packages/tracing-internal/src/index.ts @@ -13,9 +13,7 @@ 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-internal/test/browser/browsertracing.test.ts b/packages/tracing-internal/test/browser/browsertracing.test.ts index 0892169c28a2..b9830b8d754c 100644 --- a/packages/tracing-internal/test/browser/browsertracing.test.ts +++ b/packages/tracing-internal/test/browser/browsertracing.test.ts @@ -85,6 +85,61 @@ conditionalTest({ min: 10 })('BrowserTracing', () => { return instance; } + // These are important enough to check with a test as incorrect defaults could + // break a lot of users' configurations. + it('is created with default settings', () => { + const browserTracing = createBrowserTracing(); + + expect(browserTracing.options).toEqual({ + enableLongTask: true, + _experiments: {}, + ...TRACING_DEFAULTS, + markBackgroundTransactions: true, + routingInstrumentation: instrumentRoutingWithDefaults, + startTransactionOnLocationChange: true, + startTransactionOnPageLoad: true, + ...defaultRequestInstrumentationOptions, + }); + }); + + it('is allows to disable enableLongTask via _experiments', () => { + const browserTracing = createBrowserTracing(false, { + _experiments: { + enableLongTask: false, + }, + }); + + expect(browserTracing.options).toEqual({ + enableLongTask: false, + ...TRACING_DEFAULTS, + markBackgroundTransactions: true, + routingInstrumentation: instrumentRoutingWithDefaults, + startTransactionOnLocationChange: true, + startTransactionOnPageLoad: true, + ...defaultRequestInstrumentationOptions, + _experiments: { + enableLongTask: false, + }, + }); + }); + + it('is allows to disable enableLongTask', () => { + const browserTracing = createBrowserTracing(false, { + enableLongTask: false, + }); + + expect(browserTracing.options).toEqual({ + enableLongTask: false, + _experiments: {}, + ...TRACING_DEFAULTS, + markBackgroundTransactions: true, + routingInstrumentation: instrumentRoutingWithDefaults, + startTransactionOnLocationChange: true, + startTransactionOnPageLoad: true, + ...defaultRequestInstrumentationOptions, + }); + }); + /** * All of these tests under `describe('route transaction')` are tested with * `browserTracing.options = { routingInstrumentation: customInstrumentRouting }`, @@ -332,71 +387,6 @@ conditionalTest({ min: 10 })('BrowserTracing', () => { }); }); - describe('beforeStartSpan', () => { - it('is called on transaction creation', () => { - const beforeStartSpan = jest.fn().mockReturnValue({ name: 'here/is/my/path' }); - createBrowserTracing(true, { - beforeStartSpan, - routingInstrumentation: customInstrumentRouting, - }); - const transaction = getActiveTransaction(hub) as IdleTransaction; - expect(transaction).toBeDefined(); - - expect(beforeStartSpan).toHaveBeenCalledTimes(1); - }); - - it('can override default context values', () => { - const beforeStartSpan = jest.fn(ctx => ({ - ...ctx, - op: 'not-pageload', - })); - createBrowserTracing(true, { - beforeStartSpan, - routingInstrumentation: customInstrumentRouting, - }); - const transaction = getActiveTransaction(hub) as IdleTransaction; - expect(transaction).toBeDefined(); - expect(transaction.op).toBe('not-pageload'); - - expect(beforeStartSpan).toHaveBeenCalledTimes(1); - }); - - it("sets transaction name source to `'custom'` if name is changed", () => { - const beforeStartSpan = jest.fn(ctx => ({ - ...ctx, - name: 'newName', - })); - createBrowserTracing(true, { - beforeStartSpan, - routingInstrumentation: customInstrumentRouting, - }); - const transaction = getActiveTransaction(hub) as IdleTransaction; - expect(transaction).toBeDefined(); - expect(transaction.name).toBe('newName'); - expect(transaction.metadata.source).toBe('custom'); - - expect(beforeStartSpan).toHaveBeenCalledTimes(1); - }); - - it('sets transaction name source to default `url` if name is not changed', () => { - const beforeStartSpan = jest.fn(ctx => ({ - ...ctx, - })); - createBrowserTracing(true, { - beforeStartSpan, - routingInstrumentation: (customStartTransaction: (obj: any) => void) => { - customStartTransaction({ name: 'a/path', op: 'pageload', metadata: { source: 'url' } }); - }, - }); - const transaction = getActiveTransaction(hub) as IdleTransaction; - expect(transaction).toBeDefined(); - expect(transaction.name).toBe('a/path'); - expect(transaction.metadata.source).toBe('url'); - - expect(beforeStartSpan).toHaveBeenCalledTimes(1); - }); - }); - it('sets transaction context from sentry-trace header', () => { const name = 'sentry-trace'; const content = '126de09502ae4e0fb26c6967190756a4-b6e54397b12a2a0f-1'; @@ -709,58 +699,4 @@ conditionalTest({ min: 10 })('BrowserTracing', () => { ); }); }); - - describe('options', () => { - // These are important enough to check with a test as incorrect defaults could - // break a lot of users' configurations. - it('is created with default settings', () => { - const browserTracing = createBrowserTracing(); - - expect(browserTracing.options).toEqual({ - enableLongTask: true, - _experiments: {}, - ...TRACING_DEFAULTS, - routingInstrumentation: instrumentRoutingWithDefaults, - spanOnLocationChange: true, - spanOnPageLoad: true, - markBackgroundSpan: true, - ...defaultRequestInstrumentationOptions, - }); - }); - - it('handles legacy `startTransactionOnLocationChange` option', () => { - const integration = new BrowserTracing({ startTransactionOnLocationChange: false }); - expect(integration.options.spanOnLocationChange).toBe(false); - }); - - it('handles legacy `startTransactionOnPageLoad` option', () => { - const integration = new BrowserTracing({ startTransactionOnPageLoad: false }); - expect(integration.options.spanOnPageLoad).toBe(false); - }); - - it('handles legacy `markBackgroundTransactions` option', () => { - const integration = new BrowserTracing({ markBackgroundTransactions: false }); - expect(integration.options.markBackgroundSpan).toBe(false); - }); - - it('allows to disable enableLongTask via _experiments', () => { - const browserTracing = createBrowserTracing(false, { - _experiments: { - enableLongTask: false, - }, - }); - - expect(browserTracing.options.enableLongTask).toBe(false); - expect(browserTracing.options._experiments.enableLongTask).toBe(false); - }); - - it('allows to disable enableLongTask', () => { - const browserTracing = createBrowserTracing(false, { - enableLongTask: false, - }); - - expect(browserTracing.options.enableLongTask).toBe(false); - expect(browserTracing.options._experiments.enableLongTask).toBe(undefined); - }); - }); }); diff --git a/packages/tracing/src/index.ts b/packages/tracing/src/index.ts index b0a5b47554ae..8559188884d7 100644 --- a/packages/tracing/src/index.ts +++ b/packages/tracing/src/index.ts @@ -38,7 +38,6 @@ 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 @@ -51,7 +50,6 @@ export const BrowserTracing = BrowserTracingT; * import { BrowserTracing } from '@sentry/browser'; * new BrowserTracing() */ -// eslint-disable-next-line deprecation/deprecation export type BrowserTracing = BrowserTracingT; /** diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index ca4c976db1c8..7f9d66c904fa 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -100,7 +100,6 @@ export type { SpanContextData, TraceFlag, } from './span'; -export type { StartSpanOptions } from './startSpanOptions'; export type { StackFrame } from './stackframe'; export type { Stacktrace, StackParser, StackLineParser, StackLineParserFn } from './stacktrace'; export type { TextEncoderInternal } from './textencoder'; diff --git a/packages/types/src/startSpanOptions.ts b/packages/types/src/startSpanOptions.ts deleted file mode 100644 index 49f81250008c..000000000000 --- a/packages/types/src/startSpanOptions.ts +++ /dev/null @@ -1,104 +0,0 @@ -import type { Instrumenter } from './instrumenter'; -import type { Primitive } from './misc'; -import type { Scope } from './scope'; -import type { SpanAttributes, SpanOrigin, SpanTimeInput } from './span'; -import type { TransactionContext, TransactionMetadata, TransactionSource } from './transaction'; - -export interface StartSpanOptions extends TransactionContext { - /** A manually specified start time for the created `Span` object. */ - startTime?: SpanTimeInput; - - /** If defined, start this span off this scope instead off the current scope. */ - scope?: Scope; - - /** The name of the span. */ - name: string; - - /** An op for the span. This is a categorization for spans. */ - op?: string; - - /** The origin of the span - if it comes from auto instrumenation or manual instrumentation. */ - origin?: SpanOrigin; - - /** Attributes for the span. */ - attributes?: SpanAttributes; - - // All remaining fields are deprecated - - /** - * @deprecated Manually set the end timestamp instead. - */ - trimEnd?: boolean; - - /** - * @deprecated This cannot be set manually anymore. - */ - parentSampled?: boolean; - - /** - * @deprecated Use attributes or set data on scopes instead. - */ - metadata?: Partial; - - /** - * The name thingy. - * @deprecated Use `name` instead. - */ - description?: string; - - /** - * @deprecated Use `span.setStatus()` instead. - */ - status?: string; - - /** - * @deprecated Use `scope` instead. - */ - parentSpanId?: string; - - /** - * @deprecated You cannot manually set the span to sampled anymore. - */ - sampled?: boolean; - - /** - * @deprecated You cannot manually set the spanId anymore. - */ - spanId?: string; - - /** - * @deprecated You cannot manually set the traceId anymore. - */ - traceId?: string; - - /** - * @deprecated Use an attribute instead. - */ - source?: TransactionSource; - - /** - * @deprecated Use attributes or set tags on the scope instead. - */ - tags?: { [key: string]: Primitive }; - - /** - * @deprecated Use attributes instead. - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - data?: { [key: string]: any }; - - /** - * @deprecated Use `startTime` instead. - */ - startTimestamp?: number; - - /** - * @deprecated Use `span.end()` instead. - */ - endTimestamp?: number; - - /** - * @deprecated You cannot set the instrumenter manually anymore. - */ - instrumenter?: Instrumenter; -}