11import { applySdkMetadata , hasTracingEnabled } from '@sentry/core' ;
22import type { BrowserOptions } from '@sentry/react' ;
33import {
4- Integrations as OriginalIntegrations ,
4+ DEFAULT_TRACE_PROPAGATION_TARGETS ,
55 getCurrentScope ,
66 getDefaultIntegrations as getReactDefaultIntegrations ,
77 init as reactInit ,
@@ -11,47 +11,38 @@ import type { EventProcessor, Integration } from '@sentry/types';
1111import { devErrorSymbolicationEventProcessor } from '../common/devErrorSymbolicationEventProcessor' ;
1212import { getVercelEnv } from '../common/getVercelEnv' ;
1313import { browserTracingIntegration } from './browserTracingIntegration' ;
14- import { BrowserTracing } from './browserTracingIntegration' ;
15- import { rewriteFramesIntegration } from './rewriteFramesIntegration' ;
14+ import { nextjsClientStackFrameNormalizationIntegration } from './clientNormalizationIntegration' ;
1615import { applyTunnelRouteOption } from './tunnelRoute' ;
1716
1817export * from '@sentry/react' ;
19- // eslint-disable-next-line deprecation/deprecation
20- export { nextRouterInstrumentation } from './routing/nextRoutingInstrumentation' ;
18+
2119export { captureUnderscoreErrorException } from '../common/_error' ;
2220
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 ;
2823} ;
2924
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-
4325// Treeshakable guard to remove all code related to tracing
4426declare const __SENTRY_TRACING__ : boolean ;
4527
4628/** Inits the Sentry NextJS SDK on the browser with the React SDK. */
4729export function init ( options : BrowserOptions ) : void {
4830 const opts = {
4931 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 \/ ) / ] ,
5043 defaultIntegrations : getDefaultIntegrations ( options ) ,
5144 ...options ,
52- } ;
53-
54- fixBrowserTracingIntegration ( opts ) ;
45+ } satisfies BrowserOptions ;
5546
5647 applyTunnelRouteOption ( opts ) ;
5748 applySdkMetadata ( opts , 'nextjs' , [ 'nextjs' , 'react' ] ) ;
@@ -70,65 +61,8 @@ export function init(options: BrowserOptions): void {
7061 }
7162}
7263
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-
13064function getDefaultIntegrations ( options : BrowserOptions ) : Integration [ ] {
131- const customDefaultIntegrations = [ ... getReactDefaultIntegrations ( options ) , rewriteFramesIntegration ( ) ] ;
65+ const customDefaultIntegrations = getReactDefaultIntegrations ( options ) ;
13266
13367 // This evaluates to true unless __SENTRY_TRACING__ is text-replaced with "false", in which case everything inside
13468 // will get treeshaken away
@@ -138,6 +72,11 @@ function getDefaultIntegrations(options: BrowserOptions): Integration[] {
13872 }
13973 }
14074
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+
14180 return customDefaultIntegrations ;
14281}
14382
0 commit comments