♻️ Move global monitor functions to js-core - #4986
Conversation
|
✅ All CI checks and tests passed. 🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: a644568 | Docs | View more details | Give us feedback! |
e8af479 to
7c4464d
Compare
Bundles Sizes Evolution
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7c4464de8b
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
e12d967 to
81ad825
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 81ad825fbb
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
81ad825 to
93233fa
Compare
93233fa to
a644568
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a644568205
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| * | ||
| * @returns void; replaces the method's descriptor value in place. | ||
| */ | ||
| export const monitored = globalMonitor.monitored |
There was a problem hiding this comment.
Document the decorator parameters
issue: Add @param documentation for the decorator target, property name, and descriptor. This newly exported stable alias exposes parameters named _ and __, so consumers cannot infer what they represent, while the package’s non-negotiable export-documentation rule requires parameter descriptions when names are not self-explanatory.
AGENTS.md reference: packages/js-core/AGENTS.md:L24-L31
Useful? React with 👍 / 👎.
Motivation
As more utilities move from
browser-coretojs-core(starting withhttpRequest), several shared functions need access to themonitorerror-collection helpers. These are used pervasively as bare globals — passed toaddEventListener,setTimeout, Observable subscriptions, etc. — so they must remain globally available rather than threaded through every call site. Hosting the global monitor injs-corelets shared code there use it directly and unblocks further utility migrations.When several SDKs share the same
js-coremodule 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.Alternative considered
I investigated how we could have one "Monitor" instance per SDK using js-core, and pass it implicitly to asynchronous functions via
monitorwrappers. But I hit a road block, as there is no good way to apply this strategy toasyncfunctions:awaiting a promise creates a new microtask that cannot be wrapped in anyway. As I want to move forward on js-core, I chose the simple way, exposemonitorglobal functions that anyone can use. SDKs can still create their ownmonitorfunctions if they want to.Changes
@datadog/js-core/monitor(monitor,callMonitored,monitored,monitorError) alongside the existingcreateMonitorfactory.startMonitorErrorCollection(cb)(first-wins, returnsfalseif already claimed) andstopMonitorErrorCollection()(production detach path) to manage the error-collection sink.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.monitorDisplayfrom@datadog/js-core/monitorso tests can spy on the monitor's debug output (the global monitor no longer shares a display instance withbrowser-core).startMonitorErrorCollectionJSDoc.Test instructions
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.DD_RUM._setDebug(true)/DD_LOGS._setDebug(true)) and trigger a monitored error; confirm a[MONITOR]error is logged to the console with theDatadog SDK:prefix.Checklist