Skip to content

[RUM-14619] Add setViewLoadingTime() public API#4180

Open
MaelNamNam wants to merge 2 commits intomainfrom
mael.lilensten/manually_report_view_loading_time
Open

[RUM-14619] Add setViewLoadingTime() public API#4180
MaelNamNam wants to merge 2 commits intomainfrom
mael.lilensten/manually_report_view_loading_time

Conversation

@MaelNamNam
Copy link

@MaelNamNam MaelNamNam commented Feb 13, 2026

Motivation

Allow developers to manually report view loading time for complex async patterns (SPAs with deferred fetching, skeleton screens) where auto-detection is inaccurate.

Brings Browser SDK to parity with iOS/Android SDKs.

Changes

New experimental public API: DD_RUM.setViewLoadingTime()

  • Marked as [Experimental] via JSDoc annotation (no runtime feature flag required)
  • Loading time = elapsed since current view start
  • First call suppresses auto-detected loading time
  • Last call always wins
  • Pre-start buffering supported (calls before init() are drained with preserved timestamps)
  • Works with startView() / manuallyTrackViews — timer resets for each new view
  • Telemetry sends feature: 'addViewLoadingTime' only (browser omits overwritten, no_view, and no_active_view — kept optional in schema for mobile compat)

Note: The enableExperimentalFeatures: ['set_view_loading_time'] runtime gate has been removed. The API is available without any flag, consistent with other experimental APIs (startAction, stopAction, startResource, stopResource).

Upstream dep: rum-events-format#352 has been merged, submodule updated to 5ddfd3b, types regenerated, and [MANUAL] annotation removed from this PR. AddViewLoadingTime is now auto-generated from the schema.

Test instructions

yarn test:unit --spec packages/rum-core/src/domain/view/trackViews.spec.ts
yarn test:unit --spec packages/rum-core/src/boot/rumPublicApi.spec.ts
yarn test:unit --spec packages/rum-core/src/boot/preStartRum.spec.ts
yarn test:e2e:init && yarn test:e2e -g "manual loading time"

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file

@MaelNamNam MaelNamNam requested a review from a team as a code owner February 13, 2026 10:27
@github-actions
Copy link

github-actions bot commented Feb 13, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@cit-pr-commenter-54b7da
Copy link

cit-pr-commenter-54b7da bot commented Feb 13, 2026

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 174.43 KiB 174.85 KiB +430 B +0.24%
Rum Profiler 6.16 KiB 6.16 KiB 0 B 0.00%
Rum Recorder 25.24 KiB 25.24 KiB 0 B 0.00%
Logs 56.84 KiB 56.84 KiB 0 B 0.00%
Flagging 944 B 944 B 0 B 0.00%
Rum Slim 130.12 KiB 130.50 KiB +399 B +0.30%
Worker 23.63 KiB 23.63 KiB 0 B 0.00%
🚀 CPU Performance
Action Name Base CPU Time (ms) Local CPU Time (ms) 𝚫%
RUM - add global context 0.004 0.0041 +2.50%
RUM - add action 0.0131 0.0133 +1.53%
RUM - add error 0.0134 0.0127 -5.22%
RUM - add timing 0.0032 0.0027 -15.63%
RUM - start view 0.013 0.0132 +1.54%
RUM - start/stop session replay recording 0.0008 0.0006 -25.00%
Logs - log message 0.0185 0.015 -18.92%
🧠 Memory Performance
Action Name Base Memory Consumption Local Memory Consumption 𝚫
RUM - add global context 27.26 KiB 27.00 KiB -266 B
RUM - add action 51.75 KiB 51.78 KiB +35 B
RUM - add timing 26.51 KiB 26.61 KiB +99 B
RUM - add error 55.32 KiB 54.72 KiB -611 B
RUM - start/stop session replay recording 25.65 KiB 26.03 KiB +390 B
RUM - start view 452.33 KiB 463.29 KiB +10.96 KiB
Logs - log message 45.05 KiB 44.75 KiB -308 B

🔗 RealWorld

