Skip to content

refactor(logs): Add the @datadog/browser-logs/internal entry - #5371

Draft
mormubis wants to merge 6 commits into
adlrb/RUM-19971-logs-rum-contextsfrom
adlrb/RUM-19971-logs-internal-entry
Draft

mormubis wants to merge 6 commits into
adlrb/RUM-19971-logs-rum-contextsfrom
adlrb/RUM-19971-logs-internal-entry

Conversation

@mormubis

@mormubis mormubis commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Motivation

The Logs plugin from the RFC runs Logs on top of RUM from its own package. It needs the Logs pieces the previous PRs prepared, without importing the main entry, which defines DD_LOGS.

This is the last of 4 stacked PRs. It adds a @datadog/browser-logs/internal entry that exports those pieces. Nothing imports it yet, the plugin package comes next.

Stacked on #5349.

Refs: RUM-19971

Changes

@datadog/browser-logs/internal exports what the plugin wires on top of RUM: the configuration, startLogsEventCollection(), Logs' LifeCycle, createHooks(), startReportError(), the common, session, RUM internal and consent contexts, and Logger with HandlerType and StatusType. Like @datadog/browser-rum/internal, it's not for public use and doesn't follow semver. It doesn't define DD_LOGS.

Its comment lists the contexts a plugin registers and their order, so a log's context precedence matches standalone Logs. The account, user and global context hooks come from @datadog/browser-core (#5349).

LifeCycleEventType becomes a const object with the same values, like NodePrivacyLevel in rum-core, so the entry can export it. It also removes the isolatedModules workaround from #5320.

The entry is published through internal/package.json and files, mapped in tsconfig.base.json, and allowed by the side-effect lint rule.

Bundle size: logs, rum and rum_slim don't change.

Test instructions

The built entry exports the pieces and doesn't define DD_LOGS:

yarn build
node -e "const m = require('./packages/browser-logs/internal'); console.log(Object.keys(m).sort().join(',')); console.log(JSON.stringify(m.LifeCycleEventType)); console.log(typeof globalThis.DD_LOGS)"

Expected output:

HandlerType,LifeCycle,LifeCycleEventType,Logger,StatusType,buildCommonContext,createHooks,startLogsEventCollection,startRUMInternalContext,startReportError,startSessionContext,startTrackingConsentContext,validateAndBuildLogsConfiguration
{"RAW_LOG_COLLECTED":0,"LOG_COLLECTED":1}
undefined

The package publishes it:

yarn workspace @datadog/browser-logs pack --dry-run | grep -E "internal/package.json|entries/internal\."

Expected output:

➤ YN0000: cjs/entries/internal.d.ts
➤ YN0000: cjs/entries/internal.js
➤ YN0000: esm/entries/internal.mjs
➤ YN0000: internal/package.json
➤ YN0000: src/entries/internal.ts

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

The Logs RUM plugin can't import the main entry, which defines DD_LOGS. This entry exports what it needs to run Logs on top of RUM, following @datadog/browser-rum/internal, and stays internal. The built entry loads in Node with the expected exports and leaves DD_LOGS undefined, and the package lists internal/package.json. The enum re-export carries a disallow-enum-exports disable, which the rule's notes allow for internal modules.
… internal entry

The entry's comment named the account and user contexts without saying the entry doesn't export them. It now points at startAccountContextHook and startUserContextHook in @datadog/browser-core. Comment only: Prettier, ESLint and typecheck are clean.
The internal entry exports LifeCycleEventType, and exporting an enum from an entry is a lint error (disallow-enum-exports). A const object, like rum-core's NodePrivacyLevel, keeps the same values and needs no lint exception, and the isolatedModules workaround the const enum needed in the emitted declarations goes. yarn test:compat:tsc passes without it, and the unit suite is unchanged.
…t order

The internal entry's comment listed session, account, user and RUM internal
contexts, but standalone Logs also registers the global context between user
and RUM internal (startLogs.ts). A plugin following the comment would drop
global context or misplace it. The comment now lists all five and names
startGlobalContext with useContextNamespace false.

Comment only. typecheck, lint, test:unit, build, the Node entry check and
test:compat:tsc pass.
… hook

The Logs plugin shares RUM's global context so customers set it once for
both. The comment named startGlobalContext, which creates its own context, so
a plugin following it would not share RUM's. It now names
startGlobalContextHook, called with RUM's getGlobalContext and
useContextNamespace false, keeping the registration order.

Comment only. typecheck, lint, test:unit, build, the Node entry check and
test:compat:tsc pass.
@mormubis
mormubis added this pull request to stack #5324 December 3, 2026 18:40
@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum Salesforce 195.82 KiB 195.82 KiB 0 B 0.00% ✅
Rum 195.80 KiB 195.80 KiB 0 B 0.00% ✅
Rum Salesforce Profiler 7.93 KiB 7.93 KiB 0 B 0.00% ✅
Rum Profiler 7.93 KiB 7.93 KiB 0 B 0.00% ✅
Rum Salesforce Recorder 32.80 KiB 32.80 KiB 0 B 0.00% ✅
Rum Recorder 32.80 KiB 32.80 KiB 0 B 0.00% ✅
Logs 60.46 KiB 60.46 KiB 0 B 0.00% ✅
Rum Slim 151.19 KiB 151.19 KiB 0 B 0.00% ✅
Worker 24.23 KiB 24.23 KiB 0 B 0.00% ✅
Rum Shopify 227.34 KiB 227.34 KiB 0 B 0.00% ✅
Rum Shopify Profiler 7.93 KiB 7.93 KiB 0 B 0.00% ✅
Rum Shopify Recorder 4.85 KiB 4.85 KiB 0 B 0.00% ✅
Early Collection 309 B 309 B 0 B 0.00% ✅

@datadog-prod-us1-5

datadog-prod-us1-5 Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Pipelines  Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 78.09% (-0.00%)

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

…ry comment

A throwaway plugin built from the entry also had to register startTrackingConsentContext and pass a buffered data observable to startLogsEventCollection, which the comment didn't say. Comment only.

This branch has not been deployed

No deployments
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