For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/feature_flags/concepts/targeting_rules.md. A documentation index is available at /llms.txt.

Targeting Rules and Filters

This product is not supported for your selected Datadog site. ().

Overview

Targeting rules define which variant to serve to which subjects. Each rule can include a filter, one or more variants, and an optional percentage rollout. Rules are evaluated in order until a match is found.

Targeting rule types

Datadog supports different targeting rule types depending on your rollout strategy:

TypeDescription
Feature gateRoll out immediately to a percentage of subjects matching your filter (randomized or not)
Progressive rolloutRandomized rollout over a schedule with multiple steps
ExperimentRandomized allocation associated with an experiment

Configure targeting rules

To configure targeting rules for a flag:

  1. Navigate to Feature Flags and select your flag.
  2. Select the environment whose rules you want to modify.
  3. Click Add Targeting Rule (or click the targeting rule you want to modify).
Targeting Rules and Rollouts section on a feature flag.

For each targeting rule, configure the following:

  • Name your targeting rule: Give your targeting rule a name to describe the group it targets.
  • Define a filter (optional): If you do not define a filter, the rule matches all subjects in that environment.
  • Select variants: Choose which variants to serve to matching subjects. Click Split Traffic to randomize across multiple variants (see Traffic Splitting and Randomization).
  • Set the traffic exposure (optional): Serve the variant to a percentage of matching subjects (see Traffic Splitting and Randomization).
Targeting Rule editor side panel on a feature flag.

After configuring your targeting rules, click Save Changes, then enable the flag in the environment so SDKs can evaluate targeting rules.

SDKs do not evaluate targeting rules when the flag is disabled or overridden in an environment. If the flag is overridden with a fixed variant, the SDK returns that variant instead. If the flag is disabled, the SDK returns the coded default variant.

Filters and evaluation context

Filters use attributes from your SDK’s evaluation context. Define attributes when you set the evaluation context before evaluating flags. Attributes must be flat primitive values (strings, numbers, Booleans). Nested objects and arrays are not supported.

Example evaluation contexts and filters

With the following evaluation context, you can build filters with different operators, such as equality, is one of, is not, or numeric comparisons:

Evaluation context:

await OpenFeature.setContext({
  targetingKey: 'user-123',
  user_id: 'user-123',
  user_role: 'admin',
  email: 'user@example.com',
  country: 'US',
  tier: 'premium',
  account_age_days: 120,
});
from openfeature.evaluation_context import EvaluationContext

eval_ctx = EvaluationContext(
    targeting_key="user-123",
    attributes={
        "user_id": "user-123",
        "user_role": "admin",
        "email": "user@example.com",
        "country": "US",
        "tier": "premium",
        "account_age_days": 120,
    },
)
evalCtx := openfeature.NewEvaluationContext(
    "user-123",
    map[string]interface{}{
        "user_id":          "user-123",
        "user_role":        "admin",
        "email":            "user@example.com",
        "country":          "US",
        "tier":             "premium",
        "account_age_days": 120,
    },
)

Example filters

  • country is one of US, CA
  • tier equals premium
  • user_role is not guest
  • account_age_days greater than 90

Note: Other SDKs follow the same pattern. See your platform’s client or server SDK documentation for evaluation context setup.

Rule hierarchy

Targeting rules are evaluated in order from top to bottom:

  1. The SDK evaluates the first rule. If the subject matches the filter (or no filter is defined), the rule may serve a variant.
  2. If the subject does not match, evaluation passes through to the next rule.
  3. If no rule matches, the SDK serves the default variant for that environment.

Further reading