-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(replay): Fix re-sampled sessions after a click #17008
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
base: develop
Are you sure you want to change the base?
fix(replay): Fix re-sampled sessions after a click #17008
Conversation
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()` is called which then calls `triggerUserActivity()` 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. 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.
size-limit report 📦
|
@@ -503,6 +503,10 @@ export class ReplayContainer implements ReplayContainerInterface { | |||
// enter into an infinite loop when `stop()` is called while flushing. | |||
this._isEnabled = false; | |||
|
|||
// Make sure to reset `recordingMode` to `buffer` to avoid any additional | |||
// breadcrumbs to trigger a flush (e.g. in `addUpdate()`) | |||
this.recordingMode = 'buffer'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure, do we (need to?) reset this at some point? I guess not, as ended usually means ended for good for us I suppose...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We currently don't need to, but I think it's a safer option to have it reset here.
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:
addBreadcrumbEvent()
is called which then callstriggerUserActivity()
because it is a click_checkSession()
and_refreshSession()
are called and this is where the problem startsInside of
_refreshSession
we stop the current replay (because the session is expired), howeverstop()
is async and isawait
-ed before we re-sample. So the current replay state whilestop()
is finishing has:recordingMode
=session
(initial value)isEnabled
= falseAnother 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
isbuffer](https://github.com/getsentry/sentry-javascript/blob/develop/packages/replay-internal/src/replay.ts#L626)
.Solution
When we call
stop()
, reset therecordingMode
tobuffer
(this should be safe default as it is more restrictive behaviorally thansession
) and inaddUpdate
, add a check to see ifisEnabled()
is true (recording is enabled).