✨ Add @datadog/browser-remote-config standalone package and @datadog/browser-sdk-endpoint bundle generator#4331
Draft
mormubis wants to merge 11 commits intoadlrb/ssi-remote-configfrom
Draft
✨ Add @datadog/browser-remote-config standalone package and @datadog/browser-sdk-endpoint bundle generator#4331mormubis wants to merge 11 commits intoadlrb/ssi-remote-configfrom
mormubis wants to merge 11 commits intoadlrb/ssi-remote-configfrom
Conversation
Bundles Sizes Evolution
🚀 CPU Performance
🧠 Memory Performance
|
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: ecaf9de | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
c8d543d to
bf0351d
Compare
d7b8712 to
9de7558
Compare
bf0351d to
9b45817
Compare
9cdef32 to
1c044a4
Compare
5ec768c to
ecaf9de
Compare
62b7c0b to
adbf904
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Right now the only way to use remote configuration with the RUM SDK is to pass `remoteConfigurationId` to `DD_RUM.init()`, which triggers a fetch to the RC endpoint at page load. This PR is the foundation for SSI (Server-Side Injection): pre-fetch the RC on the server, generate a self-contained bundle with the SDK and config embedded, serve it as a single `<script>` tag. No RC fetch at page load, no `init()` call needed in app code.
Changes
Two packages:
`@datadog/browser-remote-config` extracts the RC logic into a standalone package. The main addition is a `contextItemHandler` strategy on `resolveDynamicValues` that controls how `ContextItem[]` arrays (the `user` and `context` fields in the RC schema) get resolved. The browser entry point uses getter properties that evaluate against live browser APIs at read time. The Node entry point serializes them as inline JS expressions instead (`__dd_getJs('window.user')`) for embedding in generated bundles.
`@datadog/browser-sdk-endpoint` is a Node.js package that fetches the RC config, runs the code-gen path to turn `DynamicOption` descriptors into inline expressions, downloads the SDK from CDN, and assembles a self-contained IIFE. The `generateBundle` API is designed to sit behind an Express endpoint with per-config caching.
The `contextItemHandler` strategy is the architectural backbone. The browser handler returns a plain object via getters. The Node handler returns a `CodeExpression` (a branded marker type) that tells `serializeConfigToJs` to inline the string as raw JS rather than JSON-encode it. That distinction is what lets the same config tree produce either a live-resolved object in the browser or a JS object literal with embedded expressions in a bundle.
One non-obvious thing worth calling out: `nodeContextItemHandler` receives a `resolve` callback from `resolveDynamicValues`, but calling `resolve(dynamicOption)` in Node context would try to run the live browser resolvers (`window.*`, `getCookie`) and crash. The handler ignores `_resolve` entirely and calls `serializeDynamicValueToJs` directly. Safe because `ContextItem.value` is always a `DynamicOption`.
Test instructions
Checklist