Skip to content

Commit

Permalink
fix(release-health): Prevent sending terminal status session updates
Browse files Browse the repository at this point in the history
Drops sending session updates for sessions that are already in terminal
states and caps the number of errors for session at 1
  • Loading branch information
ahmedetefy committed Jun 17, 2021
1 parent 6829c8c commit fe53dd9
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
10 changes: 8 additions & 2 deletions packages/core/src/baseclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,19 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
}
}

const initialSessionStatus = session.status;
const sessionErrorCount = session.errors;
const terminalStates = [SessionStatus.Crashed, SessionStatus.Abnormal];

session.update({
...(crashed && { status: SessionStatus.Crashed }),
user,
userAgent,
errors: session.errors + Number(errored || crashed),
errors: !sessionErrorCount ? sessionErrorCount + Number(errored || crashed) : sessionErrorCount,
});
this.captureSession(session);

// Only send a session update if session was not already in a terminal
if (!terminalStates.includes(initialSessionStatus)) this.captureSession(session);
}

/** Deliver captured session to Sentry */
Expand Down
2 changes: 1 addition & 1 deletion packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"test:watch": "jest --watch",
"test:express": "node test/manual/express-scope-separation/start.js",
"test:webpack": "cd test/manual/webpack-domain/ && yarn && node npm-build.js",
"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",
"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",
"pack": "npm pack",
"circularDepCheck": "madge --circular src/index.ts"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const Sentry = require('../../../../dist');
const { assertSessions, constructStrippedSessionObject, BaseDummyTransport } = require('../test-utils');
let sessionCounter = 0;
process.on('exit', ()=> {
if (process.exitCode !== 1) {
console.log('SUCCESS: All application mode sessions were sent to node transport as expected');
}
})

class DummyTransport extends BaseDummyTransport {
sendSession(session) {
sessionCounter++;
if (sessionCounter === 1) {
assertSessions(constructStrippedSessionObject(session),
{
init: true,
status: 'ok',
errors: 1,
release: '1.1'
}
)
}
else if (sessionCounter === 2) {
assertSessions(constructStrippedSessionObject(session),
{
init: false,
status: 'ok',
errors: 1,
release: '1.1'
}
)
}
else if (sessionCounter === 3) {
assertSessions(constructStrippedSessionObject(session),
{
init: false,
status: 'exited',
errors: 1,
release: '1.1'
}
)
}
else {
console.log('FAIL: Received way too many Sessions!');
process.exit(1);
}
return super.sendSession(session);
}
}

Sentry.init({
dsn: 'http://[email protected]/1337',
release: '1.1',
transport: DummyTransport,
autoSessionTracking: true
});
/**
* The following code snippet will throw multiple errors, and thereby send session updates everytime an error is
* captured. However, the number of errors in the session should be capped at 1, regardless of how many errors there are
*/
for (let i = 0; i < 2; i++) {
Sentry.captureException(new Error('hello world'));
}


0 comments on commit fe53dd9

Please sign in to comment.