Skip to content

feat(openfeature): include RUM user in evaluation context - #1363

Open
btthomas wants to merge 4 commits into
developfrom
blake.thomas/rum-user-evaluation-context
Open

feat(openfeature): include RUM user in evaluation context#1363
btthomas wants to merge 4 commits into
developfrom
blake.thomas/rum-user-evaluation-context

Conversation

@btthomas

@btthomas btthomas commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

Use the current RUM user as default OpenFeature evaluation context for the online Datadog provider, matching the browser SDK behavior from DataDog/openfeature-js-client#354 and the shared client contract being documented in DataDog/documentation#39000.

  • map the RUM user ID to targetingKey
  • map name, email, and flat primitive extraInfo values to evaluation attributes
  • let explicitly supplied OpenFeature fields win, including an explicitly empty targeting key
  • treat explicitly undefined OpenFeature fields as tombstones that suppress the corresponding RUM default and are omitted from the effective context
  • use the same enriched context for assignment fetching and evaluation tracking
  • refresh from the latest RUM user when the OpenFeature context is reconciled
  • keep compatibility with older compatible core package versions
  • honor rumIntegrationEnabled: false

This is implemented entirely in the JavaScript/TypeScript packages; no Android or iOS SDK changes are needed.

Acceptance plan

  • A RUM user supplies a missing OpenFeature targeting key and supported attributes.
  • Explicit OpenFeature values take precedence over RUM values.
  • Explicitly undefined OpenFeature fields remove inherited RUM values before fetching, evaluation, and tracking.
  • An explicitly empty targeting key remains an authoritative value.
  • Nested, array, null, and unsupported RUM attributes are excluded.
  • Disabling RUM integration disables context enrichment.
  • Fetching and evaluation tracking receive the same enriched context.
  • Reconciliation reads the latest RUM user.
  • Offline-provider context semantics remain unchanged.

Validation

  • yarn exec jest --watchman=false --runInBand --projects packages/core packages/react-native-openfeature
    • 56 suites passed, 1 skipped
    • 795 tests passed, 1 skipped
    • 7 snapshots passed
  • TypeScript checks passed for both affected packages.
  • Targeted ESLint and Prettier checks passed.
  • git diff --check passed.

OfflineProvider integration plan

After completing this code pass, I reviewed the in-progress dynamic OfflineProvider stack: #1346, #1347, #1348, plus the context-semantics work in #1359.

Recommended integration with that stack:

  1. Land this PR into develop, then rebase the dynamic-rules stack onto the updated develop.
  2. Keep precomputed snapshot matching against the original explicit context.
  3. Enrich only the context passed to the rules evaluator when evaluation falls through to the dynamic rules branch.
  4. Preserve explicit OpenFeature precedence, undefined tombstones, and the rumIntegrationEnabled opt-out.
  5. Reuse that enriched rules context for native exposure/evaluation tracking.
  6. Add multi-user tests that switch the RUM user between evaluations, plus mixed precomputed/rules tests proving precomputed behavior remains unchanged.
  7. Update the OfflineProvider docs to distinguish dynamic-rule RUM defaults from exact precomputed snapshot context.

This lets the shared RUM-context behavior land first without changing current offline/precomputed semantics. The dynamic OfflineProvider stack can then consume it specifically for server-SDK-style multi-user local rules evaluation.

@btthomas
btthomas marked this pull request as ready for review August 7, 2026 15:32
Copilot AI review requested due to automatic review settings August 7, 2026 15:32
@btthomas
btthomas requested review from a team as code owners August 7, 2026 15:32
@btthomas
btthomas requested review from pavlokhrebto and vjfridge and removed request for a team August 7, 2026 15:32

Copilot AI 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.

Pull request overview

This PR enriches the online Datadog OpenFeature provider’s evaluation context with the current RUM user (id/name/email + flat primitive extraInfo), aligning React Native behavior with the browser SDK and ensuring the same effective context is used for both assignment fetching and evaluation tracking.

Changes:

  • Add a core helper to enrich OpenFeature-shaped contexts with the current RUM user (and expose it for the OpenFeature package while keeping compatibility with older core versions).
  • Update the online OpenFeature provider to apply RUM enrichment during initialize and onContextChange (context reconciliation).
  • Add unit + integration coverage and document RUM-user context behavior and reconciliation guidance.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/react-native-openfeature/src/provider.ts Applies optional core-provided RUM context enrichment before mapping to Datadog evaluation context.
packages/react-native-openfeature/src/tests/provider.test.ts Adds unit tests verifying enrichment is applied on initialize and on context change.
packages/react-native-openfeature/src/tests/provider.integration.test.ts Adds integration tests validating enriched context is used for fetch + tracking and respects rumIntegrationEnabled: false.
packages/react-native-openfeature/src/tests/provider.compatibility.test.ts Ensures behavior is preserved when running against older core versions without the enrichment helper.
packages/react-native-openfeature/README.md Documents how RUM user defaults affect OpenFeature context and how to reconcile after user changes.
packages/core/src/index.tsx Exposes the enrichment helper via an internal __ddEnrichEvaluationContextWithRumUser export.
packages/core/src/flags/types.ts Updates rumIntegrationEnabled documentation to include OpenFeature context enrichment behavior.
packages/core/src/flags/rumIntegration.ts Implements RUM-user-to-context enrichment logic (id → targetingKey; name/email/flat primitive extraInfo → attributes).
packages/core/src/flags/DdFlags.ts Wires rumIntegrationEnabled configuration into the enrichment helper’s runtime behavior.
packages/core/src/flags/tests/rumIntegration.test.ts Adds unit tests for enrichment semantics and opt-out behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +59 to +62
return {
...Object.fromEntries(rumContextEntries),
...context
} as T;
Copilot AI review requested due to automatic review settings August 7, 2026 16:30

Copilot AI 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.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

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