Skip to content

Commit 2346b4c

Browse files
committed
moare debug
1 parent e32150d commit 2346b4c

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,34 @@ 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+
// Check internal values (these may or may not be replaced depending on bundler)
9+
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';
812

913
export default function SpotlightTestPage() {
1014
const [spotlightEnabled, setSpotlightEnabled] = useState<boolean | null>(null);
15+
const [integrationNames, setIntegrationNames] = useState<string[]>([]);
1116

1217
useEffect(() => {
1318
// Check if Spotlight integration is registered
1419
const client = Sentry.getClient();
1520
const integration = client?.getIntegrationByName?.('SpotlightBrowser');
1621
setSpotlightEnabled(!!integration);
1722

23+
// Get all integration names for debugging
24+
// @ts-expect-error accessing internal property for debugging
25+
const intNames = client?._integrations ? Object.keys(client._integrations) : [];
26+
setIntegrationNames(intNames);
27+
1828
// Log for debugging
1929
console.log('Spotlight test results:', {
2030
envValue: NEXT_PUBLIC_SPOTLIGHT_VALUE,
31+
internalProcessEnv: INTERNAL_SPOTLIGHT_PROCESS_ENV,
32+
internalGlobal: INTERNAL_SPOTLIGHT_GLOBAL,
2133
integrationFound: !!integration,
2234
clientExists: !!client,
35+
integrationNames: intNames,
2336
});
2437
}, []);
2538

@@ -30,13 +43,18 @@ export default function SpotlightTestPage() {
3043
<div data-testid="env-value">
3144
<h2>Environment Variable</h2>
3245
<p>NEXT_PUBLIC_SENTRY_SPOTLIGHT: {NEXT_PUBLIC_SPOTLIGHT_VALUE || 'undefined'}</p>
46+
<p>process.env._sentrySpotlight: {String(INTERNAL_SPOTLIGHT_PROCESS_ENV) || 'undefined'}</p>
47+
<p>globalThis._sentrySpotlight: {String(INTERNAL_SPOTLIGHT_GLOBAL) || 'undefined'}</p>
3348
</div>
3449

3550
<div data-testid="spotlight-status">
3651
<h2>Spotlight Integration Status</h2>
3752
<p data-testid="spotlight-enabled">
3853
{spotlightEnabled === null ? 'Loading...' : spotlightEnabled ? 'ENABLED' : 'DISABLED'}
3954
</p>
55+
<p data-testid="integration-names">
56+
Integrations: {integrationNames.join(', ') || 'none'}
57+
</p>
4058
</div>
4159
</div>
4260
);

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@ 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(
20+
spotlightStatus,
21+
`Spotlight should be ENABLED.\nEnv values: ${envValue}\nIntegrations: ${integrationNames}`,
22+
).toBe('ENABLED');
1723
});
1824

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

packages/nextjs/src/client/index.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,31 @@ function getDefaultIntegrations(options: BrowserOptions): Integration[] {
147147
// The value is injected at build time:
148148
// - Webpack: via DefinePlugin which replaces process.env._sentrySpotlight
149149
// - Turbopack: via valueInjectionLoader which sets globalThis._sentrySpotlight
150-
const spotlightEnvValue = process.env._sentrySpotlight || globalWithInjectedValues._sentrySpotlight;
150+
const processEnvSpotlight = process.env._sentrySpotlight;
151+
const globalSpotlight = globalWithInjectedValues._sentrySpotlight;
152+
const spotlightEnvValue = processEnvSpotlight || globalSpotlight;
153+
154+
// eslint-disable-next-line no-console
155+
console.log('[Sentry Next.js DEBUG] Spotlight detection:', {
156+
'process.env._sentrySpotlight': processEnvSpotlight,
157+
'globalThis._sentrySpotlight': globalSpotlight,
158+
resolved: spotlightEnvValue,
159+
'options.spotlight': options.spotlight,
160+
});
161+
151162
if (spotlightEnvValue !== undefined && options.spotlight === undefined) {
152163
const boolValue = envToBool(spotlightEnvValue, { strict: true });
153164
const spotlightConfig = boolValue !== null ? boolValue : spotlightEnvValue;
154165
const spotlightValue = resolveSpotlightOptions(undefined, spotlightConfig);
155166

167+
// eslint-disable-next-line no-console
168+
console.log('[Sentry Next.js DEBUG] Spotlight resolved:', { boolValue, spotlightConfig, spotlightValue });
169+
156170
if (spotlightValue) {
157171
const spotlightArgs = typeof spotlightValue === 'string' ? { sidecarUrl: spotlightValue } : undefined;
158172
customDefaultIntegrations.push(spotlightBrowserIntegration(spotlightArgs));
173+
// eslint-disable-next-line no-console
174+
console.log('[Sentry Next.js DEBUG] Spotlight integration ADDED');
159175
}
160176
}
161177

packages/nextjs/src/config/turbopack/generateValueInjectionRules.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export function generateValueInjectionRules({
3838
// Inject Spotlight config for client (Spotlight is a client-side feature)
3939
if (spotlightConfig) {
4040
clientValues._sentrySpotlight = spotlightConfig;
41+
// eslint-disable-next-line no-console
42+
console.log('[@sentry/nextjs] Turbopack: Injecting _sentrySpotlight =', spotlightConfig);
4143
}
4244

4345
if (Object.keys(isomorphicValues).length > 0) {

packages/nextjs/src/config/withSentryConfig.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,15 @@ function getFinalConfigObject(
355355
const spotlightConfig =
356356
incomingUserNextConfigObject.env?.NEXT_PUBLIC_SENTRY_SPOTLIGHT ?? process.env.NEXT_PUBLIC_SENTRY_SPOTLIGHT;
357357

358+
// eslint-disable-next-line no-console
359+
console.log('[@sentry/nextjs] Spotlight config detection:', {
360+
'env.NEXT_PUBLIC_SENTRY_SPOTLIGHT': incomingUserNextConfigObject.env?.NEXT_PUBLIC_SENTRY_SPOTLIGHT,
361+
'process.env.NEXT_PUBLIC_SENTRY_SPOTLIGHT': process.env.NEXT_PUBLIC_SENTRY_SPOTLIGHT,
362+
resolved: spotlightConfig,
363+
isTurbopack,
364+
isWebpack,
365+
});
366+
358367
let turboPackConfig: TurbopackOptions | undefined;
359368

360369
if (isTurbopack) {

0 commit comments

Comments
 (0)