Skip to content

✨ End WebSocket tracking when the page is discarded - #5097

Open
bdibon wants to merge 4 commits into
boris.dibon/websocket-vitals-5-metrics-beforesendfrom
boris.dibon/websocket-vitals-6-page-discard
Open

bdibon wants to merge 4 commits into
boris.dibon/websocket-vitals-5-metrics-beforesendfrom
boris.dibon/websocket-vitals-6-page-discard

Conversation

@bdibon

@bdibon bdibon commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

A connection still open when the page is unloaded never gets a close event the SDK can observe, so it would end without a closed vital. Tracking now ends explicitly when the page is discarded.

Part of the WebSocket vitals stack. Every PR targets the previous one; the first one targets the boris.dibon/websocket-vitals integration branch, which is merged into main in one go once the whole stack is approved. #5055 stays open as the reference implementation: the tip of this stack is content-identical to it, rebased on the current main.

  1. 🔧 Pin rum-events-format and add WebSocket test utilities #5092 🔧 Pin rum-events-format and add WebSocket test utilities
  2. ✨ Collect connecting, open and closed WebSocket vitals #5093 ✨ Collect connecting, open and closed WebSocket vitals
  3. ✨ Report the websocket_closing vital #5094 ✨ Report the websocket_closing vital
  4. ✨ Pulse open WebSocket vitals on a shared heartbeat #5095 ✨ Pulse open WebSocket vitals on a shared heartbeat
  5. ✨ Report WebSocket silences and send queue depth, and protect WebSocket vitals in beforeSend #5096 ✨ Report WebSocket silences and send queue depth, and protect WebSocket vitals in beforeSend
  6. ✨ End WebSocket tracking when the page is discarded #5097 ✨ End WebSocket tracking when the page is discarded 👈 this PR

Changes

Commit by commit:

  • ✨ Notify a page_discarded exit when the page is unloaded for good: pagehide without persisted (not entering the back/forward cache) notifies PageExitReason.PAGE_DISCARDED, replacing the unused PAGEHIDE reason. The batch flushes on it like on any other exit. Session Replay (mutation flush, segments, replay resources) and click actions ignore it, so their behaviour is unchanged and it never becomes a segment creation reason.
  • ✨ End WebSocket tracking when the page is discarded: every tracked connection, whatever its phase, reports its closed vital with the new page_unloaded tracking end reason, instead of a pulse.
  • ✅ Cover the WebSocket page unload end to end (skipped on Firefox, which closes the socket before pagehide).

After this PR, the stack tip is content-identical to #5055 rebased on main.

Test instructions

  • Unit: yarn test:unit --spec "packages/browser-rum-core/src/domain/webSocket/*.spec.ts" --spec packages/browser-rum-core/src/browser/webSocketObservable.spec.ts --spec packages/browser-core/src/browser/pageMayExitObservable.spec.ts --spec packages/browser-rum-core/src/domain/action/trackClickActions.spec.ts --spec packages/browser-rum/src/boot/datadogRecorder.spec.ts --spec "packages/browser-rum/src/domain/segmentCollection/*.spec.ts" --spec packages/browser-rum-core/src/transport/startRumBatch.spec.ts
  • E2E: yarn test:e2e -g "rum websockets"
  • Identity with ✨ Update WebSocket data model #5055: git diff origin/boris.dibon/websocket-rc1-data-model origin/boris.dibon/websocket-vitals-6-page-discard -- $(git diff --name-only origin/main...origin/boris.dibon/websocket-rc1-data-model) only shows what main changed since ✨ Update WebSocket data model #5055 branched: the v7.15.0 version in package.json, ✨ enable partial view updates by default for all customers #5071 in configuration.ts, and yarn.lock.

Note

check-staging-merge is expected to fail: staging-40 already contains the earlier merge of #5055, which touches the same files. It clears at the next staging bump; the other checks should be green.

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

@bdibon bdibon mentioned this pull request Oct 1, 2026
3 of 5 tasks
@datadog-prod-us1-5

datadog-prod-us1-5 Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Pipelines  Tests

✨ Unblock PR with BitsAI

❌ Errors

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 1 Pipeline job failed

DataDog/browser-sdk | check-staging-merge — 🔧 Needs a code fix, caused by this PR

View more details · View in GitLab

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
• Patch Coverage: 66.67%
• Overall Coverage: 77.34% (-0.04%)

Useful? React with 👍 / 👎

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

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum Salesforce N/A 188.17 KiB N/A N/A N/A
Rum 187.92 KiB 188.15 KiB +232 B +0.12% ✅
Rum-salesforce Profiler N/A 8.35 KiB N/A N/A N/A
Rum Profiler 8.35 KiB 8.35 KiB 0 B 0.00% ✅
Rum-salesforce Recorder N/A 32.01 KiB N/A N/A N/A
Rum Recorder 31.94 KiB 32.01 KiB +69 B +0.21% ✅
Logs 59.00 KiB 59.09 KiB +94 B +0.16% ✅
Rum Slim 145.83 KiB 146.04 KiB +211 B +0.14% ✅
Worker 22.96 KiB 22.96 KiB 0 B 0.00% ✅
Rum Shopify N/A 218.56 KiB N/A N/A N/A
Rum-shopify Profiler N/A 8.35 KiB N/A N/A N/A
Rum-shopify Recorder N/A 4.84 KiB N/A N/A N/A

@bdibon
bdibon force-pushed the boris.dibon/websocket-vitals-6-page-discard branch from 753d90e to 7bcbfc7 Compare October 1, 2026 11:59
@bdibon bdibon changed the title ✨ Flush WebSocket vitals on page discard ✨ End WebSocket tracking when the page is discarded Oct 1, 2026
@bdibon
bdibon added this pull request to stack #5099 October 1, 2026 12:13
@bdibon
bdibon marked this pull request as ready for review October 1, 2026 12:18
@bdibon
bdibon requested review from a team as code owners October 1, 2026 12:18
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-08T08:49:52.521080Z 5a54e9b New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

pagehide without persisted (the page is not entering the back/forward cache) now notifies PageExitReason.PAGE_DISCARDED, replacing the unused PAGEHIDE reason. The batch flushes on it like on any other exit. Session Replay (mutations, segments, replay resources) and click actions ignore it, so it is never a segment creation reason and their behaviour is unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
@bdibon
bdibon force-pushed the boris.dibon/websocket-vitals-6-page-discard branch from 7bcbfc7 to bcc3173 Compare October 8, 2026 08:09
bdibon and others added 3 commits October 8, 2026 10:42
On PAGE_DISCARDED every tracked connection, whatever its phase, reports its closed vital with the new page_unloaded tracking end reason, instead of a pulse: the page is going away, and no close event will follow. The batch then sends them with the rest of the page exit flush.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@bdibon
bdibon force-pushed the boris.dibon/websocket-vitals-6-page-discard branch from bcc3173 to 5a54e9b Compare October 8, 2026 08:45

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