Skip to content

Conversation

@BenoitZugmeyer
Copy link
Member

@BenoitZugmeyer BenoitZugmeyer commented Jun 3, 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.

For now, 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.

This issue will be more pronounced when we'll start to collect errors that happen before init (in a future PR). In this case, we'll want the context to apply to those events (for example, to clearly identify which user was affected by such early error).

Changes

This PR fixes this issue by slightly delaying the events assembly. It uses a new data structure, BufferedObservable, that will be used to progressively replace the BoundedBuffer and what we call "pre start strategies". This BufferedObservable is asynchrone, so we leverage this fact to delay the assembly.

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.

@codecov-commenter
Copy link

codecov-commenter commented Jun 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.38%. Comparing base (de2bc24) to head (3d012c1).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3592      +/-   ##
==========================================
+ Coverage   92.31%   92.38%   +0.06%     
==========================================
  Files         319      319              
  Lines        8104     8137      +33     
  Branches     1831     1834       +3     
==========================================
+ Hits         7481     7517      +36     
+ Misses        623      620       -3     

☔ 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.

@BenoitZugmeyer BenoitZugmeyer force-pushed the benoit/delay-assembly branch 5 times, most recently from 4eae2fc to 506bfb1 Compare June 3, 2025 17:25
This commit is purely intending to ease review. It does not introduce
any functional change or new test case, it just prepares the tests for
the assembly being asynchronous coming in the next commit.
@BenoitZugmeyer BenoitZugmeyer force-pushed the benoit/delay-assembly branch from 506bfb1 to 3d012c1 Compare June 3, 2025 17:27
@cit-pr-commenter
Copy link

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 146.07 KiB 146.70 KiB 650 B +0.43%
Rum Recorder 18.02 KiB 18.02 KiB 0 B 0.00%
Rum Profiler 4.63 KiB 4.63 KiB 0 B 0.00%
Logs 50.26 KiB 50.33 KiB 74 B +0.14%
Flagging 0 B 932 B 932 B N/A%
Rum Slim 105.70 KiB 106.28 KiB 596 B +0.55%
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.009 0.007 -0.002
addaction 0.032 0.022 -0.010
addtiming 0.006 0.005 -0.000
adderror 0.027 0.022 -0.005
startstopsessionreplayrecording 0.001 0.001 -0.001
startview 0.006 0.005 -0.001
logmessage 0.027 0.025 -0.002
🧠 Memory Performance
Action Name Base Consumption Memory (bytes) Local Consumption Memory (bytes) 𝚫 (bytes)
addglobalcontext 25.51 KiB 26.76 KiB 1.25 KiB
addaction 55.27 KiB 55.33 KiB 60 B
addtiming 26.36 KiB 25.44 KiB -934 B
adderror 62.66 KiB 58.76 KiB -3996 B
startstopsessionreplayrecording 25.13 KiB 25.10 KiB -29 B
startview 429.15 KiB 431.25 KiB 2.10 KiB
logmessage 56.02 KiB 60.86 KiB 4.84 KiB

🔗 RealWorld

@BenoitZugmeyer
Copy link
Member Author

Superseded by #3597

@BenoitZugmeyer BenoitZugmeyer deleted the benoit/delay-assembly branch June 4, 2025 15:50
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