Skip to content

Commit b0a08af

Browse files
committed
fix: Only inject spotlight env var when set
1 parent f67c8a9 commit b0a08af

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

packages/astro/src/integration/index.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,16 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
180180
}
181181

182182
// Inject SENTRY_SPOTLIGHT env var for client bundles (fallback for manual setup without PUBLIC_ prefix)
183-
updateConfig({
184-
vite: {
185-
define: {
186-
'import.meta.env.SENTRY_SPOTLIGHT': JSON.stringify(process.env.SENTRY_SPOTLIGHT || ''),
183+
// Only add if we have a value to inject and the SDK is enabled
184+
if (process.env.SENTRY_SPOTLIGHT && sdkEnabled.client) {
185+
updateConfig({
186+
vite: {
187+
define: {
188+
'import.meta.env.SENTRY_SPOTLIGHT': JSON.stringify(process.env.SENTRY_SPOTLIGHT),
189+
},
187190
},
188-
},
189-
});
191+
});
192+
}
190193

191194
const isSSR = config && (config.output === 'server' || config.output === 'hybrid');
192195
const shouldAddMiddleware = sdkEnabled.server && autoInstrumentation?.requestHandler !== false;

packages/nuxt/src/module.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,15 @@ export default defineNuxtModule<ModuleOptions>({
108108
addOTelCommonJSImportAlias(nuxt);
109109

110110
// Inject SENTRY_SPOTLIGHT env var for client bundles (fallback for manual setup without VITE_ prefix)
111-
nuxt.hook('vite:extendConfig', (viteConfig, env) => {
112-
if (env.isClient) {
113-
viteConfig.define = viteConfig.define || {};
114-
viteConfig.define['import.meta.env.SENTRY_SPOTLIGHT'] = JSON.stringify(process.env.SENTRY_SPOTLIGHT || '');
115-
}
116-
});
111+
// Only add the hook if we have a value to inject
112+
if (process.env.SENTRY_SPOTLIGHT) {
113+
nuxt.hook('vite:extendConfig', (viteConfig, env) => {
114+
if (env.isClient) {
115+
viteConfig.define = viteConfig.define || {};
116+
viteConfig.define['import.meta.env.SENTRY_SPOTLIGHT'] = JSON.stringify(process.env.SENTRY_SPOTLIGHT);
117+
}
118+
});
119+
}
117120

118121
const pagesDataTemplate = addTemplate({
119122
filename: 'sentry--nuxt-pages-data.mjs',

packages/sveltekit/src/vite/sentryVitePlugins.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ export async function sentrySvelteKit(options: SentrySvelteKitPluginOptions = {}
5151

5252
const sentryPlugins: Plugin[] = [];
5353

54-
// Add spotlight plugin unconditionally for zero-config Spotlight support
55-
sentryPlugins.push(makeSpotlightDefinePlugin());
54+
// Add spotlight plugin for zero-config Spotlight support (only if env var is set)
55+
if (process.env.PUBLIC_SENTRY_SPOTLIGHT || process.env.SENTRY_SPOTLIGHT) {
56+
sentryPlugins.push(makeSpotlightDefinePlugin());
57+
}
5658

5759
if (mergedOptions.autoInstrument) {
5860
// TODO: Once tracing is promoted stable, we need to adjust this check!

0 commit comments

Comments
 (0)