[DRAFT] ⚗️ Set view.in_foreground on all non-View RUM events#4266
Open
[DRAFT] ⚗️ Set view.in_foreground on all non-View RUM events#4266
Conversation
Extend view.in_foreground from Action/Error events to also cover Resource, Long Task, and Vital events. This allows teams to filter background vs foreground behavior across all event types. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
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 Performance
🧠 Memory Performance
|
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: 12cd4a9 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
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.
<!-- rfc-publish: richard.klein/view-in-foreground-all-events -->
RFC: Set
view.in_foregroundon All Non-View RUM EventsStatus: Complete
Branch:
richard.klein/view-in-foreground-all-eventsLast updated: 2026-03-03
PR: PR #4266
Summary
This change extends the
view.in_foregroundflag from only Action and Error events to all non-View RUM event types: Resources, Long Tasks, Long Animation Frames, and Vitals. View events already have the more granular_dd.page_states/in_foreground_periodsand are unaffected.The change is minimal — a single condition flip in the Assemble hook, type additions, and schema updates — enabling teams to filter background vs foreground behavior across all event types without any new runtime cost.
Motivation
The
view.in_foregroundboolean was originally added for Action and Error events to support Session Replay use cases. Over time, other teams found it valuable for understanding background behavior — for example, filtering out resources fetched while the tab is hidden (background API polling), ignoring long tasks that fire in inactive tabs, or scoping vital measurements to foreground-only activity.Currently, Resource, Long Task, and Vital events lack this field, forcing consumers to join event data with View
page_statesto determine foreground status — an expensive and error-prone operation at query time. Since thepageStateHistorymodule already tracks page visibility for every event'sstartTime, extending the flag to all non-View events is straightforward.Jira: RUM-10673
Solution
Approach
Rather than adding each new event type to an allowlist (the previous pattern:
eventType === ACTION || eventType === ERROR), the Assemble hook now uses a single negation: if the event is not a View, attachview.in_foreground. The View branch already handles its own_dd.page_statesand returns early, so the else branch naturally covers all current and future non-View event types.Architecture
The
startPageStateHistoryfunction inpackages/rum-core/src/domain/contexts/pageStateHistory.tsregisters an Assemble hook that enriches outgoing RUM events with page-state information. Previously, the hook had three code paths: View events got_dd.page_states, Action/Error events gotview.in_foreground, and all other event types returnedSKIPPED. After this change, the hook has two paths: View events get_dd.page_states, everything else getsview.in_foreground. TheSKIPPEDsentinel is no longer needed and its import has been removed.The
wasInPageStateDuringPeriodfunction — which checks whether the page was inPageState.ACTIVEat the event'sstartTime— is reused as-is. No new runtime logic was added.Schema
The
view.in_foregroundfield added toRawRumResourceEventinpackages/rum-core/src/rawRumEvent.types.ts:The same
view?block was added toRawRumLongTaskEvent,RawRumLongAnimationFrameEvent, andRawRumVitalEventwith the identical shape. This matches the existing pattern onRawRumActionEventandRawRumErrorEvent.The corresponding JSON schema property added to
resource-schema.json,long_task-schema.json, and_vital-common-schema.jsoninrum-events-format:This matches the existing
viewproperty inaction-schema.jsonanderror-schema.json.Testing
Run
yarn test:unit --spec packages/rum-core/src/domain/contexts/pageStateHistory.spec.tsto verify all 19 tests pass. The existing test loop at line 178 was expanded from[RumEventType.ACTION, RumEventType.ERROR]to includeRumEventType.RESOURCE,RumEventType.LONG_TASK, andRumEventType.VITAL, so the samein_foreground: true/in_foreground: falseassertions now cover all affected event types.References