1
- import { configureScope , init as reactInit , Integrations as BrowserIntegrations } from '@sentry/react' ;
1
+ import { configureScope , init as reactInit , Integrations } from '@sentry/react' ;
2
2
import { BrowserTracing , defaultRequestInstrumentationOptions } from '@sentry/tracing' ;
3
3
import { EventProcessor } from '@sentry/types' ;
4
4
@@ -10,12 +10,8 @@ import { addIntegration, UserIntegrations } from './utils/userIntegrations';
10
10
export * from '@sentry/react' ;
11
11
export { nextRouterInstrumentation } from './performance/client' ;
12
12
13
- export const Integrations = { ... BrowserIntegrations , BrowserTracing } ;
13
+ export { Integrations } ;
14
14
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
- //
19
15
// Previously we expected users to import `BrowserTracing` like this:
20
16
//
21
17
// import { Integrations } from '@sentry/nextjs';
@@ -28,16 +24,23 @@ export const Integrations = { ...BrowserIntegrations, BrowserTracing };
28
24
// const instance = new BrowserTracing();
29
25
export { BrowserTracing } ;
30
26
27
+ // Treeshakable guard to remove all code related to tracing
28
+ declare const __SENTRY_TRACING__ : boolean ;
29
+
31
30
/** Inits the Sentry NextJS SDK on the browser with the React SDK. */
32
31
export function init ( options : NextjsOptions ) : void {
33
32
buildMetadata ( options , [ 'nextjs' , 'react' ] ) ;
34
33
options . environment = options . environment || process . env . NODE_ENV ;
35
34
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
+ }
41
44
42
45
reactInit ( {
43
46
...options ,
@@ -53,12 +56,12 @@ export function init(options: NextjsOptions): void {
53
56
} ) ;
54
57
}
55
58
56
- const defaultBrowserTracingIntegration = new BrowserTracing ( {
57
- tracingOrigins : [ ...defaultRequestInstrumentationOptions . tracingOrigins , / ^ ( a p i \/ ) / ] ,
58
- routingInstrumentation : nextRouterInstrumentation ,
59
- } ) ;
60
-
61
59
function createClientIntegrations ( integrations ?: UserIntegrations ) : UserIntegrations {
60
+ const defaultBrowserTracingIntegration = new BrowserTracing ( {
61
+ tracingOrigins : [ ...defaultRequestInstrumentationOptions . tracingOrigins , / ^ ( a p i \/ ) / ] ,
62
+ routingInstrumentation : nextRouterInstrumentation ,
63
+ } ) ;
64
+
62
65
if ( integrations ) {
63
66
return addIntegration ( defaultBrowserTracingIntegration , integrations , {
64
67
BrowserTracing : { keyPath : 'options.routingInstrumentation' , value : nextRouterInstrumentation } ,
0 commit comments