File tree Expand file tree Collapse file tree 4 files changed +7
-38
lines changed
e2e-tests/test-applications/nextjs-15-spotlight Expand file tree Collapse file tree 4 files changed +7
-38
lines changed Original file line number Diff line number Diff line change 11import * as Sentry from '@sentry/nextjs' ;
22
3- // In Next.js 15, Turbopack is the default dev bundler. Turbopack doesn't replace
4- // process.env vars in node_modules code, which prevents the SDK's auto-detection
5- // from working. As a workaround, we explicitly pass the spotlight value from
6- // process.env which Next.js DOES replace in user code.
7- //
8- // Note: Auto-detection DOES work in:
9- // - Next.js with webpack (older versions or configured to use webpack)
10- // - Other frameworks like Vite, Create React App, etc.
3+ // In Next.js 15 Turbopack dev mode, custom loaders aren't applied to instrumentation files.
4+ // So we need to explicitly pass the spotlight value from process.env which Next.js DOES replace.
5+ // This is a workaround for the valueInjectionLoader not working in Turbopack.
116const spotlightValue = process . env . NEXT_PUBLIC_SENTRY_SPOTLIGHT === 'true' ;
127
138console . log ( '[Sentry Debug] Spotlight from process.env:' , spotlightValue ) ;
Original file line number Diff line number Diff line change 55 "scripts" : {
66 "dev" : " next dev -p 3030" ,
77 "build" : " next build" ,
8- "start" : " next start -p 3030" ,
98 "test" : " playwright test" ,
109 "test:build" : " pnpm install" ,
1110 "test:assert" : " pnpm test"
Original file line number Diff line number Diff line change 11import { getPlaywrightConfig } from '@sentry-internal/test-utils' ;
22
33const config = getPlaywrightConfig ( {
4- // Use next dev to test development-mode behavior where Spotlight is auto-enabled.
5- // Note: In Next.js 15, Turbopack is the default dev bundler and doesn't replace
6- // process.env vars in node_modules code. This prevents the SDK's auto-detection
7- // from working, so the test explicitly passes the spotlight value.
4+ // Use next dev to test development-mode behavior where Spotlight is auto-enabled
85 startCommand : 'pnpm dev' ,
96 port : 3030 ,
107 eventProxyFile : 'start-event-proxy.mjs' ,
Original file line number Diff line number Diff line change @@ -82,30 +82,6 @@ export function getPlaywrightConfig(
8282 } ;
8383
8484 if ( startCommand ) {
85- // Filter environment variables to only include those that are safe and needed
86- // We avoid passing ALL env vars to prevent unintended side effects in tests
87- const filteredEnv = Object . fromEntries (
88- Object . entries ( process . env ) . filter ( ( [ key ] ) => {
89- // Include E2E test DSN variables (needed by all test apps)
90- if ( key . includes ( 'E2E_TEST_DSN' ) || key === 'E2E_TEST_SENTRY_ORG_SLUG' || key === 'E2E_TEST_SENTRY_PROJECT' ) {
91- return true ;
92- }
93- // Include Spotlight environment variables (needed for Spotlight tests)
94- if ( key . includes ( 'SENTRY_SPOTLIGHT' ) ) {
95- return true ;
96- }
97- // Include Node/npm related variables for proper execution
98- if ( key === 'PATH' || key === 'NODE_ENV' || key === 'HOME' || key === 'USER' ) {
99- return true ;
100- }
101- // Include CI variable for proper test configuration
102- if ( key === 'CI' ) {
103- return true ;
104- }
105- return false ;
106- } ) ,
107- ) ;
108-
10985 // @ts -expect-error - we set `config.webserver` to an array above.
11086 // TS just can't infer that and thinks it could also be undefined or an object.
11187 config . webServer . push ( {
@@ -114,7 +90,9 @@ export function getPlaywrightConfig(
11490 stdout : 'pipe' ,
11591 stderr : 'pipe' ,
11692 env : {
117- ...filteredEnv ,
93+ // Inherit all environment variables from the parent process
94+ // This is needed for env vars like NEXT_PUBLIC_SENTRY_SPOTLIGHT to be passed through
95+ ...process . env ,
11896 PORT : appPort . toString ( ) ,
11997 } ,
12098 } ) ;
You can’t perform that action at this time.
0 commit comments