Skip to content

✨ Add monitorPromise and migrate .catch(monitorError) call sites - #4976

Draft
BenoitZugmeyer wants to merge 1 commit into
mainfrom
benoit/monitor-promise
Draft

✨ Add monitorPromise and migrate .catch(monitorError) call sites#4976
BenoitZugmeyer wants to merge 1 commit into
mainfrom
benoit/monitor-promise

Conversation

@BenoitZugmeyer

Copy link
Copy Markdown
Member

Motivation

Promise rejections from SDK-internal async work (session persistence, fetch pipelines, remote configuration, profiling) are currently routed to telemetry via .catch(monitorError). This pattern has two gaps that block the upcoming monitor-context-propagation rework:

  • It can't capture the SDK context at call time, so once the context mechanism lands, rejections firing asynchronously would have no active context and wouldn't route to the originating SDK's telemetry.
  • Sites that wrap the error in a descriptive new Error(...) require a custom .catch handler, fragmenting the pattern.

Changes

  • Add monitorPromise to the Monitor interface in @datadog/js-core/monitor: reports a rejection to telemetry and swallows it (resolves to undefined), mirroring callMonitored's on-throw return. An optional mapError argument transforms the rejection before reporting, replacing the custom .catch handlers that wrapped errors in descriptive messages.
  • Migrate all 19 .catch(monitorError) call sites across browser-core, browser-rum-core, browser-rum, and browser-logs to monitorPromise(...), including the two wrapped-error sites.
  • Allow monitorPromise as a known-safe floating call in the @typescript-eslint/no-floating-promises lint rule, so terminal call sites read naturally without a void prefix.
  • Re-export monitorPromise through @datadog/browser-core.

This is an additive, behavior-preserving change: today monitorPromise is just promise.catch(monitorError). It lays the groundwork so the later context-aware version can capture the active SDK context at call time without touching call sites again.

Test instructions

  • Run the sandbox (yarn dev) and trigger an async code path that rejects (e.g. block the intake endpoint so a fetch rejects, or force a session-store write failure). Confirm the rejection is still reported to telemetry and does not surface as an unhandled rejection in the console.
  • With debug mode enabled (debug: true in the init config), confirm rejected-promise errors still log [MONITOR] ... to the console.

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

Introduce a promise-rejection counterpart to monitor/callMonitored.
monitorPromise reports a rejection to telemetry and swallows it
(resolves to undefined), mirroring how callMonitored returns
undefined on throw. An optional mapError argument transforms the
rejection before reporting, covering sites that wrap the error in a
descriptive new Error(...).

This is an additive, behavior-preserving change: today monitorPromise
is just promise.catch(monitorError). It lays the groundwork for the
monitor context propagation rework, where a later context-aware
version of monitorPromise will capture the active SDK context at call
time so async rejections route to the originating SDK's telemetry.

Migrate all 19 .catch(monitorError) sites across the SDKs to
monitorPromise, including the two that wrapped the error via a custom
.catch handler. Allow monitorPromise as a known-safe floating call in
no-floating-promises so terminal call sites read naturally without a
void prefix.
@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 181.52 KiB 181.54 KiB +24 B +0.01%
Rum Profiler 8.43 KiB 8.43 KiB -6 B -0.07%
Rum Recorder 22.31 KiB 22.31 KiB 0 B 0.00%
Logs 57.63 KiB 57.63 KiB -1 B -0.00%
Rum Salesforce N/A 139.59 KiB N/A N/A N/A
Rum Slim 139.59 KiB 139.59 KiB -2 B -0.00%
Worker 22.96 KiB 22.96 KiB 0 B 0.00%
Rum Shopify N/A 202.37 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

@datadog-official

datadog-official Bot commented Aug 24, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 91.18%
Overall Coverage: 77.12% (-0.01%)

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

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