Skip to content

♻️ Move time utilities from browser-core to @datadog/js-core#4748

Open
thomas-lebeau wants to merge 7 commits into
mainfrom
thomas.lebeau/move-time-to-js-core
Open

♻️ Move time utilities from browser-core to @datadog/js-core#4748
thomas-lebeau wants to merge 7 commits into
mainfrom
thomas.lebeau/move-time-to-js-core

Conversation

@thomas-lebeau
Copy link
Copy Markdown
Collaborator

Motivation

The @datadog/js-core package was introduced to provide runtime-agnostic utilities that can be shared across browser and non-browser environments. Time utilities (dateNow, elapsed, relativeNow, ONE_SECOND, ONE_MINUTE, etc.) are pure, environment-agnostic helpers that are a natural fit for this package.

Changes

  • Move all time constants and utilities from packages/browser-core/src/tools/utils/timeUtils.ts to packages/js-core/src/time.ts
  • Update all packages (browser-core, browser-logs, browser-rum-core, browser-rum, browser-rum-react, browser-debugger) to import time utilities from @datadog/js-core instead of @datadog/browser-core
  • Add @datadog/js-core as a dependency to affected packages
  • Update js-core README with time utilities documentation

Test instructions

  • Run yarn typecheck to verify no type errors
  • Run yarn test:unit to verify all unit tests pass

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
Copy link
Copy Markdown

datadog-datadog-prod-us1 Bot commented Jun 8, 2026

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 81.25%
Overall Coverage: 76.77% (+0.00%)

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

@thomas-lebeau thomas-lebeau force-pushed the thomas.lebeau/move-time-to-js-core branch from 71105dc to fb5c874 Compare June 8, 2026 12:26
@cit-pr-commenter-54b7da
Copy link
Copy Markdown

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

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 171.86 KiB 171.79 KiB -65 B -0.04%
Rum Profiler 7.88 KiB 7.88 KiB 0 B 0.00%
Rum Recorder 21.21 KiB 21.21 KiB 0 B 0.00%
Logs 54.31 KiB 54.32 KiB +6 B +0.01%
Rum Slim 129.69 KiB 129.62 KiB -69 B -0.05%
Worker 22.96 KiB 22.96 KiB 0 B 0.00%

Add all time constants and utilities (`dateNow`, `elapsed`, `relativeNow`,
`ONE_SECOND`, `ONE_MINUTE`, etc.) to `packages/js-core/src/time.ts` and
delete the original `packages/browser-core/src/tools/utils/timeUtils.ts`.
Migrate all time-related imports (dateNow, ONE_SECOND, ONE_MINUTE, etc.)
from browser-core's internal timeUtils to the new @datadog/js-core/time
subpath across browser-core, browser-logs, browser-rum-core, browser-rum,
browser-rum-react, and browser-debugger packages.
@thomas-lebeau thomas-lebeau force-pushed the thomas.lebeau/move-time-to-js-core branch from fb5c874 to f0bd4fe Compare June 8, 2026 12:55
…g/js-core

Remove the re-export of @datadog/js-core/time from browser-core's public
index, and update all consuming packages to import time types and utilities
(RelativeTime, TimeStamp, ONE_MINUTE, toTimeStamp, etc.) directly from
@datadog/js-core/time. Also add @datadog/js-core as an explicit dependency
to framework packages (angular, nextjs, nuxt, vue) that now need it.
…gration

- Change `import type` to `import` for values like `Duration`, `relativeNow`, `relativeToClocks`
- Move `clocksNow` import to `@datadog/js-core/time` in plugin scenario
@thomas-lebeau thomas-lebeau marked this pull request as ready for review June 8, 2026 14:22
@thomas-lebeau thomas-lebeau requested review from a team as code owners June 8, 2026 14:22
Copy link
Copy Markdown

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

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: f320c5b6b1

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

export { createIdentityEncoder } from './tools/encoder'
export * from './tools/utils/urlPolyfill'
export * from './tools/utils/timeUtils'
export * from './tools/utils/arrayUtils'
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 Restore the browser-core time exports

issue: Removing the timeUtils barrel export is a backward-incompatible public API change for @datadog/browser-core: customers or plugins importing existing symbols such as Duration, RelativeTime, clocksNow, or ONE_SECOND from @datadog/browser-core will now fail at compile time or module evaluation even though this package is still versioned as a non-major browser SDK release. Please keep a compatibility re-export from @datadog/js-core/time (or otherwise preserve these symbols) while migrating internal imports.

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.

This is fine. consuming @datadog/browser-core outside of the browser sdk repo is not uspported

*/
export function getTimeOrigin(): TimeStamp {
if (timeOrigin === undefined) {
timeOrigin = (performance.timing?.navigationStart ?? performance.timeOrigin) as TimeStamp
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 Keep browser-only timing APIs out of js-core

issue: packages/js-core/AGENTS.md says @datadog/js-core is runtime-agnostic and explicitly forbids DOM APIs such as performance.timing, but this exported helper now reads browser navigation timing directly. This makes the stable @datadog/js-core/time subpath depend on browser-specific globals/semantics for non-browser consumers; keep this origin logic in browser-core or pass in the runtime-specific timing source instead.

Useful? React with 👍 / 👎.

"dependencies": {
"@datadog/browser-core": "7.2.0"
"@datadog/browser-core": "7.2.0",
"@datadog/js-core": "0.0.1"
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 depending on new time exports

issue: The browser packages now import many symbols that were just added to @datadog/js-core/time, but this new exact dependency still points at @datadog/js-core 0.0.1 while packages/js-core/package.json also remains 0.0.1. In published installs, package managers can satisfy this with the existing 0.0.1 package that only provided the old API, causing module evaluation to fail on imports like clocksNow/toServerDuration; publish these exports under a new js-core version and depend on that version.

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 script will take care of this

Comment thread packages/js-core/src/time.ts Outdated
* @returns The elapsed duration in milliseconds.
*/
export function elapsed(start: TimeStamp, end: TimeStamp): Duration
export function elapsed(start: number, end: number): Duration
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

issue:

export function elapsed(start: number, end: number): Duration

should be:

export function elapsed(start: RelativeTime, end: RelativeTime): Duration

Make the overloaded signature of `elapsed` more precise by using the
`RelativeTime` branded type instead of the plain `number` type.
@thomas-lebeau
Copy link
Copy Markdown
Collaborator Author

/to-staging

@gh-worker-devflow-routing-ef8351
Copy link
Copy Markdown

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

View all feedbacks in Devflow UI.

2026-06-08 15:07:45 UTC ℹ️ Start processing command /to-staging


2026-06-08 15:07:52 UTC ℹ️ Branch Integration: starting soon, merge expected in approximately 0s (p90)

Commit 0b205b6a6e will soon be integrated into staging-24.


2026-06-08 15:24:45 UTC ℹ️ Branch Integration: this commit was successfully integrated

Commit 0b205b6a6e has been merged into staging-24 in merge commit ce2ab31899.

If you need to revert this integration, you can use the following command: /code revert-integration -b staging-24

gh-worker-dd-mergequeue-cf854d Bot added a commit that referenced this pull request Jun 8, 2026
Integrated commit sha: 0b205b6

Co-authored-by: thomas-lebeau <thomas.lebeau@datadoghq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants