Skip to content

[RUM Profiler] Add profiling context to Long Task and View events #3583

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

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

Conversation

thomasbertet
Copy link
Contributor

@thomasbertet thomasbertet commented Jun 2, 2025

Motivation

  • In the RUM x Profiling integration, we would like to explain why there is no Profiling data on a specific Long Tasks. It would be super useful to have a detailed profiling status to be able to help users understand why. There could be a bunch of different reasons and this status tries to reflects all of them.

This PR is based on work done in DataDog/rum-events-format#274 defining the context.

Changes

  • new _dd.profiling field on RumViewEvent, RumLongTaskEvent (updated the rum-events-format PR)
  • This new status describes what is the current state of the Profiling at a "high level".

View emitted now has a profiling field in _dd:
Screenshot 2025-06-04 at 18 06 56

Long Task emitted also has a profiling field in _dd:
Screenshot 2025-06-04 at 18 07 09

  • These status have been designed so that it will be possible to aggregate them when a single view is receiving multiple of them

  • For Long Tasks, there is no aggregation so it's easier and the exact status of the Profiler that is collected on Long Task collection is the one used, always.

Test instructions

  • Open the Browser SDK Browser Extension, and assert you can now see _dd.profiling.status field on top level of both Views and Long Task events, with a meaningful status.

Checklist

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

@thomasbertet thomasbertet changed the title [RUM Profiler] new ProfilingStatusManager to add profiling_status to Long Task and View events [RUM Profiler] Add profiling_status to Long Task and View events Jun 2, 2025
* - failed-to-lazy-load: The Profiler script failed to be loaded by the Browser. (may be connection issue or the chunk was not found)
* - failed-to-start: The Profiler failed to start. (most probable cause if when the web server did not return the `Document-Policy: js-profiling` HTTP Response header)
* - running: The Profiler is running.
* - stopped: The Profiler is stopped.
Copy link
Collaborator

Choose a reason for hiding this comment

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

🥜 nitpick: ‏not sure exactly how this status is planned to be used but from an end-user perspective, looking for events with profiles by searching @profiling_status: stopped seems a bit odd to me.

Copy link
Contributor Author

@thomasbertet thomasbertet Jun 2, 2025

Choose a reason for hiding this comment

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

I don't expect a lot of View or Long Tasks will have this stopped but overall it will be used by us on the UI to be able to let users know why there is no Profiling data.

export type ProfilingStatus =
| 'not-available-in-slim-bundle'
| 'initializing'
| 'missing-profiling-experimental-feature'
Copy link
Collaborator

Choose a reason for hiding this comment

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

💬 suggestion: ‏we'll probably won't provide a version with experimental flag to customers, so not sure if this case need to be handled

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As long as we have an experimental version, I think we should keep it. It will help us identify issues with potential design partners.

Copy link
Collaborator

Choose a reason for hiding this comment

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

afaik, we don't want to communicate experimental flag to external parties.

cleanupTasks.push(stopLongAnimationFrameCollection)
} else {
startLongTaskCollection(lifeCycle, configuration)
startLongTaskCollection(lifeCycle, configuration, profilerApi)
Copy link
Collaborator

Choose a reason for hiding this comment

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

💬 suggestion: ‏instead of passing profilerApi around, it could be interesting to see if you could subscribe to the assemble hook instead.
look at hooks.register(HookNames.Assemble usages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did just that in the last commit. PTAL and let me know if that's what you envisioned.

@thomasbertet thomasbertet force-pushed the thomas.bertet/rum-profiler-add-profiling-status-to-events branch from bec3ff0 to 7944d6f Compare June 3, 2025 11:53
@codecov-commenter
Copy link

codecov-commenter commented Jun 3, 2025

Codecov Report

Attention: Patch coverage is 73.68421% with 5 lines in your changes missing coverage. Please review.

Project coverage is 92.41%. Comparing base (c947b2d) to head (c609a63).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
packages/rum/src/domain/profiling/profiler.ts 28.57% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3583      +/-   ##
==========================================
- Coverage   92.44%   92.41%   -0.04%     
==========================================
  Files         322      323       +1     
  Lines        8129     8147      +18     
  Branches     1838     1839       +1     
==========================================
+ Hits         7515     7529      +14     
- Misses        614      618       +4     

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

@thomasbertet thomasbertet changed the title [RUM Profiler] Add profiling_status to Long Task and View events [RUM Profiler] Add profiling context to Long Task and View events Jun 3, 2025
Copy link

cit-pr-commenter bot commented Jun 3, 2025

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 146.84 KiB 147.37 KiB 544 B +0.36%
Rum Recorder 18.02 KiB 18.02 KiB 0 B 0.00%
Rum Profiler 4.63 KiB 5.06 KiB 441 B +9.30% ⚠️
Logs 51.72 KiB 51.72 KiB 0 B 0.00%
Flagging 0 B 935 B 935 B N/A%
Rum Slim 106.46 KiB 106.63 KiB 179 B +0.16%
Worker 23.59 KiB 23.59 KiB 0 B 0.00%

⚠️ The increase is particularly high and exceeds 5%. Please check the changes.

🚀 CPU Performance
Action Name Base Average Cpu Time (ms) Local Average Cpu Time (ms) 𝚫
addglobalcontext 0.013 0.009 -0.004
addaction 0.041 0.033 -0.008
addtiming 0.010 0.007 -0.002
adderror 0.037 0.035 -0.003
startstopsessionreplayrecording 0.002 0.001 -0.000
startview 0.011 0.007 -0.003
logmessage 0.056 0.035 -0.022
🧠 Memory Performance
Action Name Base Consumption Memory (bytes) Local Consumption Memory (bytes) 𝚫 (bytes)
addglobalcontext 28.96 KiB 25.88 KiB -3162 B
addaction 57.46 KiB 54.05 KiB -3494 B
addtiming 25.91 KiB 26.21 KiB 300 B
adderror 56.69 KiB 60.64 KiB 3.96 KiB
startstopsessionreplayrecording 23.70 KiB 24.71 KiB 1.01 KiB
startview 429.04 KiB 425.41 KiB -3721 B
logmessage 56.65 KiB 58.24 KiB 1.59 KiB

🔗 RealWorld

HookNames.Assemble,
({ eventType }): DefaultRumEventAttributes => ({
type: eventType,
profiling: profilerApi.getProfilingContext(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

My guess is that I should filter on the eventType I'm interested in before actually appending the profiling context. WDYT ? I kinda expected the typechecker to yell at me 🤔

@thomasbertet thomasbertet force-pushed the thomas.bertet/rum-profiler-add-profiling-status-to-events branch from 1ffc8d9 to 6b6bb99 Compare June 11, 2025 13:57
@@ -33,7 +33,8 @@
"test:e2e:ci:bs": "yarn build && yarn build:apps && yarn test:e2e:bs",
"test:compat:tsc": "node scripts/check-typescript-compatibility.js",
"test:compat:ssr": "scripts/cli check_server_side_rendering_compatibility",
"rum-events-format:sync": "scripts/cli update_submodule && scripts/cli build_json2type && node scripts/generate-schema-types.js",
"rum-events-format:sync": "scripts/cli update_submodule && yarn rum-events-format:generate",
"rum-events-format:generate": "scripts/cli build_json2type && node scripts/generate-schema-types.js",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found it useful to generate locally the files I had checked-out in the rum-events-format submodule, mainly to confirm everything works as expected.
It's slightly different from rum-events-format:sync because there is no sync, on the file generation taken from the submodule.

@thomasbertet thomasbertet marked this pull request as ready for review June 13, 2025 11:49
@thomasbertet thomasbertet requested a review from a team as a code owner June 13, 2025 11:49
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