> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/continuous-delivery/use-continuous-delivery/verify-deployments/configure-cv/health-sources/datadog.md).

# Datadog

Add Datadog as a Continuous Verification health source for metrics or logs

This topic shows how to add Datadog as a health source for Continuous Verification (CV) in Harness. A health source maps a Harness service to the service in a deployment environment monitored by an application performance monitoring (APM) or logging tool.

***

## What you will learn from this topic

* How to meet the [prerequisites](#before-you-begin) for a Datadog health source
* How to [add Datadog as a health source](#add-datadog-as-a-health-source)
* How to configure [Cloud Metrics](#cloud-metrics), including formulas and common queries
* How to configure [Cloud Logs](#cloud-logs) and map queries to Harness services

***

## Before you begin

Confirm the following before you add a Datadog health source:

* **CV setup**: Complete the shared Continuous Verification setup for your pipeline. Go to [Configure CV](/continuous-delivery/use-continuous-delivery/verify-deployments/configure-cv/verify-deployments.md) to configure verification.
* **Datadog connector**: Create a Datadog connector in Harness. Go to [Connect to monitoring and logging systems](https://developer.harness.io/docs/platform/use-harness-platform/connectors/monitoring-and-logging-systems/connect-to-monitoring-and-logging-systems#add-datadog) to add Datadog as a verification provider.
* **Fixed service and environment**: The health source option described in this topic is available only when you configure the service and environment as fixed values.

***

## Add Datadog as a health source

Perform the following steps to add Datadog as a health source:

1. In **Health Sources**, select **Add**. The **Add New Health Source** settings appear.

   ![Add New Health Source dialog](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-4fc3a45c4b7d759486c535cbc9640b539b39df6c%2Fverify-deployments-with-datadog-51.png?alt=media)
2. In **Select health source type**, select **Datadog**.
3. In **Health Source Name**, enter a name for the health source.
4. Under **Connect Health Source**, select **Select Connector**.
5. In **Connector** settings, choose an existing connector or select **New Connector**.

   ![Select or create a Datadog connector](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-5c8b582f5cd2cd3ea9ac602c0e84b111544a3a1c%2Fverify-deployments-with-datadog-52.png?alt=media)
6. Select **Apply Selected**. The connector is added to the health source.
7. In **Select Feature**, select the Datadog feature to use. You can choose **Cloud Metrics** or **Cloud Logs**.

   ![Select Cloud Metrics or Cloud Logs](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-041d151d4b70b8f988d487443cebf321385d3a71%2Fverify-deployments-with-datadog-53.png?alt=media)
8. Select **Next**.

The settings in **Customize Health Source** depend on the feature you selected.

***

## Cloud Metrics

If you select **Cloud Metrics**, the **Select Dashboards** settings appear and display a list of Datadog dashboards.

![Select Datadog dashboards for Cloud Metrics](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-c0f6bd36d8937b6ff2ddef499eb0796476429d6a%2Fverify-deployments-with-datadog-54.png?alt=media)

Perform the following steps to finish Cloud Metrics configuration:

1. Select the dashboards you want to use. If you do not have preexisting dashboards, or you do not want to select the ones displayed, select **Manually input query**.
2. Select **Next**. The **Customize Health Source** settings appear.
3. Select a query from the options displayed on the left side of the settings panel. The specification of the selected query populates the fields under **Query Specifications**.

   ![Query specifications for a selected Datadog query](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-a6c1e081296695bf7b9f7cfdb861b81b1f618dcc%2Fverify-deployments-with-datadog-55.png?alt=media)
4. Select **Submit**. The health source is displayed in the AI Verify (v1) step.

### Configure Datadog formulas as Harness queries

In manual query mode, the Datadog metrics health source supports formulas. These formulas follow this format:

`Query a ; Query b ; Formula using a, b`

* Query a: `"Query-with-a"`
* Query b: `"Query-with-b"`
* The formula is `"(a/b) * 100 - 5"`

The following example illustrates the pattern:

```
kubernetes.cpu.usage{cluster-name:chi-play};kubernetes.memory.total{cluster-name:chi-play};(a/b) * 100 - 5
```

In this example, `a` and `b` represent the respective queries:

* `a` = `kubernetes.memory.usage{cluster-name:chi-play}`
* `b` = `kubernetes.memory.total{cluster-name:chi-play}`

You can use multiple queries represented by alphabetical variables (for example, `a`, `b`, `c`) in the final formula, but only one formula is allowed per query.

### Commonly used Datadog queries

The following examples show common Datadog query patterns. Validate each query against your Datadog account before you use it in production.

**Performance**

* P90: `synthetics.http.response.time.distrib{availability_zone:*}, pod=~"harness-dummy-.*"}[5m])) by (le))`
* P50: `synthetics.http.response.time.distrib{availability_zone:*}`

**API**

* 5xx response: `sum:synthetics.http.response{status_code_class:5xx}.as_rate() , sum:synthetics.http.response{status_code:502}.as_rate()`
* 4xx response: `sum:synthetics.http.response{status_code_class:4xx}.as_rate() , sum:synthetics.http.response{status_code:401}.as_rate()`

**Infrastructure**

* CPU: `per_minute(sum:container.cpu.usage{cluster_name:del-play-* cluster-location:us-*}) , system.cpu.num_cores{*} ; Final Value: a/b * 100`
* Memory: `per_minute(sum:container.cpu.usage{cluster_name:del-**, cluster-location:us-**})`

{% hint style="warning" %}
**Query sample accuracy**

Several commonly used query strings above may contain typographical or copy errors from earlier documentation. Treat them as starting points only until Continuous Verification or Datadog specialists validate them.
{% endhint %}

***

## Cloud Logs

Select **Cloud Logs**, then select **Next**. The **Customize Health Source** settings appear.

You can customize the metrics to map the Harness service to the monitored environment in **Query Specifications and Mapping** settings.

Perform the following steps to map log queries:

1. Select **Map Queries to Harness Services**.

   ![Map Datadog log queries to Harness services](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-dcdefd23c95e67bf82a7770464ef33cd708035a7%2Fverify-deployments-with-datadog-56.png?alt=media)
2. Enter a name for the query in **Name your Query**.
3. In **Log Indexes**, select a log index from the list.
4. In **Service Instance Identifier**, select the path of the service instance. Any tag used in a metric or log can be a service instance identifier. It should correspond to instances that are running. The list contains all tags returned by data through the API. Go to [List tags by metric name](https://docs.datadoghq.com/api/latest/metrics/#list-tags-by-metric-name) to review Datadog tag APIs.
5. Select **Submit**. The health source is displayed in the AI Verify (v1) step.

***

## Troubleshooting

<details>

<summary>Add health source is not available</summary>

Confirm that the service and environment are configured as fixed values. The Datadog health source option described in this topic is available only in that configuration.

</details>

<details>

<summary>Connector list is empty or Apply Selected fails</summary>

Create or repair a Datadog connector first. Go to [Connect to monitoring and logging systems](https://developer.harness.io/docs/platform/use-harness-platform/connectors/monitoring-and-logging-systems/connect-to-monitoring-and-logging-systems#add-datadog) to add Datadog as a verification provider, then return to the health source wizard.

</details>

<details>

<summary>Manual formula query returns unexpected values</summary>

Confirm that each alphabetical variable maps to the intended Datadog query, that only one formula appears at the end of the string, and that separators use `;` between queries and the formula. Validate the query in Datadog before you save it in Harness.

</details>

***

## Next steps

* [Configure CV](/continuous-delivery/use-continuous-delivery/verify-deployments/configure-cv/verify-deployments.md): Finish Continuous Verification setup for the pipeline.
* [Connect to monitoring and logging systems](https://developer.harness.io/docs/platform/use-harness-platform/connectors/monitoring-and-logging-systems/connect-to-monitoring-and-logging-systems#add-datadog): Create or update the Datadog connector.
* [List tags by metric name](https://docs.datadoghq.com/api/latest/metrics/#list-tags-by-metric-name): Review Datadog tag APIs used for service instance identifiers.

{% @harness-feedback/feedback %}
