Commit c8ca286
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>1 parent 7efb1d2 commit c8ca286
File tree
4 files changed
+128
-4
lines changed- packages/node-core
- src/sdk
- test/sdk
4 files changed
+128
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
243 | | - | |
| 243 | + | |
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
186 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
187 | 203 | | |
188 | 204 | | |
189 | 205 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
219 | 327 | | |
220 | 328 | | |
221 | 329 | | |
| |||
0 commit comments