← Back to Pull requests

feat(openfeature): add flag_selection provider option #6652

Closed
unknown closed this pull request without merging on Nov 16, 2026 19:55 UTC
View on GitHub
unknown unknown commented on Nov 06, 2026 16:15 UTC
Author

Why

Services that use only some of their feature flags still download and hold the full flag configuration. The browser, iOS, and Android SDKs already let an application request a subset.

What

Datadog::OpenFeature::Provider.new(flag_selection: {tags:, key_patterns:}) sends a canonical selection on the agentless rules request, so the backend returns only matching flags. Invalid, oversized, or server-ignored selections load every flag and are logged and counted; without the option, the request is unchanged.

Risk

Two-way door, scoped to agentless Feature Flags delivery for providers that set the new option. Revert the PR to remove it.

Details

<details><summary>Notes</summary>

  • Option: Symbol or String keys, unknown keys ignored, never raises. Canonicalization trims Unicode White_Space, drops empty values, dedupes, and sorts by UTF-8 bytes. A non-Hash option, a non-Array list, a non-String element, invalid UTF-8, or an option with both the Symbol and the String key for the same list (for example tags: and "tags") is malformed_selection.

  • Request: repeated selected_flag_tags and selected_flag_key_patterns parameters, tags first, RFC 3986 percent-encoded with uppercase hex, appended to the existing query (managed dd_env or a custom base URL's). The whole request URL must be at most 8192 bytes, otherwise the selection is not sent (too_many_values).

  • A custom base URL whose query has an invalid percent escape (for example ?token=abc%) no longer raises: the selection is not sent, and the drop is logged and counted as too_many_values with the URL limit text. This is a known limitation for that edge case.

  • Sharing: every provider in a process shares one agentless source, so the first provider to start it claims the selection (a provider without one claims all flags). A later provider with a different selection uses the claimed one; it logs and counts its own drop if its selection is malformed or over a limit, and logs the "differs" warning once per process only when it would load different flags (a dropped selection and no selection both load every flag). The next start after delivery stops claims again.

  • Logs, through the Datadog logger: flag_selection was not sent (<reason>: <limit>). Loading the full flag configuration. once per provider init, and flag_selection was ignored by the server (<reason>). Loaded the full flag configuration. once per process per reason, after the configuration is applied. The malformed_selection limit text is flag_selection must be a Hash with optional tags and key_patterns string arrays.

  • DD-Flag-Selection-Ignored is read only on a 200 to a request that carried a selection; anything other than a byte-exact known reason of at most 32 bytes is unknown.

  • Telemetry: flag_selection.dropped and flag_selection.ignored counts in the tracers namespace, tagged with reason, once per process per reason.

  • Remote Config delivery logs one warning per process when a provider sets a selection, and loads every flag.

  • Once-per-process guards reset in a forked child, and a child that inherits a dropped selection counts flag_selection.dropped for its own process.

  • Shared vectors: flag-selection/selection-vectors.json from DataDog/ffe-system-test-data at the repo's fixture pin (1ae3eda). The 38 sdk cases run; the 6 rawQuery cases test server-side percent-decoding and have no SDK expectation. The fixture download keeps flag-selection/ and caches under tmp/ffe-system-test-data/v2, so a cache written without that directory is not reused.

  • Known limitation: a custom proxy that rejects the longer request URL (for example with HTTP 414 below 8192 bytes) fails delivery with the generic HTTP warning; the SDK does not retry without the selection.

  • Related: DataDog/ffe-system-test-data#63 and DataDog/system-tests#8304 (mock backend and evaluation suite).
  • </details>

    Validation:

    The system-tests and CI results are at the current head, 5cf49939269b4283fb3c7bffb3a8cf7a26adf207. The local spec and type-check runs are at 26dc8446e4956cf4bccb8507be06d18adad7f3a0, in the CI images (ghcr.io/datadog/images-rb/engines/ruby:3.1-gnu-gcc and ruby:4.0-gnu-gcc); the head differs from 26dc844 only in lib/datadog/open_feature/activation.rb, lib/datadog/open_feature/configuration/flag_selection.rb, spec/datadog/open_feature/activation_spec.rb, spec/datadog/open_feature/flag_selection_reporter_spec.rb, and docs/GettingStarted.md.

  • System-tests flag-selection suite (local, forced), at 5cf49939269b4283fb3c7bffb3a8cf7a26adf207:

  • - Suite: tests/parametric/test_ffe/test_flag_selection.py from DataDog/system-tests at 24a28b649fb74c109ee0401f5051ef89c8009ff9 (main; the file is unchanged since DataDog/system-tests#8304 merged).
    - Library: loaded through binaries/ruby-load-from-bundle-add containing gem 'datadog', git: 'https://github.com/DataDog/dd-trace-rb', ref: '5cf49939269b4283fb3c7bffb3a8cf7a26adf207', require: 'datadog/auto_instrument'. The built image's Gemfile.lock has revision: 5cf49939269b4283fb3c7bffb3a8cf7a26adf207, bundler reported Using datadog 2.49.0.dev from https://github.com/DataDog/dd-trace-rb (at 5cf4993@5cf4993), and the run reported the library as ruby@2.49.0-dev.
    - Parametric-app wiring, the Ruby part of DataDog/system-tests#8474 applied locally: server.rb parses the /ffe/start body, renames keyPatterns to key_patterns, and passes flag_selection: to Datadog::OpenFeature::Provider.new only when the field is present.
    - Build: docker build --progress=plain -t ruby-test-client -f utils/build/docker/ruby/parametric/Dockerfile ., the same command run.sh runs. It is a separate step here because the image is linux/amd64 and, built under emulation on an arm64 host, it takes longer than run.sh's 10-minute build timeout.
    - Run: TEST_LIBRARY=ruby ./run.sh PARAMETRIC --skip-parametric-build -F tests/parametric/test_ffe/test_flag_selection.py tests/parametric/test_ffe/test_flag_selection.py.
    - Result: 12 passed, 0 failed, 0 skipped. That is the 11 case files of the flag-selection evaluation suite (tags, key-patterns, tags-or-key-patterns, canonical-form, interior-whitespace-tag, selection-matches-no-flag, sdk-sends-selection-at-limits, server-ignores-selection, empty-selection, sdk-drops-too-many-values, sdk-drops-long-url) plus the ETag revalidation test.
    - Regression check, all of tests/parametric/test_ffe/ without -F, same image: TEST_LIBRARY=ruby ./run.sh PARAMETRIC --skip-parametric-build tests/parametric/test_ffe/, 82 passed, 25 skipped, 12 xfailed, 32 xpassed, 0 failed.
    - The suite's manifest entry for this library is still missing_feature, and the parametric-app wiring lands in a separate system-tests PR, so PR CI cannot show this run yet.
  • OpenFeature specs, Ruby 3.1, gemfiles/ruby_3.1_openfeature_latest.gemfile, at 26dc844: bundle exec rake spec:open_feature, 1509 examples, 0 failures.

  • OpenFeature specs, Ruby 3.1, gemfiles/ruby_3.1_openfeature_min.gemfile, at 26dc844: bundle exec rake spec:open_feature, 1509 examples, 0 failures.

  • Shared selection vectors, at 26dc844: bundle exec rspec spec/datadog/open_feature/configuration/flag_selection_spec.rb -e 'with the shared selection vectors', 38 examples (every sdk case of flag-selection/selection-vectors.json at DataDog/ffe-system-test-data 1ae3eda), 0 failures. The 6 rawQuery cases have no SDK expectation.

  • Type check, Ruby 4.0, gemfiles/ruby-4.0.gemfile, at 26dc844: bundle exec rake 'steep:check[--jobs=4]', "No type error detected".

  • CI at 5cf4993: 427 check runs pass and 3 are skipped, including steep/check, rubocop/lint, standard/lint, and all-jobs-are-green; all 30 GitLab commit statuses pass.

  • Staging end-to-end flag selection check against this branch at 5cf49939, in an internal staging test application: the application installed the gem built from this commit (every library file in the installed gem matched the commit), and all 12 cases passed. Tag, key-pattern and combined selections returned exactly the expected flags, a non-matching tag returned none, and values were trimmed and sent in UTF-8 byte order. For more than 31 tags, a key pattern over 200 bytes, and a null element, the provider did not send the selection, logged one flag_selection was not sent (<reason>) error, and loaded the full configuration. The test-proxy request checks (server-ignored header) were not run in this pass.

  • Staging end to end, at 0f75746eb4b36a69ef91f11130d51d4c816822da, an earlier head of this branch: a test app builds the provider with each selection against the staging backend. 12/12 cases pass direct, and 14/14 pass through a recording proxy that also checks the exact query the SDK sent. As a negative control, master 7feafb81, which has agentless delivery but no selection option, loads every flag for all 8 selection cases (the published 2.43.0 predates agentless delivery). Ruby has no lone-surrogate case: its JSON parser rejects one before the SDK sees it.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: joepeeples Review duration: 14619m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #6652"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%