Skip to content

feat(browser): Add persisted session lifecycle to browserSessionIntegration - #23446

Draft
logaretm wants to merge 2 commits into
feat/session-id-telemetryfrom
awad/session-lifecycle-persistence
Draft

feat(browser): Add persisted session lifecycle to browserSessionIntegration#23446
logaretm wants to merge 2 commits into
feat/session-id-telemetryfrom
awad/session-lifecycle-persistence

Conversation

@logaretm

Copy link
Copy Markdown
Member

Adds lifecycle: 'session' to browserSessionIntegration, under which one session spans the user's whole visit: persisted in sessionStorage, resumed on the next page load, rotated once it idles out (30 min) or hits its max duration (8 h). Both bounds are configurable.

Stacked on #23442. That PR attaches session.id to telemetry, but today's session is really a page-view id, so a reload mid-checkout looks like several unrelated sessions.

'page' and 'route' are untouched and 'page' stays the default. Opt-in because resuming passes init: false, so crash-free rate here measures sessions rather than page views. Flipping the default is a separate call.

previous_id chaining, naming and outcomes are follow-ups.

…egration

Adds `lifecycle: 'session'`, under which one session spans the user's whole
visit: it is persisted in `sessionStorage`, resumed on the next page load, and
rotated once it idles out (30 min) or hits its max duration (8 h). Both bounds
are configurable via `idleTimeout` and `maxDuration`.

`'page'` and `'route'` keep their existing behaviour and `'page'` stays the
default, so nothing changes unless the new lifecycle is opted into.
@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 30.78 kB added added
@sentry/browser - with treeshaking flags 28.9 kB added added
@sentry/browser - with treeshaking flags tracing without tracing 27.24 kB added added
@sentry/browser (incl. Tracing) 48.99 kB added added
@sentry/browser (incl. Tracing + Span Streaming) 49 kB added added
@sentry/browser (incl. Tracing, Profiling) 51.89 kB added added
@sentry/browser (incl. Tracing, Replay) 88.4 kB added added
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.8 kB added added
@sentry/browser (incl. Tracing, Replay with Canvas) 93.13 kB added added
@sentry/browser (incl. Tracing, Replay, Feedback) 105.84 kB added added
@sentry/browser (incl. Feedback) 48.12 kB added added
@sentry/browser (incl. sendFeedback) 35.6 kB added added
@sentry/browser (incl. FeedbackAsync) 40.75 kB added added
@sentry/browser (incl. Metrics) 31.71 kB added added
@sentry/browser (incl. Logs) 31.99 kB added added
@sentry/browser (incl. Metrics & Logs) 32.62 kB added added
@sentry/react 32.53 kB added added
@sentry/react (incl. Tracing) 51.21 kB added added
@sentry/vue 35.82 kB added added
@sentry/vue (incl. Tracing) 50.96 kB added added
@sentry/svelte 30.8 kB added added
CDN Bundle 32.06 kB added added
CDN Bundle (incl. Tracing) 49.34 kB added added
CDN Bundle (incl. Logs, Metrics) 34.25 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) 51.26 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) 74.73 kB added added
CDN Bundle (incl. Tracing, Replay) 86.9 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 88.76 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) 92.66 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 94.6 kB added added
CDN Bundle - uncompressed 95.04 kB added added
CDN Bundle (incl. Tracing) - uncompressed 147.95 kB added added
CDN Bundle (incl. Logs, Metrics) - uncompressed 101.34 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 153.64 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 230.27 kB added added
CDN Bundle (incl. Tracing, Replay) - uncompressed 267.2 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 272.88 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 280.9 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 286.57 kB added added
@sentry/nextjs (client) 53.74 kB added added
@sentry/sveltekit (client) 49.41 kB added added
@sentry/core/server 65.39 kB added added
@sentry/core/browser 51.74 kB added added
@sentry/node 116.99 kB added added
@sentry/node/import (ESM hook with diagnostics-channel injection) 0 B added added
@sentry/node - without tracing 81.43 kB added added
@sentry/aws-serverless 90.92 kB added added
@sentry/cloudflare (withSentry) - minified 213.99 kB added added
@sentry/cloudflare (withSentry) 528.93 kB added added

@Lms24 Lms24 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

For post-hackweek: I'm wondering if we need the idling logic or if we could hard-cap sessions at a lower max time instead. Say, 1-2hrs? No objections in general to this other than bundle size concerns. Absolutely happy to hear more opinions on this :)

@logaretm

logaretm commented Aug 18, 2026

Copy link
Copy Markdown
Member Author

I'm wondering if we need the idling logic or if we could hard-cap sessions at a lower max time

I think idling is valuable to filter out garbage telemetry, for example a polling fetch or something that keeps working in the background could flood the session with telemetry and keep it alive while containing no valuable telemetry pertaining to user interaction. A lower max time fixes that tho.

I don't have a strong opinion, just something I wanted to surface and discuss. It is not exactly what I wanted tbh, I wanted to introduce idle "gaps" or "pause" a session if that makes any sense. Also happy to drop it to not over complicate things that aren't fully understood.

`endSession` is now exported from `@sentry/browser` rather than re-exported
from core. Calling it ends the current session and immediately starts a new
one, so telemetry emitted after the call is attributed to the new session
instead of to nothing.

Expiry, navigation in the `route` lifecycle, and `endSession` all go through
the same rotate step, which under the `session` lifecycle also replaces the
`sessionStorage` record so the ended session is not resumed on the next page
load.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants