Skip to content

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

Draft
BenoitZugmeyer wants to merge 9 commits into
mainfrom
benoit/delay-initial-view
Draft

✨ [RUM-10144] apply context defined just after init to View event generated during init#3597
BenoitZugmeyer wants to merge 9 commits into
mainfrom
benoit/delay-initial-view

Conversation

@BenoitZugmeyer

@BenoitZugmeyer BenoitZugmeyer commented Jun 4, 2025

Copy link
Copy Markdown
Member

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.

Fixes #3935

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 3 times, most recently from e28ba32 to 2b6121e Compare June 4, 2025 15:45
@codecov-commenter

codecov-commenter commented Jun 4, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.39%. Comparing base (b3ee2b8) to head (2b6121e).
⚠️ Report is 587 commits behind head on main.

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.

@cit-pr-commenter

cit-pr-commenter Bot commented Jun 4, 2025

Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 180.58 KiB 180.68 KiB +98 B +0.05%
Rum Profiler 8.43 KiB 8.43 KiB 0 B 0.00%
Rum Recorder 21.12 KiB 21.12 KiB 0 B 0.00%
Logs 57.03 KiB 57.03 KiB 0 B 0.00%
Rum Salesforce N/A 138.49 KiB N/A N/A N/A
Rum Slim 138.46 KiB 138.48 KiB +18 B +0.01%
Worker 22.96 KiB 22.96 KiB 0 B 0.00%
Rum Shopify N/A 200.25 KiB N/A N/A N/A
Rum-shopify Profiler N/A 8.43 KiB N/A N/A N/A
Rum-shopify Recorder N/A 3.72 KiB N/A N/A N/A

@BenoitZugmeyer

Copy link
Copy Markdown
Member Author

/to-staging

@dd-devflow

dd-devflow Bot commented Jun 4, 2025

Copy link
Copy Markdown
Contributor

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 <benoit.zugmeyer@datadoghq.com>
@dd-devflow dd-devflow Bot added the staging-23 label Jun 4, 2025
@BenoitZugmeyer
BenoitZugmeyer force-pushed the benoit/delay-initial-view branch from 2b6121e to bbf879f Compare August 10, 2026 13:59
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Aug 10, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 87.50%
Overall Coverage: 77.21% (+0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 303932c | Docs | Datadog PR Page | Give us feedback!

Safari processes buffered PerformanceObserver resource entries when the mock clock ticks, so assert only on view events.
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.

🐛 Initial version of RUM view event is missing global context

2 participants