🐛 [RUM-7694] - Keep more ReplayStats history to avoid wrongly marking views as having no replay #3318
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
The browser SDK generates internal metadata about the size of replay data for each view in a data structure called
ReplayStats
; this helps us debug when something goes wrong. This metadata is also used internally to track whether each view has any replay data at all; when a view update is sent to the server, theReplayStats
data is translated into a flag calledhas_replay
that's used by Datadog's Session Replay UI.To avoid consuming memory unnecessary, the browser SDK currently only tracks
ReplayStats
for the last 10 views; theReplayStats
for older views are dropped. This is controlled in the code by theMAX_STATS_HISTORY
constant.Some SPA websites change
document.location
very quickly, which can cause them to generate new views extremely fast. We've observed that in rare cases, it's possible to generate new views quickly enough that we can end up discarding theReplayStats
for some views before their replay data is sent to the server. This can cause thehas_replay
flag for these views to be unset, even though they really have replay data; the result is that the view can't be played back in the Session Replay. Obviously that's a problem!Changes
This PR greatly raises the
MAX_STATS_HISTORY
limit. The result should be that it will now be practically impossible to trigger this issue, even on sites which changedocument.location
extremely fast.Eliminating the fixed
MAX_STATS_HISTORY
limit would likely be a better solution in the long term, and I'll investigate that as a followup, but it's more complicated. This PR should be sufficient to solve the problem from a practical perspective, so it's a good starting point.Testing
I have gone over the contributing documentation.