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-5536 [SR] Start / Stop API #1986

Merged
merged 5 commits into from
Aug 20, 2024
Merged

Conversation

mariedm
Copy link
Contributor

@mariedm mariedm commented Aug 2, 2024

What and why?

This PR adds the ability for customers to:

  • Start and stop a recording
  • Disable automatic recording when enabling Session Replay

See RFC for more details.

How?

  • Introduce a new startRecordingImmediately optional parameter when enabling Session Replay, defaulting to true
  • Add new set of start and stop public APIs to the existing SessionReplay public enum, through static functions
  • Introduce a recordingEnabled variable to RecordingCoordinator to track when the user wants to start or stop a recording
  • Update the RUM flag has_replay accordingly when starting or stopping a recording
  • Modified a bit the logic in RecordingCoordinator:
    • The scheduler is only started if the recording has been enabled by the user and the RUM session is sampled
    • We decouple the update of the has_replay flag from the RUM view ID; whether it's nil or not has no impact on this flag anymore

Note: ignoring webviews' snapshots will be tackled separately

Review checklist

  • Feature or bugfix MUST have appropriate tests (unit, integration)
  • Make sure each commit and the PR mention the Issue number or JIRA reference
  • Add CHANGELOG entry for user facing changes

@mariedm mariedm force-pushed the mariedm/feat/RUM-5536-start-stop-api branch 7 times, most recently from 7ccf8ad to bce906e Compare August 7, 2024 15:37
@mariedm mariedm marked this pull request as ready for review August 7, 2024 15:47
@mariedm mariedm requested review from a team as code owners August 7, 2024 15:47
@mariedm mariedm marked this pull request as draft August 7, 2024 16:10
@mariedm mariedm force-pushed the mariedm/feat/RUM-5536-start-stop-api branch from bce906e to 2c62e43 Compare August 7, 2024 16:59
@mariedm mariedm marked this pull request as ready for review August 7, 2024 17:00
@mariedm mariedm force-pushed the mariedm/feat/RUM-5536-start-stop-api branch from 2c62e43 to 55891cc Compare August 7, 2024 17:06
Copy link
Collaborator

@ncreated ncreated left a comment

Choose a reason for hiding this comment

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

Looks great 💪 and I appreciate the work on tests coverage 🏅 👌. I left one blocking commend on potential problem in synchronizing the isSampled state (I think now it can be mutated from different threads).

Also, let's move the new option to SessionReplay.Configuration to be consistent with other feature APIs 🙏.

@mariedm mariedm requested a review from ncreated August 9, 2024 10:07
ncreated
ncreated previously approved these changes Aug 9, 2024
Copy link
Collaborator

@ncreated ncreated left a comment

Choose a reason for hiding this comment

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

Looks great 🎯. I left one small feedback on API comment.

Copy link
Member

@maxep maxep left a comment

Choose a reason for hiding this comment

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

Looks great! I have left couple of question/suggestion.

DatadogSessionReplay/Sources/SessionReplay.swift Outdated Show resolved Hide resolved
@mariedm
Copy link
Contributor Author

mariedm commented Aug 14, 2024

@maxep Following our discussion, I’ve updated the logic to use the scheduler’s queue. Sharing here the reasoning for later reference.

With this approach, all state changes are synchronized on the same queue. It maintains consistency without the overhead of locks.

A trade-off of this approach is that recordingEnabled is now private to prevent direct access from outside the class, which means we can no longer access it directly in tests. We can still rely on the scheduler’s isRunning variable to verify when the recording is active, though we lose the ability to directly test whether the recording was enabled or disabled by the user.

This change prioritizes thread and synchronization safety, which can avoid hard-to-debug issues. This should save us time and prevent potential problems in the future.

@mariedm
Copy link
Contributor Author

mariedm commented Aug 14, 2024

Note: I logged a ticket to deal with webviews' snapshots later, as this should be an edge case not blocking GA.

@mariedm mariedm requested a review from maxep August 14, 2024 14:51
Copy link
Member

@maxep maxep left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

@mariedm mariedm merged commit e9e4355 into develop Aug 20, 2024
16 checks passed
@mariedm mariedm deleted the mariedm/feat/RUM-5536-start-stop-api branch August 20, 2024 10:26
@mariedm mariedm mentioned this pull request Sep 11, 2024
3 tasks
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.

3 participants