Skip to content

feat(openfeature): add explicit RUM context enrichment - #1363

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

feat(openfeature): add explicit RUM context enrichment#1363
btthomas wants to merge 5 commits into
developfrom
blake.thomas/rum-user-evaluation-context

Conversation

@btthomas

@btthomas btthomas commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add an explicit enrichRumContext(applicationContext) helper for applications that want to use the current RUM user in their OpenFeature evaluation context.

const applicationContext = { region: 'us-east-1' };

await DdSdkReactNative.setUserInfo(user);
await OpenFeature.setContext(enrichRumContext(applicationContext));
  • map the RUM user ID to targetingKey
  • map name, email, and flat primitive extraInfo values to evaluation attributes
  • let application-supplied values win, including an explicitly empty targeting key
  • treat explicitly undefined application fields as tombstones that remove corresponding RUM values
  • read the current RUM user each time the helper is called without mutating the application context
  • keep the enriched context visible to OpenFeature hooks and other providers
  • keep rumIntegrationEnabled scoped to RUM evaluation tracking; it does not control the helper
  • keep both online and offline providers free of implicit RUM enrichment

The helper is point-in-time rather than a live binding. After login, logout, or an account switch, applications update the RUM user and call OpenFeature.setContext(enrichRumContext(applicationContext)) again. They should retain the original application-owned context instead of enriching OpenFeature.getContext(), which may contain values inherited from the previous RUM user.

This is implemented entirely in JavaScript/TypeScript; no Android or iOS SDK changes are needed. The provider remains usable with older compatible core package versions. Calling the new helper with an older core version produces a clear package-version error.

Acceptance plan

  • Providers do not add RUM data unless the application calls enrichRumContext().
  • The helper supplies the RUM user ID and supported flat user attributes.
  • Application values take precedence over RUM values.
  • Explicitly undefined application fields remove inherited RUM values.
  • An explicitly empty targeting key remains authoritative.
  • Nested, array, null, and unsupported RUM attributes are excluded.
  • Each helper call reads the latest RUM user and does not mutate application context.
  • The resulting context is visible through OpenFeature and is used consistently for fetching and evaluation tracking.
  • Context enrichment remains available when RUM evaluation tracking is disabled.
  • Older core versions still support normal provider use and fail clearly only when the new helper is called.
  • Existing offline-provider context semantics remain unchanged.

Validation

  • yarn exec jest --watchman=false --runInBand --projects packages/core packages/react-native-openfeature
    • 57 suites passed, 1 skipped
    • 798 tests passed, 1 skipped
    • 7 snapshots passed
  • yarn bob build passed for both affected packages, including TypeScript declaration generation.
  • Targeted ESLint checks passed.
  • git diff --check passed.

@btthomas
btthomas marked this pull request as ready for review August 7, 2026 15:32
Copilot AI lite 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.

Copilot AI review requested due to automatic review settings August 11, 2026 20:51
@btthomas
btthomas force-pushed the blake.thomas/rum-user-evaluation-context branch from b46ce00 to b3e773f Compare August 11, 2026 20:51
@btthomas btthomas changed the title feat(openfeature): include RUM user in evaluation context feat(openfeature): add explicit RUM context enrichment Aug 11, 2026

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 9 out of 9 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