Skip to content

Commit e10697d

Browse files
authored
ref(types): deprecate request status enum (#4316)
* ref(types): deprecate request status * ref(types): deprecate session status * ref(types): remove unused logLevel (#4317) (#4320)
1 parent 6f9069e commit e10697d

19 files changed

+112
-128
lines changed

packages/core/src/baseclient.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
Integration,
88
IntegrationClass,
99
Options,
10-
SessionStatus,
1110
SeverityLevel,
1211
Transport,
1312
} from '@sentry/types';
@@ -267,12 +266,12 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
267266
// A session is updated and that session update is sent in only one of the two following scenarios:
268267
// 1. Session with non terminal status and 0 errors + an error occurred -> Will set error count to 1 and send update
269268
// 2. Session with non terminal status and 1 error + a crash occurred -> Will set status crashed and send update
270-
const sessionNonTerminal = session.status === SessionStatus.Ok;
269+
const sessionNonTerminal = session.status === 'ok';
271270
const shouldUpdateAndSend = (sessionNonTerminal && session.errors === 0) || (sessionNonTerminal && crashed);
272271

273272
if (shouldUpdateAndSend) {
274273
session.update({
275-
...(crashed && { status: SessionStatus.Crashed }),
274+
...(crashed && { status: 'crashed' }),
276275
errors: session.errors || Number(errored || crashed),
277276
});
278277
this.captureSession(session);

packages/hub/src/hub.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
IntegrationClass,
1414
Primitive,
1515
SessionContext,
16-
SessionStatus,
1716
SeverityLevel,
1817
Span,
1918
SpanContext,
@@ -451,8 +450,8 @@ export class Hub implements HubInterface {
451450
if (scope) {
452451
// End existing session if there's one
453452
const currentSession = scope.getSession && scope.getSession();
454-
if (currentSession && currentSession.status === SessionStatus.Ok) {
455-
currentSession.update({ status: SessionStatus.Exited });
453+
if (currentSession && currentSession.status === 'ok') {
454+
currentSession.update({ status: 'exited' });
456455
}
457456
this.endSession();
458457

packages/hub/src/session.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class Session implements SessionInterface {
1313
public timestamp: number;
1414
public started: number;
1515
public duration?: number = 0;
16-
public status: SessionStatus = SessionStatus.Ok;
16+
public status: SessionStatus = 'ok';
1717
public environment?: string;
1818
public ipAddress?: string;
1919
public init: boolean = true;
@@ -88,11 +88,11 @@ export class Session implements SessionInterface {
8888
}
8989

9090
/** JSDoc */
91-
public close(status?: Exclude<SessionStatus, SessionStatus.Ok>): void {
91+
public close(status?: Exclude<SessionStatus, 'ok'>): void {
9292
if (status) {
9393
this.update({ status });
94-
} else if (this.status === SessionStatus.Ok) {
95-
this.update({ status: SessionStatus.Exited });
94+
} else if (this.status === 'ok') {
95+
this.update({ status: 'exited' });
9696
} else {
9797
this.update();
9898
}

packages/hub/src/sessionflusher.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ export class SessionFlusher implements SessionFlusherLike {
113113
}
114114

115115
switch (status) {
116-
case RequestSessionStatus.Errored:
116+
case 'errored':
117117
aggregationCounts.errored = (aggregationCounts.errored || 0) + 1;
118118
return aggregationCounts.errored;
119-
case RequestSessionStatus.Ok:
119+
case 'ok':
120120
aggregationCounts.exited = (aggregationCounts.exited || 0) + 1;
121121
return aggregationCounts.exited;
122-
case RequestSessionStatus.Crashed:
122+
default:
123123
aggregationCounts.crashed = (aggregationCounts.crashed || 0) + 1;
124124
return aggregationCounts.crashed;
125125
}

packages/hub/test/scope.test.ts

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

44
import { addGlobalEventProcessor, Scope } from '../src';
@@ -147,7 +147,7 @@ describe('Scope', () => {
147147

148148
test('_requestSession clone', () => {
149149
const parentScope = new Scope();
150-
parentScope.setRequestSession({ status: RequestSessionStatus.Errored });
150+
parentScope.setRequestSession({ status: 'errored' });
151151
const scope = Scope.clone(parentScope);
152152
expect(parentScope.getRequestSession()).toEqual(scope.getRequestSession());
153153
});
@@ -174,16 +174,16 @@ describe('Scope', () => {
174174
// Test that ensures if the status value of `status` of `_requestSession` is changed in a child scope
175175
// that it should also change in parent scope because we are copying the reference to the object
176176
const parentScope = new Scope();
177-
parentScope.setRequestSession({ status: RequestSessionStatus.Errored });
177+
parentScope.setRequestSession({ status: 'errored' });
178178

179179
const scope = Scope.clone(parentScope);
180180
const requestSession = scope.getRequestSession();
181181
if (requestSession) {
182-
requestSession.status = RequestSessionStatus.Ok;
182+
requestSession.status = 'ok';
183183
}
184184

185-
expect(parentScope.getRequestSession()).toEqual({ status: RequestSessionStatus.Ok });
186-
expect(scope.getRequestSession()).toEqual({ status: RequestSessionStatus.Ok });
185+
expect(parentScope.getRequestSession()).toEqual({ status: 'ok' });
186+
expect(scope.getRequestSession()).toEqual({ status: 'ok' });
187187
});
188188
});
189189

@@ -375,7 +375,7 @@ describe('Scope', () => {
375375
scope.setUser({ id: '1' });
376376
scope.setFingerprint(['abcd']);
377377
scope.addBreadcrumb({ message: 'test' });
378-
scope.setRequestSession({ status: RequestSessionStatus.Ok });
378+
scope.setRequestSession({ status: 'ok' });
379379
expect((scope as any)._extra).toEqual({ a: 2 });
380380
scope.clear();
381381
expect((scope as any)._extra).toEqual({});
@@ -402,7 +402,7 @@ describe('Scope', () => {
402402
scope.setUser({ id: '1337' });
403403
scope.setLevel('info');
404404
scope.setFingerprint(['foo']);
405-
scope.setRequestSession({ status: RequestSessionStatus.Ok });
405+
scope.setRequestSession({ status: 'ok' });
406406
});
407407

408408
test('given no data, returns the original scope', () => {
@@ -450,7 +450,7 @@ describe('Scope', () => {
450450
localScope.setUser({ id: '42' });
451451
localScope.setLevel('warning');
452452
localScope.setFingerprint(['bar']);
453-
(localScope as any)._requestSession = { status: RequestSessionStatus.Ok };
453+
(localScope as any)._requestSession = { status: 'ok' };
454454

455455
const updatedScope = scope.update(localScope) as any;
456456

@@ -472,7 +472,7 @@ describe('Scope', () => {
472472
expect(updatedScope._user).toEqual({ id: '42' });
473473
expect(updatedScope._level).toEqual('warning');
474474
expect(updatedScope._fingerprint).toEqual(['bar']);
475-
expect(updatedScope._requestSession.status).toEqual(RequestSessionStatus.Ok);
475+
expect(updatedScope._requestSession.status).toEqual('ok');
476476
});
477477

478478
test('given an empty instance of Scope, it should preserve all the original scope data', () => {
@@ -493,7 +493,7 @@ describe('Scope', () => {
493493
expect(updatedScope._user).toEqual({ id: '1337' });
494494
expect(updatedScope._level).toEqual('info');
495495
expect(updatedScope._fingerprint).toEqual(['foo']);
496-
expect(updatedScope._requestSession.status).toEqual(RequestSessionStatus.Ok);
496+
expect(updatedScope._requestSession.status).toEqual('ok');
497497
});
498498

499499
test('given a plain object, it should merge two together, with the passed object having priority', () => {
@@ -504,7 +504,7 @@ describe('Scope', () => {
504504
level: 'warning',
505505
tags: { bar: '3', baz: '4' },
506506
user: { id: '42' },
507-
requestSession: { status: RequestSessionStatus.Errored },
507+
requestSession: { status: 'errored' },
508508
};
509509
const updatedScope = scope.update(localAttributes) as any;
510510

@@ -526,7 +526,7 @@ describe('Scope', () => {
526526
expect(updatedScope._user).toEqual({ id: '42' });
527527
expect(updatedScope._level).toEqual('warning');
528528
expect(updatedScope._fingerprint).toEqual(['bar']);
529-
expect(updatedScope._requestSession).toEqual({ status: RequestSessionStatus.Errored });
529+
expect(updatedScope._requestSession).toEqual({ status: 'errored' });
530530
});
531531
});
532532

packages/hub/test/session.test.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SessionContext, SessionStatus } from '@sentry/types';
1+
import { SessionContext } from '@sentry/types';
22
import { timestampInSeconds } from '@sentry/utils';
33

44
import { Session } from '../src/session';
@@ -16,7 +16,7 @@ describe('Session', () => {
1616
init: true,
1717
sid: expect.any(String),
1818
started: expect.stringMatching(currentYear),
19-
status: SessionStatus.Ok,
19+
status: 'ok',
2020
timestamp: expect.stringMatching(currentYear),
2121
});
2222

@@ -74,7 +74,7 @@ describe('Session', () => {
7474
],
7575
['sets an userAgent', { userAgent: 'Mozilla/5.0' }, { attrs: { user_agent: 'Mozilla/5.0' } }],
7676
['sets errors', { errors: 3 }, { errors: 3 }],
77-
['sets status', { status: SessionStatus.Crashed }, { status: SessionStatus.Crashed }],
77+
['sets status', { status: 'crashed' }, { status: 'crashed' }],
7878
];
7979

8080
test.each(table)('%s', (...test) => {
@@ -93,26 +93,26 @@ describe('Session', () => {
9393
describe('close', () => {
9494
it('exits a normal session', () => {
9595
const session = new Session();
96-
expect(session.status).toEqual(SessionStatus.Ok);
96+
expect(session.status).toEqual('ok');
9797
session.close();
98-
expect(session.status).toEqual(SessionStatus.Exited);
98+
expect(session.status).toEqual('exited');
9999
});
100100

101101
it('updates session status when give status', () => {
102102
const session = new Session();
103-
expect(session.status).toEqual(SessionStatus.Ok);
103+
expect(session.status).toEqual('ok');
104104

105-
session.close(SessionStatus.Abnormal);
106-
expect(session.status).toEqual(SessionStatus.Abnormal);
105+
session.close('abnormal');
106+
expect(session.status).toEqual('abnormal');
107107
});
108108

109109
it('only changes status ok to exited', () => {
110110
const session = new Session();
111-
session.update({ status: SessionStatus.Crashed });
112-
expect(session.status).toEqual(SessionStatus.Crashed);
111+
session.update({ status: 'crashed' });
112+
expect(session.status).toEqual('crashed');
113113

114114
session.close();
115-
expect(session.status).toEqual(SessionStatus.Crashed);
115+
expect(session.status).toEqual('crashed');
116116
});
117117
});
118118
});

packages/hub/test/sessionflusher.test.ts

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { RequestSessionStatus } from '@sentry/types';
2-
31
import { SessionFlusher } from '../src/sessionflusher';
42

53
describe('Session Flusher', () => {
@@ -28,16 +26,16 @@ describe('Session Flusher', () => {
2826
const flusher = new SessionFlusher(transport, { release: '1.0.0', environment: 'dev' });
2927

3028
const date = new Date('2021-04-08T12:18:23.043Z');
31-
let count = (flusher as any)._incrementSessionStatusCount(RequestSessionStatus.Ok, date);
29+
let count = (flusher as any)._incrementSessionStatusCount('ok', date);
3230
expect(count).toEqual(1);
33-
count = (flusher as any)._incrementSessionStatusCount(RequestSessionStatus.Ok, date);
31+
count = (flusher as any)._incrementSessionStatusCount('ok', date);
3432
expect(count).toEqual(2);
35-
count = (flusher as any)._incrementSessionStatusCount(RequestSessionStatus.Errored, date);
33+
count = (flusher as any)._incrementSessionStatusCount('errored', date);
3634
expect(count).toEqual(1);
3735
date.setMinutes(date.getMinutes() + 1);
38-
count = (flusher as any)._incrementSessionStatusCount(RequestSessionStatus.Ok, date);
36+
count = (flusher as any)._incrementSessionStatusCount('ok', date);
3937
expect(count).toEqual(1);
40-
count = (flusher as any)._incrementSessionStatusCount(RequestSessionStatus.Errored, date);
38+
count = (flusher as any)._incrementSessionStatusCount('errored', date);
4139
expect(count).toEqual(1);
4240

4341
expect(flusher.getSessionAggregates().aggregates).toEqual([
@@ -51,8 +49,8 @@ describe('Session Flusher', () => {
5149
const flusher = new SessionFlusher(transport, { release: '1.0.0' });
5250

5351
const date = new Date('2021-04-08T12:18:23.043Z');
54-
(flusher as any)._incrementSessionStatusCount(RequestSessionStatus.Ok, date);
55-
(flusher as any)._incrementSessionStatusCount(RequestSessionStatus.Errored, date);
52+
(flusher as any)._incrementSessionStatusCount('ok', date);
53+
(flusher as any)._incrementSessionStatusCount('errored', date);
5654

5755
expect(flusher.getSessionAggregates()).toEqual({
5856
aggregates: [{ errored: 1, exited: 1, started: '2021-04-08T12:18:00.000Z' }],
@@ -77,8 +75,8 @@ describe('Session Flusher', () => {
7775
const flusher = new SessionFlusher(transport, { release: '1.0.0', environment: 'dev' });
7876
const flusherFlushFunc = jest.spyOn(flusher, 'flush');
7977
const date = new Date('2021-04-08T12:18:23.043Z');
80-
(flusher as any)._incrementSessionStatusCount(RequestSessionStatus.Ok, date);
81-
(flusher as any)._incrementSessionStatusCount(RequestSessionStatus.Ok, date);
78+
(flusher as any)._incrementSessionStatusCount('ok', date);
79+
(flusher as any)._incrementSessionStatusCount('ok', date);
8280

8381
expect(sendSession).toHaveBeenCalledTimes(0);
8482

@@ -113,8 +111,8 @@ describe('Session Flusher', () => {
113111
const flusher = new SessionFlusher(transport, { release: '1.0.x' });
114112
const flusherFlushFunc = jest.spyOn(flusher, 'flush');
115113
const date = new Date('2021-04-08T12:18:23.043Z');
116-
(flusher as any)._incrementSessionStatusCount(RequestSessionStatus.Ok, date);
117-
(flusher as any)._incrementSessionStatusCount(RequestSessionStatus.Ok, date);
114+
(flusher as any)._incrementSessionStatusCount('ok', date);
115+
(flusher as any)._incrementSessionStatusCount('ok', date);
118116
flusher.close();
119117

120118
expect(flusherFlushFunc).toHaveBeenCalledTimes(1);

packages/node/src/client.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BaseClient, Scope, SDK_VERSION } from '@sentry/core';
22
import { SessionFlusher } from '@sentry/hub';
3-
import { Event, EventHint, RequestSessionStatus } from '@sentry/types';
3+
import { Event, EventHint } from '@sentry/types';
44
import { logger } from '@sentry/utils';
55

66
import { NodeBackend } from './backend';
@@ -48,8 +48,8 @@ export class NodeClient extends BaseClient<NodeBackend, NodeOptions> {
4848

4949
// Necessary checks to ensure this is code block is executed only within a request
5050
// Should override the status only if `requestSession.status` is `Ok`, which is its initial stage
51-
if (requestSession && requestSession.status === RequestSessionStatus.Ok) {
52-
requestSession.status = RequestSessionStatus.Errored;
51+
if (requestSession && requestSession.status === 'ok') {
52+
requestSession.status = 'errored';
5353
}
5454
}
5555

@@ -74,8 +74,8 @@ export class NodeClient extends BaseClient<NodeBackend, NodeOptions> {
7474

7575
// Ensure that this is happening within the bounds of a request, and make sure not to override
7676
// Session Status if Errored / Crashed
77-
if (requestSession && requestSession.status === RequestSessionStatus.Ok) {
78-
requestSession.status = RequestSessionStatus.Errored;
77+
if (requestSession && requestSession.status === 'ok') {
78+
requestSession.status = 'errored';
7979
}
8080
}
8181
}

packages/node/src/handlers.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* eslint-disable @typescript-eslint/no-explicit-any */
33
import { captureException, getCurrentHub, startTransaction, withScope } from '@sentry/core';
44
import { extractTraceparentData, Span } from '@sentry/tracing';
5-
import { Event, ExtractedNodeRequestData, RequestSessionStatus, Transaction } from '@sentry/types';
5+
import { Event, ExtractedNodeRequestData, Transaction } from '@sentry/types';
66
import { isPlainObject, isString, logger, normalize, stripUrlQueryAndFragment } from '@sentry/utils';
77
import * as cookie from 'cookie';
88
import * as domain from 'domain';
@@ -424,7 +424,7 @@ export function requestHandler(
424424
const scope = currentHub.getScope();
425425
if (scope) {
426426
// Set `status` of `RequestSession` to Ok, at the beginning of the request
427-
scope.setRequestSession({ status: RequestSessionStatus.Ok });
427+
scope.setRequestSession({ status: 'ok' });
428428
}
429429
}
430430
});
@@ -517,8 +517,9 @@ export function errorHandler(options?: {
517517
// If an error bubbles to the `errorHandler`, then this is an unhandled error, and should be reported as a
518518
// Crashed session. The `_requestSession.status` is checked to ensure that this error is happening within
519519
// the bounds of a request, and if so the status is updated
520-
if (requestSession && requestSession.status !== undefined)
521-
requestSession.status = RequestSessionStatus.Crashed;
520+
if (requestSession && requestSession.status !== undefined) {
521+
requestSession.status = 'crashed';
522+
}
522523
}
523524
}
524525

packages/node/src/sdk.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ function startSessionTracking(): void {
232232
// Ref: https://nodejs.org/api/process.html#process_event_beforeexit
233233
process.on('beforeExit', () => {
234234
const session = hub.getScope()?.getSession();
235-
const terminalStates = [SessionStatus.Exited, SessionStatus.Crashed];
235+
const terminalStates: SessionStatus[] = ['exited', 'crashed'];
236236
// Only call endSession, if the Session exists on Scope and SessionStatus is not a
237237
// Terminal Status i.e. Exited or Crashed because
238238
// "When a session is moved away from ok it must not be updated anymore."

0 commit comments

Comments
 (0)