Skip to content

localStorage strategy for remote configuration#4071

Open
mormubis wants to merge 12 commits intomainfrom
adlrb/remote-config-localstorage
Open

localStorage strategy for remote configuration#4071
mormubis wants to merge 12 commits intomainfrom
adlrb/remote-config-localstorage

Conversation

@mormubis
Copy link
Contributor

@mormubis mormubis commented Jan 9, 2026

Motivation

Remote configuration lets customers tweak their Browser SDK settings (sample rates, privacy levels, tracing URLs, user context, etc.) from the Datadog UI without redeploying their app. At init, the SDK fetches a JSON config and applies it on top of the init() options.

Dynamic options can resolve values at runtime from different sources using a strategy-based approach — JavaScript variables (js), cookies (cookie), or DOM elements (dom). But localStorage wasn't supported, even though it's a super common way for apps to store metadata like version strings or user IDs.

image

Changes

Adds localStorage as a new strategy for remote configuration dynamic options.

  • New localStorage strategy in the remote config types and schema
  • resolveLocalStorageValue() with error handling for when localStorage access throws
  • Telemetry metrics for localStorage resolution (success, missing, failure)
  • Supports optional regex extractor (same as other strategies)

Test instructions

No backend ready for it yet.

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.

@cit-pr-commenter
Copy link

cit-pr-commenter bot commented Jan 9, 2026

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 169.43 KiB 169.65 KiB +225 B +0.13%
Rum Profiler 4.29 KiB 4.29 KiB 0 B 0.00%
Rum Recorder 24.54 KiB 24.54 KiB 0 B 0.00%
Logs 56.72 KiB 56.72 KiB 0 B 0.00%
Flagging 944 B 944 B 0 B 0.00%
Rum Slim 126.26 KiB 126.48 KiB +225 B +0.17%
Worker 23.63 KiB 23.63 KiB 0 B 0.00%
🚀 CPU Performance
Action Name Base CPU Time (ms) Local CPU Time (ms) 𝚫%
RUM - add global context 0.0045 0.0054 +20.00%
RUM - add action 0.0142 0.0194 +36.62%
RUM - add error 0.0133 0.024 +80.45%
RUM - add timing 0.0028 0.0044 +57.14%
RUM - start view 0.0134 0.0138 +2.99%
RUM - start/stop session replay recording 0.0007 0.0008 +14.29%
Logs - log message 0.0155 0.0198 +27.74%
🧠 Memory Performance
Action Name Base Memory Consumption Local Memory Consumption 𝚫
RUM - add global context 27.68 KiB 27.10 KiB -593 B
RUM - add action 51.86 KiB 50.52 KiB -1.34 KiB
RUM - add timing 26.47 KiB 27.00 KiB +544 B
RUM - add error 57.53 KiB 54.95 KiB -2.58 KiB
RUM - start/stop session replay recording 25.70 KiB 26.16 KiB +476 B
RUM - start view 453.18 KiB 451.93 KiB -1.26 KiB
Logs - log message 47.21 KiB 46.35 KiB -878 B

🔗 RealWorld

@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Jan 9, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 50.00%
Overall Coverage: 77.25% (-0.02%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 3da50fb | Docs | Datadog PR Page | Was this helpful? Give us feedback!

@mormubis mormubis force-pushed the adlrb/remote-config-localstorage branch from 9e8e512 to 94d9a59 Compare January 30, 2026 09:10
@mormubis
Copy link
Contributor Author

@codex review

@DataDog DataDog deleted a comment from chatgpt-codex-connector bot Jan 30, 2026
Copy link

@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: 94d9a591b0

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

@mormubis mormubis changed the title feat: add localStorage strategy to remote config localStorage strategy for remote configuration Feb 2, 2026
@mormubis mormubis force-pushed the adlrb/remote-config-localstorage branch from c812560 to a8d262d Compare February 4, 2026 10:01
mormubis and others added 11 commits February 12, 2026 16:02
Add 4 new E2E tests for the localStorage strategy:
1. Basic localStorage retrieval - reads simple string values
2. localStorage with regex extractor - parses extracted values
3. Missing key handling - gracefully falls back when key doesn't exist
4. localStorage unavailable - handles access errors and falls back

Tests follow the same pattern as the js strategy tests (PR #3766) and validate:
- Synchronous value resolution during SDK initialization
- Regex extraction functionality
- Fallback behavior for missing or inaccessible keys
- Integration with both CDN and npm setups

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
When a remote configuration value fails to resolve (e.g., localStorage key
is missing or access fails), the system now preserves the initial configuration
fallback value instead of overwriting it with undefined.

This fixes the issue where the SDK would lose the fallback version when:
- localStorage key is not found
- localStorage access throws an error
- Any other dynamic resolution returns undefined

The fix adds an undefined check before assigning resolved values, ensuring
that undefined values do not override the initial configuration.

Fixes E2E tests:
- should resolve to undefined when localStorage key is missing
- should handle localStorage access failure gracefully

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
…ng comment

Restore 'electron' union members removed by the submodule bump (unrelated
to the localStorage feature) and add a comment explaining the undefined
preservation logic in applyRemoteConfiguration.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mormubis mormubis force-pushed the adlrb/remote-config-localstorage branch from 961a387 to d8a54ae Compare February 12, 2026 15:02
@mormubis mormubis marked this pull request as ready for review February 13, 2026 14:45
@mormubis mormubis requested a review from a team as a code owner February 13, 2026 14:45
expect(initConfiguration.version).toBe('fallback-version')
})

createTest('should handle localStorage access failure gracefully')
Copy link
Collaborator

Choose a reason for hiding this comment

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

👏 praise: ‏nice catch 👍

Remove the `if (resolvedValue !== undefined)` guard since no property
currently supports both init config and dynamic config override. Revert
test expectations to `{ version: undefined }`, rename cookie missing
test, and update E2E tests accordingly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Collaborator

@bcaudan bcaudan left a comment

Choose a reason for hiding this comment

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

Nice addition 👍

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.

3 participants