Skip to content

Commit a313e1c

Browse files
committed
debugging
1 parent d9d7124 commit a313e1c

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,31 @@ import * as Sentry from '@sentry/nextjs';
55

66
// Next.js replaces process.env.NEXT_PUBLIC_* at BUILD TIME with literal values
77
const NEXT_PUBLIC_SPOTLIGHT_VALUE = process.env.NEXT_PUBLIC_SENTRY_SPOTLIGHT;
8+
// Also check the internal _sentrySpotlight that withSentryConfig injects
9+
const INTERNAL_SPOTLIGHT_VALUE = process.env._sentrySpotlight;
810

911
export default function SpotlightTestPage() {
1012
const [spotlightEnabled, setSpotlightEnabled] = useState<boolean | null>(null);
13+
const [integrationNames, setIntegrationNames] = useState<string[]>([]);
1114

1215
useEffect(() => {
1316
// Check if Spotlight integration is registered
1417
const client = Sentry.getClient();
1518
const integration = client?.getIntegrationByName?.('SpotlightBrowser');
1619
setSpotlightEnabled(!!integration);
1720

21+
// Get all integration names for debugging
22+
// @ts-expect-error accessing internal property for debugging
23+
const intNames = client?._integrations ? Object.keys(client._integrations) : [];
24+
setIntegrationNames(intNames);
25+
1826
// Log for debugging
1927
console.log('Spotlight test results:', {
2028
envValue: NEXT_PUBLIC_SPOTLIGHT_VALUE,
29+
internalEnvValue: INTERNAL_SPOTLIGHT_VALUE,
2130
integrationFound: !!integration,
2231
clientExists: !!client,
32+
integrationNames: intNames,
2333
});
2434
}, []);
2535

@@ -30,13 +40,17 @@ export default function SpotlightTestPage() {
3040
<div data-testid="env-value">
3141
<h2>Environment Variable</h2>
3242
<p>NEXT_PUBLIC_SENTRY_SPOTLIGHT: {NEXT_PUBLIC_SPOTLIGHT_VALUE || 'undefined'}</p>
43+
<p>_sentrySpotlight (internal): {INTERNAL_SPOTLIGHT_VALUE || 'undefined'}</p>
3344
</div>
3445

3546
<div data-testid="spotlight-status">
3647
<h2>Spotlight Integration Status</h2>
3748
<p data-testid="spotlight-enabled">
3849
{spotlightEnabled === null ? 'Loading...' : spotlightEnabled ? 'ENABLED' : 'DISABLED'}
3950
</p>
51+
<p data-testid="integration-names">
52+
Integrations: {integrationNames.join(', ') || 'none'}
53+
</p>
4054
</div>
4155
</div>
4256
);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ test.describe('Spotlight auto-enablement in Next.js development mode', () => {
1111
const envValue = await page.getByTestId('env-value').textContent();
1212
expect(envValue).toContain('true');
1313

14+
// Get diagnostic info before asserting
15+
const integrationNames = await page.getByTestId('integration-names').textContent();
16+
1417
// Check Spotlight integration is enabled
1518
const spotlightStatus = await page.getByTestId('spotlight-enabled').textContent();
16-
expect(spotlightStatus).toBe('ENABLED');
19+
expect(spotlightStatus, `Spotlight should be ENABLED. Env value: ${envValue}. Integrations: ${integrationNames}`).toBe(
20+
'ENABLED',
21+
);
1722
});
1823

1924
test('no console errors during initialization', async ({ page }) => {

packages/nextjs/src/client/index.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,27 @@ function getDefaultIntegrations(options: BrowserOptions): Integration[] {
143143
);
144144

145145
// Auto-enable Spotlight from NEXT_PUBLIC_SENTRY_SPOTLIGHT env var
146-
// We read NEXT_PUBLIC_SENTRY_SPOTLIGHT directly because Next.js guarantees that
147-
// NEXT_PUBLIC_* variables are exposed to the browser via webpack DefinePlugin replacement.
148-
// Using a custom _sentrySpotlight variable doesn't work reliably because Next.js doesn't
149-
// always replace arbitrary env vars in node_modules code.
150-
const spotlightEnvValue = process.env.NEXT_PUBLIC_SENTRY_SPOTLIGHT;
146+
// The value is injected at build time via buildTimeVariables in withSentryConfig
147+
// following the same pattern as _sentryRelease
148+
const spotlightEnvValue = process.env._sentrySpotlight;
149+
// eslint-disable-next-line no-console
150+
console.log('[Sentry Next.js] Spotlight debug:', {
151+
spotlightEnvValue,
152+
optionsSpotlight: options.spotlight,
153+
typeofSpotlightEnvValue: typeof spotlightEnvValue,
154+
});
151155
if (spotlightEnvValue !== undefined && options.spotlight === undefined) {
152156
const boolValue = envToBool(spotlightEnvValue, { strict: true });
153157
const spotlightConfig = boolValue !== null ? boolValue : spotlightEnvValue;
154158
const spotlightValue = resolveSpotlightOptions(undefined, spotlightConfig);
159+
// eslint-disable-next-line no-console
160+
console.log('[Sentry Next.js] Spotlight resolved:', { boolValue, spotlightConfig, spotlightValue });
155161

156162
if (spotlightValue) {
157163
const spotlightArgs = typeof spotlightValue === 'string' ? { sidecarUrl: spotlightValue } : undefined;
158164
customDefaultIntegrations.push(spotlightBrowserIntegration(spotlightArgs));
165+
// eslint-disable-next-line no-console
166+
console.log('[Sentry Next.js] Spotlight integration added');
159167
}
160168
}
161169

packages/nextjs/src/config/withSentryConfig.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,12 @@ function setUpBuildTimeVariables(
610610
buildTimeVariables._sentryRelease = releaseName;
611611
}
612612

613-
// Note: NEXT_PUBLIC_SENTRY_SPOTLIGHT is read directly in the client code because
614-
// Next.js guarantees that NEXT_PUBLIC_* variables are exposed to the browser.
615-
// No need to inject it as a build-time variable here.
613+
// Inject Spotlight config from NEXT_PUBLIC_SENTRY_SPOTLIGHT env var
614+
// We check both userNextConfig.env (from next.config.js) and process.env (from .env files or shell)
615+
const spotlightValue = userNextConfig.env?.NEXT_PUBLIC_SENTRY_SPOTLIGHT ?? process.env.NEXT_PUBLIC_SENTRY_SPOTLIGHT;
616+
if (spotlightValue) {
617+
buildTimeVariables._sentrySpotlight = spotlightValue;
618+
}
616619

617620
if (typeof userNextConfig.env === 'object') {
618621
userNextConfig.env = { ...buildTimeVariables, ...userNextConfig.env };

0 commit comments

Comments
 (0)