Skip to content

fix(v9/replay): Fix re-sampled sessions after a click #17195

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

Conversation

billyvg
Copy link
Member

@billyvg billyvg commented Jul 28, 2025

This is the v9 backport of
#17008, which fixes a bug where an expired session-based replay will always force a new session-based replay after a click, regardless of the actual recording mode.

This fixes a bug where an expired session-based replay will always force
a new session-based replay after a click, regardless of the actual
recording mode.

What is happening is:

- a session-based replay is left idle
- user comes back and clicks on the page and triggers the click listener
-
[`addBreadcrumbEvent()`](https://github.com/getsentry/sentry-javascript/blob/develop/packages/replay-internal/src/coreHandlers/util/addBreadcrumbEvent.ts#L9)
is called which then calls
[`triggerUserActivity()`](https://github.com/getsentry/sentry-javascript/blob/develop/packages/replay-internal/src/coreHandlers/util/addBreadcrumbEvent.ts#L15)
because it is a click
- next, `_checkSession()` and `_refreshSession()` are called and this is
where the problem starts

Inside of `_refreshSession` we stop the current replay (because the
session is expired), [however `stop()` is async and is `await`-ed before
we
re-sample](https://github.com/getsentry/sentry-javascript/blob/develop/packages/replay-internal/src/replay.ts#L917-L918).
So the current replay state while `stop()` is finishing has:

- `recordingMode` = `session` (initial value)
- `isEnabled` = false

Another however, `addBreadcrumbEvent` (and everything called until
`_refreshSession`) are not async and does wait for resampling
(`initializeSampling()`) to occur. This means that the click breadcrumb
ends up causing a flush and always starting a new replay recording
because we only check that [`recordingMode` is
`buffer](https://github.com/getsentry/sentry-javascript/blob/develop/packages/replay-internal/src/replay.ts#L626)`.


## Solution

When we call `stop()`, reset the `recordingMode` to `buffer` (this
should be safe default as it is more restrictive behaviorally than
`session`) and in `addUpdate`, add a check to see if `isEnabled()` is
true (recording is enabled).
Copy link

linear bot commented Jul 28, 2025

@billyvg billyvg changed the base branch from develop to v9 July 28, 2025 16:48
@billyvg billyvg changed the title feat(v9/core): Deprecate experimental enableLogs and beforeSendLog option (#17092) fix(v9/replay): Fix re-sampled sessions after a click Jul 28, 2025
@billyvg billyvg marked this pull request as ready for review July 28, 2025 16:49
@billyvg billyvg requested a review from a team as a code owner July 28, 2025 16:49
@billyvg billyvg requested a review from chargome July 28, 2025 16:49
Copy link
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.79 kB - -
@sentry/browser - with treeshaking flags 22.36 kB - -
@sentry/browser (incl. Tracing) 39.66 kB - -
@sentry/browser (incl. Tracing, Replay) 77.81 kB +0.02% +10 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 67.6 kB +0.02% +13 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 82.5 kB +0.02% +9 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 94.6 kB +0.01% +5 B 🔺
@sentry/browser (incl. Feedback) 40.48 kB - -
@sentry/browser (incl. sendFeedback) 28.48 kB - -
@sentry/browser (incl. FeedbackAsync) 33.37 kB - -
@sentry/react 25.55 kB - -
@sentry/react (incl. Tracing) 41.62 kB - -
@sentry/vue 28.24 kB - -
@sentry/vue (incl. Tracing) 41.45 kB - -
@sentry/svelte 23.81 kB - -
CDN Bundle 25.18 kB - -
CDN Bundle (incl. Tracing) 39.42 kB - -
CDN Bundle (incl. Tracing, Replay) 75.42 kB +0.02% +9 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 80.9 kB +0.02% +11 B 🔺
CDN Bundle - uncompressed 73.45 kB - -
CDN Bundle (incl. Tracing) - uncompressed 116.86 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 231.07 kB +0.03% +66 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 243.88 kB +0.03% +66 B 🔺
@sentry/nextjs (client) 43.66 kB - -
@sentry/sveltekit (client) 40.08 kB - -
@sentry/node 169.14 kB - -
@sentry/node - without tracing 100.31 kB - -
@sentry/aws-serverless 128.47 kB - -

View base workflow run

@AbhiPrasad AbhiPrasad merged commit f8935d9 into v9 Jul 29, 2025
128 of 129 checks passed
@AbhiPrasad AbhiPrasad deleted the billy/replay-437-buffered-replays-are-being-captured-with-no-linked-errors-v9 branch July 29, 2025 14:15
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.

3 participants