[RUM-14619] Add addViewLoadingTime() public API#4180
[RUM-14619] Add addViewLoadingTime() public API#4180MaelNamNam wants to merge 3 commits intomainfrom
Conversation
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
Bundles Sizes Evolution
🚀 CPU PerformancePending... 🧠 Memory PerformancePending... |
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: 7d86ef3 | Docs | Datadog PR Page | Was this helpful? Give us feedback! |
There was a problem hiding this comment.
💡 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".
| no_active_view: isResult && 'no_active_view' in result, | ||
| overwritten: isResult && 'overwritten' in result && result.overwritten !== false, |
There was a problem hiding this comment.
Default telemetry flags to false for buffered calls
When addViewLoadingTime() is called before init, strategy.addLoadingTime(...) returns undefined, so isResult && ... evaluates to undefined for both no_active_view and overwritten. Those fields are then omitted from the telemetry payload instead of being sent as explicit booleans, which contradicts the AddViewLoadingTime usage schema and makes pre-start telemetry inaccurate. Please coerce these expressions to false when no result is available.
Useful? React with 👍 / 👎.
Add a new public API `DD_RUM.addViewLoadingTime(options?)` that allows
developers to manually report when a view has finished loading.
- Computes loading time as elapsed time since view start
- Suppresses auto-detected loading time on first manual call
- First-call-wins by default; `{ overwrite: true }` to replace
- Pre-start buffering with preserved call timestamps
- Telemetry usage tracking
- Gracefully no-ops on ended/expired views
- Unit tests + E2E test
f4e1030 to
169989b
Compare
packages/rum-core/src/domain/view/viewMetrics/trackCommonViewMetrics.ts
Outdated
Show resolved
Hide resolved
packages/rum-core/src/domain/view/viewMetrics/trackCommonViewMetrics.ts
Outdated
Show resolved
Hide resolved
| addTelemetryUsage({ | ||
| feature: 'addViewLoadingTime', | ||
| no_view: false, | ||
| no_active_view: isResult && 'no_active_view' in result, | ||
| overwritten: isResult && 'overwritten' in result && result.overwritten !== false, | ||
| }) |
There was a problem hiding this comment.
❓ question: TelemetryUsage is meant to understand which API the customer are using and with which option when available. I don't think we should return run-time analysis like this.
| addTelemetryUsage({ | |
| feature: 'addViewLoadingTime', | |
| no_view: false, | |
| no_active_view: isResult && 'no_active_view' in result, | |
| overwritten: isResult && 'overwritten' in result && result.overwritten !== false, | |
| }) | |
| addTelemetryUsage({ | |
| feature: 'addViewLoadingTime', | |
| overwrite | |
| }) |
There was a problem hiding this comment.
Good point. I went a different direction though — I aligned the telemetry with the mobile SDK schema instead, which tracks runtime state (no_view, no_active_view, overwritten). This matches what iOS/Android already report for AddViewLoadingTime. See c25c762.
| const result = strategy.addLoadingTime(callTimestamp, options?.overwrite ?? false) | ||
|
|
||
| // For pre-start buffered calls, result is undefined so we emit best-guess default values. | ||
| const isResult = result && typeof result === 'object' |
There was a problem hiding this comment.
💬 suggestion: use Types to prevent runtime assertion
There was a problem hiding this comment.
Kept the runtime assertion — it feeds the no_active_view and overwritten telemetry fields that are now aligned with the mobile SDK schema. See c25c762.
…JSDoc link - Remove '(CONTEXT decision)' comment from trackCommonViewMetrics.ts - Remove 'Phase 2 telemetry' comment from trackCommonViewMetrics.ts - Remove broken JSDoc link to non-existent doc page from rumPublicApi.ts
cc33dd8 to
c25c762
Compare
- Refactor addLoadingTime to return void at newView and trackViews layers - Simplify telemetry to user intent, remove runtime assertion - Add unit and E2E tests for manual loading time coverage - Draft RFC for addViewLoadingTime() public API
46d9511 to
7d86ef3
Compare
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 public API:
DD_RUM.addViewLoadingTime(options?){ overwrite: true }to replaceinit()are drained with preserved timestamps)no_view,no_active_view,overwritten(aligned with mobile schema)Upstream dep: rum-events-format#352 — once merged, the manual type in
telemetryEvent.types.tscan be replaced by the generated one.Test instructions
Checklist