Skip to content

✨ add @datadog/js-core/runtime sub-path with defineGlobal#4845

Draft
thomas-lebeau wants to merge 2 commits into
mainfrom
worktree-js-core-runtime-entry
Draft

✨ add @datadog/js-core/runtime sub-path with defineGlobal#4845
thomas-lebeau wants to merge 2 commits into
mainfrom
worktree-js-core-runtime-entry

Conversation

@thomas-lebeau

Copy link
Copy Markdown
Collaborator

Motivation

Per the @datadog/js-core RFC, openfeature-js-client needs defineGlobal (to expose the DD_FLAGGING global), which requires a new @datadog/js-core/runtime sub-path — previously there was no runtime entry at all.

getGlobalObject (the RFC's other runtime TODO) was intentionally not added: @datadog/js-core/util already exposes an equivalent globalObject constant (globalThis, already consumed by browser-core's own timer code), so there's nothing new to build for that need.

Changes

  • New sub-path @datadog/js-core/runtime, exporting defineGlobal, ported from browser-core/boot/init.ts.
  • One deliberate behavior change from the browser-core version: defineGlobal builds its own generic 'Datadog SDK:'-prefixed display via @datadog/js-core/util's createDisplay, instead of reusing browser-core's 'Datadog Browser SDK:'-prefixed singleton — this function is meant for any Datadog SDK (electron-sdk, openfeature-js-client, ...), not just the browser one, so hardcoding "Browser SDK" in the warning message would be misleading for those consumers.
  • Wired up per packages/js-core/AGENTS.md's "adding a new sub-path" checklist:
    • package.json exports field + physical runtime/package.json fallback (legacy resolvers)
    • tsconfig.base.json path mapping
    • typedoc.json entry point
    • api/runtime.api.md API Extractor golden file (auto-generated by yarn api:check --update)

Pure additive change (brand new sub-path), 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 (66/66), including a new runtime.spec.ts mirroring browser-core's defineGlobal test coverage, plus additional coverage for the "SDK loaded more than once" warning path.

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

Introduces a new runtime sub-path per the js-core RFC, containing
defineGlobal, ported from browser-core's boot/init.ts. Used by
openfeature-js-client to expose the DD_FLAGGING global.

getGlobalObject was intentionally left out of this sub-path: js-core's
util entry already exposes an equivalent globalObject constant that
covers the same need, so no new API was added for it.

defineGlobal creates its own generic 'Datadog SDK:' display (via
@datadog/js-core/util's createDisplay) rather than reusing
browser-core's 'Datadog Browser SDK:'-prefixed singleton, since this
function is meant for any Datadog SDK, not just the browser one.

Wires up the new sub-path: package.json exports + physical
runtime/package.json fallback, tsconfig.base.json path mapping, and
typedoc.json entry point, per packages/js-core/AGENTS.md.
Adds an optional 'display' parameter to js-core's defineGlobal
(defaulting to a generic 'Datadog SDK:'-prefixed one), so browser-core
can pass its own 'Datadog Browser SDK:'-prefixed display and preserve
the exact console warning text end users already see. This is an
additive signature change (new optional trailing param), not a
breaking one.

browser-core/boot/init.ts's defineGlobal is now a one-line delegation
to @datadog/js-core/runtime's defineGlobal, passing browser-core's own
display. catchUserErrors is no longer used here (still used elsewhere,
e.g. configuration.ts, so tools/catchUserErrors.ts stays).

Trims init.spec.ts's defineGlobal tests down to the two behaviors that
are actually specific to browser-core's wrapper (delegation works, and
the browser-core display is the one used for warnings) since the
underlying logic now has full coverage in js-core's own
runtime.spec.ts; keeping the exhaustive matrix here would have
duplicated test names across files.

Adds '@datadog/js-core/runtime' to the disallow-side-effects lint
rule's allowlist, alongside the other side-effect-free js-core
sub-paths.

Downstream packages (browser-logs, browser-rum, browser-rum-slim,
browser-debugger) are unaffected: they still import defineGlobal from
'@datadog/browser-core', unchanged.
@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 172.76 KiB 172.77 KiB +6 B +0.00%
Rum Profiler 8.22 KiB 8.22 KiB 0 B 0.00%
Rum Recorder 21.14 KiB 21.14 KiB 0 B 0.00%
Logs 55.44 KiB 55.48 KiB +48 B +0.08%
Rum Slim 130.87 KiB 130.92 KiB +47 B +0.04%
Worker 22.96 KiB 22.96 KiB 0 B 0.00%

@datadog-prod-us1-6

datadog-prod-us1-6 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: 80.00%
Overall Coverage: 77.20% (+0.01%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: bb3c92d | 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