Skip to content

✨ [RUM-10144] apply context defined just after init to View event generated during init #3597

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

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

Conversation

BenoitZugmeyer
Copy link
Member

@BenoitZugmeyer BenoitZugmeyer commented Jun 4, 2025

Motivation

Usually, context (global/user/account/feature flags etc.) is defined just after calling RUM.init(), which is an issue because events that are generated during init() will not have this context.

This is only problematic for View events: RUM.init() generates a first View event that is missing the context defined right after. It is usually fine, as we can expect a RUM View Update to be generated at some point later. But sometimes no View Update happen for some reason (connectivity error, browser exiting abruptly...). In those cases, it is unexpected that the View isn't including the context.

Changes

This PR fixes this issue by slightly delaying the first View update. It uses Promise.resolve() to schedule a view update in the next micro task. It should not impact reliability as using Promise.resolve().then() to schedule a micro task is not impacted by timers throttling.

Please review commit by commit.

Test instructions

In the sandbox, define a user just after init():

      DD_RUM.init({
        clientToken: 'xxx',
        applicationId: 'xxx',
        ...
      })
      DD_RUM.setUser({ id: 'foo' })

Using the devtools extension, look at individual View events by unchecking Show only the latest View event in the "Events" tab.

When loading the sandbox URL, all View events should contain the @usr.id, even the very first View.

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.

@BenoitZugmeyer BenoitZugmeyer force-pushed the benoit/delay-initial-view branch 2 times, most recently from d511589 to e28ba32 Compare June 4, 2025 15:43
@BenoitZugmeyer BenoitZugmeyer force-pushed the benoit/delay-initial-view branch from e28ba32 to 2b6121e Compare June 4, 2025 15:45
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.39%. Comparing base (b3ee2b8) to head (2b6121e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3597      +/-   ##
==========================================
+ Coverage   92.37%   92.39%   +0.01%     
==========================================
  Files         323      323              
  Lines        8135     8148      +13     
  Branches     1841     1842       +1     
==========================================
+ Hits         7515     7528      +13     
  Misses        620      620              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 146.84 KiB 146.97 KiB 127 B +0.08%
Rum Recorder 18.02 KiB 18.03 KiB 9 B +0.05%
Rum Profiler 4.63 KiB 4.63 KiB 0 B 0.00%
Logs 51.60 KiB 51.60 KiB 0 B 0.00%
Flagging 0 B 935 B 935 B N/A%
Rum Slim 106.47 KiB 106.52 KiB 50 B +0.05%
Worker 23.59 KiB 23.59 KiB 0 B 0.00%
🚀 CPU Performance
Action Name Base Average Cpu Time (ms) Local Average Cpu Time (ms) 𝚫
addglobalcontext 0.011 0.006 -0.004
addaction 0.030 0.021 -0.009
addtiming 0.005 0.005 -0.001
adderror 0.020 0.020 -0.000
startstopsessionreplayrecording 0.001 0.001 -0.000
startview 0.008 0.005 -0.003
logmessage 0.027 0.023 -0.005
🧠 Memory Performance
Action Name Base Consumption Memory (bytes) Local Consumption Memory (bytes) 𝚫 (bytes)
addglobalcontext 25.24 KiB 27.71 KiB 2.46 KiB
addaction 52.48 KiB 55.40 KiB 2.92 KiB
addtiming 25.73 KiB 25.96 KiB 238 B
adderror 58.13 KiB 59.45 KiB 1.32 KiB
startstopsessionreplayrecording 24.03 KiB 25.09 KiB 1.06 KiB
startview 431.48 KiB 424.01 KiB -7649 B
logmessage 57.04 KiB 56.85 KiB -200 B

🔗 RealWorld

@BenoitZugmeyer
Copy link
Member Author

/to-staging

@dd-devflow
Copy link
Contributor

dd-devflow bot commented Jun 4, 2025

View all feedbacks in Devflow UI.

2025-06-04 16:03:38 UTC ℹ️ Start processing command /to-staging


2025-06-04 16:03:48 UTC ℹ️ Branch Integration: starting soon, merge expected in approximately 17m43s (p90)

Commit 2b6121e26e will soon be integrated into staging-23.


2025-06-04 16:15:46 UTC ℹ️ Branch Integration: This commit was successfully integrated

Commit 2b6121e26e has been merged into staging-23 in merge commit 6826f9d5e7.

Check out the triggered pipeline on Gitlab 🦊

If you need to revert this integration, you can use the following command: /code revert-integration -b staging-23

dd-mergequeue bot added a commit that referenced this pull request Jun 4, 2025
Integrated commit sha: 2b6121e

Co-authored-by: BenoitZugmeyer <[email protected]>
@dd-devflow dd-devflow bot added the staging-23 label Jun 4, 2025
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.

2 participants