Skip to content
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

♻️ [RUM-8767] Use assembly hooks for global, user and account context #3457

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

amortemousque
Copy link
Collaborator

@amortemousque amortemousque commented Apr 1, 2025

Motivation

Use assembly hooks for global, user and account context

Changes

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 1, 2025 13:27
@codecov-commenter
Copy link

codecov-commenter commented Apr 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.98%. Comparing base (66ce71d) to head (5cea6d2).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3457      +/-   ##
==========================================
- Coverage   91.98%   91.98%   -0.01%     
==========================================
  Files         310      309       -1     
  Lines        8026     8031       +5     
  Branches     1820     1821       +1     
==========================================
+ Hits         7383     7387       +4     
- Misses        643      644       +1     

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

Comment on lines 20 to 36
accountContext = startAccountContext(customerDataTrackerManager, mockRumConfiguration())
})

it('should get account', () => {
accountContext.setContext({ id: '123' })
expect(accountContext.getContext()).toEqual({ id: '123' })
})

it('should set account property', () => {
accountContext.setContextProperty('foo', 'bar')
expect(accountContext.getContext()).toEqual({ foo: 'bar' })
})

it('should remove account property', () => {
accountContext.setContext({ id: '123', foo: 'bar' })
accountContext.removeContextProperty('foo')
expect(accountContext.getContext()).toEqual({ id: '123' })
})

it('should clear account', () => {
accountContext.setContext({ id: '123' })
accountContext.clearContext()
expect(accountContext.getContext()).toEqual({})
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These tests are redundant with contextManager.spec.ts

Comment on lines -19 to -33
it('should get context', () => {
globalContext.setContext({ id: '123' })
expect(globalContext.getContext()).toEqual({ id: '123' })
})

it('should set context property', () => {
globalContext.setContextProperty('foo', 'bar')
expect(globalContext.getContext()).toEqual({ foo: 'bar' })
})

it('should remove context property', () => {
globalContext.setContext({ id: '123', foo: 'bar' })
globalContext.removeContextProperty('foo')
expect(globalContext.getContext()).toEqual({ id: '123' })
})

it('should clear context', () => {
globalContext.setContext({ id: '123' })
globalContext.clearContext()
expect(globalContext.getContext()).toEqual({})
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These tests are redundant with contextManager.spec.ts

Comment on lines 17 to 33
userContext = startUserContext(customerDataTrackerManager, mockRumConfiguration())
})

it('should get user', () => {
userContext.setContext({ id: '123' })
expect(userContext.getContext()).toEqual({ id: '123' })
})

it('should set user property', () => {
userContext.setContextProperty('foo', 'bar')
expect(userContext.getContext()).toEqual({ foo: 'bar' })
})

it('should remove user property', () => {
userContext.setContext({ id: '123', foo: 'bar' })
userContext.removeContextProperty('foo')
expect(userContext.getContext()).toEqual({ id: '123' })
})

it('should clear user', () => {
userContext.setContext({ id: '123' })
userContext.clearContext()
expect(userContext.getContext()).toEqual({})
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These tests are redundant with contextManager.spec.ts

Comment on lines -92 to -88

accountContext.setContextProperty('foo', 'bar')
expect(accountContext.getContext()).toEqual({ id: 'foo', qux: 'qix', foo: 'bar' })
expect(localStorage.getItem('_dd_c_rum_4')).toBe('{"id":"foo","qux":"qix","foo":"bar"}')

accountContext.removeContextProperty('foo')
expect(accountContext.getContext()).toEqual({ id: 'foo', qux: 'qix' })
expect(localStorage.getItem('_dd_c_rum_4')).toBe('{"id":"foo","qux":"qix"}')

accountContext.clearContext()
expect(accountContext.getContext()).toEqual({})
expect(localStorage.getItem('_dd_c_rum_4')).toBe('{}')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These tests are redundant with contextManager.spec.ts

Comment on lines -75 to -72

globalContext.setContextProperty('foo', 'bar')
expect(globalContext.getContext()).toEqual({ id: 'foo', qux: 'qix', foo: 'bar' })
expect(localStorage.getItem('_dd_c_rum_2')).toBe('{"id":"foo","qux":"qix","foo":"bar"}')

globalContext.removeContextProperty('foo')
expect(globalContext.getContext()).toEqual({ id: 'foo', qux: 'qix' })
expect(localStorage.getItem('_dd_c_rum_2')).toBe('{"id":"foo","qux":"qix"}')

globalContext.clearContext()
expect(globalContext.getContext()).toEqual({})
expect(localStorage.getItem('_dd_c_rum_2')).toBe('{}')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These tests are redundant with contextManager.spec.ts

Comment on lines -83 to -82

userContext.setContextProperty('foo', 'bar')
expect(userContext.getContext()).toEqual({ id: 'foo', qux: 'qix', foo: 'bar' })
expect(localStorage.getItem('_dd_c_rum_1')).toBe('{"id":"foo","qux":"qix","foo":"bar"}')

userContext.removeContextProperty('foo')
expect(userContext.getContext()).toEqual({ id: 'foo', qux: 'qix' })
expect(localStorage.getItem('_dd_c_rum_1')).toBe('{"id":"foo","qux":"qix"}')

userContext.clearContext()
expect(userContext.getContext()).toEqual({})
expect(localStorage.getItem('_dd_c_rum_1')).toBe('{}')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These tests are redundant with contextManager.spec.ts

Copy link
Contributor

@sethfowler-datadog sethfowler-datadog left a comment

Choose a reason for hiding this comment

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

LGTM!

;(serverRumEvent.session as Mutable<RumEvent['session']>).has_replay = commonContext.hasReplay
;(serverRumEvent.session as Mutable<RumEvent['session']>).has_replay = recorderApi.isRecording()
? true
: undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

I like that this makes the expected behavior clear; this has caused some confusion recently!

})
})

