← Back to Pull requests

feat(flags): add flagSelection to load only matching flags #1305

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 13, 2026 15:58 UTC
Author

What

Adds the flagSelection option to datadog_flags, so the precompute request asks only for flags that match the selected tags or key patterns. Behavior matches the iOS (DataDog/dd-sdk-ios#3344), Android (DataDog/dd-sdk-android#4031) and browser SDKs.

  • FlagSelection({tags, keyPatterns}) (new flag_selection.dart, exported from datadog_flags and datadog_flags_flutter) and DatadogFlagsConfiguration.flagSelection. The constructor stays const; the selection is canonicalized when a client is built.

  • Canonicalization: trims the 25 Unicode White_Space code points with a linear scan (not String.trim(), which differs at U+0085 and U+FEFF), keeps interior whitespace, drops empty values, dedupes, and sorts by UTF-8 bytes. Unpaired surrogates are malformed_selection. Limits: 31 values per list, 200 UTF-8 bytes per value, precedence malformed_selection > too_many_values > invalid_key_pattern > invalid_tag. Both lists empty means no selection.

  • Request: data.attributes.flag_selection {tags, key_patterns}, omitted without a selection (includeIfNull: false; generated code regenerated).

  • DD-Flag-Selection-Ignored: read only on a 2xx response with a decoded body when a selection was sent. Only the 5 server reasons are reported; anything else (including repeated fields, which package:http joins with , ) is unknown; an empty value is absent. Logged after the assignments are installed.

  • Error logs (wording and limit texts match the browser):

  • - flagSelection was not sent (<reason>: <limit>). Loading the full flag configuration., once per OpenFeature provider (not again on context changes or refreshes), or once per client built through DatadogFlags.sharedClient.
    - flagSelection was ignored by the server (<reason>). Loaded the full flag configuration.
  • Cache: FlagsData stores the canonical selection, and a snapshot fetched under another selection (or without one) is not restored. Selected assignments are written under selectedFlags, a key older SDKs do not read, so a downgraded SDK never takes them as the full flag set. DatadogFlagsStore is unchanged.

  • datadog_flags_flutter passes the option through.

  • Dartdoc notes that a custom web proxy must forward DD-Flag-Selection-Ignored and list it in Access-Control-Expose-Headers.

  • No telemetry: datadog_flags has no telemetry channel.

  • Diagnostics opt-in: setting DatadogOpenFeatureProvider.verbosity to a FlagsLoggerLevel (debug, warning, error; exported from both packages) also prints datadog_flags diagnostics at or above that level in any build mode, including release builds, where the Dart developer log is not shown. It is null by default, which prints nothing, as on iOS and Android.
  • Tests

  • test/fixtures/flag-selection/selection-vectors.json mirrors DataDog/ffe-system-test-data flag-selection/selection-vectors.json at 29ba6bf2e7514cf1b75c046b8956a22565221ee8 (pin in the sibling README). selection_vectors.dart compiles the same vectors in for web, and a VM test fails if the two differ. One test per case: 38 SDK cases run, the 6 rawQuery cases are skipped by name (URL decoding does not apply to a POST body).

  • Hand-written: unpaired surrogates, every White_Space code point, header sanitizing, exact log text per reason, request body, header gating, log-after-install, cache keying across selections, and the persisted layout.
  • Validation (Flutter 3.50.0, Dart 3.14.0):

    | Command (in packages/datadog_flags) | Result |
    |---|---|
    | flutter test | 333 passed, 6 skipped (the rawQuery vectors) |
    | dart test --platform chrome | 329 passed, 6 skipped (VM-only file tests excluded) |
    | dart test --platform chrome --compiler dart2wasm | 329 passed, 6 skipped |
    | dart format --output=none --set-exit-if-changed . | clean |
    | dart analyze . | no issues |
    | dart run build_runner build | no diff after regeneration |

    packages/datadog_flags_flutter (path overrides for local packages): flutter test 18 passed, flutter analyze lib test no issues, format clean.

    build_runner with the pinned json_serializable 6.14.1 does not compile against the newest source_helper (1.4.0); the generated file was produced with source_helper 1.3.13 through a local, uncommitted override.

    Staging (us1 staging)

    SDK commit 9965239f, against us1 staging (DD_SITE=datad0g.com, env staging). A small harness app depends on datadog_flags by path and registers DatadogOpenFeatureProvider with flagSelection. The cases and expected flag keys come from the shared flag-selection fixture, run against staging flags tagged for it.

    | Platform | Cases | Result |
    |---|---|---|
    | Dart VM (Dart 3.14.0) | 73 | 73 passed |
    | Flutter web, release (dart2js), headless Chromium | 73 | 73 passed |
    | Flutter web, debug (DDC), headless Chromium | 73 | 73 passed |

  • Cases: no selection (every flag in the environment); tags only (case sensitivity, NFC vs NFD, emoji, reserved characters, a 200-byte tag, trimming, duplicates and empty values); key patterns only (exact, prefix, middle and suffix *, literal ? and [); tags OR key patterns; selections that match no flag; 31 values, and 100 raw values that canonicalize to 31; SDK-dropped selections (too_many_values, invalid_key_pattern, invalid_tag, malformed_selection); and a selection the server ignores (too_many_values).

  • Each case checks the resolved flag keys and the flag count, the flag_selection request body (canonical order, or absent), DD-Flag-Selection-Ignored, and the error logs.

  • "not sent" is logged once per provider across two context changes and a refresh (4 requests). "ignored by the server" is logged once per fetch.

  • On web, the CDN lists DD-Flag-Selection-Ignored in Access-Control-Expose-Headers, and the SDK read too_many_values cross-origin from http://localhost.

  • Logs were checked on the Dart VM and in the DDC build. dart2js compiles dart:developer log() to a no-op, so a release web build shows no SDK logs unless verbosity is set.

  • The typed_evaluation example, with a local flagSelection edit, resolves flags inside the selection and returns flagNotFound outside it.

  • One transient HTTP 500 from staging was retried (Dart VM run).

  • Android and iOS staging runs were not done here.
  • Dependencies

  • #1294 has not merged.

  • Diagnostics go through the FlagsLogger from #1291; this PR adds its error() level.

  • #1297 touches flags_configuration, flags_repository, flags_store and precompute_request; whichever merges second resolves the overlap.
  • Logging frequency

    The OpenFeature provider builds a new client for each context revision. Those clients share one drop log, so the "not sent" error is logged once per provider, not at each context change or refresh. Clients created through DatadogFlags.sharedClient log once per client.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: joepeeples Review duration: 5723m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). 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.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #1305"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 27.7% · Safe to merge
    27.7%