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

⚡ [RUM-116] On view change, take the full snapshot asynchronously #2887

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

RomanGaignault
Copy link
Contributor

@RomanGaignault RomanGaignault commented Jul 23, 2024

Motivation

In the Datadog App, we are starting a new view when the URL changes (via the onChange react-router callback). But at this time, the old page component is still displayed, and we take a full snapshot of the ending view instead of the new view.

Changes

A solution would be to take the fullsnapshot asynchronously. This would let a bit of time to the application UI to be updated. While waiting for the FS to be taken, we could ignore any emitted record, since we would know that a FS is coming to capture the whole state:

startView() is called

ignore any emitted record

[async] wait a bit

if stopSessionReplayRecording() was not called in the meantime

full snapshot is taken

start collecting emitted record again

For the asynchronous delay, we could even use requestIdleCallback to limit our impact on the application perceptible performance.

Testing

  • Local
  • Staging
  • Unit
  • End to end

I have gone over the contributing documentation.

@codecov-commenter
Copy link

codecov-commenter commented Jul 23, 2024

Codecov Report

Attention: Patch coverage is 96.22642% with 2 lines in your changes missing coverage. Please review.

Project coverage is 93.71%. Comparing base (d71c0bd) to head (fd4b76c).
Report is 5 commits behind head on main.

Files Patch % Lines
...kages/core/test/emulate/mockRequestIdleCallback.ts 90.47% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2887      +/-   ##
==========================================
+ Coverage   93.68%   93.71%   +0.03%     
==========================================
  Files         266      268       +2     
  Lines        7584     7623      +39     
  Branches     1687     1692       +5     
==========================================
+ Hits         7105     7144      +39     
  Misses        479      479              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@RomanGaignault
Copy link
Contributor Author

/to-staging

@dd-devflow
Copy link

dd-devflow bot commented Jul 23, 2024

🚂 Branch Integration: starting soon, median merge time is 12m

Commit 479736c960 will soon be integrated into staging-30.

Use /to-staging -c to cancel this operation!

@RomanGaignault RomanGaignault marked this pull request as ready for review July 23, 2024 12:07
@RomanGaignault RomanGaignault requested a review from a team as a code owner July 23, 2024 12:07
Copy link

cit-pr-commenter bot commented Jul 23, 2024

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 161.62 KiB 161.80 KiB 181 B +0.11%
Logs 57.95 KiB 57.99 KiB 44 B +0.07%
Rum Slim 110.14 KiB 110.18 KiB 44 B +0.04%
Worker 25.21 KiB 25.21 KiB 0 B 0.00%
🚀 CPU Performance
Action Name Base Average Cpu Time (ms) Local Average Cpu Time (ms) 𝚫
addglobalcontext 0.002 0.002 -0.000
addaction 0.041 0.033 -0.007
adderror 0.042 0.031 -0.011
addtiming 0.001 0.001 -0.000
startview 0.974 0.925 -0.049
startstopsessionreplayrecording 1.128 0.812 -0.316
logmessage 0.022 0.019 -0.003
🧠 Memory Performance
Action Name Base Consumption Memory (bytes) Local Consumption Memory (bytes) 𝚫 (bytes)
addglobalcontext 20.45 KiB 20.61 KiB 160 B
addaction 73.08 KiB 70.68 KiB -2460 B
adderror 87.32 KiB 86.08 KiB -1267 B
addtiming 19.70 KiB 18.50 KiB -1233 B
startview 350.06 KiB 352.12 KiB 2.06 KiB
startstopsessionreplayrecording 14.03 KiB 15.54 KiB 1.50 KiB
logmessage 68.89 KiB 72.54 KiB 3.64 KiB

🔗 RealWorld

dd-mergequeue bot added a commit that referenced this pull request Jul 23, 2024
…ng-30

Integrated commit sha: 479736c

Co-authored-by: roman.gaignault <roman.gaignault@datadoghq.com>
@dd-devflow
Copy link

dd-devflow bot commented Jul 23, 2024

🚂 Branch Integration: This commit was successfully integrated

Commit 479736c960 has been merged into staging-30 in merge commit cc5e316eee.

Check out the triggered pipeline on Gitlab 🦊


let cancelIdleCallback: (() => void) | undefined
const { unsubscribe } = lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, (view) => {
flushMutations()
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ question: ‏Is this flushMutations() necessary?

sendToExtension('record', { record })
const view = options.viewContexts.findView()!
replayStats.addRecord(view.id)
if (!isFullSnapshotPending) {
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ question: ‏By discarding records during the fullsnapshot are we confident not to miss important ones like scroll, mouseInteraction, move?

@N-Boutaib N-Boutaib requested a review from a team July 23, 2024 15:31
@BenoitZugmeyer BenoitZugmeyer marked this pull request as draft September 10, 2024 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants