Skip to content

Commit cbfc5a8

Browse files
committed
feat: Undeprecate Severity Enum
In #4280, specifically in commit dd3aa70, we deprecated the `Severity` enum in favour of using a string union type, `SeverityLevel`. It's important to note that this change affected the type signature of one of our public API methods, `captureMessage`. The change to deprecate the `Severity` enum was done for bundle size reasons. After releasing the beta with these changes, it was found that deprecating the `Severity` enum and replacing it with `SeverityLevel` was quite the disruptive change, which would make upgrading to the minor version a hassle for users. As a result, this patch undeprecates the `Severity` enum. The `Severity` enum will be removed in the upcoming major release instead, as a breaking change.
1 parent 8eabfe7 commit cbfc5a8

27 files changed

+70
-67
lines changed

packages/browser/src/backend.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BaseBackend } from '@sentry/core';
2-
import { Event, EventHint, Options, SeverityLevel, Transport } from '@sentry/types';
2+
import { Event, EventHint, Options, Severity, Transport } from '@sentry/types';
33
import { supportsFetch } from '@sentry/utils';
44

55
import { eventFromException, eventFromMessage } from './eventbuilder';
@@ -45,7 +45,7 @@ export class BrowserBackend extends BaseBackend<BrowserOptions> {
4545
/**
4646
* @inheritDoc
4747
*/
48-
public eventFromMessage(message: string, level: SeverityLevel = 'info', hint?: EventHint): PromiseLike<Event> {
48+
public eventFromMessage(message: string, level: Severity = Severity.Info, hint?: EventHint): PromiseLike<Event> {
4949
return eventFromMessage(this._options, message, level, hint);
5050
}
5151

packages/browser/src/eventbuilder.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Event, EventHint, Options, SeverityLevel } from '@sentry/types';
1+
import { Event, EventHint, Options, Severity } from '@sentry/types';
22
import {
33
addExceptionMechanism,
44
addExceptionTypeValue,
@@ -24,7 +24,7 @@ export function eventFromException(options: Options, exception: unknown, hint?:
2424
attachStacktrace: options.attachStacktrace,
2525
});
2626
addExceptionMechanism(event); // defaults to { type: 'generic', handled: true }
27-
event.level = 'error';
27+
event.level = Severity.Error;
2828
if (hint && hint.event_id) {
2929
event.event_id = hint.event_id;
3030
}
@@ -38,7 +38,7 @@ export function eventFromException(options: Options, exception: unknown, hint?:
3838
export function eventFromMessage(
3939
options: Options,
4040
message: string,
41-
level: SeverityLevel = 'info',
41+
level: Severity = Severity.Info,
4242
hint?: EventHint,
4343
): PromiseLike<Event> {
4444
const syntheticException = (hint && hint.syntheticException) || undefined;

packages/browser/src/exports.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export {
88
EventStatus,
99
Exception,
1010
Response,
11+
Severity,
1112
SeverityLevel,
1213
StackFrame,
1314
Stacktrace,

packages/browser/src/integrations/breadcrumbs.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
22
/* eslint-disable max-lines */
33
import { getCurrentHub } from '@sentry/core';
4-
import { Event, Integration } from '@sentry/types';
4+
import { Event, Integration, Severity } from '@sentry/types';
55
import {
66
addInstrumentationHandler,
77
getEventDescription,
@@ -230,7 +230,7 @@ function _fetchBreadcrumb(handlerData: { [key: string]: any }): void {
230230
{
231231
category: 'fetch',
232232
data: handlerData.fetchData,
233-
level: 'error',
233+
level: Severity.Error,
234234
type: 'http',
235235
},
236236
{

packages/browser/src/integrations/globalhandlers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
22
import { getCurrentHub } from '@sentry/core';
3-
import { Event, EventHint, Hub, Integration, Primitive } from '@sentry/types';
3+
import { Event, EventHint, Hub, Integration, Primitive, Severity } from '@sentry/types';
44
import {
55
addExceptionMechanism,
66
addInstrumentationHandler,
@@ -148,7 +148,7 @@ function _installGlobalOnUnhandledRejectionHandler(): void {
148148
isRejection: true,
149149
});
150150

151-
event.level = 'error';
151+
event.level = Severity.Error;
152152

153153
addMechanismAndCapture(hub, error, event, 'onunhandledrejection');
154154
return;

packages/core/src/basebackend.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Event, EventHint, Options, Session, SeverityLevel, Transport } from '@sentry/types';
1+
import { Event, EventHint, Options, Session, Severity, Transport } from '@sentry/types';
22
import { isDebugBuild, logger, SentryError } from '@sentry/utils';
33

44
import { NoopTransport } from './transports/noop';
@@ -29,7 +29,7 @@ export interface Backend {
2929
eventFromException(exception: any, hint?: EventHint): PromiseLike<Event>;
3030

3131
/** Creates an {@link Event} from primitive inputs to `captureMessage`. */
32-
eventFromMessage(message: string, level?: SeverityLevel, hint?: EventHint): PromiseLike<Event>;
32+
eventFromMessage(message: string, level?: Severity, hint?: EventHint): PromiseLike<Event>;
3333

3434
/** Submits the event to Sentry */
3535
sendEvent(event: Event): void;
@@ -83,7 +83,7 @@ export abstract class BaseBackend<O extends Options> implements Backend {
8383
/**
8484
* @inheritDoc
8585
*/
86-
public eventFromMessage(_message: string, _level?: SeverityLevel, _hint?: EventHint): PromiseLike<Event> {
86+
public eventFromMessage(_message: string, _level?: Severity, _hint?: EventHint): PromiseLike<Event> {
8787
throw new SentryError('Backend has to implement `eventFromMessage` method');
8888
}
8989

packages/core/src/baseclient.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
Integration,
99
IntegrationClass,
1010
Options,
11-
SeverityLevel,
11+
Severity,
1212
Transport,
1313
} from '@sentry/types';
1414
import {
@@ -129,7 +129,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
129129
/**
130130
* @inheritDoc
131131
*/
132-
public captureMessage(message: string, level?: SeverityLevel, hint?: EventHint, scope?: Scope): string | undefined {
132+
public captureMessage(message: string, level?: Severity, hint?: EventHint, scope?: Scope): string | undefined {
133133
let eventId: string | undefined = hint && hint.event_id;
134134

135135
const promisedEvent = isPrimitive(message)

packages/core/test/mocks/backend.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Session } from '@sentry/hub';
2-
import { Event, Options, SeverityLevel, Transport } from '@sentry/types';
2+
import { Event, Options, Severity, Transport } from '@sentry/types';
33
import { resolvedSyncPromise } from '@sentry/utils';
44

55
import { BaseBackend } from '../../src/basebackend';
@@ -38,7 +38,7 @@ export class TestBackend extends BaseBackend<TestOptions> {
3838
});
3939
}
4040

41-
public eventFromMessage(message: string, level: SeverityLevel = 'info'): PromiseLike<Event> {
41+
public eventFromMessage(message: string, level: Severity = Severity.Info): PromiseLike<Event> {
4242
return resolvedSyncPromise({ message, level });
4343
}
4444

packages/hub/src/hub.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
IntegrationClass,
1414
Primitive,
1515
SessionContext,
16-
SeverityLevel,
16+
Severity,
1717
Span,
1818
SpanContext,
1919
Transaction,
@@ -215,7 +215,7 @@ export class Hub implements HubInterface {
215215
/**
216216
* @inheritDoc
217217
*/
218-
public captureMessage(message: string, level?: SeverityLevel, hint?: EventHint): string {
218+
public captureMessage(message: string, level?: Severity, hint?: EventHint): string {
219219
const eventId = (this._lastEventId = uuid4());
220220
let finalHint = hint;
221221

packages/hub/src/scope.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
RequestSession,
1414
Scope as ScopeInterface,
1515
ScopeContext,
16-
SeverityLevel,
16+
Severity,
1717
Span,
1818
Transaction,
1919
User,
@@ -61,7 +61,7 @@ export class Scope implements ScopeInterface {
6161
protected _fingerprint?: string[];
6262

6363
/** Severity */
64-
protected _level?: SeverityLevel;
64+
protected _level?: Severity;
6565

6666
/** Transaction Name */
6767
protected _transactionName?: string;
@@ -208,7 +208,7 @@ export class Scope implements ScopeInterface {
208208
/**
209209
* @inheritDoc
210210
*/
211-
public setLevel(level: SeverityLevel): this {
211+
public setLevel(level: Severity): this {
212212
this._level = level;
213213
this._notifyScopeListeners();
214214
return this;

packages/hub/test/scope.test.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Event, EventHint } from '@sentry/types';
1+
import { Event, EventHint, Severity } from '@sentry/types';
22
import { getGlobalObject } from '@sentry/utils';
33

44
import { addGlobalEventProcessor, Scope } from '../src';
@@ -85,8 +85,8 @@ describe('Scope', () => {
8585

8686
test('setLevel', () => {
8787
const scope = new Scope();
88-
scope.setLevel('critical');
89-
expect((scope as any)._level).toEqual('critical');
88+
scope.setLevel(Severity.Critical);
89+
expect((scope as any)._level).toEqual(Severity.Critical);
9090
});
9191

9292
test('setTransactionName', () => {
@@ -137,8 +137,8 @@ describe('Scope', () => {
137137

138138
test('chaining', () => {
139139
const scope = new Scope();
140-
scope.setLevel('critical').setUser({ id: '1' });
141-
expect((scope as any)._level).toEqual('critical');
140+
scope.setLevel(Severity.Critical).setUser({ id: '1' });
141+
expect((scope as any)._level).toEqual(Severity.Critical);
142142
expect((scope as any)._user).toEqual({ id: '1' });
143143
});
144144
});
@@ -202,7 +202,7 @@ describe('Scope', () => {
202202
scope.setTag('a', 'b');
203203
scope.setUser({ id: '1' });
204204
scope.setFingerprint(['abcd']);
205-
scope.setLevel('warning');
205+
scope.setLevel(Severity.Warning);
206206
scope.setTransactionName('/abc');
207207
scope.addBreadcrumb({ message: 'test' });
208208
scope.setContext('os', { id: '1' });
@@ -294,11 +294,11 @@ describe('Scope', () => {
294294
test('scope level should have priority over event level', () => {
295295
expect.assertions(1);
296296
const scope = new Scope();
297-
scope.setLevel('warning');
297+
scope.setLevel(Severity.Warning);
298298
const event: Event = {};
299-
event.level = 'critical';
299+
event.level = Severity.Critical;
300300
return scope.applyToEvent(event).then(processedEvent => {
301-
expect(processedEvent!.level).toEqual('warning');
301+
expect(processedEvent!.level).toEqual(Severity.Warning);
302302
});
303303
});
304304

@@ -410,7 +410,7 @@ describe('Scope', () => {
410410
scope.setContext('foo', { id: '1' });
411411
scope.setContext('bar', { id: '2' });
412412
scope.setUser({ id: '1337' });
413-
scope.setLevel('info');
413+
scope.setLevel(Severity.Info);
414414
scope.setFingerprint(['foo']);
415415
scope.setRequestSession({ status: 'ok' });
416416
});
@@ -458,7 +458,7 @@ describe('Scope', () => {
458458
localScope.setContext('bar', { id: '3' });
459459
localScope.setContext('baz', { id: '4' });
460460
localScope.setUser({ id: '42' });
461-
localScope.setLevel('warning');
461+
localScope.setLevel(Severity.Warning);
462462
localScope.setFingerprint(['bar']);
463463
(localScope as any)._requestSession = { status: 'ok' };
464464

packages/minimal/src/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
Extra,
88
Extras,
99
Primitive,
10-
SeverityLevel,
10+
Severity,
1111
Transaction,
1212
TransactionContext,
1313
User,
@@ -53,10 +53,10 @@ export function captureException(exception: any, captureContext?: CaptureContext
5353
* Captures a message event and sends it to Sentry.
5454
*
5555
* @param message The message to send to Sentry.
56-
* @param SeverityLevel Define the level of the message.
56+
* @param Severity Define the level of the message.
5757
* @returns The generated eventId.
5858
*/
59-
export function captureMessage(message: string, captureContext?: CaptureContext | SeverityLevel): string {
59+
export function captureMessage(message: string, captureContext?: CaptureContext | Severity): string {
6060
let syntheticException: Error;
6161
try {
6262
throw new Error(message);

packages/minimal/test/lib/minimal.test.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
withScope,
1616
} from '../../src';
1717
import { init, TestClient, TestClient2 } from '../mocks/client';
18+
import { Severity } from '@sentry/types';
1819

1920
// eslint-disable-next-line no-var
2021
declare var global: any;
@@ -164,8 +165,8 @@ describe('Minimal', () => {
164165
const client: any = new TestClient({});
165166
const scope = getCurrentHub().pushScope();
166167
getCurrentHub().bindClient(client);
167-
scope.setLevel('warning');
168-
expect(global.__SENTRY__.hub._stack[1].scope._level).toEqual('warning');
168+
scope.setLevel(Severity.Warning);
169+
expect(global.__SENTRY__.hub._stack[1].scope._level).toEqual(Severity.Warning);
169170
});
170171
});
171172

@@ -244,16 +245,16 @@ describe('Minimal', () => {
244245

245246
test('withScope', () => {
246247
withScope(scope => {
247-
scope.setLevel('warning');
248+
scope.setLevel(Severity.Warning);
248249
scope.setFingerprint(['1']);
249250
withScope(scope2 => {
250-
scope2.setLevel('info');
251+
scope2.setLevel(Severity.Info);
251252
scope2.setFingerprint(['2']);
252253
withScope(scope3 => {
253254
scope3.clear();
254-
expect(global.__SENTRY__.hub._stack[1].scope._level).toEqual('warning');
255+
expect(global.__SENTRY__.hub._stack[1].scope._level).toEqual(Severity.Warning);
255256
expect(global.__SENTRY__.hub._stack[1].scope._fingerprint).toEqual(['1']);
256-
expect(global.__SENTRY__.hub._stack[2].scope._level).toEqual('info');
257+
expect(global.__SENTRY__.hub._stack[2].scope._level).toEqual(Severity.Info);
257258
expect(global.__SENTRY__.hub._stack[2].scope._fingerprint).toEqual(['2']);
258259
expect(global.__SENTRY__.hub._stack[3].scope._level).toBeUndefined();
259260
});

packages/node/src/backend.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BaseBackend } from '@sentry/core';
2-
import { Event, EventHint, SeverityLevel, Transport, TransportOptions } from '@sentry/types';
2+
import { Event, EventHint, Severity, Transport, TransportOptions } from '@sentry/types';
33
import { makeDsn } from '@sentry/utils';
44

55
import { eventFromException, eventFromMessage } from './eventbuilder';
@@ -22,7 +22,7 @@ export class NodeBackend extends BaseBackend<NodeOptions> {
2222
/**
2323
* @inheritDoc
2424
*/
25-
public eventFromMessage(message: string, level: SeverityLevel = 'info', hint?: EventHint): PromiseLike<Event> {
25+
public eventFromMessage(message: string, level: Severity = Severity.Info, hint?: EventHint): PromiseLike<Event> {
2626
return eventFromMessage(this._options, message, level, hint);
2727
}
2828

packages/node/src/eventbuilder.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getCurrentHub } from '@sentry/hub';
2-
import { Event, EventHint, Mechanism, Options, SeverityLevel } from '@sentry/types';
2+
import { Event, EventHint, Mechanism, Options, Severity } from '@sentry/types';
33
import {
44
addExceptionMechanism,
55
addExceptionTypeValue,
@@ -69,7 +69,7 @@ export function eventFromException(options: Options, exception: unknown, hint?:
6969
export function eventFromMessage(
7070
options: Options,
7171
message: string,
72-
level: SeverityLevel = 'info',
72+
level: Severity = Severity.Info,
7373
hint?: EventHint,
7474
): PromiseLike<Event> {
7575
const event: Event = {

packages/node/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export {
88
EventStatus,
99
Exception,
1010
Response,
11+
Severity,
1112
SeverityLevel,
1213
StackFrame,
1314
Stacktrace,

packages/node/src/integrations/onuncaughtexception.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getCurrentHub, Scope } from '@sentry/core';
2-
import { Integration } from '@sentry/types';
2+
import { Integration, Severity } from '@sentry/types';
33
import { logger } from '@sentry/utils';
44

55
import { NodeClient } from '../client';
@@ -77,7 +77,7 @@ export class OnUncaughtException implements Integration {
7777

7878
if (hub.getIntegration(OnUncaughtException)) {
7979
hub.withScope((scope: Scope) => {
80-
scope.setLevel('fatal');
80+
scope.setLevel(Severity.Fatal);
8181
hub.captureException(error, {
8282
originalException: error,
8383
data: { mechanism: { handled: false, type: 'onuncaughtexception' } },

packages/serverless/src/awslambda.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ export function wrapHandler<TEvent, TResult>(
274274
timeoutWarningTimer = setTimeout(() => {
275275
withScope(scope => {
276276
scope.setTag('timeout', humanReadableTimeout);
277-
captureMessage(`Possible function timeout: ${context.functionName}`, 'warning');
277+
captureMessage(`Possible function timeout: ${context.functionName}`, Sentry.Severity.Warning);
278278
});
279279
}, timeoutWarningDelay);
280280
}

packages/tracing/src/index.bundle.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export {
66
EventStatus,
77
Exception,
88
Response,
9+
Severity,
910
SeverityLevel,
1011
StackFrame,
1112
Stacktrace,

0 commit comments

Comments
 (0)