Skip to content

Commit ca898d9

Browse files
committed
hmm
1 parent 8d639f4 commit ca898d9

File tree

5 files changed

+42
-21
lines changed

5 files changed

+42
-21
lines changed

dev-packages/e2e-tests/test-applications/nextjs-15-spotlight/app/page.tsx

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,35 @@ import * as Sentry from '@sentry/nextjs';
77
const NEXT_PUBLIC_SPOTLIGHT_VALUE = process.env.NEXT_PUBLIC_SENTRY_SPOTLIGHT;
88
// Check internal values (these may or may not be replaced depending on bundler)
99
const INTERNAL_SPOTLIGHT_PROCESS_ENV = process.env._sentrySpotlight;
10-
// @ts-expect-error - accessing globalThis for debugging
11-
const INTERNAL_SPOTLIGHT_GLOBAL = typeof globalThis !== 'undefined' ? globalThis._sentrySpotlight : 'globalThis undefined';
12-
// @ts-expect-error - accessing manual global set in instrumentation-client.ts
13-
const MANUAL_SPOTLIGHT_GLOBAL = typeof globalThis !== 'undefined' ? globalThis._sentrySpotlightManual : 'globalThis undefined';
14-
// @ts-expect-error - accessing SDK debug info
15-
const SDK_DEBUG_INFO = typeof globalThis !== 'undefined' ? globalThis._sentrySpotlightDebug : undefined;
16-
// @ts-expect-error - accessing init marker
17-
const INIT_CALLED = typeof globalThis !== 'undefined' ? globalThis._sentryNextjsInitCalled : undefined;
18-
// @ts-expect-error - accessing init timestamp
19-
const INIT_TIMESTAMP = typeof globalThis !== 'undefined' ? globalThis._sentryNextjsInitTimestamp : undefined;
2010

