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-3837] Force Replay recording on sampled-out sessions #2777

Merged

Conversation

N-Boutaib
Copy link
Contributor

@N-Boutaib N-Boutaib commented May 23, 2024

Motivation

Allow session replay recording on sampled out sessions

Changes

On the RUM's public API, session replay recording can be forced even if the session is sampled out for replay. This is achieved by passing { force: true } to DD_RUM.startSessionReplayRecording function.

When this method is called with force option, we need to keep recording until the session ends. To achieve that:

  • A flag is added to _dd_s cookie
  • The cookie is updated to reflect that change when the recording is forced
  • Session cache and history context are synchronised across all tabs

Testing

  • Local
  • Staging
  • Unit
  • End to end

I have gone over the contributing documentation.

Copy link

cit-pr-commenter bot commented May 23, 2024

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 157.98 KiB 158.68 KiB 713 B +0.44%
Logs 56.71 KiB 57.02 KiB 311 B +0.54%
Rum Slim 104.54 KiB 105.15 KiB 620 B +0.58%
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.001
addaction 0.040 0.033 -0.007
adderror 0.034 0.034 0.000
addtiming 0.001 0.001 -0.000
startview 0.986 1.065 0.080
startstopsessionreplayrecording 0.802 0.756 -0.045
logmessage 0.005 0.005 -0.000
🧠 Memory Performance
Action Name Base Consumption Memory (bytes) Local Consumption Memory (bytes) 𝚫
addglobalcontext NaN KiB 32.94 KiB NaN KiB
addaction NaN KiB 120.37 KiB NaN KiB
adderror NaN KiB 113.28 KiB NaN KiB
addtiming NaN KiB 18.68 KiB NaN KiB
startview NaN KiB 2023.86 KiB NaN KiB
startstopsessionreplayrecording NaN KiB 18.72 KiB NaN KiB
logmessage NaN KiB 116.21 KiB NaN KiB

@N-Boutaib N-Boutaib force-pushed the najib.boutaib/RUM-3837-recording-of-sampled-out-sessions branch from e633213 to 488177d Compare May 23, 2024 13:18
@codecov-commenter
Copy link

codecov-commenter commented May 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.61%. Comparing base (e55a185) to head (0dac36d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2777      +/-   ##
==========================================
+ Coverage   93.59%   93.61%   +0.02%     
==========================================
  Files         243      243              
  Lines        7068     7094      +26     
  Branches     1567     1580      +13     
==========================================
+ Hits         6615     6641      +26     
  Misses        453      453              

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

@N-Boutaib N-Boutaib force-pushed the najib.boutaib/RUM-3837-recording-of-sampled-out-sessions branch from b24dbfe to 637814d Compare May 23, 2024 15:45
@N-Boutaib N-Boutaib marked this pull request as ready for review May 27, 2024 08:04
@N-Boutaib N-Boutaib requested a review from a team as a code owner May 27, 2024 08:04
@N-Boutaib
Copy link
Contributor Author

/to-staging

@dd-devflow
Copy link

dd-devflow bot commented May 27, 2024

🚂 Branch Integration: this build is next, merge in < 32m

Commit 88c335a0e2 will soon be integrated into staging-22.

This build is next! (estimated merge in less than 32m)

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

@dd-devflow
Copy link

dd-devflow bot commented May 27, 2024

🚨 Branch Integration: The build pipeline contains failing jobs for this merge request

We couldn't automatically merge the commit 88c335a0e2 into staging-22.
Build pipeline has failing jobs for 5abc2b8

Since those jobs are not marked as being allowed to fail, the pipeline will most likely fail.
Therefore, and to allow other builds to be processed, this merge request has been rejected before the end of the pipeline.

You should have a look at the pipeline, wait for the build to finish and investigate the failures.
When you are ready, re-add your pull request to the queue!

⚠️ Do NOT retry failed jobs directly.

They were executed on a temporary branch created by the merge queue. If you retry them, they are going to fail because the branch no longer exists.

If you think the errors come from a logical conflict with the target branch, you can create a fix by commenting this pull request with /create-fix-branch -b staging-22

Details

List of failed jobs:

Go to failed Gitlab pipeline.

If you need support, contact us on Slack #devflow with those details!

@N-Boutaib N-Boutaib requested a review from a team May 28, 2024 07:59
@N-Boutaib N-Boutaib changed the title [RUM-3837] Force Replay recording on sampled-out sessions ✨ [RUM-3837] Force Replay recording on sampled-out sessions May 28, 2024
@N-Boutaib
Copy link
Contributor Author

/to-staging

@dd-devflow
Copy link

dd-devflow bot commented May 28, 2024

🚂 Branch Integration: starting soon, merge in < 32m

Commit bea862d58c will soon be integrated into staging-22.

This build is going to start soon! (estimated merge in less than 32m)

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

dd-mergequeue bot added a commit that referenced this pull request May 28, 2024
…2777) into staging-22

