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

Function startSession

packages/core/src/exports.ts:318–344  ·  view source on GitHub ↗
(context?: SessionContext)

Source from the content-addressed store, hash-verified

316 * @returns the new active session
317 */
318export function startSession(context?: SessionContext): Session {
319 const isolationScope = getIsolationScope();
320
321 const { user } = getCombinedScopeData(isolationScope, getCurrentScope());
322
323 // Will fetch userAgent if called from browser sdk
324 const { userAgent } = GLOBAL_OBJ.navigator || {};
325
326 const session = makeSession({
327 user,
328 ...(userAgent && { userAgent }),
329 ...context,
330 });
331
332 // End existing session if there's one
333 const currentSession = isolationScope.getSession();
334 if (currentSession?.status === 'ok') {
335 updateSession(currentSession, { status: 'exited' });
336 }
337
338 endSession();
339
340 // Afterwards we set the new session on the scope
341 isolationScope.setSession(session);
342
343 return session;
344}
345
346/**
347 * End the session on the current isolation scope.

Callers 2

setupOnceFunction · 0.90
setupOnceFunction · 0.85

Calls 8

getIsolationScopeFunction · 0.90
getCombinedScopeDataFunction · 0.90
getCurrentScopeFunction · 0.90
makeSessionFunction · 0.90
updateSessionFunction · 0.90
getSessionMethod · 0.80
setSessionMethod · 0.80
endSessionFunction · 0.70

Tested by

no test coverage detected