Skip to content

Commit f99bdd1

Browse files
committed
ref(types): deprecate request status
1 parent 6f9069e commit f99bdd1

File tree

9 files changed

+76
-74
lines changed

9 files changed

+76
-74
lines changed

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/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/test/client.test.ts

+18-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Scope, SessionFlusher } from '@sentry/hub';
2-
import { RequestSessionStatus } from '@sentry/types';
32

43
import { NodeClient } from '../src';
54

@@ -17,12 +16,12 @@ describe('NodeClient', () => {
1716
test('when autoSessionTracking is enabled, and requestHandler is not used -> requestStatus should not be set', () => {
1817
client = new NodeClient({ dsn: PUBLIC_DSN, autoSessionTracking: true, release: '1.4' });
1918
const scope = new Scope();
20-
scope.setRequestSession({ status: RequestSessionStatus.Ok });
19+
scope.setRequestSession({ status: 'ok' });
2120

2221
client.captureException(new Error('test exception'), undefined, scope);
2322

2423
const requestSession = scope.getRequestSession();
25-
expect(requestSession!.status).toEqual(RequestSessionStatus.Ok);
24+
expect(requestSession!.status).toEqual('ok');
2625
});
2726
test('when autoSessionTracking is disabled -> requestStatus should not be set', () => {
2827
client = new NodeClient({ dsn: PUBLIC_DSN, autoSessionTracking: false, release: '1.4' });
@@ -31,12 +30,12 @@ describe('NodeClient', () => {
3130
client.initSessionFlusher();
3231

3332
const scope = new Scope();
34-
scope.setRequestSession({ status: RequestSessionStatus.Ok });
33+
scope.setRequestSession({ status: 'ok' });
3534

3635
client.captureException(new Error('test exception'), undefined, scope);
3736

3837
const requestSession = scope.getRequestSession();
39-
expect(requestSession!.status).toEqual(RequestSessionStatus.Ok);
38+
expect(requestSession!.status).toEqual('ok');
4039
});
4140
test('when autoSessionTracking is enabled + requestSession status is Crashed -> requestStatus should not be overridden', () => {
4241
client = new NodeClient({ dsn: PUBLIC_DSN, autoSessionTracking: true, release: '1.4' });
@@ -45,12 +44,12 @@ describe('NodeClient', () => {
4544
client.initSessionFlusher();
4645

4746
const scope = new Scope();
48-
scope.setRequestSession({ status: RequestSessionStatus.Crashed });
47+
scope.setRequestSession({ status: 'crashed' });
4948

5049
client.captureException(new Error('test exception'), undefined, scope);
5150

5251
const requestSession = scope.getRequestSession();
53-
expect(requestSession!.status).toEqual(RequestSessionStatus.Crashed);
52+
expect(requestSession!.status).toEqual('crashed');
5453
});
5554
test('when autoSessionTracking is enabled + error occurs within request bounds -> requestStatus should be set to Errored', () => {
5655
client = new NodeClient({ dsn: PUBLIC_DSN, autoSessionTracking: true, release: '1.4' });
@@ -59,12 +58,12 @@ describe('NodeClient', () => {
5958
client.initSessionFlusher();
6059

6160
const scope = new Scope();
62-
scope.setRequestSession({ status: RequestSessionStatus.Ok });
61+
scope.setRequestSession({ status: 'ok' });
6362

6463
client.captureException(new Error('test exception'), undefined, scope);
6564

6665
const requestSession = scope.getRequestSession();
67-
expect(requestSession!.status).toEqual(RequestSessionStatus.Errored);
66+
expect(requestSession!.status).toEqual('errored');
6867
});
6968
test('when autoSessionTracking is enabled + error occurs outside of request bounds -> requestStatus should not be set to Errored', () => {
7069
client = new NodeClient({ dsn: PUBLIC_DSN, autoSessionTracking: true, release: '1.4' });
@@ -89,15 +88,15 @@ describe('NodeClient', () => {
8988
client.initSessionFlusher();
9089

9190
const scope = new Scope();
92-
scope.setRequestSession({ status: RequestSessionStatus.Ok });
91+
scope.setRequestSession({ status: 'ok' });
9392
client.captureEvent(
9493
{ message: 'message', exception: { values: [{ type: 'exception type 1' }] } },
9594
undefined,
9695
scope,
9796
);
9897

9998
const requestSession = scope.getRequestSession();
100-
expect(requestSession!.status).toEqual(RequestSessionStatus.Ok);
99+
expect(requestSession!.status).toEqual('ok');
101100
});
102101

103102
test('When captureEvent is called with an exception, requestSession status should be set to Errored', () => {
@@ -107,12 +106,12 @@ describe('NodeClient', () => {
107106
client.initSessionFlusher();
108107

109108
const scope = new Scope();
110-
scope.setRequestSession({ status: RequestSessionStatus.Ok });
109+
scope.setRequestSession({ status: 'ok' });
111110

112111
client.captureEvent({ message: 'message', exception: { values: [{ type: 'exception type 1' }] } }, {}, scope);
113112

114113
const requestSession = scope.getRequestSession();
115-
expect(requestSession!.status).toEqual(RequestSessionStatus.Errored);
114+
expect(requestSession!.status).toEqual('errored');
116115
});
117116

118117
test('When captureEvent is called without an exception, requestSession status should not be set to Errored', () => {
@@ -122,12 +121,12 @@ describe('NodeClient', () => {
122121
client.initSessionFlusher();
123122

124123
const scope = new Scope();
125-
scope.setRequestSession({ status: RequestSessionStatus.Ok });
124+
scope.setRequestSession({ status: 'ok' });
126125

127126
client.captureEvent({ message: 'message' }, {}, scope);
128127

129128
const requestSession = scope.getRequestSession();
130-
expect(requestSession!.status).toEqual(RequestSessionStatus.Ok);
129+
expect(requestSession!.status).toEqual('ok');
131130
});
132131

133132
test('When captureEvent is called with an exception but outside of a request, then requestStatus should not be set', () => {
@@ -154,26 +153,26 @@ describe('NodeClient', () => {
154153
client.initSessionFlusher();
155154

156155
const scope = new Scope();
157-
scope.setRequestSession({ status: RequestSessionStatus.Ok });
156+
scope.setRequestSession({ status: 'ok' });
158157
client.captureEvent({ message: 'message', type: 'transaction' }, undefined, scope);
159158

160159
const requestSession = scope.getRequestSession();
161-
expect(requestSession!.status).toEqual(RequestSessionStatus.Ok);
160+
expect(requestSession!.status).toEqual('ok');
162161
});
163162

164163
test('When captureEvent is called with an exception but requestHandler is not used, then requestSession status should not be set', () => {
165164
client = new NodeClient({ dsn: PUBLIC_DSN, autoSessionTracking: true, release: '1.3' });
166165

167166
const scope = new Scope();
168-
scope.setRequestSession({ status: RequestSessionStatus.Ok });
167+
scope.setRequestSession({ status: 'ok' });
169168
client.captureEvent(
170169
{ message: 'message', exception: { values: [{ type: 'exception type 1' }] } },
171170
undefined,
172171
scope,
173172
);
174173

175174
const requestSession = scope.getRequestSession();
176-
expect(requestSession!.status).toEqual(RequestSessionStatus.Ok);
175+
expect(requestSession!.status).toEqual('ok');
177176
});
178177
});
179178
});

0 commit comments

Comments
 (0)