Skip to content

✨ Add remote configuration support for logs fields - #4884

Open
mormubis wants to merge 8 commits into
mainfrom
adlrb/remote-config-logs
Open

✨ Add remote configuration support for logs fields#4884
mormubis wants to merge 8 commits into
mainfrom
adlrb/remote-config-logs

Conversation

@mormubis

@mormubis mormubis commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Motivation

The previous PR (#4877) intentionally excluded logs.* fields from remote configuration because browser-logs is a separate package with no dependency on browser-rum-core, where all the remote config infrastructure lived. This PR solves that.

Changes

To make remote configuration available to browser-logs, the shared infrastructure had to move to browser-core. Three things were extracted:

  • The cache (createConfigurationCache) — made generic <T> so it works for any config shape
  • The generated types (RumSdkConfig / RemoteConfiguration) — previously in browser-rum-core, now generated into browser-core
  • The fetch (fetchRemoteConfiguration, buildEndpoint, getRemoteConfigurationId) — generic, no SDK-specific guards

browser-rum-core re-exports everything from browser-core, so there's no public API breakage.

On the logs side, the implementation follows the same two-function pattern as RUM:

  • getLogsRemoteConfiguration — reads from cache, kicks off a background sync, returns the resolved init config (or undefined if required and cache miss)
  • fetchAndApplyLogsRemoteConfiguration — fetches live and applies the result

preStartLogs uses the same isSyncLoading branching as preStartRum: sync path for remoteConfigurationId, cache path for remoteConfiguration: { id }.

The three logs fields now supported: forwardErrorsToLogs, forwardConsoleLogs, forwardReports.

No double-fetch. When both RUM and Logs are initialized with the same remote config ID, only one HTTP request goes out — even when loaded as separate CDN bundles. fetchRemoteConfiguration deduplicates concurrent calls for the same endpoint using a window-level registry (window.__ddRcInflight), so the promise is shared across bundle boundaries.

Test instructions

  1. Set up a remote configuration with logs.forwardErrorsToLogs: false
  2. Initialize DD_LOGS with remoteConfiguration: { id: '<your-id>' } (cache path — takes effect on the second page load after the background sync populates the cache)
  3. Trigger console.error('test')
  4. Verify no log event is collected

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

return options.remoteConfigurationProxy
}
const id = getRemoteConfigurationId(options)!
return buildEndpointUrl({

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The generic fetch doesn't validate whether the response has a rum or logs section. That's intentional — each SDK wraps it with its own guard. RUM checks rum || profiling before proceeding; Logs just skips applying if logs is absent. What do you think?

@datadog-prod-us1-5

datadog-prod-us1-5 Bot commented Jul 16, 2026

Copy link
Copy Markdown

Pipelines  Tests

Unblock PR with BitsAI

⚠️ Warnings

🚦 1 Pipeline job failed

DataDog/browser-sdk | check-staging-merge   View in Datadog   GitLab

❄️ 4 New flaky tests detected

fetchAndApplyLogsRemoteConfiguration returns the init configuration with overrides applied on success from Chrome 80.0.3987.132 (Windows 10)   View in Datadog
Unexpected console call: error: &#39;Datadog Browser SDK:&#39;, Error: Error fetching the remote configuration.
Error: Error fetching the remote configuration.
    at doFetchRemoteConfiguration (webpack:///packages/browser-core/src/domain/remoteConfiguration/remoteConfigurationFetch.ts:74:32 &lt;- /tmp/_karma_webpack_640448/commons.js:51239:36)

New test introduced in this PR is flaky.

getLogsRemoteConfiguration returns the initConfiguration unchanged on cache miss when not required from Chrome Headless 150.0.0.0 (Linux 0.0.0)   View in Datadog
Unexpected console call: error: &#39;Datadog Browser SDK:&#39;, Error: Error fetching the remote configuration.
Error: Error fetching the remote configuration.
    at doFetchRemoteConfiguration (/tmp/_karma_webpack_479402/commons.js:35444:14)

New test introduced in this PR is flaky.

View in Flaky Test Management

ℹ️ Info

No other issues found (see more)

🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 71.95%
Overall Coverage: 77.15% (-0.06%)

Useful? React with 👍 / 👎

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

@cit-pr-commenter-54b7da

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

Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 179.09 KiB 179.46 KiB +376 B +0.21%
Rum Profiler 8.43 KiB 8.43 KiB 0 B 0.00%
Rum Recorder 21.12 KiB 21.12 KiB 0 B 0.00%
Logs 55.71 KiB 57.87 KiB +2.15 KiB +3.86%
Rum Salesforce N/A 137.43 KiB N/A N/A N/A
Rum Slim 137.06 KiB 137.42 KiB +372 B +0.27%
Worker 22.96 KiB 22.96 KiB 0 B 0.00%
Rum Shopify N/A 199.03 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

@mormubis
mormubis marked this pull request as ready for review July 28, 2026 08:28
@mormubis
mormubis requested a review from a team as a code owner July 28, 2026 08:28
@mormubis
mormubis marked this pull request as draft July 28, 2026 08:28

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

Copy link
Copy Markdown

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: 756c9d22f0

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

Comment thread packages/browser-core/src/domain/remoteConfiguration/remoteConfigurationFetch.ts Outdated
Comment thread packages/browser-logs/src/domain/remoteConfiguration.spec.ts Outdated
Comment thread packages/browser-logs/src/boot/preStartLogs.ts Outdated
Comment thread packages/browser-logs/src/domain/configuration.ts
Comment thread packages/browser-logs/src/domain/remoteConfiguration.ts
@mormubis
mormubis force-pushed the adlrb/remote-config-logs branch from 756c9d2 to 61208b1 Compare July 28, 2026 09:53
@mormubis
mormubis marked this pull request as ready for review July 28, 2026 12:42

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

Copy link
Copy Markdown

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: 62c3b5273e

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

"properties": {
"forwardErrorsToLogs": {
"type": "boolean",
"description": "Whether to forward console.error calls as Datadog log events"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Correct the documented effect of forwardErrorsToLogs

issue: When this schema is used to present or generate Logs remote configuration, it tells operators that this field controls console.error. The runtime contract in packages/browser-logs/src/domain/configuration.ts instead says it controls uncaught exceptions and network errors, while console.error requires forwardConsoleLogs. A configuration created from this description therefore will not collect the advertised console calls and may unintentionally change unrelated error collection.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is just internal types.

const cacheResult = cache.read()

// Background sync — update the cache for the next page load
fetchRemoteConfiguration(initConfiguration)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Exclude background configuration fetches from network logs

issue: On the non-blocking path with forwardErrorsToLogs enabled (the default), this request is issued after startBufferingData() has instrumented fetch and remains observable when startNetworkErrorCollection() starts. The remote-configuration endpoint is not recognized by isIntakeUrl, so a rejected request or 5xx response is emitted as a customer Fetch error log. A remote-configuration outage therefore pollutes the customer's Logs data with an SDK-internal request; this fetch needs to be marked or excluded from network-error collection.

Useful? React with 👍 / 👎.

Comment thread packages/browser-logs/src/domain/remoteConfiguration.ts

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

Copy link
Copy Markdown

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: 913742dbfd

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

Comment thread packages/browser-logs/src/boot/preStartLogs.ts
remoteConfigurationId: getRemoteConfigurationId(initConfiguration)!,
})

const cacheResult = cache.read()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Fall back from the cache path in service workers

issue: When Logs runs in a supported service-worker context with remoteConfiguration: { id }, localStorage is unavailable, so cache.read() always reports an error and the background write is silently ignored. As a result, non-required overrides are never applied on any worker restart, while required: true prevents Logs from starting on every attempt. Use worker-compatible storage or fall back to the live-fetch path when persistent cache storage is unavailable.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we can try to use Cookie Store as a fallback for LS in service-worker or (even worse) Indexed DB

@sbarrio
sbarrio requested a review from bdibon July 29, 2026 07:05

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

Copy link
Copy Markdown

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

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

Comment thread packages/browser-logs/src/domain/remoteConfiguration.ts
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.

2 participants