---
title: Evaluation Context
description: >-
  Learn how Datadog Feature Flags uses evaluation context and the targeting key
  to evaluate flags for a subject.
breadcrumbs: Docs > Feature Flags > Concepts > Evaluation Context
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# Evaluation Context

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com, us2.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site.md). ({% placeholder "user-datadog-site-name" /%}).
{% /alert %}

{% /callout %}

## Overview{% #overview %}

An **evaluation context** is the set of attributes an SDK passes to Datadog when it evaluates a flag. Datadog Feature Flags uses [OpenFeature](https://openfeature.dev/docs/reference/concepts/evaluation-context)'s evaluation context: a flat map of attributes describing the subject being evaluated, such as a user, session, or device. [Targeting rules](https://docs.datadoghq.com/feature_flags/concepts/targeting_rules.md) and [percentage rollouts](https://docs.datadoghq.com/feature_flags/concepts/traffic_splitting.md) read these attributes to decide which variant a subject receives.

Without an evaluation context, the SDK can still evaluate Boolean on/off flags. It cannot match targeting rules that filter on subject attributes, or produce a consistent rollout assignment for that subject.

## The targeting key{% #the-targeting-key %}

The `targetingKey` is the primary identifier in an evaluation context. It's typically a user ID, session ID, or device ID. Datadog uses the `targetingKey` for [deterministic randomization](https://docs.datadoghq.com/feature_flags/concepts/traffic_splitting.md), so the same subject consistently receives the same variant for a flag.

Use a stable, consistent identifier for the same subject across sessions. For logged-out or anonymous subjects, use a persistent identifier, such as a UUID stored in local storage or `SharedPreferences`, instead of omitting the `targetingKey` or regenerating it each session.

## Context attributes{% #context-attributes %}

Beyond the `targetingKey`, an evaluation context can include any number of additional attributes, such as `user_role`, `country`, or `tier`. Reference these attributes in targeting rule [filters](https://docs.datadoghq.com/feature_flags/concepts/targeting_rules.md) to control who sees each variant.

{% alert level="warning" %}
Datadog Feature Flags requires evaluation context attributes to be flat primitive values: strings, numbers, and Booleans. Nested objects and arrays are not supported and can cause exposure data to be dropped.
{% /alert %}

### Example evaluation context{% #example-evaluation-context %}

{% tab title="JavaScript" %}

```javascript
const evaluationContext = {
  targetingKey: 'user-123',
  user_id: 'user-123',
  user_role: 'admin',
  country: 'US',
  tier: 'premium',
};
```

{% /tab %}

{% tab title="Python" %}

```python
from openfeature.evaluation_context import EvaluationContext

eval_ctx = EvaluationContext(
    targeting_key="user-123",
    attributes={
        "user_id": "user-123",
        "user_role": "admin",
        "country": "US",
        "tier": "premium",
    },
)
```

{% /tab %}

{% tab title="Go" %}

```go
evalCtx := openfeature.NewEvaluationContext(
    "user-123",
    map[string]interface{}{
        "user_id":   "user-123",
        "user_role": "admin",
        "country":   "US",
        "tier":      "premium",
    },
)
```

{% /tab %}

## Client-side vs. server-side context{% #client-side-vs-server-side-context %}

Client and server SDKs set the evaluation context differently:

- **Client-side SDKs** hold a single global evaluation context for the SDK instance. Set it once during initialization, then call `OpenFeature.setContext()` to update it when subject attributes change, such as after a user logs in. All subsequent flag evaluations use the updated context.
- **Server-side SDKs** don't hold a global context. Build an evaluation context for each incoming request, based on the current user or session, and pass it explicitly to every flag evaluation call for that request. Reuse the same context object across evaluations within a request, and only rebuild it if subject attributes change.

## Further reading{% #further-reading %}

Additional helpful documentation, links, and articles:

- [Targeting Rules and Filters](https://docs.datadoghq.com/feature_flags/concepts/targeting_rules.md)
- [Traffic Splitting and Randomization](https://docs.datadoghq.com/feature_flags/concepts/traffic_splitting.md)
- [Client-Side SDKs](https://docs.datadoghq.com/feature_flags/client.md)
- [Server-Side SDKs](https://docs.datadoghq.com/feature_flags/server.md)
