1
1
import { configureScope , init as reactInit , Integrations } from '@sentry/react' ;
2
- import { BrowserTracing , defaultRequestInstrumentationOptions } from '@sentry/tracing' ;
2
+ import { BrowserTracing , defaultRequestInstrumentationOptions , hasTracingEnabled } from '@sentry/tracing' ;
3
3
import { EventProcessor } from '@sentry/types' ;
4
4
5
5
import { nextRouterInstrumentation } from './performance/client' ;
6
6
import { buildMetadata } from './utils/metadata' ;
7
7
import { NextjsOptions } from './utils/nextjsOptions' ;
8
- import { addOrUpdateIntegration , UserIntegrations } from './utils/userIntegrations' ;
8
+ import { addOrUpdateIntegration } from './utils/userIntegrations' ;
9
9
10
10
export * from '@sentry/react' ;
11
11
export { nextRouterInstrumentation } from './performance/client' ;
@@ -32,21 +32,9 @@ declare const __SENTRY_TRACING__: boolean;
32
32
export function init ( options : NextjsOptions ) : void {
33
33
buildMetadata ( options , [ 'nextjs' , 'react' ] ) ;
34
34
options . environment = options . environment || process . env . NODE_ENV ;
35
+ addClientIntegrations ( options ) ;
35
36
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 ) ;
50
38
51
39
configureScope ( scope => {
52
40
scope . setTag ( 'runtime' , 'browser' ) ;
@@ -57,14 +45,24 @@ export function init(options: NextjsOptions): void {
57
45
} ) ;
58
46
}
59
47
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 || [ ] ;
66
50
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 ;
70
68
}
0 commit comments