> ## Documentation Index
> Fetch the complete documentation index at: https://docs2.growthbook.io/llms.txt
> Use this file to discover all available pages before exploring further.

# DataDog Integration

> Send GrowthBook feature flag evaluations to Datadog RUM so you can see which experience users got, and auto-toggle flags when error rates spike.

## DataDog RUM with Feature Flag Data

Integrating DataDog's Real User Monitoring (RUM) with GrowthBook's feature flag data lets you quickly identify which experience your users were exposed to and if the changes introduced affect the user experience.

This guide will cover the initial setup and an advanced example of how to leverage DataDog and GrowthBook's powerful APIs to create a dynamic system that automatically toggles GrowthBook feature flags based on error thresholds.

### Setup

<Info>
  **Older DataDog RUM browser SDK versions**

  If your DataDog RUM browser SDK version is below v5.17.0, [enable feature flags during RUM SDK initialization](https://docs.datadoghq.com/real_user_monitoring/guide/setup-feature-flag-data-collection/?tab=browser#setup).
</Info>

We can report all feature flag evaluations to DataDog using GrowthBook’s SDK `onFeatureUsage` callback, as shown in the snippet below.

```javascript theme={null}
const gb = new GrowthBookClient({
  onFeatureUsage: (featureKey, result) => {
    datadogRum.addFeatureFlagEvaluation(featureKey, result.value);
  }
});
```

### Advanced example

Now that you're passing Feature Flag data to DataDog, you can build monitors and alerts when the error rate between Feature Flags variations cross a specific threshold within a pre-defined time period.

#### 1. Create a DataDog monitor

The beta Feature Flag Tracking feature allows you to see error rates between the various feature flag states.

<Frame>
  <img src="https://mintcdn.com/growthbook-ea15456d/hKkmiLOwhH6E2xcD/static/images/integrations/datadog/1-view-feature-flags-error-rates-in-data-dog.png?fit=max&auto=format&n=hKkmiLOwhH6E2xcD&q=85&s=3f8c554c64adfba2651c69fcecb5b8cd" alt="Screenshot showing error rates between feature flag variations in DataDog RUM interface" width="2000" height="1095" data-path="static/images/integrations/datadog/1-view-feature-flags-error-rates-in-data-dog.png" />
</Frame>

You can then save the Error rate view to a Dashboard.

<Frame>
  <img src="https://mintcdn.com/growthbook-ea15456d/hKkmiLOwhH6E2xcD/static/images/integrations/datadog/2-add-feature-flags-to-dashboard-data-dog.png?fit=max&auto=format&n=hKkmiLOwhH6E2xcD&q=85&s=260cba84e9437737b4cae532b7c45149" alt="Screenshot adding feature flags errors per view to a DataDog dashboard" width="2000" height="1091" data-path="static/images/integrations/datadog/2-add-feature-flags-to-dashboard-data-dog.png" />
</Frame>

And from the Dashboard, there is a handy “Create Monitor” option that can seed much of the monitor's search query for you.

<Frame>
  <img src="https://mintcdn.com/growthbook-ea15456d/hKkmiLOwhH6E2xcD/static/images/integrations/datadog/3-create-data-dog-monitor-from-dashboard.png?fit=max&auto=format&n=hKkmiLOwhH6E2xcD&q=85&s=780293cd3b7932794e88f5c057ab882f" alt="Screenshot showing the &#x22;Create Monitor&#x22; option in a DataDog dashboard" width="2000" height="1377" data-path="static/images/integrations/datadog/3-create-data-dog-monitor-from-dashboard.png" />
</Frame>

This is the out-of-the-box search query created from the Create Monitor link above. You could take it a step further and calculate the difference in error rates between the Feature Flag variations (e.g. error rate when the Feature Flag is enabled vs disabled) and use that value as your alert threshold.

<Frame>
  <img src="https://mintcdn.com/growthbook-ea15456d/hKkmiLOwhH6E2xcD/static/images/integrations/datadog/4-customize-monitor-query-in-data-dog.png?fit=max&auto=format&n=hKkmiLOwhH6E2xcD&q=85&s=2e81f4c59590ea93fbd648813c898bc0" alt="Screenshot customizing a monitor query in DataDog" width="2000" height="1092" data-path="static/images/integrations/datadog/4-customize-monitor-query-in-data-dog.png" />
</Frame>

#### 2. Create a DataDog webhook

Once you've defined a monitor's search query, you can then build an alert that uses DataDog's Webhooks to make a request to the GrowthBook API.

Before you can call a [Webhook](https://docs.datadoghq.com/integrations/webhooks/) via a monitor alert, you'll need to build the Webhook within DataDog.

You can do that via the Integrations tab.

<Frame>
  <img src="https://mintcdn.com/growthbook-ea15456d/hKkmiLOwhH6E2xcD/static/images/integrations/datadog/5-create-datadog-webhook.png?fit=max&auto=format&n=hKkmiLOwhH6E2xcD&q=85&s=843c6613610b93766b720674380ac9b9" alt="Screenshot showing a DataDog tile integration to create a webhook" width="2000" height="1420" data-path="static/images/integrations/datadog/5-create-datadog-webhook.png" />
</Frame>

Once installed, you can build the Webhook that will turn the feature flag off for the desired environments.

Remember to update the Webhook URL with your feature flag ID [as described here](/api/features/operation/toggleFeature).

<Frame>
  <img src="https://mintcdn.com/growthbook-ea15456d/hKkmiLOwhH6E2xcD/static/images/integrations/datadog/6-customize-webhook-to-hit-api-url.png?fit=max&auto=format&n=hKkmiLOwhH6E2xcD&q=85&s=eb5dc5d51ddb700893722bffb4ed2ac2" alt="Screenshot customizing a webhook in DataDog to make a request to GrowthBook feature toggle endpoint" width="1356" height="1242" data-path="static/images/integrations/datadog/6-customize-webhook-to-hit-api-url.png" />
</Frame>

#### 3. Update the monitor to trigger the webhook

Now that you've built the Webhook, you can go back to the monitor alert and instead of emailing a team member, you can configure the alert to call the Webhook.
