feat(rum): add trackWebVitals config to opt out of initial view metrics#15
Merged
Conversation
Initial view metrics (FCP/LCP/FID/loading time) are anchored to the page navigation start (`clocksOrigin()`) and only collected on the INITIAL_LOAD view. For pages that load in the background or are pre-warmed and kept hidden (e.g. a hidden Electron BrowserWindow that only renders content much later via IPC), LCP ends up measured from the original navigation and is reported as an abnormally large value. The existing safeguards (`firstHidden`, the 10-minute cap) don't help because such hidden windows don't reliably report `document.visibilityState === 'hidden'`. Add a `trackWebVitals` init option (default `true`). When set to `false`, `trackInitialViewMetrics` is not started, so no FCP/LCP/FID/loading-time is collected for that SDK instance — the field is simply absent rather than a misleading value. Like `profilingSampleRate` and `propagateTraceBaggage`, this fork-specific option is not part of the upstream telemetry schema, so it is intentionally excluded from `serializeRumConfiguration` (the generated telemetry types must not be hand-edited). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
A customer integrates the browser SDK into a pre-warmed, hidden Electron
BrowserWindow: the window is created withshow: false, RUM is initialized immediately, and the actual image content is rendered much later (via IPC) when a preview is needed. RUM then reports an abnormally large LCP.Root cause
Initial view metrics (FCP / LCP / FID / loading time) are:
clocksOrigin()intrackViews.ts), not to wheninit()/startView()is called, andINITIAL_LOADview.So when content paints long after navigation, LCP =
paint - navigationStart, i.e. huge. The existing safeguards don't catch it:trackFirstHiddendiscards LCP after the page first becomes hidden — but a hidden Electron window does not reliably reportdocument.visibilityState === 'hidden', so the safeguard never triggers.LCP_MAXIMUM_DELAYcap only filters truly extreme values.Deferring
init()/ usingtrackViewsManually+ manualstartView()does not fix it either, because none of those re-baselinetimeOrigin— only a real navigation does.Change
Add a
trackWebVitalsinit option (defaulttrue). Whenfalse,trackInitialViewMetricsis not started for that SDK instance, so FCP/LCP/FID/loading-time are simply absent for that page rather than reported as a misleading value. This fits the "separate window has its owninit" case cleanly — the preview window opts out, the main app is unaffected.Notes
profilingSampleRateandpropagateTraceBaggage, this fork-specific option is not part of the upstream telemetry schema, so it is intentionally excluded fromserializeRumConfiguration(telemetryEvent.types.tsis generated — "DO NOT MODIFY BY HAND"). The exhaustiveserializeRumConfigurationtest is updated accordingly.beforeSend(the metric value is deliberately not in the modifiable whitelist).Tests
configuration.spec.ts:trackWebVitalsdefaults totrue, honors provided value, casts to boolean.trackViews.spec.ts: initial view metrics are not collected whentrackWebVitals: false.🤖 Generated with Claude Code