Getting Started with Feature Flags

This product is not supported for your selected Datadog site. ().
このページは日本語には対応しておりません。随時翻訳に取り組んでいます。
翻訳に関してご質問やご意見ございましたら、お気軽にご連絡ください

Overview

Datadog feature flags offer a powerful, integrated way to manage feature delivery, with built-in observability and seamless integration across the platform.

  • Real-time metrics: Understand who’s receiving each variant, as well as how your flag impacts the health & performance of your application—all in real time.

  • Supports common flag types: Use Boolean, string, integer, numeric (float/double), or JSON variants. JavaScript SDKs use getNumberValue() for both integer and numeric variants, while Java, Swift, Kotlin, and Python expose separate integer and floating-point evaluation methods.

  • Built for experimentation: Target specific audiences for A/B tests, roll out features gradually with canary releases, and automatically roll back when regressions are detected.

  • OpenFeature compatible: Built on the OpenFeature standard, ensuring compatibility with existing OpenFeature implementations and providing a vendor-neutral approach to feature flag management.

Feature Flags SDKs

This guide uses the JavaScript browser SDK as an example. You can integrate Datadog Feature Flags into any application using one of the following SDKs:

Client-side SDKs

Android
Android TV
Angular
iOS
JavaScript
React
React Native
tvOS
Unity

Server-side SDKs

.NET
Go
Java
Node.js
PHP
Python
Ruby

Configure your environments

Your organization likely already has pre-configured environments for Development, Staging, and Production. For details on environment queries, production marking, and managing environments, see Environments.

Create your first feature flag

Step 1: Import and initialize the SDK

Choose the SDK that matches where the flag is evaluated and initialize the Datadog Feature Flags provider.

Install @datadog/openfeature-browser, @openfeature/web-sdk, and @openfeature/core as dependencies in your project:

yarn add @datadog/openfeature-browser @openfeature/web-sdk @openfeature/core

Then, add the following to your project to initialize the SDK:

Browser Feature Flags are not supported for the selected Datadog site ().
import { DatadogProvider } from '@datadog/openfeature-browser';
import { OpenFeature } from '@openfeature/web-sdk';

// Initialize the provider
const provider = new DatadogProvider({
    // Required client-side Datadog credentials
    applicationId: '<APPLICATION_ID>',
    clientToken: '<CLIENT_TOKEN>',
    site: '<code class="js-region-param region-param" data-region-param="dd_site"></code>',
    env: '<YOUR_ENV>', // Same environment normally passed to the RUM SDK
    service: '<SERVICE_NAME>',
    version: '1.0.0'
});

// Set the provider
await OpenFeature.setProviderAndWait(provider);
The browser SDK emits three independent telemetry streams, all enabled by default. enableExposureLogging sends per-evaluation exposure events to the exposures intake. enableFlagEvaluationTracking sends aggregated evaluation telemetry to the flag-evaluation intake. enableRumFeatureFlagTracking attaches flag evaluations to RUM events and is the setting that can affect RUM usage. Disable only the stream you do not need.

Install dd-trace and the OpenFeature server SDK:

npm install dd-trace @openfeature/server-sdk

Enable the provider with environment variables:

# Required: Enable the feature flags provider
DD_EXPERIMENTAL_FLAGGING_PROVIDER_ENABLED=true

# Optional: Enable flag evaluation metrics
DD_METRICS_OTEL_ENABLED=true

Or enable the provider in code:

import { OpenFeature } from '@openfeature/server-sdk'
import tracer from 'dd-trace';

tracer.init({
  experimental: {
    flaggingProvider: {
      enabled: true,
    }
  }
});

OpenFeature.setProvider(tracer.openfeature);

Add the OpenFeature SDK and Datadog OpenFeature provider dependencies:

build.gradle

dependencies {
    // OpenFeature SDK for flag evaluation
    implementation 'dev.openfeature:sdk:1.18.2'

    // Datadog OpenFeature Provider
    implementation 'com.datadoghq:dd-openfeature:1.57.0'
}

Enable the provider and start your application with the Java tracer:

# Required: Enable the feature flagging provider
# The EXPERIMENTAL_ prefix is historical; the provider is no longer experimental.
export DD_EXPERIMENTAL_FLAGGING_PROVIDER_ENABLED=true

# Optional: Enable flag evaluation metrics
export DD_METRICS_OTEL_ENABLED=true

java -javaagent:path/to/dd-java-agent.jar -jar your-application.jar

Register the Datadog OpenFeature provider:

