1
1
import { applySdkMetadata , hasTracingEnabled } from '@sentry/core' ;
2
2
import type { BrowserOptions } from '@sentry/react' ;
3
3
import {
4
- Integrations as OriginalIntegrations ,
4
+ DEFAULT_TRACE_PROPAGATION_TARGETS ,
5
5
getCurrentScope ,
6
6
getDefaultIntegrations as getReactDefaultIntegrations ,
7
7
init as reactInit ,
@@ -11,47 +11,38 @@ import type { EventProcessor, Integration } from '@sentry/types';
11
11
import { devErrorSymbolicationEventProcessor } from '../common/devErrorSymbolicationEventProcessor' ;
12
12
import { getVercelEnv } from '../common/getVercelEnv' ;
13
13
import { browserTracingIntegration } from './browserTracingIntegration' ;
14
- import { BrowserTracing } from './browserTracingIntegration' ;
15
- import { rewriteFramesIntegration } from './rewriteFramesIntegration' ;
14
+ import { nextjsClientStackFrameNormalizationIntegration } from './clientNormalizationIntegration' ;
16
15
import { applyTunnelRouteOption } from './tunnelRoute' ;
17
16
18
17
export * from '@sentry/react' ;
19
- // eslint-disable-next-line deprecation/deprecation
20
- export { nextRouterInstrumentation } from './routing/nextRoutingInstrumentation' ;
18
+
21
19
export { captureUnderscoreErrorException } from '../common/_error' ;
22
20
23
- /** @deprecated Import the integration function directly, e.g. `inboundFiltersIntegration()` instead of `new Integrations.InboundFilter(). */
24
- export const Integrations = {
25
- // eslint-disable-next-line deprecation/deprecation
26
- ...OriginalIntegrations ,
27
- BrowserTracing,
21
+ const globalWithInjectedValues = global as typeof global & {
22
+ __rewriteFramesAssetPrefixPath__ : string ;
28
23
} ;
29
24
30
- // Previously we expected users to import `BrowserTracing` like this:
31
- //
32
- // import { Integrations } from '@sentry/nextjs';
33
- // const instance = new Integrations.BrowserTracing();
34
- //
35
- // This makes the integrations unable to be treeshaken though. To address this, we now have
36
- // this individual export. We now expect users to consume BrowserTracing like so:
37
- //
38
- // import { BrowserTracing } from '@sentry/nextjs';
39
- // const instance = new BrowserTracing();
40
- // eslint-disable-next-line deprecation/deprecation
41
- export { BrowserTracing , rewriteFramesIntegration } ;
42
-
43
25
// Treeshakable guard to remove all code related to tracing
44
26
declare const __SENTRY_TRACING__ : boolean ;
45
27
46
28
/** Inits the Sentry NextJS SDK on the browser with the React SDK. */
47
29
export function init ( options : BrowserOptions ) : void {
48
30
const opts = {
49
31
environment : getVercelEnv ( true ) || process . env . NODE_ENV ,
32
+
33
+ tracePropagationTargets :
34
+ process . env . NODE_ENV === 'development'
35
+ ? [
36
+ // Will match any URL that contains "localhost" but not "webpack.hot-update.json" - The webpack dev-server
37
+ // has cors and it doesn't like extra headers when it's accessed from a different URL.
38
+ // TODO(v8): Ideally we rework our tracePropagationTargets logic so this hack won't be necessary anymore (see issue #9764)
39
+ / ^ (? = .* l o c a l h o s t ) (? ! .* w e b p a c k \. h o t - u p d a t e \. j s o n ) .* / ,
40
+ / ^ \/ (? ! \/ ) / ,
41
+ ]
42
+ : [ ...DEFAULT_TRACE_PROPAGATION_TARGETS , / ^ ( a p i \/ ) / ] ,
50
43
defaultIntegrations : getDefaultIntegrations ( options ) ,
51
44
...options ,
52
- } ;
53
-
54
- fixBrowserTracingIntegration ( opts ) ;
45
+ } satisfies BrowserOptions ;
55
46
56
47
applyTunnelRouteOption ( opts ) ;
57
48
applySdkMetadata ( opts , 'nextjs' , [ 'nextjs' , 'react' ] ) ;
@@ -70,65 +61,8 @@ export function init(options: BrowserOptions): void {
70
61
}
71
62
}
72
63
73
- // TODO v8: Remove this again
74
- // We need to handle BrowserTracing passed to `integrations` that comes from `@sentry/tracing`, not `@sentry/nextjs` :(
75
- function fixBrowserTracingIntegration ( options : BrowserOptions ) : void {
76
- const { integrations } = options ;
77
- if ( ! integrations ) {
78
- return ;
79
- }
80
-
81
- if ( Array . isArray ( integrations ) ) {
82
- options . integrations = maybeUpdateBrowserTracingIntegration ( integrations ) ;
83
- } else {
84
- options . integrations = defaultIntegrations => {
85
- const userFinalIntegrations = integrations ( defaultIntegrations ) ;
86
-
87
- return maybeUpdateBrowserTracingIntegration ( userFinalIntegrations ) ;
88
- } ;
89
- }
90
- }
91
-
92
- function isNewBrowserTracingIntegration (
93
- integration : Integration ,
94
- ) : integration is Integration & { options ?: Parameters < typeof browserTracingIntegration > [ 0 ] } {
95
- // eslint-disable-next-line deprecation/deprecation
96
- return ! ! integration . afterAllSetup && ! ! ( integration as BrowserTracing ) . options ;
97
- }
98
-
99
- function maybeUpdateBrowserTracingIntegration ( integrations : Integration [ ] ) : Integration [ ] {
100
- const browserTracing = integrations . find ( integration => integration . name === 'BrowserTracing' ) ;
101
-
102
- if ( ! browserTracing ) {
103
- return integrations ;
104
- }
105
-
106
- // If `browserTracingIntegration()` was added, we need to force-convert it to our custom one
107
- if ( isNewBrowserTracingIntegration ( browserTracing ) ) {
108
- const { options } = browserTracing ;
109
- // eslint-disable-next-line deprecation/deprecation
110
- integrations [ integrations . indexOf ( browserTracing ) ] = new BrowserTracing ( options ) ;
111
- }
112
-
113
- // If BrowserTracing was added, but it is not our forked version,
114
- // replace it with our forked version with the same options
115
- // eslint-disable-next-line deprecation/deprecation
116
- if ( ! ( browserTracing instanceof BrowserTracing ) ) {
117
- // eslint-disable-next-line deprecation/deprecation
118
- const options : ConstructorParameters < typeof BrowserTracing > [ 0 ] = ( browserTracing as BrowserTracing ) . options ;
119
- // This option is overwritten by the custom integration
120
- delete options . routingInstrumentation ;
121
- // eslint-disable-next-line deprecation/deprecation
122
- delete options . tracingOrigins ;
123
- // eslint-disable-next-line deprecation/deprecation
124
- integrations [ integrations . indexOf ( browserTracing ) ] = new BrowserTracing ( options ) ;
125
- }
126
-
127
- return integrations ;
128
- }
129
-
130
64
function getDefaultIntegrations ( options : BrowserOptions ) : Integration [ ] {
131
- const customDefaultIntegrations = [ ... getReactDefaultIntegrations ( options ) , rewriteFramesIntegration ( ) ] ;
65
+ const customDefaultIntegrations = getReactDefaultIntegrations ( options ) ;
132
66
133
67
// This evaluates to true unless __SENTRY_TRACING__ is text-replaced with "false", in which case everything inside
134
68
// will get treeshaken away
@@ -138,6 +72,11 @@ function getDefaultIntegrations(options: BrowserOptions): Integration[] {
138
72
}
139
73
}
140
74
75
+ // This value is injected at build time, based on the output directory specified in the build config. Though a default
76
+ // is set there, we set it here as well, just in case something has gone wrong with the injection.
77
+ const assetPrefixPath = globalWithInjectedValues . __rewriteFramesAssetPrefixPath__ || '' ;
78
+ customDefaultIntegrations . push ( nextjsClientStackFrameNormalizationIntegration ( { assetPrefixPath } ) ) ;
79
+
141
80
return customDefaultIntegrations ;
142
81
}
143
82
0 commit comments