This product is not supported for your selected Datadog site. ().
Overview
This page describes how to instrument your PHP application with the Datadog Feature Flags SDK. The PHP SDK uses the Datadog SDK’s Remote Configuration to receive flag updates in real time.
The PHP SDK provides two application APIs:
Datadog PHP API: Use DDTrace\FeatureFlags\Client with PHP 7 or PHP 8 applications.
OpenFeature adapter: Use DDTrace\OpenFeature\DataDogProvider with PHP 8 applications that use the OpenFeature standard API.
Flag evaluation is local and fast. The SDK uses locally cached configuration data, so no network requests occur during evaluation.
Prerequisites
Before setting up the PHP Feature Flags SDK, ensure you have:
Datadog PHP SDKdatadog/dd-trace version 1.21.0 or later
Supported PHP runtime: PHP 7 or later with the Datadog PHP API, or PHP 8 or later with the OpenFeature adapter
OpenFeature PHP SDKopen-feature/sdk version 2.1 or later, if you use the OpenFeature adapter
Set the following environment variables:
# Required: Enable the feature flags providerexportDD_EXPERIMENTAL_FLAGGING_PROVIDER_ENABLED=true# Required: Enable Remote Configuration in the SDKexportDD_REMOTE_CONFIG_ENABLED=true# Required: Service identificationexportDD_SERVICE=<YOUR_SERVICE_NAME>
exportDD_ENV=<YOUR_ENVIRONMENT>
exportDD_VERSION=<YOUR_APP_VERSION>
# Required for flag evaluation metricsexportDD_METRICS_OTEL_ENABLED=true
The EXPERIMENTAL_ prefix is retained for backwards compatibility; the provider itself is stable.
Feature Flagging is provided by Application Performance Monitoring (APM). Install and configure the Datadog PHP tracer by following Tracing PHP Applications.
If you use the OpenFeature adapter in a PHP 8 application, install the OpenFeature PHP SDK:
composer require open-feature/sdk:^2.1
Initialize the SDK
Choose the API that matches your PHP runtime and application architecture.
PHP 7 and PHP 8: Datadog API
Use DDTrace\FeatureFlags\Client directly in PHP 7 or PHP 8 applications:
The OpenFeature provider returns default values until Remote Configuration delivers the initial flag configuration. Initialize the provider early in application startup so flag configuration has time to load before business logic evaluates flags.
Set the evaluation context
Define an evaluation context that identifies the user or entity for flag targeting. The targeting key is used for consistent traffic distribution, such as percentage rollouts. Additional attributes enable targeting rules, such as “enable for users in the US” or “enable for premium tier users.”
Datadog API
For the Datadog PHP API, pass context as an array with targetingKey and attributes keys:
Evaluation context attributes must be flat primitive values: strings, numbers, and Booleans. Nested arrays, objects, and null values are ignored for targeting and exposure reporting.
Evaluate flags
After setting up the client, you can evaluate flags throughout your application. Each flag is identified by a unique string key and evaluated with a typed method that returns a value of the expected type. If the flag does not exist or cannot be evaluated, the SDK returns the provided default value.
Boolean flags
Use getBooleanValue for flags that represent on/off or true/false conditions:
For numeric flags, use getIntegerValue or getFloatValue. These methods are appropriate when a feature depends on a numeric parameter such as a limit, percentage, or multiplier:
When you need more than just the flag value, use the get<Type>Details methods. These return both the evaluated value and metadata explaining the evaluation:
You can test against a dedicated Datadog test environment with the real Datadog provider, or replace feature flag evaluation with a test double in unit tests.
The OpenFeature PHP SDK 2.1 does not include a built-in in-memory provider. For unit tests, wrap feature flag evaluation behind an application interface and inject a fake implementation:
If feature flags unexpectedly always return default values, check the following:
Verify DD_EXPERIMENTAL_FLAGGING_PROVIDER_ENABLED=true is set in your application environment.
Verify Remote Configuration is enabled in your Datadog Agent configuration.
Ensure DD_SERVICE and DD_ENV are set and match the service and environment configured for your flag.
Confirm your Datadog PHP SDK version includes feature flags support.
Check that the PHP process can communicate with the Datadog Agent.
Check that the Datadog Agent was available when the application started. If problems continue after the Agent becomes available, restart the application. See Agent availability.
OpenFeature provider not found
The OpenFeature adapter is available only for PHP 8 applications. If DDTrace\OpenFeature\DataDogProvider is not found:
Verify the application is running on PHP 8 or later.
Verify open-feature/sdk is installed through Composer.
Verify the Datadog PHP tracer version includes feature flags support.
Targeting rules do not match
If targeting rules do not match as expected:
Set a stable targetingKey for the user, organization, session, or entity being evaluated.
Pass custom targeting data under the attributes key when using the Datadog API.
Use only flat primitive attributes. Nested arrays, objects, and null values are ignored.
Flag evaluation counts appear in Datadog when DD_METRICS_OTEL_ENABLED=true is set for the PHP tracer. Each evaluation emits a feature_flag.evaluations counter metric tagged with the flag key, result variant, and evaluation reason. If this metric does not appear, confirm DD_METRICS_OTEL_ENABLED=true is set in your environment and that your PHP tracer version supports flag evaluation metrics. See Set Up Server-Side Flag Evaluation Metrics for Agent OTLP receiver setup and troubleshooting.
Experiment exposures
Exposures appear in Datadog only for flags associated with an experiment. Standard feature flags without an experiment association do not generate exposure events. If exposures are missing:
Verify the flag is associated with an experiment in the Datadog UI.
Verify the Agent’s DD_API_KEY is correct and the Agent is receiving events.
Verify the evaluation context uses flat primitive attributes. Nested arrays, objects, and null values are ignored for exposure reporting.
Further reading
Additional helpful documentation, links, and articles: