forked from getsentry/sentry-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for SENTRY_SPOTLIGHT env var in Node (getsentry#13325)
Enable sending events to spotlight by setting the `SENTRY_SPOTLIGHT` environment variable --------- Co-authored-by: Burak Yigit Kaya <bkaya21@bloomberg.net>
- Loading branch information
Showing
5 changed files
with
120 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
export const FALSY_ENV_VALUES = new Set(['false', 'f', 'n', 'no', 'off', '0']); | ||
export const TRUTHY_ENV_VALUES = new Set(['true', 't', 'y', 'yes', 'on', '1']); | ||
|
||
export type StrictBoolCast = { | ||
strict: true; | ||
}; | ||
|
||
export type LooseBoolCast = { | ||
strict?: false; | ||
}; | ||
|
||
export type BoolCastOptions = StrictBoolCast | LooseBoolCast; | ||
|
||
export function envToBool(value: unknown, options?: LooseBoolCast): boolean; | ||
export function envToBool(value: unknown, options: StrictBoolCast): boolean | null; | ||
export function envToBool(value: unknown, options?: BoolCastOptions): boolean | null; | ||
/** | ||
* A helper function which casts an ENV variable value to `true` or `false` using the constants defined above. | ||
* In strict mode, it may return `null` if the value doesn't match any of the predefined values. | ||
* | ||
* @param value The value of the env variable | ||
* @param options -- Only has `strict` key for now, which requires a strict match for `true` in TRUTHY_ENV_VALUES | ||
* @returns true/false if the lowercase value matches the predefined values above. If not, null in strict mode, | ||
* and Boolean(value) in loose mode. | ||
*/ | ||
export function envToBool(value: unknown, options?: BoolCastOptions): boolean | null { | ||
const normalized = String(value).toLowerCase(); | ||
|
||
if (FALSY_ENV_VALUES.has(normalized)) { | ||
return false; | ||
} | ||
|
||
if (TRUTHY_ENV_VALUES.has(normalized)) { | ||
return true; | ||
} | ||
|
||
return options && options.strict ? null : Boolean(value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { envToBool } from '../../src/utils/envToBool'; | ||
|
||
describe('envToBool', () => { | ||
it.each([ | ||
['', true, null], | ||
['', false, false], | ||
['t', true, true], | ||
['T', true, true], | ||
['t', false, true], | ||
['T', false, true], | ||
['y', true, true], | ||
['Y', true, true], | ||
['y', false, true], | ||
['Y', false, true], | ||
['1', true, true], | ||
['1', false, true], | ||
['true', true, true], | ||
['true', false, true], | ||
['tRuE', true, true], | ||
['tRuE', false, true], | ||
['Yes', true, true], | ||
['Yes', false, true], | ||
['yes', true, true], | ||
['yes', false, true], | ||
['yEs', true, true], | ||
['yEs', false, true], | ||
['On', true, true], | ||
['On', false, true], | ||
['on', true, true], | ||
['on', false, true], | ||
['oN', true, true], | ||
['oN', false, true], | ||
['f', true, false], | ||
['f', false, false], | ||
['n', true, false], | ||
['N', true, false], | ||
['n', false, false], | ||
['N', false, false], | ||
['0', true, false], | ||
['0', false, false], | ||
['false', true, false], | ||
['false', false, false], | ||
['false', true, false], | ||
['false', false, false], | ||
['FaLsE', true, false], | ||
['FaLsE', false, false], | ||
['No', true, false], | ||
['No', false, false], | ||
['no', true, false], | ||
['no', false, false], | ||
['nO', true, false], | ||
['nO', false, false], | ||
['Off', true, false], | ||
['Off', false, false], | ||
['off', true, false], | ||
['off', false, false], | ||
['oFf', true, false], | ||
['oFf', false, false], | ||
['xxx', true, null], | ||
['xxx', false, true], | ||
[undefined, false, false], | ||
[undefined, true, null], | ||
])('%s becomes (strict: %s): %s', (value, strict, expected) => { | ||
expect(envToBool(value, { strict })).toBe(expected); | ||
}); | ||
}); |