Skip to content

Commit 1534e1e

Browse files
committed
fix(release-health): Prevent sending terminal status session updates
Drops sending session updates for sessions that are already in terminal states and caps the number of errors for session at 1
1 parent 6829c8c commit 1534e1e

File tree

3 files changed

+73
-3
lines changed

3 files changed

+73
-3
lines changed

packages/core/src/baseclient.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,18 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
253253
}
254254
}
255255

256+
const initialSessionStatus = session.status;
257+
const terminalStates = [SessionStatus.Crashed, SessionStatus.Abnormal];
258+
256259
session.update({
257260
...(crashed && { status: SessionStatus.Crashed }),
258261
user,
259262
userAgent,
260-
errors: session.errors + Number(errored || crashed),
263+
errors: Math.max(session.errors, Number(errored || crashed)),
261264
});
262-
this.captureSession(session);
265+
266+
// Only send a session update if session was not already in a terminal
267+
if (!terminalStates.includes(initialSessionStatus)) this.captureSession(session);
263268
}
264269

265270
/** Deliver captured session to Sentry */

packages/node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"test:watch": "jest --watch",
6161
"test:express": "node test/manual/express-scope-separation/start.js",
6262
"test:webpack": "cd test/manual/webpack-domain/ && yarn && node npm-build.js",
63-
"test:release-health": "node test/manual/release-health/single-session/healthy-session.js && node test/manual/release-health/single-session/caught-exception-errored-session.js && node test/manual/release-health/single-session/uncaught-exception-crashed-session.js && node test/manual/release-health/single-session/unhandled-rejection-crashed-session.js && node test/manual/release-health/session-aggregates/aggregates-disable-single-session.js",
63+
"test:release-health": "node test/manual/release-health/single-session/healthy-session.js && node test/manual/release-health/single-session/caught-exception-errored-session.js && node test/manual/release-health/single-session/uncaught-exception-crashed-session.js && node test/manual/release-health/single-session/unhandled-rejection-crashed-session.js && node test/manual/release-health/session-aggregates/aggregates-disable-single-session.js && node test/manual/release-health/single-session/errors-in-session-capped-to-one.js",
6464
"pack": "npm pack",
6565
"circularDepCheck": "madge --circular src/index.ts"
6666
},
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
const Sentry = require('../../../../dist');
2+
const { assertSessions, constructStrippedSessionObject, BaseDummyTransport } = require('../test-utils');
3+
let sessionCounter = 0;
4+
process.on('exit', ()=> {
5+
if (process.exitCode !== 1) {
6+
console.log('SUCCESS: All application mode sessions were sent to node transport as expected');
7+
}
8+
})
9+
10+
class DummyTransport extends BaseDummyTransport {
11+
sendSession(session) {
12+
sessionCounter++;
13+
if (sessionCounter === 1) {
14+
assertSessions(constructStrippedSessionObject(session),
15+
{
16+
init: true,
17+
status: 'ok',
18+
errors: 1,
19+
release: '1.1'
20+
}
21+
)
22+
}
23+
else if (sessionCounter === 2) {
24+
assertSessions(constructStrippedSessionObject(session),
25+
{
26+
init: false,
27+
status: 'ok',
28+
errors: 1,
29+
release: '1.1'
30+
}
31+
)
32+
}
33+
else if (sessionCounter === 3) {
34+
assertSessions(constructStrippedSessionObject(session),
35+
{
36+
init: false,
37+
status: 'exited',
38+
errors: 1,
39+
release: '1.1'
40+
}
41+
)
42+
}
43+
else {
44+
console.log('FAIL: Received way too many Sessions!');
45+
process.exit(1);
46+
}
47+
return super.sendSession(session);
48+
}
49+
}
50+
51+
Sentry.init({
52+
dsn: 'http://[email protected]/1337',
53+
release: '1.1',
54+
transport: DummyTransport,
55+
autoSessionTracking: true
56+
});
57+
/**
58+
* The following code snippet will throw multiple errors, and thereby send session updates everytime an error is
59+
* captured. However, the number of errors in the session should be capped at 1, regardless of how many errors there are
60+
*/
61+
for (let i = 0; i < 2; i++) {
62+
Sentry.captureException(new Error('hello world'));
63+
}
64+
65+

0 commit comments

Comments
 (0)