Skip to content

✨ add generateUUID, jsonStringify, byte constants, timer utils, throttle to @datadog/js-core/util#4843

Draft
thomas-lebeau wants to merge 2 commits into
mainfrom
worktree-js-core-util-todos
Draft

✨ add generateUUID, jsonStringify, byte constants, timer utils, throttle to @datadog/js-core/util#4843
thomas-lebeau wants to merge 2 commits into
mainfrom
worktree-js-core-util-todos

Conversation

@thomas-lebeau

Copy link
Copy Markdown
Collaborator

Motivation

Per the @datadog/js-core RFC, several util sub-path APIs consumed by electron-sdk were still marked as TODO: generateUUID, jsonStringify, ONE_KIBI_BYTE/ONE_MEBI_BYTE, setTimeout (and friends), and throttle.

Changes

  • generateUUID — ported verbatim from browser-core/tools/utils/stringUtils.ts (self-contained, no deps).
  • jsonStringify — ported from browser-core/tools/serialisation/jsonStringify.ts; its noop/detachToJsonMethod helpers are kept private (not part of the public surface, only jsonStringify was requested).
  • ONE_KIBI_BYTE, ONE_MEBI_BYTE — ported verbatim from browser-core/tools/utils/byteUtils.ts (the byte-counting/buffer-concat helpers in that same file were left out — not in scope).
  • setTimeout, clearTimeout, setInterval, clearInterval, TimeoutId — ported from browser-core/tools/timer.ts, including the Zone.js-unwrapping behavior (safe in Node: it only probes for a global Zone object before falling back to a plain property lookup). Deliberately dropped browser-core's implicit monitor() wrapping of the callback: js-core's monitor is a per-consumer factory (createMonitor) rather than a global singleton, so there's no monitor instance to hook into without changing the function signature. Callback errors now propagate like a native timer would — consumers who want error isolation can wrap their callback with their own @datadog/js-core/monitor instance before passing it in.
  • throttle — ported verbatim from browser-core/tools/utils/functionUtils.ts, now built on the local timer.ts.
  • Updated api/util.api.md (API Extractor golden file) accordingly.

Pure additive change (new exports only), no existing behavior changes.

Test instructions

  • yarn workspace @datadog/js-core build && yarn api:check passes.
  • yarn typecheck passes.
  • yarn test:unit --spec 'packages/js-core/src/**/*.spec.ts' passes (81/81), including new specs for generateUUID, jsonStringify, timer, and throttle (using jasmine.clock() instead of browser-core's internal mockClock test helper, which isn't available to js-core).

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

…rottle to @datadog/js-core/util

Ports the remaining TODO items from the js-core RFC's util table:
- generateUUID (electron-sdk: session/view/error/operation/resource event IDs)
- jsonStringify (electron-sdk: formatting non-Error values in error paths)
- ONE_KIBI_BYTE / ONE_MEBI_BYTE (electron-sdk: batch size constants)
- setTimeout/clearTimeout/setInterval/clearInterval + TimeoutId (electron-sdk: batch upload scheduling)
- throttle (electron-sdk: throttled view update emission)

The timer utilities keep browser-core's Zone.js-unwrapping behavior (safe in
Node.js: it only checks for a global `Zone` object before falling back to a
plain property lookup) but drop browser-core's implicit monitor() wrapping,
since js-core's monitor is a per-consumer factory (createMonitor) rather than
a global singleton — callback errors now propagate like a native timer would.
@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Jul 3, 2026

Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 172.76 KiB 173.04 KiB +280 B +0.16%
Rum Profiler 8.22 KiB 8.22 KiB -2 B -0.02%
Rum Recorder 21.14 KiB 21.14 KiB -2 B -0.01%
Logs 55.44 KiB 55.75 KiB +317 B +0.56%
Rum Slim 130.87 KiB 131.18 KiB +311 B +0.23%
Worker 22.96 KiB 22.96 KiB 0 B 0.00%

…Stringify, byte constants, and timer

Deletes the duplicated implementations now that they live in
@datadog/js-core/util, and points every internal consumer plus
browser-core's own public re-export in index.ts at the js-core
version instead.

- generateUUID: removed from tools/utils/stringUtils.ts (other exports
  there are untouched), all 6 internal call sites updated.
- jsonStringify: removed from tools/serialisation/jsonStringify.ts,
  which now only keeps detachToJsonMethod/ObjectWithToJsonMethod (still
  used by sanitize.ts). Its now-redundant spec file is deleted since
  jsonStringify has identical coverage in js-core.
- ONE_KIBI_BYTE/ONE_MEBI_BYTE: removed from tools/utils/byteUtils.ts
  (computeBytesCount/concatBuffers/Uint8ArrayBuffer stay, they're not
  migrated), 6 internal call sites updated.
- timer.ts: rewritten as a thin wrapper. js-core's setTimeout/
  clearTimeout/setInterval/clearInterval already bypass Zone.js
  patching, so the duplicated getZoneJsOriginalValue-based logic is
  gone; browser-core's own monitor() wrapping is kept on top so
  callback errors are still caught and reported exactly as before.
  throttle (functionUtils.ts) needed no changes: it already goes
  through this same timer.ts wrapper.
- Deduplicated two near-identical tests in timer.spec.ts that were
  colliding by name with js-core's own timer.spec.ts.

Downstream packages (browser-rum-core, browser-logs, ...) are
unaffected: they still import these from '@datadog/browser-core',
which now just re-exports the js-core versions under the hood.
@datadog-official

datadog-official Bot commented Jul 8, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 83.93%
Overall Coverage: 77.19% (+0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 071b24a | Docs | Datadog PR Page | 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