You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(node): Fix Spotlight configuration precedence to match specification (#18195)
## 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](https://raw.githubusercontent.com/getsentry/sentry-docs/b38e3b307f900665a348f855559ac1d1c58914cc/develop-docs/sdk/expected-features/spotlight.mdx),
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:**
```typescript
// Config: spotlight: true
// Env: SENTRY_SPOTLIGHT=http://custom:3000/stream
// Result: spotlight = true ❌ (incorrect)
```
**Expected behavior per spec:**
```typescript
// 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
- Original Spotlight implementation: #13325
- Spotlight specification: https://spotlightjs.com/
---------
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
0 commit comments