Skip to content

Commit 0ad25a3

Browse files
committed
fix(nextjs): Honor explicit spotlight option even without env var
Previously, the Spotlight integration logic was gated behind checking if the NEXT_PUBLIC_SENTRY_SPOTLIGHT env var was set. This meant that if a user set `spotlight: true` in Sentry.init() without the env var, their explicit configuration was silently ignored. Now the code always checks resolveSpotlightOptions which properly handles both the explicit option and the env var with correct precedence.
1 parent eca64b5 commit 0ad25a3

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

packages/nextjs/src/client/index.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,23 +143,27 @@ function getDefaultIntegrations(options: BrowserOptions): Integration[] {
143143
}),
144144
);
145145

146-
// Add Spotlight integration if enabled via NEXT_PUBLIC_SENTRY_SPOTLIGHT env var.
147-
// The env var is injected by the Next.js build config:
148-
// - Webpack: valueInjectionLoader sets globalThis.NEXT_PUBLIC_SENTRY_SPOTLIGHT
149-
// - Turbopack: valueInjectionLoader sets globalThis.NEXT_PUBLIC_SENTRY_SPOTLIGHT
146+
// Add Spotlight integration if enabled via:
147+
// 1. NEXT_PUBLIC_SENTRY_SPOTLIGHT env var (injected by Next.js build config)
148+
// 2. Explicit `spotlight` option in Sentry.init()
149+
//
150150
// We handle this in the Next.js SDK rather than the browser SDK because the browser SDK's
151151
// auto-detection is development-only (stripped from production builds that users install).
152152
const spotlightEnvValue = globalWithInjectedValues.NEXT_PUBLIC_SENTRY_SPOTLIGHT;
153+
154+
// Parse the env var value if present (could be 'true', 'false', or a URL)
155+
let envSpotlight: boolean | string | undefined;
153156
if (spotlightEnvValue !== undefined) {
154-
// Parse the env var value (could be 'true', 'false', or a URL)
155157
const boolValue = envToBool(spotlightEnvValue, { strict: true });
156-
const envSpotlight = boolValue !== null ? boolValue : spotlightEnvValue;
157-
const spotlightValue = resolveSpotlightOptions(options.spotlight, envSpotlight);
158+
envSpotlight = boolValue !== null ? boolValue : spotlightEnvValue;
159+
}
158160

159-
if (spotlightValue) {
160-
const args = typeof spotlightValue === 'string' ? { sidecarUrl: spotlightValue } : undefined;
161-
customDefaultIntegrations.push(spotlightBrowserIntegration(args));
162-
}
161+
// Resolve the final Spotlight config: explicit option takes precedence over env var
162+
const spotlightValue = resolveSpotlightOptions(options.spotlight, envSpotlight);
163+
164+
if (spotlightValue) {
165+
const args = typeof spotlightValue === 'string' ? { sidecarUrl: spotlightValue } : undefined;
166+
customDefaultIntegrations.push(spotlightBrowserIntegration(args));
163167
}
164168

165169
return customDefaultIntegrations;

0 commit comments

Comments
 (0)