Skip to content

Commit

Permalink
feat: Undeprecate Severity Enum
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AbhiPrasad committed Jan 17, 2022
1 parent 8eabfe7 commit de2b70d
Show file tree
Hide file tree
Showing 24 changed files with 58 additions and 56 deletions.
4 changes: 2 additions & 2 deletions packages/browser/src/backend.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseBackend } from '@sentry/core';
import { Event, EventHint, Options, SeverityLevel, Transport } from '@sentry/types';
import { Event, EventHint, Options, Severity, Transport } from '@sentry/types';
import { supportsFetch } from '@sentry/utils';

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

Expand Down
6 changes: 3 additions & 3 deletions packages/browser/src/eventbuilder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Event, EventHint, Options, SeverityLevel } from '@sentry/types';
import { Event, EventHint, Options, Severity } from '@sentry/types';
import {
addExceptionMechanism,
addExceptionTypeValue,
Expand All @@ -24,7 +24,7 @@ export function eventFromException(options: Options, exception: unknown, hint?:
attachStacktrace: options.attachStacktrace,
});
addExceptionMechanism(event); // defaults to { type: 'generic', handled: true }
event.level = 'error';
event.level = Severity.Error;
if (hint && hint.event_id) {
event.event_id = hint.event_id;
}
Expand All @@ -38,7 +38,7 @@ export function eventFromException(options: Options, exception: unknown, hint?:
export function eventFromMessage(
options: Options,
message: string,
level: SeverityLevel = 'info',
level: Severity = Severity.Info,
hint?: EventHint,
): PromiseLike<Event> {
const syntheticException = (hint && hint.syntheticException) || undefined;
Expand Down
1 change: 1 addition & 0 deletions packages/browser/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export {
EventStatus,
Exception,
Response,
Severity,
SeverityLevel,
StackFrame,
Stacktrace,
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/integrations/breadcrumbs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable max-lines */
import { getCurrentHub } from '@sentry/core';
import { Event, Integration } from '@sentry/types';
import { Event, Integration, Severity } from '@sentry/types';
import {
addInstrumentationHandler,
getEventDescription,
Expand Down Expand Up @@ -230,7 +230,7 @@ function _fetchBreadcrumb(handlerData: { [key: string]: any }): void {
{
category: 'fetch',
data: handlerData.fetchData,
level: 'error',
level: Severity.Error,
type: 'http',
},
{
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/integrations/globalhandlers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { getCurrentHub } from '@sentry/core';
import { Event, EventHint, Hub, Integration, Primitive } from '@sentry/types';
import { Event, EventHint, Hub, Integration, Primitive, Severity } from '@sentry/types';
import {
addExceptionMechanism,
addInstrumentationHandler,
Expand Down Expand Up @@ -148,7 +148,7 @@ function _installGlobalOnUnhandledRejectionHandler(): void {
isRejection: true,
});

event.level = 'error';
event.level = Severity.Error;

addMechanismAndCapture(hub, error, event, 'onunhandledrejection');
return;
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/basebackend.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Event, EventHint, Options, Session, SeverityLevel, Transport } from '@sentry/types';
import { Event, EventHint, Options, Session, Severity, Transport } from '@sentry/types';
import { isDebugBuild, logger, SentryError } from '@sentry/utils';

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/baseclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Integration,
IntegrationClass,
Options,
SeverityLevel,
Severity,
Transport,
} from '@sentry/types';
import {
Expand Down Expand Up @@ -129,7 +129,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
/**
* @inheritDoc
*/
public captureMessage(message: string, level?: SeverityLevel, hint?: EventHint, scope?: Scope): string | undefined {
public captureMessage(message: string, level?: Severity, hint?: EventHint, scope?: Scope): string | undefined {
let eventId: string | undefined = hint && hint.event_id;

const promisedEvent = isPrimitive(message)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/mocks/backend.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Session } from '@sentry/hub';
import { Event, Options, SeverityLevel, Transport } from '@sentry/types';
import { Event, Options, Severity, Transport } from '@sentry/types';
import { resolvedSyncPromise } from '@sentry/utils';

import { BaseBackend } from '../../src/basebackend';
Expand Down Expand Up @@ -38,7 +38,7 @@ export class TestBackend extends BaseBackend<TestOptions> {
});
}

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

Expand Down
4 changes: 2 additions & 2 deletions packages/hub/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
IntegrationClass,
Primitive,
SessionContext,
SeverityLevel,
Severity,
Span,
SpanContext,
Transaction,
Expand Down Expand Up @@ -215,7 +215,7 @@ export class Hub implements HubInterface {
/**
* @inheritDoc
*/
public captureMessage(message: string, level?: SeverityLevel, hint?: EventHint): string {
public captureMessage(message: string, level?: Severity, hint?: EventHint): string {
const eventId = (this._lastEventId = uuid4());
let finalHint = hint;

Expand Down
6 changes: 3 additions & 3 deletions packages/hub/src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
RequestSession,
Scope as ScopeInterface,
ScopeContext,
SeverityLevel,
Severity,
Span,
Transaction,
User,
Expand Down Expand Up @@ -61,7 +61,7 @@ export class Scope implements ScopeInterface {
protected _fingerprint?: string[];

/** Severity */
protected _level?: SeverityLevel;
protected _level?: Severity;

/** Transaction Name */
protected _transactionName?: string;
Expand Down Expand Up @@ -208,7 +208,7 @@ export class Scope implements ScopeInterface {
/**
* @inheritDoc
*/
public setLevel(level: SeverityLevel): this {
public setLevel(level: Severity): this {
this._level = level;
this._notifyScopeListeners();
return this;
Expand Down
18 changes: 9 additions & 9 deletions packages/hub/test/scope.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Event, EventHint } from '@sentry/types';
import { Event, EventHint, Severity } from '@sentry/types';
import { getGlobalObject } from '@sentry/utils';

import { addGlobalEventProcessor, Scope } from '../src';
Expand Down Expand Up @@ -137,8 +137,8 @@ describe('Scope', () => {

test('chaining', () => {
const scope = new Scope();
scope.setLevel('critical').setUser({ id: '1' });
expect((scope as any)._level).toEqual('critical');
scope.setLevel(Severity.Critical).setUser({ id: '1' });
expect((scope as any)._level).toEqual(Severity.Critical);
expect((scope as any)._user).toEqual({ id: '1' });
});
});
Expand Down Expand Up @@ -202,7 +202,7 @@ describe('Scope', () => {
scope.setTag('a', 'b');
scope.setUser({ id: '1' });
scope.setFingerprint(['abcd']);
scope.setLevel('warning');
scope.setLevel(Severity.Warning);
scope.setTransactionName('/abc');
scope.addBreadcrumb({ message: 'test' });
scope.setContext('os', { id: '1' });
Expand Down Expand Up @@ -294,11 +294,11 @@ describe('Scope', () => {
test('scope level should have priority over event level', () => {
expect.assertions(1);
const scope = new Scope();
scope.setLevel('warning');
scope.setLevel(Severity.Warning);
const event: Event = {};
event.level = 'critical';
event.level = Severity.Critical;
return scope.applyToEvent(event).then(processedEvent => {
expect(processedEvent!.level).toEqual('warning');
expect(processedEvent!.level).toEqual(Severity.Warning);
});
});

Expand Down Expand Up @@ -410,7 +410,7 @@ describe('Scope', () => {
scope.setContext('foo', { id: '1' });
scope.setContext('bar', { id: '2' });
scope.setUser({ id: '1337' });
scope.setLevel('info');
scope.setLevel(Severity.Info);
scope.setFingerprint(['foo']);
scope.setRequestSession({ status: 'ok' });
});
Expand Down Expand Up @@ -458,7 +458,7 @@ describe('Scope', () => {
localScope.setContext('bar', { id: '3' });
localScope.setContext('baz', { id: '4' });
localScope.setUser({ id: '42' });
localScope.setLevel('warning');
localScope.setLevel(Severity.Warning);
localScope.setFingerprint(['bar']);
(localScope as any)._requestSession = { status: 'ok' };

Expand Down
6 changes: 3 additions & 3 deletions packages/minimal/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Extra,
Extras,
Primitive,
SeverityLevel,
Severity,
Transaction,
TransactionContext,
User,
Expand Down Expand Up @@ -53,10 +53,10 @@ export function captureException(exception: any, captureContext?: CaptureContext
* Captures a message event and sends it to Sentry.
*
* @param message The message to send to Sentry.
* @param SeverityLevel Define the level of the message.
* @param Severity Define the level of the message.
* @returns The generated eventId.
*/
export function captureMessage(message: string, captureContext?: CaptureContext | SeverityLevel): string {
export function captureMessage(message: string, captureContext?: CaptureContext | Severity): string {
let syntheticException: Error;
try {
throw new Error(message);
Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/backend.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseBackend } from '@sentry/core';
import { Event, EventHint, SeverityLevel, Transport, TransportOptions } from '@sentry/types';
import { Event, EventHint, Severity, Transport, TransportOptions } from '@sentry/types';
import { makeDsn } from '@sentry/utils';

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

Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/eventbuilder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getCurrentHub } from '@sentry/hub';
import { Event, EventHint, Mechanism, Options, SeverityLevel } from '@sentry/types';
import { Event, EventHint, Mechanism, Options, Severity } from '@sentry/types';
import {
addExceptionMechanism,
addExceptionTypeValue,
Expand Down Expand Up @@ -69,7 +69,7 @@ export function eventFromException(options: Options, exception: unknown, hint?:
export function eventFromMessage(
options: Options,
message: string,
level: SeverityLevel = 'info',
level: Severity = Severity.Info,
hint?: EventHint,
): PromiseLike<Event> {
const event: Event = {
Expand Down
1 change: 1 addition & 0 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export {
EventStatus,
Exception,
Response,
Severity,
SeverityLevel,
StackFrame,
Stacktrace,
Expand Down
1 change: 1 addition & 0 deletions packages/tracing/src/index.bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export {
EventStatus,
Exception,
Response,
Severity,
SeverityLevel,
StackFrame,
Stacktrace,
Expand Down
4 changes: 2 additions & 2 deletions packages/types/src/breadcrumb.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { SeverityLevel } from './severity';
import { Severity } from './severity';

/** JSDoc */
export interface Breadcrumb {
type?: string;
level?: SeverityLevel;
level?: Severity;
event_id?: string;
category?: string;
message?: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/types/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Integration, IntegrationClass } from './integration';
import { Options } from './options';
import { Scope } from './scope';
import { Session } from './session';
import { SeverityLevel } from './severity';
import { Severity } from './severity';
import { Transport } from './transport';

/**
Expand Down Expand Up @@ -36,7 +36,7 @@ export interface Client<O extends Options = Options> {
* @param scope An optional scope containing event metadata.
* @returns The event id
*/
captureMessage(message: string, level?: SeverityLevel, hint?: EventHint, scope?: Scope): string | undefined;
captureMessage(message: string, level?: Severity, hint?: EventHint, scope?: Scope): string | undefined;

/**
* Captures a manually created event and sends it to Sentry.
Expand Down
4 changes: 2 additions & 2 deletions packages/types/src/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Primitive } from './misc';
import { Request } from './request';
import { CaptureContext } from './scope';
import { SdkInfo } from './sdkinfo';
import { SeverityLevel } from './severity';
import { Severity } from './severity';
import { Span } from './span';
import { Stacktrace } from './stacktrace';
import { Measurements } from './transaction';
Expand All @@ -19,7 +19,7 @@ export interface Event {
message?: string;
timestamp?: number;
start_timestamp?: number;
level?: SeverityLevel;
level?: Severity;
platform?: string;
logger?: string;
server_name?: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/types/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Integration, IntegrationClass } from './integration';
import { Primitive } from './misc';
import { Scope } from './scope';
import { Session, SessionContext } from './session';
import { SeverityLevel } from './severity';
import { Severity } from './severity';
import { Span, SpanContext } from './span';
import { CustomSamplingContext, Transaction, TransactionContext } from './transaction';
import { User } from './user';
Expand Down Expand Up @@ -88,7 +88,7 @@ export interface Hub {
* @param hint May contain additional information about the original exception.
* @returns The generated eventId.
*/
captureMessage(message: string, level?: SeverityLevel, hint?: EventHint): string;
captureMessage(message: string, level?: Severity, hint?: EventHint): string;

/**
* Captures a manually created event and sends it to Sentry.
Expand Down
1 change: 0 additions & 1 deletion packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export {
SessionFlusherLike,
} from './session';

/* eslint-disable-next-line deprecation/deprecation */
export { Severity } from './severity';
export { SeverityLevel, SeverityLevels } from './severity';
export { Span, SpanContext } from './span';
Expand Down
Loading

0 comments on commit de2b70d

Please sign in to comment.