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 #2684

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

Conversation

N-Boutaib
Copy link
Contributor

@N-Boutaib N-Boutaib commented Apr 3, 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 new tracking type is added
  • The cookie is updated to reflect that change, with the new tracking type
  • Session cache and history context are synchronised across all tabs

Testing

  • Local
  • Staging
  • Unit
  • End to end

I have gone over the contributing documentation.

@codecov-commenter
Copy link

codecov-commenter commented Apr 3, 2024

Codecov Report

Attention: Patch coverage is 97.72727% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 93.28%. Comparing base (5249c39) to head (b7323fc).
Report is 8 commits behind head on main.

Files Patch % Lines
packages/rum-core/src/domain/rumSessionManager.ts 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2684      +/-   ##
==========================================
+ Coverage   93.26%   93.28%   +0.01%     
==========================================
  Files         241      241              
  Lines        7028     7057      +29     
  Branches     1553     1569      +16     
==========================================
+ Hits         6555     6583      +28     
- Misses        473      474       +1     

☔ 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-force-replay-recording-on-sampled-out-sessions branch from 3e48bbc to 59d7883 Compare April 3, 2024 15:34
Copy link

cit-pr-commenter bot commented Apr 3, 2024

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 157.47 KiB 158.10 KiB 643 B +0.40%
Logs 56.09 KiB 56.40 KiB 319 B +0.56%
Rum Slim 103.96 KiB 104.51 KiB 563 B +0.53%
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) 𝚫
adderror 0.031 0.032 0.001
addaction 0.016 0.015 -0.001
logmessage 0.005 0.006 0.001
startview 0.920 0.848 -0.072
startstopsessionreplayrecording 1.017 0.762 -0.255
addtiming 0.001 0.001 -0.000
addglobalcontext 0.001 0.001 -0.000

@N-Boutaib N-Boutaib force-pushed the najib.boutaib/RUM-3837-force-replay-recording-on-sampled-out-sessions branch 2 times, most recently from 562e9c6 to 7b93d67 Compare April 23, 2024 15:10
@N-Boutaib N-Boutaib marked this pull request as ready for review April 23, 2024 15:31
@N-Boutaib N-Boutaib requested a review from a team as a code owner April 23, 2024 15:31
packages/core/src/domain/session/sessionStore.ts Outdated Show resolved Hide resolved
packages/rum-core/src/domain/rumSessionManager.ts Outdated Show resolved Hide resolved
packages/rum/src/boot/recorderApi.ts Outdated Show resolved Hide resolved
packages/core/src/domain/session/sessionManager.ts Outdated Show resolved Hide resolved
packages/rum-core/src/domain/rumSessionManager.ts Outdated Show resolved Hide resolved
packages/rum-core/src/boot/rumPublicApi.ts Outdated Show resolved Hide resolved
packages/rum-core/src/boot/rumPublicApi.ts Outdated Show resolved Hide resolved
Comment on lines 299 to 292
recorderApi.start(options)
addTelemetryUsage({ feature: 'start-session-replay-recording' })
Copy link
Contributor

Choose a reason for hiding this comment

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

💬 suggestion: ‏what about collecting the usage of this new option? 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Definitely 👌

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add this in a followup PR, since I need to update rum-event-format

@@ -179,6 +181,16 @@ export function startSessionStore<TrackingType extends string>(
renewObservable.notify()
}

