Skip to content

[FFL-2837] Expose precomputed configuration context - #353

Open
btthomas wants to merge 4 commits into
sameerank/FFL-2835/configuration-from-stringfrom
blake.thomas/FFL-2837/precomputed-context
Open

[FFL-2837] Expose precomputed configuration context#353
btthomas wants to merge 4 commits into
sameerank/FFL-2835/configuration-from-stringfrom
blake.thomas/FFL-2837/precomputed-context

Conversation

@btthomas

@btthomas btthomas commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Stack

  1. Parse flags configuration wire format: #344
  2. Expose the precomputed context <- you are here

This PR uses #344 as its base. Merge #344 first. Then retarget this PR to main.

Summary

This PR adds getPrecomputedContext(configuration) to @datadog/flagging-core.

The function returns a detached copy of the context from a valid precomputed configuration. It returns undefined when the configuration does not have a context-specific precomputed branch. The function does not change the configuration, OpenFeature, or provider state.

The function is available from these entry points:

  • @datadog/flagging-core
  • @datadog/flagging-core/configuration
  • @datadog/flagging-core/precomputed
  • @datadog/openfeature-browser
  • @datadog/openfeature-browser/precomputed

The precomputed entry points remain free of Protobuf-ES modules.

Reason

The configuration wire and parsed configuration are opaque contracts. SDK users need a supported way to set the OpenFeature context for a context-specific precomputed configuration.

Without this function, each SDK must inspect internal configuration fields or implement the same accessor. A shared function keeps browser and React Native behavior consistent.

Behavior

  • Preserve an explicit empty context.
  • Preserve an explicit empty targeting key.
  • Deep-copy nested objects, arrays, and dates.
  • Return undefined for empty, rules-only, invalid-precomputed, and context-agnostic configurations.
  • Return the precomputed context from a mixed valid configuration.

Validation

  • 435 flagging-core tests passed.
  • 156 browser tests passed.
  • Flagging-core and browser type checks passed.
  • Flagging-core and browser builds passed.
  • Biome and Prettier checks passed.

Comment thread packages/browser/README.md Outdated
env: 'production',
initialFlagsConfiguration: configuration,
})
await OpenFeature.setProvider(provider)

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.

.setProvider is not awaitable so

Suggested change
await OpenFeature.setProvider(provider)
await OpenFeature.setProviderAndWait(provider)

or if we want to show an atomic registration of the context and initialization

Suggested change
await OpenFeature.setProvider(provider)
if (context !== undefined) {
await OpenFeature.setProviderAndWait(provider, context)
} else {
await OpenFeature.setProviderAndWait(provider)
}

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.

Thank you!
d0d2f51

Comment on lines +107 to +112
const provider = new DatadogProvider({
clientToken: 'pub_...',
site: 'datadoghq.com',
env: 'production',
initialFlagsConfiguration: configuration,
})

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.

I see that applicationId is optional in the public type

But DatadogProvider currently rejects its runtime configuration without it

if (!initConfiguration.applicationId) {
display.error('Application ID is not configured, no flagging data will be collected.')
return
}

Should we include applicationId in this example to match the current runtime behavior?

@btthomas btthomas Aug 7, 2026

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.

Another PR coming soon for the optional/required bit.

Either way, fixed the README here: d0d2f51

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.

@btthomas
btthomas marked this pull request as ready for review August 7, 2026 16:02
@btthomas
btthomas requested a review from a team as a code owner August 7, 2026 16:02
@btthomas
btthomas requested review from pavlokhrebto and vjfridge and removed request for a team August 7, 2026 16:02
@sameerank
sameerank force-pushed the sameerank/FFL-2835/configuration-from-string branch from 82bfc2e to 939da97 Compare August 9, 2026 13:51
@sameerank

sameerank commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

#344 has been rebased onto the latest main and force-pushed at 939da976. Could you rebase blake.thomas/FFL-2837/precomputed-context onto the updated sameerank/FFL-2835/configuration-from-string? (Never mind, I went ahead with the rebase) #346’s documented initialization flow depends on #353.

@leoromanovsky leoromanovsky left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍

@sameerank
sameerank force-pushed the blake.thomas/FFL-2837/precomputed-context branch from 6ca8335 to 74ed072 Compare August 13, 2026 22:51
@sameerank
sameerank force-pushed the sameerank/FFL-2835/configuration-from-string branch from 5a5511e to d91771f Compare August 18, 2026 15:21
@sameerank
sameerank force-pushed the blake.thomas/FFL-2837/precomputed-context branch from 74ed072 to b11ce39 Compare August 18, 2026 15:21
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