Skip to content

RUM-9977: Update RUM feature context only after event processing completion#2650

Merged
0xnm merged 1 commit into
nogorodnikov/rum-8170/feature-context-syncfrom
nogorodnikov/rum-9977/update-rum-feature-context-once
May 15, 2025
Merged

RUM-9977: Update RUM feature context only after event processing completion#2650
0xnm merged 1 commit into
nogorodnikov/rum-8170/feature-context-syncfrom
nogorodnikov/rum-9977/update-rum-feature-context-once

Conversation

@0xnm

@0xnm 0xnm commented May 15, 2025

Copy link
Copy Markdown
Member

What does this PR do?

This PR brings the following change: now we will update RUM feature context only once, once RUM events processing is complete.

This change requires breaking a bit encapsulation by exposing concrete sub-types of RumScope, but advantage is that we remove multiple feature context update call sites and leave only one place where it is done. Anyway, the hierarchy of the scopes is always the same, we never changed it.

This is similar to what iOS SDK is doing https://github.com/DataDog/dd-sdk-ios/blob/61010e401dfa42bd7a98495f6e2cd04547c2f75a/DatadogRUM/Sources/RUMMonitor/Monitor.swift#L141-L164.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@0xnm
0xnm requested review from a team as code owners May 15, 2025 09:25
@0xnm
0xnm force-pushed the nogorodnikov/rum-9977/update-rum-feature-context-once branch from 99091ac to e27d65f Compare May 15, 2025 09:25
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 91.30435% with 4 lines in your changes missing coverage. Please review.

Project coverage is 70.10%. Comparing base (4431985) to head (e27d65f).
Report is 13 commits behind head on nogorodnikov/rum-8170/feature-context-sync.

Files with missing lines Patch % Lines
...droid/rum/internal/domain/scope/RumSessionScope.kt 66.67% 0 Missing and 2 partials ⚠️
...d/rum/internal/domain/scope/RumApplicationScope.kt 88.89% 1 Missing ⚠️
.../android/rum/internal/monitor/DatadogRumMonitor.kt 91.67% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@                              Coverage Diff                               @@
##           nogorodnikov/rum-8170/feature-context-sync    #2650      +/-   ##
==============================================================================
- Coverage                                       70.11%   70.10%   -0.01%     
==============================================================================
  Files                                             819      819              
  Lines                                           30611    30594      -17     
  Branches                                         5111     5107       -4     
==============================================================================
- Hits                                            21460    21446      -14     
+ Misses                                           7734     7726       -8     
- Partials                                         1417     1422       +5     
Files with missing lines Coverage Δ
...d/rum/internal/domain/scope/RumViewManagerScope.kt 92.27% <100.00%> (+0.35%) ⬆️
.../android/rum/internal/domain/scope/RumViewScope.kt 94.16% <100.00%> (+0.23%) ⬆️
...d/rum/internal/domain/scope/RumApplicationScope.kt 95.28% <88.89%> (+0.14%) ⬆️
.../android/rum/internal/monitor/DatadogRumMonitor.kt 85.97% <91.67%> (+0.26%) ⬆️
...droid/rum/internal/domain/scope/RumSessionScope.kt 95.93% <66.67%> (-0.79%) ⬇️

... and 32 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

executorService.executeSafe("Rum event handling", sdkCore.internalLogger) {
synchronized(rootScope) {
rootScope.handleEvent(event, datadogContext, writeScope, writer)
updateFeatureContext()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Question: If I understand correctly, prior to this PR, RumViewSceope only update RUM feature context for onStartAction, with this change, we try to update the context for every event, is that correct?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, RUM feature context was updated from multiple places, not only from RumViewScope. Even RumViewScope was doing it from multiple places.

@ambushwork ambushwork May 15, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we take RumRawEvent.ActionSent as an example, this event will be delegated to RumViewScope.onActionSent, when handling this event, I see it will only update the context for has_replay attribute.

However with this PR, it will have an additional updateFeatureContext here when it is completely handled, if it is true, we are updating feature context more frequently than before?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ambushwork I understand what you are saying but I don't think it is too much harm in that, I guess removing this complexity is worthy, what do you think ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We will update context more often, this is true, but in fact any event can change the RUM context. Imagine some event triggering session validity check and invalidating it, for example.

So we bring more predictability and stability here.

Also, if taking RumViewScope, before this change it was updating RUM view context from different places: when RUM view scope is created, when stopped, when action is started and stopped, and, most importantly, at the sendViewUpdate, which is called for many events.

The last call site is still there, but it is just because there is dependency with SR. I will have to handle SR context handling as well (in another PR) before removing this call site (ideally).

@ambushwork ambushwork May 15, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK, make sense, I am not against simplify the call site of updating feature context, my questions is just to make sure that you are aware of the additional call of update feature context (especially because updateFeatureContext has synchronized block inside, we need to pay attention). if it's an expected behavior, then LGTM.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes, it is an expected behavior. Later on we can even do an optimization - since RumContext is a data class, we can store the previous snapshot and call updateFeatureContext only if something changed in the class.

return childScopes.find { it.isActive() }
val activeSessions = childScopes.filter { it.isActive() }
if (activeSessions.size > 1) {
sdkCore.internalLogger.log(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is this related with this PR ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes, it is. It is just a safeguard to inform that we have to make a selection from the multiple active sessions.

executorService.executeSafe("Rum event handling", sdkCore.internalLogger) {
synchronized(rootScope) {
rootScope.handleEvent(event, datadogContext, writeScope, writer)
updateFeatureContext()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ambushwork I understand what you are saying but I don't think it is too much harm in that, I guess removing this complexity is worthy, what do you think ?

@0xnm
0xnm merged commit d188b59 into nogorodnikov/rum-8170/feature-context-sync May 15, 2025
@0xnm
0xnm deleted the nogorodnikov/rum-9977/update-rum-feature-context-once branch May 15, 2025 13:34
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.

4 participants