MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / _updateSessionFromEvent

Function _updateSessionFromEvent

packages/core/src/client.ts:1257–1289  ·  view source on GitHub ↗

Updates existing session based on the provided event

(session: Session, event: Event)

Source from the content-addressed store, hash-verified

1255
1256 /** Updates existing session based on the provided event */
1257 protected _updateSessionFromEvent(session: Session, event: Event): void {
1258 // initially, set `crashed` based on the event level and update from exceptions if there are any later on
1259 let crashed = event.level === 'fatal';
1260 let errored = false;
1261 const exceptions = event.exception?.values;
1262
1263 if (exceptions) {
1264 errored = true;
1265 // reset crashed to false if there are exceptions, to ensure `mechanism.handled` is respected.
1266 crashed = false;
1267
1268 for (const ex of exceptions) {
1269 if (ex.mechanism?.handled === false) {
1270 crashed = true;
1271 break;
1272 }
1273 }
1274 }
1275
1276 // A session is updated and that session update is sent in only one of the two following scenarios:
1277 // 1. Session with non terminal status and 0 errors + an error occurred -> Will set error count to 1 and send update
1278 // 2. Session with non terminal status and 1 error + a crash occurred -> Will set status crashed and send update
1279 const sessionNonTerminal = session.status === 'ok';
1280 const shouldUpdateAndSend = (sessionNonTerminal && session.errors === 0) || (sessionNonTerminal && crashed);
1281
1282 if (shouldUpdateAndSend) {
1283 updateSession(session, {
1284 ...(crashed && { status: 'crashed' }),
1285 errors: session.errors || Number(errored || crashed),
1286 });
1287 this.captureSession(session);
1288 }
1289 }
1290
1291 /**
1292 * Determine if the client is finished processing. Returns a promise because it will wait `timeout` ms before saying

Callers

nothing calls this directly

Calls 1

updateSessionFunction · 0.90

Tested by

no test coverage detected