Skip to content

♻️ [RUM-9614] Decouple default context from assembly using hooks #3498

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

Merged
merged 5 commits into from
May 7, 2025

Conversation

amortemousque
Copy link
Collaborator

@amortemousque amortemousque commented Apr 23, 2025

Motivation

Decouple the default context from the assembly. The 'default context' includes the following data:

 _dd: {
  format_version: 2,
  drift: currentDrift(),
  configuration: {
    session_sample_rate: round(configuration.sessionSampleRate, 3),
    session_replay_sample_rate: round(configuration.sessionReplaySampleRate, 3),
  },
  browser_sdk_version: canUseEventBridge() ? __BUILD_ENV__SDK_VERSION__ : undefined,
},
application: {
  id: configuration.applicationId,
},
date: timeStampNow(),
source: 'browser',

Changes

  • Create a defaultContext module that uses assemble hook
  • Remove default context from assembly

Testing

  • Local
  • Staging
  • Unit
  • End to end

I have gone over the contributing documentation.

@amortemousque amortemousque requested a review from a team as a code owner April 23, 2025 07:31
Copy link
Member

@BenoitZugmeyer BenoitZugmeyer left a comment

Choose a reason for hiding this comment

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

Amazing

@codecov-commenter
Copy link

codecov-commenter commented Apr 29, 2025

Codecov Report

Attention: Patch coverage is 97.56098% with 1 line in your changes missing coverage. Please review.

Project coverage is 92.22%. Comparing base (ee44e41) to head (3611819).
Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
...ges/rum-core/src/domain/action/actionCollection.ts 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3498      +/-   ##
==========================================
+ Coverage   92.17%   92.22%   +0.04%     
==========================================
  Files         312      313       +1     
  Lines        8043     8053      +10     
  Branches     1819     1820       +1     
==========================================
+ Hits         7414     7427      +13     
+ Misses        629      626       -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.

Copy link

cit-pr-commenter bot commented Apr 29, 2025

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 145.27 KiB 145.36 KiB 88 B +0.06%
Rum Recorder 18.02 KiB 18.02 KiB 0 B 0.00%
Rum Profiler 4.64 KiB 4.64 KiB 0 B 0.00%
Logs 49.96 KiB 49.96 KiB 0 B 0.00%
Rum Slim 104.85 KiB 104.93 KiB 83 B +0.08%
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.002 0.003 0.001
addaction 0.039 0.088 0.049
addtiming 0.001 0.001 0.000
adderror 0.041 0.054 0.013
startstopsessionreplayrecording 0.007 0.014 0.007
startview 0.388 0.554 0.165
logmessage 0.020 0.024 0.005
🧠 Memory Performance
Action Name Base Consumption Memory (bytes) Local Consumption Memory (bytes) 𝚫 (bytes)
addglobalcontext 24.93 KiB 25.80 KiB 891 B
addaction 52.02 KiB 56.70 KiB 4.67 KiB
addtiming 23.73 KiB 25.41 KiB 1.69 KiB
adderror 55.22 KiB 58.27 KiB 3.05 KiB
startstopsessionreplayrecording 22.47 KiB 25.26 KiB 2.78 KiB
startview 426.71 KiB 426.20 KiB -522 B
logmessage 52.32 KiB 57.91 KiB 5.59 KiB

🔗 RealWorld

}
results.push(result)
}
return combine(...(results as unknown as [object, object])) as ReturnType<HookCallbackMap[K]>

return (results.length > 0 ? combine(...(results as unknown as [object, object])) : {}) as PartialRumEvent
Copy link
Member

Choose a reason for hiding this comment

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

thought: The non-null assertion we wanted to avoid seemed better than this {} as PartialRumEvent cast.

With the former, we acknowledge‏ that although triggerHook can return undefined in theory, it can't happen in assembly.ts. We also assume the PartialRumEvent is in fact a valid RUM event with all the required properties defined.

With the latter, we return an empty object, which is not only incorrect from a type perspective (PartialRumEvent expect to have a type property), but also doesn't improve the situation in assembly.ts as we'll still need to implicitly assume that it won't return an empty object.

@amortemousque
Copy link
Collaborator Author

/to-staging

@dd-devflow
Copy link
Contributor

dd-devflow bot commented May 6, 2025

View all feedbacks in Devflow UI.

2025-05-06 13:29:39 UTC ℹ️ Start processing command /to-staging


2025-05-06 13:29:53 UTC ℹ️ Branch Integration: starting soon, merge expected in approximately 0s (p90)

Commit 3611819207 will soon be integrated into staging-19.


2025-05-06 13:44:52 UTC ℹ️ Branch Integration: This commit was successfully integrated

Commit 3611819207 has been merged into staging-19 in merge commit dfc1c59dab.

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-19

dd-mergequeue bot added a commit that referenced this pull request May 6, 2025
…ing-19

Integrated commit sha: 3611819

Co-authored-by: amortemousque <[email protected]>
@dd-devflow dd-devflow bot added the staging-19 label May 6, 2025
@amortemousque amortemousque merged commit 54d3f79 into main May 7, 2025
19 checks passed
@amortemousque amortemousque deleted the aymeric/decouple-default-context-assembly branch May 7, 2025 08:24
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.

5 participants