-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(node): Fix Spotlight configuration precedence to match specification #18195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
size-limit report 📦
|
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.
|
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> <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>
There was a problem hiding this 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:
sentry-javascript/.size-limit.js
Lines 237 to 244 in 2deb000
| { | |
| 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).
Problem
The Spotlight configuration logic had a precedence bug where when
spotlight: truewas set in config AND theSENTRY_SPOTLIGHTenvironment variable contained a URL string, the SDK would incorrectly usetrueinstead of the URL from the environment variable.According to the Spotlight specification, when
spotlight: trueis 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:
Expected behavior per spec:
Solution
Fixed the precedence logic in
getClientOptions()to properly implement the specification:spotlight: false→ Always disabled (overrides env var)spotlight: string→ Uses the config URL (ignores env var)spotlight: true+ env var URL → Uses the env var URL (the bug fix)spotlight: true+ env var truthy → Uses default URLThe implementation reuses the existing
envToBool()utility to avoid code duplication.Changes
packages/node-core/src/sdk/index.tspackages/node-core/test/sdk/init.test.tsTest Coverage
The new tests cover:
true,false, URL stringfalseoverrides env var (URL, truthy, falsy)true+ env var URL uses env var URL (the fix)true+ env var truthy uses default URLRelated