import dev.openfeature.sdk.OpenFeatureAPI;
import dev.openfeature.sdk.Client;
import datadog.trace.api.openfeature.Provider;

OpenFeatureAPI api = OpenFeatureAPI.getInstance();
api.setProviderAndWait(new Provider());
Client client = api.getClient("my-app");

Enable the provider with environment variables:

# Required: Enable the feature flags provider
export DD_EXPERIMENTAL_FLAGGING_PROVIDER_ENABLED=true

# Optional: Enable flag evaluation metrics
export DD_METRICS_OTEL_ENABLED=true

Install the Datadog Python SDK and OpenFeature SDK:

pip install ddtrace openfeature-sdk

Register the Datadog OpenFeature provider:

from ddtrace import tracer
from openfeature import api
from ddtrace.openfeature import DataDogProvider

# Initialize the tracer (required for Remote Configuration)
tracer.configure()

# Create and register the Datadog provider
provider = DataDogProvider()
api.set_provider(provider)

# Create an OpenFeature client
client = api.get_client()

Credentials at a glance

CredentialUsed byWhere it goesSensitive?
Client tokenBrowser, mobile, and game SDKsClient application configurationNo — safe to ship in public client code
Application IDBrowser and RUM-backed client SDKsClient application configurationNo — public identifier
API keyDatadog Agent for server-side Remote ConfigurationAgent configuration onlyYes — keep server-side only

Do not put API keys in browser, mobile, or game applications.

More information about OpenFeature SDK configuration options can be found in its documentation. For more information on creating client tokens and application IDs, see API and Application Keys.

Step 2: Create a feature flag

Go to Create Feature Flag in Datadog and configure the following:

Flag keys, variant keys, and variant values should be considered public when sent to client SDKs.
Create Feature Flag

Step 3: Evaluate the flag and write feature code

In your application code, use the SDK to evaluate the flag and gate the new feature.

Datadog Feature Flags requires evaluation context attributes to be flat primitive values: strings, numbers, and Booleans. Do not pass nested objects or arrays; they are not supported and can cause exposure data to be dropped.
import { OpenFeature } from '@openfeature/web-sdk';

const client = OpenFeature.getClient();

// If applicable, set relevant attributes on the client's global context
// (e.g. org id, user email)
await OpenFeature.setContext({
    org_id: 2,
    user_id: 'user-123',
    email: 'user@example.com',
    targetingKey: 'user-123'
});

// This is what the SDK returns if the flag is disabled in
// the current environment
const fallback = false;

const showFeature = await client.getBooleanValue('show-new-feature', fallback);
if (showFeature) {
    // Feature code here
}
const evaluationContext = {
  targetingKey: req.session?.userID ?? 'unknown',
  companyID: req.session?.companyID
};

const isNewCheckoutEnabled = await client.getBooleanValue(
    'new-checkout-flow', // flag key
    false, // default value
    evaluationContext, // context
);

if (isNewCheckoutEnabled) {
    showNewCheckoutFlow();
} else {
    showLegacyCheckout();
}
import dev.openfeature.sdk.EvaluationContext;
import dev.openfeature.sdk.MutableContext;

EvaluationContext context = new MutableContext("user-123")
    .add("email", "user@example.com")
    .add("tier", "premium");

boolean enabled = client.getBooleanValue("checkout.new", false, context);

if (enabled) {
    // New checkout flow
} else {
    // Old checkout flow
}
from openfeature.evaluation_context import EvaluationContext

eval_ctx = EvaluationContext(
    targeting_key="user-123",
    attributes={
        "email": "user@example.com",
        "tier": "premium"
    }
)

enabled = client.get_boolean_value("new-checkout-flow", False, eval_ctx)

if enabled:
    show_new_checkout()
else:
    show_legacy_checkout()

After you’ve completed this step, redeploy the application to pick up these changes. Additional usage examples can be found in the platform-specific SDK pages linked above.

Step 4: Define targeting rules and enable the feature flag

Configure targeting rules to define which subjects receive each variant. After saving your rules, enable the flag in your chosen environment.

As a general best practice, roll out changes in a Staging environment before Production.

For percentage rollouts, see Traffic Splitting and Randomization.

Step 5: Monitor your rollout

Monitor the feature rollout from the feature flag details page, which provides real-time exposure tracking and metrics such as error rate and page load time. As you incrementally release the feature with the flag, view the Real-Time Metric Overview panel in the Datadog UI to see how the feature impacts application performance.

Real-time flag metrics panel

Further reading