Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(replay): Streamline session creation/refresh #8813

Merged
merged 6 commits into from
Aug 18, 2023

Conversation

mydea
Copy link
Member

@mydea mydea commented Aug 14, 2023

We've been using _loadAndCheckSession both in initial session setup as well as when checking for expiration of session.
This leads to some not-so-optimized stuff, as we kind of have to do double duty in there (e.g. we constantly re-assign the session etc).

This streamlines this by splitting this into:

  • _initializeSessionForSampling(): Only called in initializeSampling()
  • _checkSession(): Called everywhere else, assumes we have a session setup yet

Only the former actually looks into sessionStorage, the latter can assume we always have a session already.

This also extends the behavior so that if we fetch a buffer session from storage and segment_id > 0, we start the session in session mode. Without this, we could theoretically run into endless sessions if the user keeps refreshing and keeps having errors, leading to continuous switchovers from buffer>session mode.

@mydea mydea requested a review from billyvg August 14, 2023 14:25
@mydea mydea self-assigned this Aug 14, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Aug 14, 2023

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 75.19 KB (+0.46% 🔺)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 31.17 KB (+0.2% 🔺)
@sentry/browser - Webpack (gzipped) 21.85 KB (+0.19% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 69.72 KB (+0.27% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 28.18 KB (+0.1% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped) 20.18 KB (+0.05% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 219.95 KB (+0.41% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 84.78 KB (+0.13% 🔺)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 59.86 KB (+0.04% 🔺)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 31.04 KB (+0.09% 🔺)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 75.21 KB (+15.62% 🔺)
@sentry/react - Webpack (gzipped) 21.88 KB (+0.18% 🔺)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 93.03 KB (+0.41% 🔺)
@sentry/nextjs Client - Webpack (gzipped) 50.7 KB (+0.19% 🔺)

Copy link
Member

@billyvg billyvg left a comment

Choose a reason for hiding this comment

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

LGTM, will do some manual testing tomorrow

packages/replay/src/session/getSession.ts Outdated Show resolved Hide resolved
packages/replay/src/session/getSession.ts Outdated Show resolved Hide resolved
@billyvg
Copy link
Member

billyvg commented Aug 15, 2023

Hmm do we not use codecov in this repo?

@billyvg
Copy link
Member

billyvg commented Aug 16, 2023

Seeing an issue where we have stale events being flushed alongside the new session, Francesco will be looking into this tomorrow.

@mydea
Copy link
Member Author

mydea commented Aug 17, 2023

Note: I updated this PR to fix another bug:

Now, when we restore a session for sessionStorage, we only start in buffer mode if sampled === buffer and segmentId === 0. This means that if we have a buffer that was previously converted to a session mode due to an error, when the user reloads they will continue in session mode, not in buffer mode. Without this, you could theoretically have endless sessions if you continuously have errors, and reload, without ever reaching the session max. time before reloading.

packages/replay/src/replay.ts Outdated Show resolved Hide resolved
@mydea mydea merged commit 4a4df0d into develop Aug 18, 2023
73 checks passed
@mydea mydea deleted the fn/replay-restart-buffer branch August 18, 2023 06:12
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.

None yet

2 participants