@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Feb 13, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 85.00%
Overall Coverage: 76.78% (-0.41%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 0188cfa | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback!

@MaelNamNam MaelNamNam changed the title ✨ feat(rum): add addViewLoadingTime() public API Add addViewLoadingTime() public API Feb 13, 2026
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f4e10304d9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@MaelNamNam MaelNamNam force-pushed the mael.lilensten/manually_report_view_loading_time branch from f4e1030 to 169989b Compare February 13, 2026 10:32
@MaelNamNam MaelNamNam marked this pull request as draft February 13, 2026 19:10
@MaelNamNam MaelNamNam force-pushed the mael.lilensten/manually_report_view_loading_time branch from cc33dd8 to c25c762 Compare February 17, 2026 10:40
@MaelNamNam MaelNamNam changed the title Add addViewLoadingTime() public API [RUM-14619] Add addViewLoadingTime() public API Feb 17, 2026
@MaelNamNam MaelNamNam force-pushed the mael.lilensten/manually_report_view_loading_time branch from 46d9511 to 7d86ef3 Compare February 18, 2026 21:17
@MaelNamNam MaelNamNam force-pushed the mael.lilensten/manually_report_view_loading_time branch 2 times, most recently from d7e5d0b to 9b2fd0e Compare March 3, 2026 12:42
@MaelNamNam MaelNamNam self-assigned this Mar 3, 2026
@MaelNamNam MaelNamNam force-pushed the mael.lilensten/manually_report_view_loading_time branch from 9b2fd0e to deca8c8 Compare March 3, 2026 14:47
@MaelNamNam
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

@MaelNamNam MaelNamNam force-pushed the mael.lilensten/manually_report_view_loading_time branch 4 times, most recently from f6cdfbd to 44c3e11 Compare March 3, 2026 22:59
@MaelNamNam MaelNamNam force-pushed the mael.lilensten/manually_report_view_loading_time branch from 712ed76 to 1d44d73 Compare March 5, 2026 22:08
@MaelNamNam MaelNamNam marked this pull request as ready for review March 6, 2026 09:27
Copy link
Contributor

@mormubis mormubis left a comment

Choose a reason for hiding this comment

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

Overall the implementation is clean and well-tested — moving the state into trackCommonViewMetrics was the right call. A few things worth addressing.

@@ -948,21 +950,15 @@ export interface StopResource {
}
export interface AddViewLoadingTime {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you're already hand-editing this block under [MANUAL], worth renaming the interface to SetViewLoadingTime to match the feature string ('set-view-loading-time') and the public API (setViewLoadingTime). AddViewLoadingTime is a leftover from the old name.

Copy link
Author

Choose a reason for hiding this comment

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

Woooooops, sorry, I missed this one. Thanks & renamed in 4bb65b3.

Copy link
Author

@MaelNamNam MaelNamNam Mar 9, 2026

Choose a reason for hiding this comment

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

Actually, I went too fast on this and I'm reverting it (cf 00a28dc): the telemetry event is called add-view-loading-time because it was define as such in the Mobile SDKs. As this setViewLoadingTime is an experimental API, I feel it's best to re-use already existing event names rather than add a new one just for Browser that might eventually get removed.

@MaelNamNam MaelNamNam requested a review from mormubis March 6, 2026 12:25
@MaelNamNam MaelNamNam changed the title [RUM-14619] Add addViewLoadingTime() public API [RUM-14619] Add setViewLoadingTime() public API Mar 9, 2026
@MaelNamNam MaelNamNam requested a review from mormubis March 9, 2026 10:16
@MaelNamNam MaelNamNam requested a review from bcaudan March 9, 2026 14:21
@MaelNamNam MaelNamNam force-pushed the mael.lilensten/manually_report_view_loading_time branch 2 times, most recently from 8c7198d to 320c8ea Compare March 9, 2026 14:50
@MaelNamNam MaelNamNam force-pushed the mael.lilensten/manually_report_view_loading_time branch from 320c8ea to 99b1b18 Compare March 9, 2026 19:48
Copy link
Collaborator

@bcaudan bcaudan left a comment

Choose a reason for hiding this comment

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

Nice work 👍

Copy link
Contributor

@mormubis mormubis left a comment

Choose a reason for hiding this comment

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

setLoadingTime is only ever called from the public API — auto-detection writes directly to commonViewMetrics.loadingTime via its own callback and never touches this function. so by the time hasManualLoadingTime is true, the only way to get here again is the user explicitly calling setViewLoadingTime() a second time. that's already an unambiguous intent to update the value, which makes the overwrite param redundant.

the guard if (hasManualLoadingTime && !overwrite) only makes sense if some internal code path could also call setLoadingTime — but nothing does. the parameter exists because the no-op behavior was pushed down into trackCommonViewMetrics instead of being handled higher up where the intent is clear.

a cleaner design would be to remove overwrite entirely and just always apply the new value — or if first-call-wins is genuinely desired, enforce it at the rumPublicApi level where the user's options are already resolved, rather than leaking it down through the whole call chain as a boolean flag.

@MaelNamNam MaelNamNam requested a review from mormubis March 11, 2026 22:25
@MaelNamNam MaelNamNam force-pushed the mael.lilensten/manually_report_view_loading_time branch from 6142e5b to 0188cfa Compare March 11, 2026 22:40
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