Integrated commit sha: bea862d

Co-authored-by: Najib Boutaib <[email protected]>
@dd-devflow
Copy link

dd-devflow bot commented May 28, 2024

🚂 Branch Integration: This commit was successfully integrated

Commit bea862d58c has been merged into staging-22 in merge commit e54e3eb0ee.

Check out the triggered pipeline on Gitlab 🦊

@amortemousque
Copy link
Contributor

💬 suggestion: ‏We should make the extension support this feature:

  • Addind something in the session info

image

  • Making the live replay work. For now I see:

image

@@ -53,6 +55,12 @@ export function startSessionManager<TrackingType extends string>(
expireObservable.notify()
sessionContextHistory.closeActive(relativeNow())
})
sessionStore.forceReplayObservable.subscribe(() => {
Copy link
Member

Choose a reason for hiding this comment

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

💭 thought: ‏RUM logic is leaking into core. Maybe we can think of a way to abstract it, via computeSessionState?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, but that wouldn't be enough because the sessionContextHistory entry won't be updated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done ✔️

packages/rum/src/boot/recorderApi.spec.ts Show resolved Hide resolved
packages/rum-core/src/domain/rumSessionManager.ts Outdated Show resolved Hide resolved
@N-Boutaib N-Boutaib requested a review from BenoitZugmeyer May 29, 2024 13:31
@N-Boutaib
Copy link
Contributor Author

/to-staging

@dd-devflow
Copy link

dd-devflow bot commented May 30, 2024

🚂 Branch Integration: starting soon, merge in < 33m

Commit 18876276b2 will soon be integrated into staging-22.

This build is going to start soon! (estimated merge in less than 33m)

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

@dd-devflow
Copy link

dd-devflow bot commented May 30, 2024

⚠️ Branch Integration: This commit was already integrated

Commit 18876276b2 had already been merged into staging-22

If you need support, contact us on Slack #devflow!

packages/core/src/domain/session/sessionStore.ts Outdated Show resolved Hide resolved
packages/rum-core/src/domain/rumSessionManager.ts Outdated Show resolved Hide resolved
}

export interface SessionContext<TrackingType extends string> extends Context {
id: string
trackingType: TrackingType
isReplayForced: boolean
Copy link
Member

Choose a reason for hiding this comment

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

💭 thought: ‏Ideally we should remove any notion of "replay" from @datadog/browser-core. But I understand this last bit is not trivial to fix, so let's keep it like this for now, and we'll re-explore this later (I opened https://datadoghq.atlassian.net/browse/RUM-4740 for that)

packages/core/src/domain/session/sessionManager.ts Outdated Show resolved Hide resolved
test/e2e/scenario/recorder/recorder.scenario.ts Outdated Show resolved Hide resolved
@@ -57,6 +58,8 @@ type RecorderState =
stopRecording: () => void
}

type StartStrategyFn = (options?: StartRecordingOptions) => void
Copy link
Contributor

Choose a reason for hiding this comment

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

💬 suggestion: ‏‏Since there is 1 ref to that type we could inline it.

@@ -139,9 +142,9 @@ export function makeRecorderApi(
return cachedDeflateEncoder
}

startStrategy = () => {
startStrategy = (options?: StartRecordingOptions) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

💬 suggestion: ‏The type can be infered, so

Suggested change
startStrategy = (options?: StartRecordingOptions) => {
startStrategy = (options) => {

also here

startStrategy = (options?: StartRecordingOptions) => {

@N-Boutaib N-Boutaib merged commit dfcb3cc into main Jun 4, 2024
20 checks passed
@N-Boutaib N-Boutaib deleted the najib.boutaib/RUM-3837-recording-of-sampled-out-sessions branch June 4, 2024 09: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.

6 participants