Skip to content

✨ Add browser tab ID to all RUM and Logs events#4184

Draft
mormubis wants to merge 6 commits intomainfrom
adlrb/context-tab-id
Draft

✨ Add browser tab ID to all RUM and Logs events#4184
mormubis wants to merge 6 commits intomainfrom
adlrb/context-tab-id

Conversation

@mormubis
Copy link
Contributor

@mormubis mormubis commented Feb 13, 2026

Motivation

The Browser SDK shares session state across tabs via cookies/localStorage, but has no way to identify which specific tab produced a given event. Adding _dd.browser_tab_id enables distinguishing events from different tabs within the same session.

Changes

  • New tabContext module (packages/core/src/domain/contexts/tabContext.ts): Generates a UUID v4 per browser tab, persisted in sessionStorage so it survives page reloads. Falls back to in-memory UUID when sessionStorage is unavailable (Web Workers, sandboxed iframes).
  • Wired into RUM and Logs: Both SDKs register the tab context via the Assemble hook, so every event includes _dd.browser_tab_id.
  • Unit tests: Covering hook output, ID consistency, sessionStorage persistence/reuse, and error fallbacks (both getItem and setItem failures).

Why _dd?

browser_tab_id lives under _dd (not view) because it has a different lifecycle than a view. A single tab can have many views (SPA navigations), while the tab ID persists across them via sessionStorage. Placing it under view would be misleading since view.id changes per navigation. _dd is the right home as internal SDK metadata, alongside browser_sdk_version and sdk_name.

Behavior

Scenario Behavior
New tab Generates UUID, persists to sessionStorage
Page reload Reuses existing UUID from sessionStorage
Tab duplication Both tabs share the same ID (accepted tradeoff)
sessionStorage unavailable In-memory UUID per page load

Test instructions

yarn test:unit --spec packages/core/src/domain/contexts/tabContext.spec.ts
yarn test:unit  # full suite passes
yarn typecheck
yarn lint

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

@github-actions
Copy link

github-actions bot commented Feb 13, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

mormubis and others added 3 commits February 18, 2026 11:22
Introduce tabContext that generates a UUID v4 per browser tab, persisted
in sessionStorage to survive reloads, with an in-memory fallback when
storage is unavailable.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add _dd.browser_tab_id UUID field to the RUM common schema and the
Logs event types.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Register tabContext in both RUM and Logs event assembly so every
event includes _dd.browser_tab_id.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mormubis mormubis force-pushed the adlrb/context-tab-id branch from 8698d86 to 7aff300 Compare February 18, 2026 10:24
@cit-pr-commenter-54b7da
Copy link

cit-pr-commenter-54b7da bot commented Feb 18, 2026

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 169.44 KiB 169.67 KiB +233 B +0.13%
Rum Profiler 4.29 KiB 4.29 KiB 0 B 0.00%
Rum Recorder 24.61 KiB 24.61 KiB 0 B 0.00%
Logs 56.72 KiB 56.94 KiB +225 B +0.39%
Flagging 944 B 944 B 0 B 0.00%
Rum Slim 126.29 KiB 126.51 KiB +225 B +0.17%
Worker 23.63 KiB 23.63 KiB 0 B 0.00%
🚀 CPU Performance
Action Name Base CPU Time (ms) Local CPU Time (ms) 𝚫%
RUM - add global context 0.0052 0.0039 -25.00%
RUM - add action 0.0186 0.0143 -23.12%
RUM - add error 0.0184 0.0137 -25.54%
RUM - add timing 0.0033 0.0028 -15.15%
RUM - start view 0.0152 0.0134 -11.84%
RUM - start/stop session replay recording 0.001 0.0007 -30.00%
Logs - log message 0.0181 0.0152 -16.02%
🧠 Memory Performance
Action Name Base Memory Consumption Local Memory Consumption 𝚫
RUM - add global context 27.92 KiB 27.48 KiB -455 B
RUM - add action 50.56 KiB 51.90 KiB +1.34 KiB
RUM - add timing 26.35 KiB 27.43 KiB +1.08 KiB
RUM - add error 56.85 KiB 54.98 KiB -1.86 KiB
RUM - start/stop session replay recording 25.61 KiB 26.14 KiB +552 B
RUM - start view 453.91 KiB 460.03 KiB +6.11 KiB
Logs - log message 44.93 KiB 45.95 KiB +1.02 KiB

🔗 RealWorld

@datadog-datadog-prod-us1

This comment has been minimized.

mormubis and others added 3 commits February 18, 2026 12:31
- Make retrieveOrCreateTabId internal (not exported)
- Rewrite tabContext tests to use public startTabContext API
- Add edge case test for sessionStorage.setItem throwing
- Add RUM integration test for browser_tab_id in assembly
- Remove unrelated INP sub_parts from rumEvent.types.ts
- Add TODO comment for browser_tab_id schema sync

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The _dd object already has [k: string]: unknown, so the explicit
field is unnecessary. The proper type definition belongs in the
upstream rum-events-format schema.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Revert submodule and generated type changes that were unrelated to
the tab context feature. The browser_tab_id field flows through
_dd's [k: string]: unknown index signature and does not need
explicit type definitions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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

Comments