Skip to content

Conversation

@BYK
Copy link
Member

@BYK BYK commented Nov 13, 2025

Problem

The Spotlight configuration logic had a precedence bug where when spotlight: true was set in config AND the SENTRY_SPOTLIGHT environment variable contained a URL string, the SDK would incorrectly use true instead of the URL from the environment variable.

According to the Spotlight specification, when spotlight: true is set and the env var contains a URL, the URL from the env var should be used to allow developers to override the Spotlight URL via environment variables.

Previous behavior:

// Config: spotlight: true
// Env: SENTRY_SPOTLIGHT=http://custom:3000/stream
// Result: spotlight = true ❌ (incorrect)

Expected behavior per spec:

// Config: spotlight: true
// Env: SENTRY_SPOTLIGHT=http://custom:3000/stream
// Result: spotlight = "http://custom:3000/stream" ✅ (correct)

Solution

Fixed the precedence logic in getClientOptions() to properly implement the specification:

  1. spotlight: false → Always disabled (overrides env var)
  2. spotlight: string → Uses the config URL (ignores env var)
  3. spotlight: true + env var URL → Uses the env var URL (the bug fix)
  4. spotlight: true + env var truthy → Uses default URL
  5. No config + env var → Parses and uses env var

The implementation reuses the existing envToBool() utility to avoid code duplication.

Changes

  • Fixed Spotlight precedence logic in packages/node-core/src/sdk/index.ts
  • Added 12 comprehensive test cases covering all precedence scenarios in packages/node-core/test/sdk/init.test.ts
  • Updated CHANGELOG.md

Test Coverage

The new tests cover:

  • ✅ Env var only: truthy values, falsy values, URL strings
  • ✅ Config only: true, false, URL string
  • ✅ Precedence: config false overrides env var (URL, truthy, falsy)
  • ✅ Precedence: config URL overrides env var
  • ✅ Precedence: config true + env var URL uses env var URL (the fix)
  • ✅ Precedence: config true + env var truthy uses default URL

Related

BYK added 2 commits November 13, 2025 13:01
The Spotlight configuration logic had a precedence bug where when
'spotlight: true' was set AND the 'SENTRY_SPOTLIGHT' env var contained
a URL string, the SDK would use 'true' instead of the URL from the env var.

According to the Spotlight specification, when 'spotlight: true' is set
and the env var contains a URL, the URL should be used.

Changes:
- Fixed precedence logic in getClientOptions() to properly handle the
  case where config is 'true' and env var is a URL string
- Added 12 comprehensive test cases covering all precedence scenarios
- Reused existing envToBool() utility for env var parsing

Fixes the issue where developers couldn't override the Spotlight URL
via environment variable when using 'spotlight: true' in config.
@BYK BYK requested review from Lms24 and andreiborza November 13, 2025 13:02
@github-actions
Copy link
Contributor

github-actions bot commented Nov 13, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 24.6 kB - -
@sentry/browser - with treeshaking flags 23.09 kB - -
@sentry/browser (incl. Tracing) 41.26 kB - -
@sentry/browser (incl. Tracing, Profiling) 45.53 kB - -
@sentry/browser (incl. Tracing, Replay) 79.73 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 69.4 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 84.42 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 96.58 kB - -
@sentry/browser (incl. Feedback) 41.27 kB - -
@sentry/browser (incl. sendFeedback) 29.27 kB - -
@sentry/browser (incl. FeedbackAsync) 34.2 kB - -
@sentry/react 26.29 kB - -
@sentry/react (incl. Tracing) 43.22 kB - -
@sentry/vue 29.09 kB - -
@sentry/vue (incl. Tracing) 43.03 kB - -
@sentry/svelte 24.61 kB - -
CDN Bundle 26.9 kB - -
CDN Bundle (incl. Tracing) 41.81 kB - -
CDN Bundle (incl. Tracing, Replay) 78.33 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 83.81 kB - -
CDN Bundle - uncompressed 78.84 kB - -
CDN Bundle (incl. Tracing) - uncompressed 124 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 240.03 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 252.79 kB - -
@sentry/nextjs (client) 45.34 kB - -
@sentry/sveltekit (client) 41.64 kB - -
@sentry/node-core 50.86 kB +0.1% +47 B 🔺
@sentry/node 158.04 kB +0.03% +44 B 🔺
@sentry/node - without tracing 92.73 kB +0.06% +49 B 🔺
@sentry/aws-serverless 106.5 kB +0.05% +46 B 🔺

View base workflow run

@github-actions
Copy link
Contributor

github-actions bot commented Nov 13, 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,997 - 8,922 +1%
GET With Sentry 1,333 15% 1,350 -1%
GET With Sentry (error only) 5,908 66% 6,147 -4%
POST Baseline 1,185 - 1,205 -2%
POST With Sentry 507 43% 524 -3%
POST With Sentry (error only) 1,075 91% 1,072 +0%
MYSQL Baseline 3,317 - 3,368 -2%
MYSQL With Sentry 468 14% 517 -9%
MYSQL With Sentry (error only) 2,714 82% 2,772 -2%

View base workflow run

Before submitting a pull request, please take a look at our

[Contributing](https://github.com/getsentry/sentry-javascript/blob/master/CONTRIBUTING.md)
guidelines and verify:

- [x] If you've added code that should be tested, please add tests.
- [x] Ensure your code lints and the test suite passes (`yarn lint`) &
(`yarn test`).

Fixes a test failure where `process.env.SENTRY_SPOTLIGHT` was not
cleaned up after a test, causing environment variable pollution for
subsequent tests.

The failing test expected `spotlight: true` to resolve to `true`, but
due to the lingering environment variable, it received the URL from
`SENTRY_SPOTLIGHT` instead.

This PR adds an `afterEach` hook to the `spotlight configuration`
describe block to ensure `process.env.SENTRY_SPOTLIGHT` is deleted after
each test, preventing cross-test contamination.

---
<a
href="https://cursor.com/background-agent?bcId=bc-9f9696f9-3843-4420-b2e9-26aedf9b0e2e"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/open-in-cursor-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/open-in-cursor-light.svg"><img alt="Open in
Cursor"
src="https://cursor.com/open-in-cursor.svg"></picture></a>&nbsp;<a
href="https://cursor.com/agents?id=bc-9f9696f9-3843-4420-b2e9-26aedf9b0e2e"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/open-in-web-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/open-in-web-light.svg"><img alt="Open in Web"
src="https://cursor.com/open-in-web.svg"></picture></a>

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
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.

LGTM! Thanks!

you can bump the size limit config for the failing entry here:

{
name: '@sentry/node',
path: 'packages/node/build/esm/index.js',
import: createImport('init'),
ignore: [...builtinModules, ...nodePrefixedBuiltinModules],
gzip: true,
limit: '158 KB',
},

Feel free to go with 160 or so (I already have that as a limit on a branch of mine, so we'll get there anyway).

@BYK BYK enabled auto-merge (squash) November 13, 2025 15:30
@BYK BYK merged commit c8ca286 into develop Nov 13, 2025
141 checks passed
@BYK BYK deleted the feat/node-spotlight-precedence-fix branch November 13, 2025 15:41
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