Skip to content

🐛 [RUM-19516] Collect pending resources in a page exit phase before finalizing events - #5230

Draft
BeltranBulbarellaDD wants to merge 1 commit into
mainfrom
beltran.bulbarella/flush-resources-two-phase-exit
Draft

BeltranBulbarellaDD wants to merge 1 commit into
mainfrom
beltran.bulbarella/flush-resources-two-phase-exit

Conversation

@BeltranBulbarellaDD

@BeltranBulbarellaDD BeltranBulbarellaDD commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Alternative to #5227 for RUM-19516: resource events wait in an idle-callback task queue (up to 1s) and are dropped when the page exits, so resources that finish right before the user leaves are never sent.

#5227 drains the queue on PREPARE_URGENT_FLUSH and relies on resource collection starting before view collection in startRum, so the final view update counts the drained resources. This PR makes that order explicit instead, with two page exit phases.

Changes

  • New COLLECT_PENDING_EVENTS lifecycle event, notified right before PREPARE_URGENT_FLUSH (batch and event bridge paths):
    1. COLLECT_PENDING_EVENTS: collections emit what they are still processing. Resource collection flushes its task queue.
    2. PREPARE_URGENT_FLUSH: collections finalize their events (views, click actions…), which include what phase 1 collected.
  • TaskQueue.flush(): runs pending tasks synchronously, each through callMonitored so a failing task doesn't prevent the batch from being sent.
  • Discard resources with a non-finite duration (when performance is replaced, e.g. Playwright's page.clock.install()).

Same behavior as #5227, without depending on the order collections are started in. COLLECT_PENDING_EVENTS is also where takeRecords() or the replay mutation flush could go later.

Test instructions

yarn test:unit: startRum.spec.ts checks that the view and click action resource.count include the resources collected on unload. See #5227 for the e2e reproduction.

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

🤖 Generated with Claude Code

…inalizing events

refs: RUM-19516

Resource events wait in an idle-callback task queue for up to 1s, and
pending tasks were dropped when the page exited, so resources that
finished right before the exit were never sent.

Split page exit in two lifecycle phases, notified synchronously before the
batch flush: COLLECT_PENDING_EVENTS, where resource collection flushes its
task queue, then PREPARE_URGENT_FLUSH, where views and actions finalize
their events and so count the collected resources. This doesn't depend on
the order collections are started in.

- TaskQueue.flush() runs pending tasks synchronously, each through
  callMonitored so a failing task doesn't prevent the batch from being sent.
- Discard resources with a non-finite duration (ex: when `performance` is
  replaced by Playwright's fake clock).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum Salesforce 191.13 KiB 191.27 KiB +144 B +0.07% ✅
Rum 191.11 KiB 191.25 KiB +144 B +0.07% ✅
Rum Salesforce Profiler 8.35 KiB 8.35 KiB 0 B 0.00% ✅
Rum Profiler 8.35 KiB 8.35 KiB 0 B 0.00% ✅
Rum Salesforce Recorder 32.04 KiB 32.04 KiB 0 B 0.00% ✅
Rum Recorder 32.04 KiB 32.04 KiB 0 B 0.00% ✅
Logs 60.10 KiB 60.10 KiB 0 B 0.00% ✅
Rum Slim 147.27 KiB 147.40 KiB +139 B +0.09% ✅
Worker 24.23 KiB 24.23 KiB 0 B 0.00% ✅
Rum Shopify 221.56 KiB 221.70 KiB +144 B +0.06% ✅
Rum Shopify Profiler 8.35 KiB 8.35 KiB 0 B 0.00% ✅
Rum Shopify Recorder 4.85 KiB 4.85 KiB 0 B 0.00% ✅

@datadog-prod-us1-3

Copy link
Copy Markdown

Pipelines  Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
• Patch Coverage: 91.67%
• Overall Coverage: 77.30% (-0.01%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: c34f13e | Docs | View more details | Give us feedback!

This branch has not been deployed

No deployments
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.

1 participant