Skip to content

[FFL-3726] feat: Add flagSelection to the Flags configuration - #1560

Draft
mark-caii wants to merge 1 commit into
mark.cai/bump-ios-sdk-3-22from
mark.cai/FFL-3726
Draft

mark-caii wants to merge 1 commit into
mark.cai/bump-ios-sdk-3-22from
mark.cai/FFL-3726

Conversation

@mark-caii

@mark-caii mark-caii commented Nov 16, 2026 •

Copy link
Copy Markdown

What does this PR do?

Summary: Adds a flagSelection option to DdFlags.enable(). With it, the native SDKs request only the flags that match any of the given tags or key patterns. React Native checks the shape of the value and passes it to the native Flags configuration. The native SDKs canonicalize it, enforce the limits, send it in the precompute request, handle the DD-Flag-Selection-Ignored response header, and log and report drops.

Important

Draft until dd-sdk-android 3.17.0 is released. FlagsConfiguration.Builder.flagSelection is on dd-sdk-android develop (dd-sdk-android#4031) but not in 3.16.0, which this branch pins. The Android build fails until the Android pin is bumped to 3.17.0. The bump follows the release, and this PR leaves draft after it.

Stacked on #1559 (iOS SDK 3.22.0), which adds Flags.Configuration.flagSelection. The base branch is #1559's branch, so the diff shows only this change.

Changes:

  • Public API (@datadog/mobile-react-native): an exported FlagSelection type, { tags?: readonly string[]; keyPatterns?: readonly string[] }, and FlagsConfiguration.flagSelection. The name and shape match the FlagSelection that [FFL-3355] feat: add standalone rules configuration fetching #1508 exports from @datadog/mobile-react-native-openfeature/rules-based, so both entry points take the same object.
  • JS validation (DdFlags.enable): only what the bridges can't carry. A selection that is not an object, a list that is not an array, a non-string or null element, a hole, or an unpaired UTF-16 surrogate is malformed. So is a selection whose getters throw.
    • Malformed: DdFlags.enable() logs this error once per call through InternalLog, and sends no selection, so every flag loads:
      flagSelection was not sent (malformed_selection: flagSelection must be an object with optional tags and keyPatterns string arrays). Loading the full flag configuration.
      The text is the browser SDK's, also used by [FFL-3355] feat: add standalone rules configuration fetching #1508.
    • Valid: copies of the lists go to native as given. JS doesn't trim, deduplicate or check limits. A null or absent list is omitted, and a selection with neither list is not sent.
  • iOS bridge: maps the value to Flags.FlagSelection(tags:keyPatterns:).
  • Android bridge: maps the value to FlagsConfiguration.Builder.flagSelection(tags, keyPatterns).
  • Both bridges drop non-string values defensively. JS already rejects them.
  • README: a "Load a subset of flags" section in packages/react-native-openfeature/README.md.

Why JS rejects unpaired surrogates and null elements: iOS's option is typed and has no malformed_selection check, while Android rejects both. Rejecting them before the bridge gives both platforms the same result: an error log and no selection.

Logs: the malformed log above comes from JS and uses flagSelection. The limit and "ignored by the server" logs come from the native SDKs, with their own option names: Flags.Configuration.flagSelection on iOS and flagSelection on Android. All of them are visible only when the core configuration sets verbosity, which also sets the native verbosity.

Motivation

FFL-3726. The browser, iOS (dd-sdk-ios#3344, in 3.22.0) and Android (dd-sdk-android#4031, in 3.17.0) Flags SDKs support flag selection. React Native apps could not set it.

Additional Notes

QA:

  • yarn lint, yarn test, yarn prepare pass.
  • JS unit tests: yarn jest packages/core/src/flags. flagSelection.test.ts covers each malformed shape, lone high and low surrogates, reversed pairs, well-formed pairs, throwing getters and proxies, and copying. DdFlags.test.ts covers pass-through, omitted lists, the exact log text, one log per enable() call, and that no selection is sent when malformed.
  • Android, locally against 3.17.0-SNAPSHOT with a temporary, uncommitted pin and snapshot-repository override: ./gradlew ktlintCheck detekt testDebugUnitTest -PDdSdkReactNative_minSdkVersion=24 passes (210 tests), and compileDebugKotlin and compileReleaseKotlin succeed. The full ./gradlew build stops at verifyReleaseResources on the linux arm64 host used, because AAPT2 ships only as x86_64. New DdFlagsImplementationTest cases compare the built FlagsConfiguration with one made through the public builder: both lists, one list, none, a non-map value, non-string values dropped, and surrogates passed unchanged.
  • iOS: not built locally (no macOS host). CI passes test:native-ios, test:native-ios-newarch and test:native-ios-sr on iOS 3.22.0. New DdFlagsTests cases: dictionary to flagSelection, one list, surrogate pair kept, non-string values dropped, non-dictionary ignored, absent to nil.
  • Manual staging run of example/ on iOS and Android, checking the precompute request body: pending, after the Android bump.

Expo: JS-only option, no native project changes, so expo-datadog needs no change.

Out of scope: the JS rules-based helper (#1508), and the offline provider, which serves a configuration the app supplies and is not filtered.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)
  • If this PR is auto-generated, please make sure also to manually update the code related to the change

@datadog-prod-us1-3

datadog-prod-us1-3 Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Pipelines  Tests

✨ Unblock PR with BitsAI

❌ Errors

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 2 Pipeline jobs failed

DDCI - DataDog/dd-sdk-reactnative | test:native-android — 🔧 Needs a code fix, caused by this PR

View more details · View in DDCI

DataDog/dd-sdk-reactnative | test:native-android — 🔧 Needs a code fix, caused by this PR

View more details · View in GitLab

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: c4075a8 | Docs | View more details | Give us feedback!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant