Skip to content

Conversation

@BYK
Copy link
Member

@BYK BYK commented Oct 29, 2025

  • Move envToBool utility from node-core to core for code sharing
  • Add spotlight option to BrowserSpecificOptions type
  • Support SENTRY_SPOTLIGHT env var in browser SDK with graceful fallback
  • Auto-inject spotlightBrowserIntegration when enabled via env var
  • Match Node.js behavior: truthy values use default URL, custom strings use that URL

BYK added 3 commits October 29, 2025 11:47
- Move envToBool utility from node-core to core for code sharing
- Add spotlight option to BrowserSpecificOptions type
- Support SENTRY_SPOTLIGHT env var in browser SDK with graceful fallback
- Auto-inject spotlightBrowserIntegration when enabled via env var
- Match Node.js behavior: truthy values use default URL, custom strings use that URL
@github-actions
Copy link
Contributor

github-actions bot commented Oct 29, 2025

size-limit report 📦

Path Size % Change Change
⛔️ @sentry/browser (max: 25 kB) 25.14 kB +2.04% +501 B 🔺
@sentry/browser - with treeshaking flags 23.7 kB +2.48% +573 B 🔺
⛔️ @sentry/browser (incl. Tracing) (max: 41 kB) 41.54 kB +1.36% +554 B 🔺
@sentry/browser (incl. Tracing, Profiling) 45.8 kB +1.19% +538 B 🔺
@sentry/browser (incl. Tracing, Replay) 79.87 kB +0.69% +543 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 69.55 kB +0.76% +522 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 84.59 kB +0.67% +561 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 96.78 kB +0.6% +577 B 🔺
@sentry/browser (incl. Feedback) 41.93 kB +1.5% +617 B 🔺
@sentry/browser (incl. sendFeedback) 29.82 kB +1.75% +511 B 🔺
@sentry/browser (incl. FeedbackAsync) 34.77 kB +1.55% +530 B 🔺
@sentry/react 26.85 kB +2% +526 B 🔺
⛔️ @sentry/react (incl. Tracing) (max: 43 kB) 43.47 kB +1.16% +496 B 🔺
@sentry/vue 29.67 kB +1.88% +546 B 🔺
⛔️ @sentry/vue (incl. Tracing) (max: 43 kB) 43.3 kB +1.19% +509 B 🔺
⛔️ @sentry/svelte (max: 25 kB) 25.16 kB +2.06% +507 B 🔺
CDN Bundle 27.32 kB +1.57% +422 B 🔺
⛔️ CDN Bundle (incl. Tracing) (max: 42 kB) 42.05 kB +1% +416 B 🔺
CDN Bundle (incl. Tracing, Replay) 78.46 kB +0.73% +561 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 83.92 kB +0.65% +534 B 🔺
CDN Bundle - uncompressed 79.94 kB +1.33% +1.05 kB 🔺
⛔️ CDN Bundle (incl. Tracing) - uncompressed (max: 124 kB) 124.52 kB +0.85% +1.05 kB 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 239.93 kB +0.52% +1.24 kB 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 252.69 kB +0.5% +1.24 kB 🔺
@sentry/nextjs (client) 45.66 kB +1.21% +542 B 🔺
@sentry/sveltekit (client) 41.9 kB +1.2% +494 B 🔺
@sentry/node-core 50.8 kB -0.02% -7 B 🔽
@sentry/node 157.87 kB -0.01% -10 B 🔽
@sentry/node - without tracing 92.67 kB -0.03% -20 B 🔽
@sentry/aws-serverless 106.39 kB -0.03% -28 B 🔽

View base workflow run

@github-actions
Copy link
Contributor

github-actions bot commented Oct 29, 2025

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,885 - 8,934 -1%
GET With Sentry 1,344 15% 1,387 -3%
GET With Sentry (error only) 6,033 68% 6,232 -3%
POST Baseline 1,198 - 1,217 -2%
POST With Sentry 532 44% 528 +1%
POST With Sentry (error only) 1,043 87% 1,072 -3%
MYSQL Baseline 3,258 - 3,382 -4%
MYSQL With Sentry 415 13% 492 -16%
MYSQL With Sentry (error only) 2,708 83% 2,790 -3%

View base workflow run

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preliminary review

It seems like this PR does two things:

  1. add spotlightBrowserIntegration based on the spotlight init option (i.e. remove the need for users to add it manually and thereby destroy all tree-shaking abilities)
  2. if not set, enable it if the SENTRY_SPOTLIGHT env variable is set at build/dev-build time

Can we split this PR up? The reason I'm asking for this is because I'm concerned with 2 (see my review comment), so I want to be able to easily revert either part of it without removing the other one, in case our changes break users.

Comment on lines +95 to +102
// Read spotlight config from env var with graceful fallback
// This will be replaced at build time by bundlers like webpack/vite
let spotlightFromEnv: boolean | string | undefined;
if (typeof process !== 'undefined' && process.env && process.env.SENTRY_SPOTLIGHT !== undefined) {
const envValue = process.env.SENTRY_SPOTLIGHT;
const parsedEnvValue = envToBool(envValue, { strict: true });
spotlightFromEnv = parsedEnvValue ?? envValue;
}
Copy link
Member

@Lms24 Lms24 Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, process.env will almost never* be replaced by bundlers, which means that this code path will almost never work. The only bundler that straight up adds support for process.env.X seems to be Parcel.

Webpack requires users to additionally add a replacement plugin that hard-replaces strings at build time. Rollup requires the same treatment (just with its own plugin architecture, or something like rollup-plugin-replace). In either case, this current code would fail because while process might be undefined, process.env.SENTRY_SPOTLIGHT could be "defined" (in the sense of the whole thing being hard-replaced at build time). See my code suggestion for a tentative workaround.

Vite (the one I care most about, next to webpack), can dynamically replace any env variable that is prefixed with VITE_. This is a security measure to avoid users leaking keys into their public browser bundles (actually a good thing IMHO). So users would have to define VITE_SENTRY_SPOTLIGHT instead of SENTRY_SPOTLIGHT. As I understand it, this again requires a "special treatment" for Spotlight in browser which I think you want to avoid.

Now the delightful JS ecosystem can't even agree on this VITE_ prefix, so Vite allows users to customize their public prefix via envPrefix.

In a similar manner, some frameworks built their own abstractions around env variables, for example NextJS but it requires a NEXT_PUBLIC_ prefix. The good news is that process.env.NEXT_PUBLIC_SENTRY_SPOTLIGHT would work. SvelteKit allows env variables prefixed with PUBLIC_ to be replaced in its browser bundles but they must be explicitly imported. Nuxt seems to prefer defining env variables explicitly in a runtime config file.

Older frameworks like Angular or Ember don't have env variable support at all but instead recommend using environment.(prod|dev|...).ts files with the respective variables defined in an environment object.

So, as you can see, there's no universal solution that will make this "just work". So we have two choices:
a) apply a fail-safe best-effort check and document that setting SENTRY_SPOTLIGHT might sometimes work depending on framework and bundler but other times it won't in which case users need to fall back to setting the option themselves.
b) not bother with this and the bytes this costs us but simply make it explicit for users to set spotlight: true|false on their terms, with the check they prefer.

In case you want to go with a (which I don't recommend), here's an idea how this could be done, trying to keep the bundle size waste as low as possible:

// this will need a bunch of ts-ignores

// wherever we need to check this
const enableSpotlight = options.spotlight ?? getSpotlightFromEnv();

// ...
function getSpotlightFromEnv() {
  try {
    const processEnvVar = process.env.SENTRY_SPOTLIGHT || process.env.NEXT_PUBLIC_SENTRY_SPOTLIGHT;
    return envToBool(processEnv , { strict: true });
  } catch { /* ignore */ }
  
  try {
    // this still feels scary to add to the SDK because I don't know how bundlers other than Vite react to `import.meta` mentioned in the code. They could throw a build error. We should at least test this with webpack.
    return envToBool(import.meta.env.VITE_SENTRY_SPOTLIGHT, { strict: true });
  } catch { /* ignore */ }

  return false;
}

The most important aspects of this function are:

  • we must never throw at runtime or cause a build error
  • we must always default to false rather than true because otherwise, we risk sending stuff to spotlight in a live prod build.

Overall, I'd still recommend going with b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants