11import { configureScope , init as reactInit , Integrations } from '@sentry/react' ;
2- import { BrowserTracing , defaultRequestInstrumentationOptions } from '@sentry/tracing' ;
2+ import { BrowserTracing , defaultRequestInstrumentationOptions , hasTracingEnabled } from '@sentry/tracing' ;
33import { EventProcessor } from '@sentry/types' ;
44
55import { nextRouterInstrumentation } from './performance/client' ;
66import { buildMetadata } from './utils/metadata' ;
77import { NextjsOptions } from './utils/nextjsOptions' ;
8- import { addOrUpdateIntegration , UserIntegrations } from './utils/userIntegrations' ;
8+ import { addOrUpdateIntegration } from './utils/userIntegrations' ;
99
1010export * from '@sentry/react' ;
1111export { nextRouterInstrumentation } from './performance/client' ;
@@ -32,21 +32,9 @@ declare const __SENTRY_TRACING__: boolean;
3232export function init ( options : NextjsOptions ) : void {
3333 buildMetadata ( options , [ 'nextjs' , 'react' ] ) ;
3434 options . environment = options . environment || process . env . NODE_ENV ;
35+ addClientIntegrations ( options ) ;
3536
36- let integrations = options . integrations ;
37-
38- // Guard below evaluates to true unless __SENTRY_TRACING__ is text-replaced with "false"
39- if ( typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__ ) {
40- // Only add BrowserTracing if a tracesSampleRate or tracesSampler is set
41- if ( options . tracesSampleRate !== undefined || options . tracesSampler !== undefined ) {
42- integrations = createClientIntegrations ( options . integrations ) ;
43- }
44- }
45-
46- reactInit ( {
47- ...options ,
48- integrations,
49- } ) ;
37+ reactInit ( options ) ;
5038
5139 configureScope ( scope => {
5240 scope . setTag ( 'runtime' , 'browser' ) ;
@@ -57,14 +45,24 @@ export function init(options: NextjsOptions): void {
5745 } ) ;
5846}
5947
60- function createClientIntegrations ( userIntegrations : UserIntegrations = [ ] ) : UserIntegrations {
61- const defaultBrowserTracingIntegration = new BrowserTracing ( {
62- // eslint-disable-next-line deprecation/deprecation
63- tracingOrigins : [ ...defaultRequestInstrumentationOptions . tracingOrigins , / ^ ( a p i \/ ) / ] ,
64- routingInstrumentation : nextRouterInstrumentation ,
65- } ) ;
48+ function addClientIntegrations ( options : NextjsOptions ) : void {
49+ let integrations = options . integrations || [ ] ;
6650
67- return addOrUpdateIntegration ( defaultBrowserTracingIntegration , userIntegrations , {
68- 'options.routingInstrumentation' : nextRouterInstrumentation ,
69- } ) ;
51+ // This evaluates to true unless __SENTRY_TRACING__ is text-replaced with "false", in which case everything inside
52+ // will get treeshaken away
53+ if ( typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__ ) {
54+ if ( hasTracingEnabled ( options ) ) {
55+ const defaultBrowserTracingIntegration = new BrowserTracing ( {
56+ // eslint-disable-next-line deprecation/deprecation
57+ tracingOrigins : [ ...defaultRequestInstrumentationOptions . tracingOrigins , / ^ ( a p i \/ ) / ] ,
58+ routingInstrumentation : nextRouterInstrumentation ,
59+ } ) ;
60+
61+ integrations = addOrUpdateIntegration ( defaultBrowserTracingIntegration , integrations , {
62+ 'options.routingInstrumentation' : nextRouterInstrumentation ,
63+ } ) ;
64+ }
65+ }
66+
67+ options . integrations = integrations ;
7068}
0 commit comments