Skip to content

♻️ move pure utilities to @datadog/js-core/util - #4994

Draft
BenoitZugmeyer wants to merge 7 commits into
benoit/move-monitor-to-js-corefrom
benoit/move-pure-utils-to-js-core
Draft

♻️ move pure utilities to @datadog/js-core/util#4994
BenoitZugmeyer wants to merge 7 commits into
benoit/move-monitor-to-js-corefrom
benoit/move-pure-utils-to-js-core

Conversation

@BenoitZugmeyer

Copy link
Copy Markdown
Member

Motivation

The @datadog/js-core package is meant to hold runtime-agnostic SDK utilities shared across all Datadog JS SDKs. Several pure utilities (byteUtils, Context types, mockable, jsonStringify) lived exclusively in @datadog/browser-core, making them unavailable to non-browser consumers such as the Worker or future server-side SDK targets. This PR moves them to @datadog/js-core so they can be shared.

Changes

  • byteUtils (computeBytesCount, concatBuffers, ONE_KIBI_BYTE, ONE_MEBI_BYTE, Uint8ArrayBuffer) moved to @datadog/js-core/util; spec moved alongside.
  • Context types (Context, ContextValue, ContextArray) moved to @datadog/js-core/util.
  • mockable (mockable, mockableReplacements) moved to @datadog/js-core/util.
  • jsonStringify (jsonStringify, detachToJsonMethod, ObjectWithToJsonMethod) moved to @datadog/js-core/util; spec moved alongside. The noop dependency is inlined to avoid pulling browser-specific utilities into js-core.
  • Uint8ArrayBuffer simplified from a custom interface to Uint8Array<ArrayBuffer>.
  • All consumers (browser-core internals, browser-logs, browser-rum, browser-rum-core, browser-rum-slim, browser-worker, browser-debugger, developer-extension, e2e tests) now import directly from @datadog/js-core/util instead of going through browser-core re-exports.
  • @datadog/js-core added as a dependency of @datadog/browser-worker.

Test instructions

This is a pure refactor with no observable behaviour change. All existing unit tests cover the moved code. To sanity-check the SDK still initialises and sends data correctly:

  1. Run yarn dev and open http://localhost:8080.
  2. Check the Network tab — RUM and Logs requests should still be sent to the intake endpoints on the configured interval.
  3. Navigate away from the page and confirm a flush request is sent on beforeunload/visibilitychange.

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 27, 2026

Copy link
Copy Markdown

Pipelines  Tests

⚠️ Warnings

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 1 Pipeline job failed

DataDog/browser-sdk | check-staging-merge

View more details · View in GitLab

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 77.13% (+0.00%)

Useful? React with 👍 / 👎

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

@BenoitZugmeyer
BenoitZugmeyer force-pushed the benoit/move-pure-utils-to-js-core branch from 8244c7f to 11970f7 Compare August 27, 2026 15:45
@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 27, 2026

Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 181.56 KiB 181.56 KiB -3 B -0.00%
Rum Profiler 8.43 KiB 8.43 KiB 0 B 0.00%
Rum Recorder 22.31 KiB 22.31 KiB 0 B 0.00%
Logs 57.67 KiB 57.68 KiB +16 B +0.03%
Rum Salesforce N/A 139.65 KiB N/A N/A N/A
Rum Slim 139.63 KiB 139.65 KiB +15 B +0.01%
Worker 22.96 KiB 22.96 KiB 0 B 0.00%
Rum Shopify N/A 202.38 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

@BenoitZugmeyer
BenoitZugmeyer force-pushed the benoit/move-pure-utils-to-js-core branch 4 times, most recently from 66c96ed to 40b080d Compare August 28, 2026 09:03
Move `computeBytesCount`, `concatBuffers`, `ONE_KIBI_BYTE`, `ONE_MEBI_BYTE`,
and the `Uint8ArrayBuffer` type from `browser-core/src/tools/utils/byteUtils`
to `js-core/src/util/byteUtils`. The spec file moves alongside.

All consumers (browser-core internals, browser-rum, browser-rum-core,
browser-worker) now import directly from `@datadog/js-core/util` instead of
going through browser-core re-exports.
Move `Context`, `ContextValue`, and `ContextArray` type definitions from
`browser-core/src/tools/serialisation/context` to
`js-core/src/util/context`.

All consumers (browser-core internals, browser-logs, browser-rum,
browser-rum-core, browser-rum-slim, developer-extension, e2e tests) now
import directly from `@datadog/js-core/util`.
Move `mockable` and `mockableReplacements` from
`browser-core/src/tools/mockable` to `js-core/src/util/mockable`.

All consumers (browser-core internals, browser-logs, browser-rum,
browser-rum-core, browser-debugger, developer-extension) now import
directly from `@datadog/js-core/util`.
Move `jsonStringify`, `detachToJsonMethod`, and the `ObjectWithToJsonMethod`
type from `browser-core/src/tools/serialisation/jsonStringify` to
`js-core/src/util/jsonStringify`. The spec file moves alongside.

The `noop` dependency (previously imported from browser-core's
`functionUtils`) is inlined as a private function to avoid pulling
browser-specific utilities into js-core.

All consumers (browser-core internals, browser-rum-core) now import
directly from `@datadog/js-core/util`.
Add TSDoc comments to the utilities moved from browser-core to js-core
(byteUtils, Context types, mockable, jsonStringify, detachToJsonMethod,
ObjectWithToJsonMethod) so they appear as documented exports in the
API Extractor report instead of `(undocumented)`.
@BenoitZugmeyer
BenoitZugmeyer force-pushed the benoit/move-pure-utils-to-js-core branch from 40b080d to 060a320 Compare August 31, 2026 08:20
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