diff --git a/docs/migration/draft-v9-migration-guide.md b/docs/migration/draft-v9-migration-guide.md index 1b8cab48aec0..d9e1242f3be8 100644 --- a/docs/migration/draft-v9-migration-guide.md +++ b/docs/migration/draft-v9-migration-guide.md @@ -7,6 +7,7 @@ - Deprecated `AddRequestDataToEventOptions.transaction`. This option effectively doesn't do anything anymore, and will be removed in v9. - Deprecated `TransactionNamingScheme` type. +- Deprecated `validSeverityLevels`. Will not be replaced. - Deprecated `urlEncode`. No replacements. ## `@sentry/core` diff --git a/packages/core/src/utils-hoist/index.ts b/packages/core/src/utils-hoist/index.ts index b6bb7151a7e3..9498d22d3620 100644 --- a/packages/core/src/utils-hoist/index.ts +++ b/packages/core/src/utils-hoist/index.ts @@ -84,6 +84,7 @@ export type { TransactionNamingScheme, } from './requestdata'; +// eslint-disable-next-line deprecation/deprecation export { severityLevelFromString, validSeverityLevels } from './severity'; export { UNKNOWN_FUNCTION, diff --git a/packages/core/src/utils-hoist/severity.ts b/packages/core/src/utils-hoist/severity.ts index c19c047c90bf..f5217b8b87c9 100644 --- a/packages/core/src/utils-hoist/severity.ts +++ b/packages/core/src/utils-hoist/severity.ts @@ -1,15 +1,8 @@ import type { SeverityLevel } from '@sentry/types'; -// Note: Ideally the `SeverityLevel` type would be derived from `validSeverityLevels`, but that would mean either -// -// a) moving `validSeverityLevels` to `@sentry/types`, -// b) moving the`SeverityLevel` type here, or -// c) importing `validSeverityLevels` from here into `@sentry/types`. -// -// Option A would make `@sentry/types` a runtime dependency of `@sentry/core` (not good), and options B and C would -// create a circular dependency between `@sentry/types` and `@sentry/core` (also not good). So a TODO accompanying the -// type, reminding anyone who changes it to change this list also, will have to do. - +/** + * @deprecated This variable has been deprecated and will be removed in the next major version. + */ export const validSeverityLevels = ['fatal', 'error', 'warning', 'log', 'info', 'debug']; /** @@ -19,5 +12,7 @@ export const validSeverityLevels = ['fatal', 'error', 'warning', 'log', 'info', * @returns The `SeverityLevel` corresponding to the given string, or 'log' if the string isn't a valid level. */ export function severityLevelFromString(level: SeverityLevel | string): SeverityLevel { - return (level === 'warn' ? 'warning' : validSeverityLevels.includes(level) ? level : 'log') as SeverityLevel; + return ( + level === 'warn' ? 'warning' : ['fatal', 'error', 'warning', 'log', 'info', 'debug'].includes(level) ? level : 'log' + ) as SeverityLevel; } diff --git a/packages/core/test/utils-hoist/severity.test.ts b/packages/core/test/utils-hoist/severity.test.ts index 30e3dbb90e97..65388428b65c 100644 --- a/packages/core/test/utils-hoist/severity.test.ts +++ b/packages/core/test/utils-hoist/severity.test.ts @@ -1,4 +1,4 @@ -import { severityLevelFromString, validSeverityLevels } from '../../src/utils-hoist/severity'; +import { severityLevelFromString } from '../../src/utils-hoist/severity'; describe('severityLevelFromString()', () => { test("converts 'warn' to 'warning'", () => { @@ -10,7 +10,7 @@ describe('severityLevelFromString()', () => { }); test('acts as a pass-through for valid level strings', () => { - for (const level of validSeverityLevels) { + for (const level of ['fatal', 'error', 'warning', 'log', 'info', 'debug']) { expect(severityLevelFromString(level)).toBe(level); } }); diff --git a/packages/types/src/severity.ts b/packages/types/src/severity.ts index 8a59bef56f30..73a685f5c5a6 100644 --- a/packages/types/src/severity.ts +++ b/packages/types/src/severity.ts @@ -1,3 +1 @@ -// Note: If this is ever changed, the `validSeverityLevels` array in `@sentry/core` needs to be changed, also. (See -// note there for why we can't derive one from the other.) export type SeverityLevel = 'fatal' | 'error' | 'warning' | 'log' | 'info' | 'debug'; diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 17e2bb02aa99..a72d5a7ff573 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -58,6 +58,7 @@ export { winterCGHeadersToDict, winterCGRequestToRequestData, severityLevelFromString, + // eslint-disable-next-line deprecation/deprecation validSeverityLevels, UNKNOWN_FUNCTION, createStackParser,