1- import { configureScope , init as reactInit , Integrations as BrowserIntegrations } from '@sentry/react' ;
1+ import { configureScope , init as reactInit , Integrations } from '@sentry/react' ;
22import { BrowserTracing , defaultRequestInstrumentationOptions } from '@sentry/tracing' ;
33import { EventProcessor } from '@sentry/types' ;
44
@@ -10,12 +10,8 @@ import { addIntegration, UserIntegrations } from './utils/userIntegrations';
1010export * from '@sentry/react' ;
1111export { nextRouterInstrumentation } from './performance/client' ;
1212
13- export const Integrations = { ... BrowserIntegrations , BrowserTracing } ;
13+ export { Integrations } ;
1414
15- // This is already exported as part of `Integrations` above (and for the moment will remain so for
16- // backwards compatibility), but that interferes with treeshaking, so we also export it separately
17- // here.
18- //
1915// Previously we expected users to import `BrowserTracing` like this:
2016//
2117// import { Integrations } from '@sentry/nextjs';
@@ -28,16 +24,23 @@ export const Integrations = { ...BrowserIntegrations, BrowserTracing };
2824// const instance = new BrowserTracing();
2925export { BrowserTracing } ;
3026
27+ // Treeshakable guard to remove all code related to tracing
28+ declare const __SENTRY_TRACING__ : boolean ;
29+
3130/** Inits the Sentry NextJS SDK on the browser with the React SDK. */
3231export function init ( options : NextjsOptions ) : void {
3332 buildMetadata ( options , [ 'nextjs' , 'react' ] ) ;
3433 options . environment = options . environment || process . env . NODE_ENV ;
3534
36- // Only add BrowserTracing if a tracesSampleRate or tracesSampler is set
37- const integrations =
38- options . tracesSampleRate === undefined && options . tracesSampler === undefined
39- ? options . integrations
40- : createClientIntegrations ( options . integrations ) ;
35+ let integrations = options . integrations ;
36+
37+ // Guard below evaluates to true unless __SENTRY_TRACING__ is text-replaced with "false"
38+ if ( typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__ ) {
39+ // Only add BrowserTracing if a tracesSampleRate or tracesSampler is set
40+ if ( options . tracesSampleRate !== undefined || options . tracesSampler !== undefined ) {
41+ integrations = createClientIntegrations ( options . integrations ) ;
42+ }
43+ }
4144
4245 reactInit ( {
4346 ...options ,
@@ -53,12 +56,12 @@ export function init(options: NextjsOptions): void {
5356 } ) ;
5457}
5558
56- const defaultBrowserTracingIntegration = new BrowserTracing ( {
57- tracingOrigins : [ ...defaultRequestInstrumentationOptions . tracingOrigins , / ^ ( a p i \/ ) / ] ,
58- routingInstrumentation : nextRouterInstrumentation ,
59- } ) ;
60-
6159function createClientIntegrations ( integrations ?: UserIntegrations ) : UserIntegrations {
60+ const defaultBrowserTracingIntegration = new BrowserTracing ( {
61+ tracingOrigins : [ ...defaultRequestInstrumentationOptions . tracingOrigins , / ^ ( a p i \/ ) / ] ,
62+ routingInstrumentation : nextRouterInstrumentation ,
63+ } ) ;
64+
6265 if ( integrations ) {
6366 return addIntegration ( defaultBrowserTracingIntegration , integrations , {
6467 BrowserTracing : { keyPath : 'options.routingInstrumentation' , value : nextRouterInstrumentation } ,
0 commit comments