Skip to content

Commit 0d69896

Browse files
committed
lfg
1 parent 77be213 commit 0d69896

File tree

5 files changed

+22
-38
lines changed

5 files changed

+22
-38
lines changed

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,21 @@ 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;
108

119
export default function SpotlightTestPage() {
1210
const [spotlightEnabled, setSpotlightEnabled] = useState<boolean | null>(null);
13-
const [integrationNames, setIntegrationNames] = useState<string[]>([]);
1411

1512
useEffect(() => {
1613
// Check if Spotlight integration is registered
1714
const client = Sentry.getClient();
1815
const integration = client?.getIntegrationByName?.('SpotlightBrowser');
1916
setSpotlightEnabled(!!integration);
2017

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-
2618
// Log for debugging
2719
console.log('Spotlight test results:', {
2820
envValue: NEXT_PUBLIC_SPOTLIGHT_VALUE,
29-
internalEnvValue: INTERNAL_SPOTLIGHT_VALUE,
3021
integrationFound: !!integration,
3122
clientExists: !!client,
32-
integrationNames: intNames,
3323
});
3424
}, []);
3525

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

4635
<div data-testid="spotlight-status">
4736
<h2>Spotlight Integration Status</h2>
4837
<p data-testid="spotlight-enabled">
4938
{spotlightEnabled === null ? 'Loading...' : spotlightEnabled ? 'ENABLED' : 'DISABLED'}
5039
</p>
51-
<p data-testid="integration-names">
52-
Integrations: {integrationNames.join(', ') || 'none'}
53-
</p>
5440
</div>
5541
</div>
5642
);

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,9 @@ 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-
1714
// Check Spotlight integration is enabled
1815
const spotlightStatus = await page.getByTestId('spotlight-enabled').textContent();
19-
expect(spotlightStatus, `Spotlight should be ENABLED. Env value: ${envValue}. Integrations: ${integrationNames}`).toBe(
20-
'ENABLED',
21-
);
16+
expect(spotlightStatus).toBe('ENABLED');
2217
});
2318

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

packages/nextjs/src/client/index.ts

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

145145
// Auto-enable Spotlight from NEXT_PUBLIC_SENTRY_SPOTLIGHT env var
146-
// The value is injected at build time via buildTimeVariables in withSentryConfig
147-
// following the same pattern as _sentryRelease
146+
// The value is injected at build time via DefinePlugin in webpack.ts
147+
// We use DefinePlugin because Next.js doesn't replace process.env.* in node_modules code
148148
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-
});
155149
if (spotlightEnvValue !== undefined && options.spotlight === undefined) {
156150
const boolValue = envToBool(spotlightEnvValue, { strict: true });
157151
const spotlightConfig = boolValue !== null ? boolValue : spotlightEnvValue;
158152
const spotlightValue = resolveSpotlightOptions(undefined, spotlightConfig);
159-
// eslint-disable-next-line no-console
160-
console.log('[Sentry Next.js] Spotlight resolved:', { boolValue, spotlightConfig, spotlightValue });
161153

162154
if (spotlightValue) {
163155
const spotlightArgs = typeof spotlightValue === 'string' ? { sidecarUrl: spotlightValue } : undefined;
164156
customDefaultIntegrations.push(spotlightBrowserIntegration(spotlightArgs));
165-
// eslint-disable-next-line no-console
166-
console.log('[Sentry Next.js] Spotlight integration added');
167157
}
168158
}
169159

packages/nextjs/src/config/webpack.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,15 @@ export function constructWebpackConfigFunction({
4646
routeManifest,
4747
nextJsVersion,
4848
useRunAfterProductionCompileHook,
49+
spotlightConfig,
4950
}: {
5051
userNextConfig: NextConfigObject;
5152
userSentryOptions: SentryBuildOptions;
5253
releaseName: string | undefined;
5354
routeManifest: RouteManifest | undefined;
5455
nextJsVersion: string | undefined;
5556
useRunAfterProductionCompileHook: boolean | undefined;
57+
spotlightConfig: string | undefined;
5658
}): WebpackConfigFunction {
5759
// Will be called by nextjs and passed its default webpack configuration and context data about the build (whether
5860
// we're building server or client, whether we're in dev, what version of webpack we're using, etc). Note that
@@ -445,6 +447,17 @@ export function constructWebpackConfigFunction({
445447
}),
446448
);
447449

450+
// Inject Spotlight config for client builds so the SDK can auto-enable Spotlight
451+
// when NEXT_PUBLIC_SENTRY_SPOTLIGHT is set. We use DefinePlugin because Next.js
452+
// doesn't replace process.env.* in node_modules code.
453+
if (runtime === 'client' && spotlightConfig) {
454+
newConfig.plugins.push(
455+
new buildContext.webpack.DefinePlugin({
456+
'process.env._sentrySpotlight': JSON.stringify(spotlightConfig),
457+
}),
458+
);
459+
}
460+
448461
return newConfig;
449462
};
450463
}

packages/nextjs/src/config/withSentryConfig.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,10 @@ function getFinalConfigObject(
462462
routeManifest,
463463
nextJsVersion,
464464
useRunAfterProductionCompileHook: shouldUseRunAfterProductionCompileHook,
465+
// Spotlight config from NEXT_PUBLIC_SENTRY_SPOTLIGHT env var
466+
spotlightConfig:
467+
incomingUserNextConfigObject.env?.NEXT_PUBLIC_SENTRY_SPOTLIGHT ??
468+
process.env.NEXT_PUBLIC_SENTRY_SPOTLIGHT,
465469
}),
466470
}
467471
: {}),
@@ -610,12 +614,8 @@ function setUpBuildTimeVariables(
610614
buildTimeVariables._sentryRelease = releaseName;
611615
}
612616

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-
}
617+
// Note: Spotlight config (_sentrySpotlight) is injected via webpack DefinePlugin in webpack.ts
618+
// because Next.js doesn't replace process.env.* in node_modules code via next.config.js env.
619619

620620
if (typeof userNextConfig.env === 'object') {
621621
userNextConfig.env = { ...buildTimeVariables, ...userNextConfig.env };

0 commit comments

Comments
 (0)