datadog.md

April 28, 2026 ยท View on GitHub

Description

The datadog Plugin supports integration with Datadog, one of the most widely used observability services for cloud applications. When enabled, the Plugin pushes metrics to the DogStatsD server, which comes bundled with the Datadog agent, over UDP protocol.

This Plugin provides the ability to push metrics as a batch to the external Datadog agent over UDP. It might take some time to receive the metric data. It will be automatically sent after the timer function in the batch processor expires.

Attributes

NameTypeRequiredDefaultValid valuesDescription
prefer_namebooleanFalsetrue[true, false]If true, exports Route/Service name instead of their ID in metric tags.
include_pathbooleanFalsefalse[true, false]If true, includes the path pattern in metric tags.
include_methodbooleanFalsefalse[true, false]If true, includes the HTTP method in metric tags.
constant_tagsarrayFalse[]Static key-value tags attached to all metrics generated by this Route. Useful for grouping metrics over certain signals.
batch_max_sizeintegerFalse1000[1,...]Maximum number of metric entries per batch. Once reached, the batch is sent to the Datadog agent. Set to 1 for immediate processing.
inactive_timeoutintegerFalse5[1,...]Maximum time in seconds to wait for new metric entries before sending the batch. The value should be smaller than buffer_duration.
buffer_durationintegerFalse60[1,...]Maximum time in seconds from the earliest metric entry allowed before sending the batch.
retry_delayintegerFalse1[0,...]Time interval in seconds to retry sending the batch if the previous attempt failed.
max_retry_countintegerFalse0[0,...]Maximum number of unsuccessful retries before dropping the metric entries.

This Plugin supports using batch processors to aggregate and process metric data in a batch. This avoids the need to submit data too frequently. The batch processor submits data every 5 seconds or when the data in the queue reaches 1000. See Batch Processor for more information or to customize the configuration.

Plugin Metadata

You can configure the Plugin through Plugin metadata.

NameTypeRequiredDefaultDescription
hoststringFalse"127.0.0.1"DogStatsD server host address.
portintegerFalse8125DogStatsD server port.
namespacestringFalse"apisix"Prefix for all custom metrics sent by the APISIX agent. Useful for finding entities for metrics graph. For example, apisix.request.counter.
constant_tagsarrayFalse[ "source:apisix" ]Static tags to embed into generated metrics. Useful for grouping metrics over certain signals. See defining tags for more.

Metrics

The Plugin exports the following metrics by default.

All metrics will be prefixed by the namespace configured in metadata. For example, if namespace is set to apisix, the request.counter metric will be exported as apisix.request.counter in Datadog.

NameStatsD TypeDescription
request.counterCounterNumber of requests received.
request.latencyHistogramTime taken to process the request, in milliseconds.
upstream.latencyHistogramTime taken to proxy the request to the upstream server until a response is received, in milliseconds.
apisix.latencyHistogramTime taken by the APISIX agent to process the request, in milliseconds.
ingress.sizeTimerRequest body size in bytes.
egress.sizeTimerResponse body size in bytes.

Tags

The Plugin exports metrics with the following tags. When there are no suitable values for any particular tag, the tag will be omitted.

NameDescription
route_nameName of the Route. If not present or if the attribute prefer_name is set to false, falls back to the Route ID.
service_nameName of the Service. If not present or if the attribute prefer_name is set to false, falls back to the Service ID.
consumerUsername of the Consumer if the Route is connected to a Consumer.
balancer_ipIP address of the upstream balancer that processes the current request.
response_statusHTTP response status code, such as 201, 404, or 503.
response_status_classHTTP response status code class, such as 2xx, 4xx, or 5xx. Available from APISIX version 3.14.0.
schemeRequest scheme, such as HTTP and gRPC.
pathHTTP path pattern. Only available if the attribute include_path is set to true. Available from APISIX version 3.14.0.
methodHTTP method. Only available if the attribute include_method is set to true. Available from APISIX version 3.14.0.

Examples

The following examples demonstrate how you can configure the datadog Plugin for different scenarios.

Before proceeding, make sure you have installed the Datadog agent, which collects events and metrics from monitored objects and sends them to Datadog.

Start the Datadog agent with your API key, Datadog site, and hostname. Set DD_DOGSTATSD_NON_LOCAL_TRAFFIC to true to listen to DogStatsD packets from other containers:

docker run -d \
  --name dogstatsd-agent \
  -e DD_API_KEY=<your-api-key> \
  -e DD_SITE="us5.datadoghq.com" \
  -e DD_HOSTNAME=apisix.quickstart \
  -e DD_DOGSTATSD_NON_LOCAL_TRAFFIC=true \
  -p 8125:8125/udp \
  datadog/dogstatsd:latest

You can configure most options in the agent's main configuration file datadog.yaml through environment variables prefixed with DD_. For more information, see agent environment variables.

:::note

You can fetch the admin_key from config.yaml and save to an environment variable with the following command:

admin_key=$(yq '.deployment.admin.admin_key[0].key' conf/config.yaml | sed 's/"//g')

:::

Update Datadog Agent Address and Metadata

By default, the Plugin expects the DogStatsD server to be available at 127.0.0.1:8125. To customize the address and other metadata, update the Plugin metadata. Set the host to your Datadog agent address, the port to the agent listening port, the namespace to prefix all metrics, and add any constant tags:

curl "http://127.0.0.1:9180/apisix/admin/plugin_metadata/datadog" -X PUT \
  -H "X-API-KEY: ${admin_key}" \
  -d '{
    "host": "192.168.0.90",
    "port": 8125,
    "namespace": "apisix",
    "constant_tags": [
      "source:apisix",
      "service:custom"
    ]
  }'

To reset to default configuration, send a request to the datadog Plugin metadata with an empty body:

curl "http://127.0.0.1:9180/apisix/admin/plugin_metadata/datadog" -X PUT \
  -H "X-API-KEY: ${admin_key}" \
  -d '{}'

Monitor Route Metrics

The following example demonstrates how to send the metrics of a particular Route to Datadog.

Create a Route with the datadog Plugin. Set batch_max_size to 1 to send each metric immediately, and max_retry_count to 0 to disallow retries if metrics were unsuccessfully sent:

curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \
  -H "X-API-KEY: ${admin_key}" \
  -d '{
    "id": "datadog-route",
    "uri": "/anything",
    "plugins": {
      "datadog": {
        "batch_max_size": 1,
        "max_retry_count": 0
      }
    },
    "upstream": {
      "type": "roundrobin",
      "nodes": {
        "httpbin.org:80": 1
      }
    }
  }'

Generate a few requests to the Route:

curl "http://127.0.0.1:9080/anything"

In Datadog, select Metrics from the left menu and go to Explorer. Select apisix.ingress.size.count as the metric. You should see the count reflecting the number of requests generated.