2111
export default function SpotlightTestPage() {
2212
const [spotlightEnabled, setSpotlightEnabled] = useState<boolean | null>(null);
2313
const [integrationNames, setIntegrationNames] = useState<string[]>([]);
14+
const [debugInfo, setDebugInfo] = useState<{
15+
internalGlobal: string;
16+
manualGlobal: string;
17+
sdkDebug: unknown;
18+
initCalled: unknown;
19+
} | null>(null);
2420

2521
useEffect(() => {
22+
// Read globals at runtime (after init has run)
23+
// @ts-expect-error - accessing globalThis for debugging
24+
const internalGlobal = globalThis._sentrySpotlight;
25+
// @ts-expect-error - accessing manual global
26+
const manualGlobal = globalThis._sentrySpotlightManual;
27+
// @ts-expect-error - accessing SDK debug info
28+
const sdkDebug = globalThis._sentrySpotlightDebug;
29+
// @ts-expect-error - accessing init marker
30+
const initCalled = globalThis._sentryNextjsInitCalled;
31+
32+
setDebugInfo({
33+
internalGlobal: String(internalGlobal ?? 'undefined'),
34+
manualGlobal: String(manualGlobal ?? 'undefined'),
35+
sdkDebug,
36+
initCalled,
37+
});
38+
2639
// Check if Spotlight integration is registered
2740
const client = Sentry.getClient();
2841
const integration = client?.getIntegrationByName?.('SpotlightBrowser');
@@ -37,9 +50,10 @@ export default function SpotlightTestPage() {
3750
console.log('Spotlight test results:', {
3851
envValue: NEXT_PUBLIC_SPOTLIGHT_VALUE,
3952
internalProcessEnv: INTERNAL_SPOTLIGHT_PROCESS_ENV,
40-
internalGlobal: INTERNAL_SPOTLIGHT_GLOBAL,
41-
manualGlobal: MANUAL_SPOTLIGHT_GLOBAL,
42-
sdkDebugInfo: SDK_DEBUG_INFO,
53+
internalGlobal,
54+
manualGlobal,
55+
sdkDebugInfo: sdkDebug,
56+
initCalled,
4357
integrationFound: !!integration,
4458
clientExists: !!client,
4559
integrationNames: intNames,
@@ -54,15 +68,14 @@ export default function SpotlightTestPage() {
5468
<h2>Environment Variable</h2>
5569
<p>NEXT_PUBLIC_SENTRY_SPOTLIGHT: {NEXT_PUBLIC_SPOTLIGHT_VALUE || 'undefined'}</p>
5670
<p>process.env._sentrySpotlight: {String(INTERNAL_SPOTLIGHT_PROCESS_ENV) || 'undefined'}</p>
57-
<p>globalThis._sentrySpotlight: {String(INTERNAL_SPOTLIGHT_GLOBAL) || 'undefined'}</p>
58-
<p>globalThis._sentrySpotlightManual: {String(MANUAL_SPOTLIGHT_GLOBAL) || 'undefined'}</p>
71+
<p>globalThis._sentrySpotlight: {debugInfo?.internalGlobal || 'loading...'}</p>
72+
<p>globalThis._sentrySpotlightManual: {debugInfo?.manualGlobal || 'loading...'}</p>
5973
</div>
6074

6175
<div data-testid="sdk-debug">
6276
<h2>SDK Debug Info (what SDK saw during init)</h2>
63-
<p>init() called: {String(INIT_CALLED)}</p>
64-
<p>init() timestamp: {String(INIT_TIMESTAMP)}</p>
65-
<pre>{SDK_DEBUG_INFO ? JSON.stringify(SDK_DEBUG_INFO, null, 2) : 'No debug info'}</pre>
77+
<p>init() called: {String(debugInfo?.initCalled ?? 'loading...')}</p>
78+
<pre>{debugInfo?.sdkDebug ? JSON.stringify(debugInfo.sdkDebug, null, 2) : 'No debug info'}</pre>
6679
</div>
6780

6881
<div data-testid="spotlight-status">
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3+
/// <reference path="./.next/types/routes.d.ts" />
34

45
// NOTE: This file should not be edited
5-
// see https://nextjs.org/docs/basic-features/typescript for more information.
6+
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

dev-packages/e2e-tests/test-applications/nextjs-15-spotlight/tests/spotlight.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ test.describe('Spotlight auto-enablement in Next.js development mode', () => {
77
// Wait for client-side hydration and Sentry initialization
88
await page.waitForTimeout(2000);
99

10+
// Wait a bit for useEffect to run and update state
11+
await page.waitForTimeout(1000);
12+
1013
// Check environment variable is accessible
1114
const envValue = await page.getByTestId('env-value').textContent();
1215
expect(envValue).toContain('true');

packages/nextjs/src/client/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ declare const __SENTRY_TRACING__: boolean;
5252

5353
/** Inits the Sentry NextJS SDK on the browser with the React SDK. */
5454
export function init(options: BrowserOptions): Client | undefined {
55-
// Debug marker to verify this init() is being called
55+
// Debug marker to verify this init() is being called (for e2e tests)
5656
if (typeof globalThis !== 'undefined') {
5757
(globalThis as Record<string, unknown>)._sentryNextjsInitCalled = true;
58-
(globalThis as Record<string, unknown>)._sentryNextjsInitTimestamp = Date.now();
5958
}
6059

6160
if (clientIsInitialized) {

packages/nextjs/src/config/webpack.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,16 @@ export function constructWebpackConfigFunction({
451451
// when NEXT_PUBLIC_SENTRY_SPOTLIGHT is set. We use DefinePlugin because Next.js
452452
// doesn't replace process.env.* in node_modules code.
453453
if (runtime === 'client' && spotlightConfig) {
454+
// eslint-disable-next-line no-console
455+
console.log('[@sentry/nextjs] Webpack DefinePlugin: Injecting process.env._sentrySpotlight =', JSON.stringify(spotlightConfig));
454456
newConfig.plugins.push(
455457
new buildContext.webpack.DefinePlugin({
456458
'process.env._sentrySpotlight': JSON.stringify(spotlightConfig),
457459
}),
458460
);
461+
} else if (runtime === 'client') {
462+
// eslint-disable-next-line no-console
463+
console.log('[@sentry/nextjs] Webpack DefinePlugin: NOT injecting spotlight. runtime=', runtime, 'spotlightConfig=', spotlightConfig);
459464
}
460465

461466
return newConfig;

0 commit comments

Comments
 (0)