Skip to content

♻️ Migrate browser-core monitoring/display to @datadog/js-core#4758

Open
thomas-lebeau wants to merge 8 commits into
worktree-migrate-build-to-tsdownfrom
thomas.lebeau/add-browser-core-agents-md
Open

♻️ Migrate browser-core monitoring/display to @datadog/js-core#4758
thomas-lebeau wants to merge 8 commits into
worktree-migrate-build-to-tsdownfrom
thomas.lebeau/add-browser-core-agents-md

Conversation

@thomas-lebeau

Copy link
Copy Markdown
Collaborator

Motivation

Continue extracting runtime-agnostic primitives out of browser-core into the stable @datadog/js-core package. This moves the monitoring and display utilities so they can be shared across Datadog JavaScript SDKs.

Changes

  • Add monitor and util sub-paths to @datadog/js-core, exposing monitor, display, and debug helpers.
  • Migrate browser-core monitoring/display tooling to consume the @datadog/js-core implementations.
  • Add unit tests for the new @datadog/js-core monitor and display utilities.
  • Add AGENTS.md documentation for the browser-core package and update @datadog/js-core docs.

Test instructions

  • yarn test:unit --spec packages/js-core/src/monitor.spec.ts
  • yarn test:unit --spec packages/js-core/src/util/display.spec.ts
  • yarn typecheck

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

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Jun 10, 2026

Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 172.04 KiB 172.42 KiB +386 B +0.22%
Rum Profiler 7.88 KiB 7.88 KiB 0 B 0.00%
Rum Recorder 21.09 KiB 21.09 KiB 0 B 0.00%
Logs 54.21 KiB 54.48 KiB +274 B +0.49%
Rum Slim 129.72 KiB 129.98 KiB +268 B +0.20%
Worker 22.96 KiB 22.96 KiB 0 B 0.00%

@datadog-prod-us1-5

datadog-prod-us1-5 Bot commented Jun 10, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 93.10%
Overall Coverage: 76.82% (+0.01%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 7980483 | Docs | Datadog PR Page | Give us feedback!

@thomas-lebeau thomas-lebeau force-pushed the thomas.lebeau/add-browser-core-agents-md branch 2 times, most recently from ccba31a to af7a15d Compare June 12, 2026 08:26
@thomas-lebeau

Copy link
Copy Markdown
Collaborator Author

/trigger-ci

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Jun 12, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-06-12 08:46:43 UTC ℹ️ Start processing command /trigger-ci


2026-06-12 08:46:58 UTC ℹ️ Branch synced on Gitlab

Branch thomas.lebeau/add-browser-core-agents-md was out-of-sync on Gitlab - it has been resynced


2026-06-12 08:47:01 UTC ℹ️ Gitlab pipeline started

Started pipeline #118369723

@thomas-lebeau thomas-lebeau force-pushed the thomas.lebeau/add-browser-core-agents-md branch 3 times, most recently from 18ce6e4 to 2123255 Compare June 12, 2026 13:56
@thomas-lebeau thomas-lebeau marked this pull request as ready for review June 12, 2026 16:08
@thomas-lebeau thomas-lebeau requested review from a team as code owners June 12, 2026 16:08
@thomas-lebeau thomas-lebeau changed the base branch from main to worktree-migrate-build-to-tsdown June 12, 2026 16:16
Comment on lines +46 to +48
it('catches monitored errors but does not report them (no collection callback yet)', () => {
expect(() => candidate.notMonitoredThrowing()).toThrowError('not monitored')
expect(() => candidate.monitoredThrowing()).toThrowError('monitored')
expect(() => candidate.monitoredThrowing()).not.toThrowError()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this fix an behaviour inconsistency between the @monitor decorator and the monitor() function

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b1cee2adf9

ℹ️ 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".

Comment on lines +12 to +16
"./monitor": {
"import": "./esm/entries/monitor.mjs",
"require": "./cjs/entries/monitor.js",
"types": "./cjs/entries/monitor.d.ts"
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Bump js-core before adding new subpaths

issue: These new public subpaths are being added while @datadog/js-core still declares version 0.0.1, and the browser packages pin that exact version. In any release where 0.0.1 already exists, the publish job can tolerate/skip republishing js-core, but browser-core now imports @datadog/js-core/monitor; consumers would then install the old tarball and hit a module-not-found error. Please bump @datadog/js-core and update the dependent pins when adding these exports.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The release job will also release js-core

@thomas-lebeau thomas-lebeau force-pushed the thomas.lebeau/add-browser-core-agents-md branch from b1cee2a to 05ff0f1 Compare June 15, 2026 12:42
@thomas-lebeau thomas-lebeau requested a review from a team as a code owner June 15, 2026 12:42
@thomas-lebeau thomas-lebeau force-pushed the worktree-migrate-build-to-tsdown branch from 9f852fb to edc5440 Compare June 15, 2026 12:50
Documents that browser-core has no semver stability guarantee and breaking
changes are allowed, so review warnings about removed exports or signature
changes in this package should be disregarded.
- monitor: createMonitor(display, onMonitorErrorCollected) factory exposing
  a documented Monitor interface (monitor, callMonitored, monitored, monitorError)
- util: createDisplay + setDebugMode, with a debug-gated ifDebugEnabled facet
  on Display; util is a folder with a barrel index
- wire up exports, legacy fallbacks, and tsconfig paths for both sub-paths
- monitor.spec.ts: adapts the browser-core monitor spec to the createMonitor
  factory API, injecting a fake Display and a spy error callback
- util/display.spec.ts: covers each console method (always-on + ifDebugEnabled
  gating), asserting the prefixed console call; resets debug mode with afterEach
- make display.ifDebugEnabled delegate to the display's public methods so the
  gating is observable in tests (and respects method overrides)
- export originalConsoleMethods as a test seam (kept out of the util barrel)
- tidy monitor JSDoc to satisfy jsdoc lint rules
- Move debug-mode state out of `display.ts` into a dedicated `debug.ts`
  (`setDebugMode`/`getDebugMode`) and drop the `ifDebugEnabled` facet from
  `Display`
- Export `ConsoleApiName`, `globalConsole`, `originalConsoleMethods` from the
  `@datadog/js-core/util` barrel
- Re-implement browser-core `monitor`/`display` on top of `@datadog/js-core`
  (`createMonitor`, `createDisplay`) and update consumers across browser-core,
  browser-logs, browser-rum-core and browser-debugger to import from js-core
- Whitelist `@datadog/js-core/util` and `/monitor` as side-effect-free
Core monitor behavior (decorator, wrapper, callMonitored, debug logging)
is now tested in @datadog/js-core. This spec is reduced to the two cases
unique to the browser-core wrapper: errors are silently swallowed before
startMonitorErrorCollection, and reported to the callback after.
- Sync workspace dependency version references in yarn.lock
- Matches the version bumps from packages/browser-core and js-core
@thomas-lebeau thomas-lebeau force-pushed the thomas.lebeau/add-browser-core-agents-md branch from 1bef825 to 7980483 Compare June 15, 2026 13:19
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.

2 participants