Skip to content

feat(core): Deprecate validSeverityLevels #14407

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

Merged
merged 5 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions packages/core/src/api.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm wait did this get confused with another PR? This is the validSeverityLevels PR here, should this be in #14406 instead? 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes 😶 I pushed all of these PRs within like 30s and messed everything up 😂

const params: Record<string, string> = {
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();
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/utils-hoist/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export type {
TransactionNamingScheme,
} from './requestdata';

// eslint-disable-next-line deprecation/deprecation
export { severityLevelFromString, validSeverityLevels } from './severity';
export {
UNKNOWN_FUNCTION,
Expand Down
17 changes: 6 additions & 11 deletions packages/core/src/utils-hoist/severity.ts
Original file line number Diff line number Diff line change
@@ -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'];

/**
Expand All @@ -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;
}
4 changes: 2 additions & 2 deletions packages/core/test/utils-hoist/severity.test.ts
Original file line number Diff line number Diff line change
@@ -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'", () => {
Expand All @@ -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);
}
});
Expand Down
2 changes: 0 additions & 2 deletions packages/types/src/severity.ts
Original file line number Diff line number Diff line change
@@ -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';
Loading