it('should not set the account when account.id is undefined', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Worth testing other falsy cases, just to clarify the expected behavior? e.g. id property present but set to undefined, or id set to ''.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a good one and thanks to it I spotted an issue: #3475

Copy link

cit-pr-commenter bot commented Apr 7, 2025

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 0 B 145.20 KiB 145.20 KiB N/A%
Rum.recorder 0 B 18.02 KiB 18.02 KiB N/A%
Rum.profiler 0 B 4.64 KiB 4.64 KiB N/A%
Logs 0 B 50.16 KiB 50.16 KiB N/A%
Rum Slim 0 B 104.73 KiB 104.73 KiB N/A%
Worker 0 B 23.59 KiB 23.59 KiB N/A%
🚀 CPU Performance
Action Name Base Average Cpu Time (ms) Local Average Cpu Time (ms) 𝚫
addglobalcontext 0.003 0.002 -0.001
addaction 0.046 0.038 -0.008
addtiming 0.001 0.001 0.000
adderror 0.050 0.041 -0.008
startstopsessionreplayrecording 0.009 0.012 0.003
startview 0.423 0.454 0.031
logmessage 0.020 0.021 0.001
🧠 Memory Performance
Action Name Base Consumption Memory (bytes) Local Consumption Memory (bytes) 𝚫 (bytes)
addglobalcontext 26.29 KiB 25.47 KiB -840 B
addaction 56.40 KiB 54.12 KiB -2335 B
addtiming 23.58 KiB 23.90 KiB 333 B
adderror 59.77 KiB 58.14 KiB -1668 B
startstopsessionreplayrecording 24.50 KiB 23.57 KiB -957 B
startview 430.05 KiB 429.23 KiB -845 B
logmessage 61.73 KiB 58.77 KiB -3031 B

🔗 RealWorld

@amortemousque amortemousque force-pushed the aymeric/add-hook-for-contexts-2 branch from 4ed22b1 to 265bebf Compare April 7, 2025 12:53
@amortemousque amortemousque force-pushed the aymeric/add-hook-for-contexts-2 branch from 265bebf to 5cea6d2 Compare April 7, 2025 13:41
@amortemousque
Copy link
Collaborator Author

/to-staging

@dd-devflow
Copy link
Contributor

dd-devflow bot commented Apr 8, 2025

View all feedbacks in Devflow UI.

2025-04-08 07:20:26 UTC ℹ️ Start processing command /to-staging


2025-04-08 07:20:32 UTC ℹ️ Branch Integration: starting soon, merge expected in approximately 0s (p90)

Commit 5cea6d2555 will soon be integrated into staging-15.


2025-04-08 07:28:12 UTC 🚨 Branch Integration: The build pipeline contains failing jobs for this merge request

We couldn't automatically merge the commit 5cea6d2555 into staging-15.
Build pipeline has failing jobs for 4883422:

⚠️ Do NOT retry failed jobs directly (why?).

What to do next?

  • Investigate the failures and when ready, re-add your pull request to the queue!
  • If your PR checks are green, try to rebase/merge. It might be because the CI run is a bit old.
  • Any question, go check the FAQ.

If you think the errors come from a logical conflict with the target branch, you can create a fix by commenting this pull request with /create-fix-branch -b staging-15

Details

Since those jobs are not marked as being allowed to fail, the pipeline will most likely fail.
Therefore, and to allow other builds to be processed, this merge request has been rejected and the pipeline got canceled.

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