Skip to content

♻️ Move global monitor functions to js-core - #4986

Draft
BenoitZugmeyer wants to merge 2 commits into
mainfrom
benoit/move-monitor-to-js-core
Draft

♻️ Move global monitor functions to js-core#4986
BenoitZugmeyer wants to merge 2 commits into
mainfrom
benoit/move-monitor-to-js-core

Conversation

@BenoitZugmeyer

Copy link
Copy Markdown
Member

Motivation

As more utilities move from browser-core to js-core (starting with httpRequest), several shared functions need access to the monitor error-collection helpers. These are used pervasively as bare globals — passed to addEventListener, setTimeout, Observable subscriptions, etc. — so they must remain globally available rather than threaded through every call site. Hosting the global monitor in js-core lets shared code there use it directly and unblocks further utility migrations.

When several SDKs share the same js-core module instance, only the first SDK to init receives internal-error telemetry from the global monitor (first-wins). This is a deliberate trade-off for simplicity over per-SDK attribution, which can be revisited in the future.

Changes

  • Expose a global monitor from @datadog/js-core/monitor (monitor, callMonitored, monitored, monitorError) alongside the existing createMonitor factory.
  • Add startMonitorErrorCollection(cb) (first-wins, returns false if already claimed) and stopMonitorErrorCollection() (production detach path) to manage the error-collection sink.
  • Remove the global monitor implementation and its re-export from browser-core; all consumers (browser-core internals, browser-rum-core, browser-rum, browser-logs, and framework integrations) now import monitor helpers directly from @datadog/js-core/monitor.
  • Export monitorDisplay from @datadog/js-core/monitor so tests can spy on the monitor's debug output (the global monitor no longer shares a display instance with browser-core).
  • Document the multi-SDK first-wins limitation in the startMonitorErrorCollection JSDoc.

Test instructions

  • In the sandbox (yarn dev), load the SDK and trigger an internal error (e.g. misconfigure an endpoint so a monitored callback throws). Confirm the error is captured in telemetry and no uncaught exception surfaces to the page.
  • Enable debug mode (DD_RUM._setDebug(true) / DD_LOGS._setDebug(true)) and trigger a monitored error; confirm a [MONITOR] error is logged to the console with the Datadog SDK: prefix.
  • Load both RUM and Logs on the same page; confirm internal errors are attributed to the first SDK that initialised and the second does not hijack the sink.

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

@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Aug 26, 2026

Copy link
Copy Markdown

Tests

All CI checks and tests passed.

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 87.50%
Overall Coverage: 77.13% (+0.16%)

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

@BenoitZugmeyer
BenoitZugmeyer force-pushed the benoit/move-monitor-to-js-core branch from e8af479 to 7c4464d Compare August 26, 2026 09:53
@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 181.52 KiB 181.56 KiB +43 B +0.02%
Rum Profiler 8.43 KiB 8.43 KiB -1 B -0.01%
Rum Recorder 22.31 KiB 22.31 KiB -1 B -0.00%
Logs 57.63 KiB 57.67 KiB +49 B +0.08%
Rum Salesforce N/A 139.65 KiB N/A N/A N/A
Rum Slim 139.59 KiB 139.64 KiB +53 B +0.04%
Worker 22.96 KiB 22.96 KiB 0 B 0.00%
Rum Shopify N/A 202.39 KiB N/A N/A N/A
Rum-shopify Profiler N/A 8.43 KiB N/A N/A N/A
Rum-shopify Recorder N/A 3.72 KiB N/A N/A N/A

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