From 3f26bc7880252d9eb0f1a9d2eb07fabb4bce648f Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 21 Nov 2024 13:36:10 +0000 Subject: [PATCH 1/4] feat(core): Deprecate `validSeverityLevels` --- packages/core/src/api.ts | 19 +++++++++++++------ packages/core/src/utils-hoist/index.ts | 1 + packages/core/src/utils-hoist/severity.ts | 17 ++++++----------- .../core/test/utils-hoist/severity.test.ts | 4 ++-- packages/types/src/severity.ts | 2 -- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/packages/core/src/api.ts b/packages/core/src/api.ts index f8bb8cfe8eac..b7cd786d215a 100644 --- a/packages/core/src/api.ts +++ b/packages/core/src/api.ts @@ -1,6 +1,5 @@ import type { DsnComponents, DsnLike, SdkInfo } from '@sentry/types'; import { dsnToString, makeDsn } from './utils-hoist/dsn'; -import { urlEncode } from './utils-hoist/object'; const SENTRY_API_VERSION = '7'; @@ -18,13 +17,21 @@ function _getIngestEndpoint(dsn: DsnComponents): string { /** Returns a URL-encoded string with auth config suitable for a query string. */ function _encodedAuth(dsn: DsnComponents, sdkInfo: SdkInfo | undefined): string { - return urlEncode({ + const params: Record = { + sentry_version: SENTRY_API_VERSION, + }; + + if (dsn.publicKey) { // We send only the minimum set of required information. See // https://github.com/getsentry/sentry-javascript/issues/2572. - sentry_key: dsn.publicKey, - sentry_version: SENTRY_API_VERSION, - ...(sdkInfo && { sentry_client: `${sdkInfo.name}/${sdkInfo.version}` }), - }); + params.sentry_key = dsn.publicKey; + } + + if (sdkInfo) { + params.sentry_client = `${sdkInfo.name}/${sdkInfo.version}`; + } + + return new URLSearchParams(params).toString(); } /** diff --git a/packages/core/src/utils-hoist/index.ts b/packages/core/src/utils-hoist/index.ts index 1625ea6c0868..08120feae1cc 100644 --- a/packages/core/src/utils-hoist/index.ts +++ b/packages/core/src/utils-hoist/index.ts @@ -83,6 +83,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'; From dbc66100a6205a1a1719b5cd52a08301c3e3f409 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 22 Nov 2024 08:32:11 +0000 Subject: [PATCH 2/4] Revert accidental change --- packages/core/src/api.ts | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/packages/core/src/api.ts b/packages/core/src/api.ts index b7cd786d215a..f8bb8cfe8eac 100644 --- a/packages/core/src/api.ts +++ b/packages/core/src/api.ts @@ -1,5 +1,6 @@ import type { DsnComponents, DsnLike, SdkInfo } from '@sentry/types'; import { dsnToString, makeDsn } from './utils-hoist/dsn'; +import { urlEncode } from './utils-hoist/object'; const SENTRY_API_VERSION = '7'; @@ -17,21 +18,13 @@ function _getIngestEndpoint(dsn: DsnComponents): string { /** Returns a URL-encoded string with auth config suitable for a query string. */ function _encodedAuth(dsn: DsnComponents, sdkInfo: SdkInfo | undefined): string { - const params: Record = { - sentry_version: SENTRY_API_VERSION, - }; - - if (dsn.publicKey) { + return urlEncode({ // We send only the minimum set of required information. See // https://github.com/getsentry/sentry-javascript/issues/2572. - params.sentry_key = dsn.publicKey; - } - - if (sdkInfo) { - params.sentry_client = `${sdkInfo.name}/${sdkInfo.version}`; - } - - return new URLSearchParams(params).toString(); + sentry_key: dsn.publicKey, + sentry_version: SENTRY_API_VERSION, + ...(sdkInfo && { sentry_client: `${sdkInfo.name}/${sdkInfo.version}` }), + }); } /** From 768a2ae90e9a073b1fd86b1d4771ced0fbe35c94 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 22 Nov 2024 08:42:16 +0000 Subject: [PATCH 3/4] migration guide --- docs/migration/draft-v9-migration-guide.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/migration/draft-v9-migration-guide.md b/docs/migration/draft-v9-migration-guide.md index d117d66ecae3..828be81da501 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. ## `@sentry/core` From 768907ee8cdac5d80b779eb24092a9a036c9af05 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 22 Nov 2024 09:50:14 +0000 Subject: [PATCH 4/4] lint --- packages/utils/src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 0b4bcd669706..ce4f48b0492e 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,