function updateSessionInStore(updatedState: Partial<SessionState>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

💬 suggestion: could we had a test to ensure that this store update is well propagated to other tabs/store?‏

@@ -28,6 +29,7 @@ export const enum RumTrackingType {
NOT_TRACKED = '0',
TRACKED_WITH_SESSION_REPLAY = '1',
TRACKED_WITHOUT_SESSION_REPLAY = '2',
TRACKED_WITH_FORCED_REPLAY = '3',
Copy link
Contributor

Choose a reason for hiding this comment

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

💬 suggestion: could you support this new state in the extension?

2024-04-24_11-57-42 (1)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, sure. I forgot about it 😅

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 ✔️

@@ -102,13 +106,15 @@ function hasValidRumSession(trackingType?: string): trackingType is RumTrackingT
return (
trackingType === RumTrackingType.NOT_TRACKED ||
trackingType === RumTrackingType.TRACKED_WITH_SESSION_REPLAY ||
trackingType === RumTrackingType.TRACKED_WITHOUT_SESSION_REPLAY
trackingType === RumTrackingType.TRACKED_WITHOUT_SESSION_REPLAY ||
Copy link
Contributor

Choose a reason for hiding this comment

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

💬 suggestion: ‏could we add this new type in the related tests?

It would be nice to ensure somewhere that sessionReplayAllowed is false for the forced state as it is used to compute sampled_for_replay

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just a typeguard IIRC, sessionReplayAllowed compares the tracking type, and is set to true only if the state is TRACKED_WITH_SESSION_REPLAY

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a new attribute in the session object that reflect either the session was originally sampled for replay or not, to avoid any confusing (and to fix a small bug I found)

Done ✔️

packages/core/src/domain/session/sessionManager.ts Outdated Show resolved Hide resolved
@@ -84,6 +86,7 @@ export function startSessionManager<TrackingType extends string>(
renewObservable,
expireObservable,
expire: sessionStore.expire,
updateSessionInStore: sessionStore.updateSessionInStore,
Copy link
Contributor

Choose a reason for hiding this comment

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

🔨 warning: ‏ FMU, updateSessionInStore() does not update the session entry in sessionContextHistory. It means that findTrackedSession() will still return return TRACKED_WITHOUT_SESSION_REPLAY.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll check this aspect, I didn't run into any issue while testing though 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

From my test when using startSessionReplayRecording({force: true}) on sampled out session, it triggers the expireObservable. Then I have to interact with the page to trigger the renewObservable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This addressed through the synchronisation mechanism discussed

packages/rum/src/boot/recorderApi.ts Outdated Show resolved Hide resolved
@N-Boutaib N-Boutaib force-pushed the najib.boutaib/RUM-3837-force-replay-recording-on-sampled-out-sessions branch from ed48e1b to 985f6e8 Compare April 25, 2024 13:43
@N-Boutaib N-Boutaib force-pushed the najib.boutaib/RUM-3837-force-replay-recording-on-sampled-out-sessions branch from 192cc6a to f6e6a40 Compare May 2, 2024 13:28
@N-Boutaib N-Boutaib marked this pull request as draft May 2, 2024 13:28
@N-Boutaib N-Boutaib marked this pull request as ready for review May 7, 2024 09:16
})
sessionManager.updateSession({ [FIRST_PRODUCT_KEY]: FakeTrackingType.OTHER_TRACKING })

expect(sessionManager.findActiveSession()!.id).toBeDefined()
Copy link
Contributor

Choose a reason for hiding this comment

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

💬 suggestion:

Suggested change
expect(sessionManager.findActiveSession()!.id).toBeDefined()
expectSessionIdToBeDefined()

const sessionManager = startSessionManagerWithDefaults({
allowedTrackingTransition: FakeTrackingType.OTHER_TRACKING,
})
sessionManager.updateSession({ [FIRST_PRODUCT_KEY]: FakeTrackingType.DISALLOWED_TRACKING })
Copy link
Contributor

Choose a reason for hiding this comment

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

💬 suggestion:

Suggested change
sessionManager.updateSession({ [FIRST_PRODUCT_KEY]: FakeTrackingType.DISALLOWED_TRACKING })
expectSessionToBeExpired()

Comment on lines +187 to +188
const a = didSessionIdChange || untoleratedTrackingChange
return a
Copy link
Contributor

Choose a reason for hiding this comment

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

💬 suggestion:

Suggested change
const a = didSessionIdChange || untoleratedTrackingChange
return a
return didSessionIdChange || untoleratedTrackingChange

Copy link
Contributor

Choose a reason for hiding this comment

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

seems like this is not an expected change for this PR, is it?

@N-Boutaib N-Boutaib marked this pull request as draft May 24, 2024 09:55
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.

None yet

5 participants