Skip to main content

datadog

Datadog is an observability platform for monitoring applications and infrastructure. The datadog plugin sends gateway request metrics over UDP to DogStatsD, the metrics aggregation service bundled with the Datadog Agent. The Agent aggregates the metrics and forwards them to Datadog for querying, dashboards, and alerts.

Metrics​

The plugin exports the following metrics. Each name is prefixed by the namespace configured in plugin metadata. With the default apisix namespace, request.counter is exported as apisix.request.counter.

NameTypeDescription
request.counterCounterNumber of requests received.
request.latencyHistogramTotal request latency in milliseconds.
upstream.latencyHistogramTime in milliseconds from the upstream connection until the upstream response. This metric is omitted when no upstream latency is available.
apisix.latencyHistogramTime in milliseconds spent processing the request in the gateway.
ingress.sizeTimerRequest size in bytes.
egress.sizeTimerResponse size in bytes.

Tags​

The plugin attaches the following tags when their values are available:

NameDescription
route_nameRoute name when prefer_name is true and a name is configured; otherwise, the route ID.
service_nameService name when prefer_name is true and a name is configured; otherwise, the service ID.
consumerConsumer username.
balancer_ipAddress of the upstream node that handled the request.
response_statusHTTP response status code, such as 200, 404, or 503.
response_status_classHTTP response status class, such as 2xx, 4xx, or 5xx. Introduced in API7 Enterprise 3.9.0 and 3.10.0, and APISIX 3.14.0.
schemeUpstream scheme, such as http, https, or grpc.
pathMatched route path when include_path is true.
methodHTTP method when include_method is true.

Examples​

The examples deploy a pinned DogStatsD Agent, configure the gateway to reach it, and verify gateway metrics in Datadog. The Docker setup uses a dedicated network so the gateway can send UDP metrics to the Agent by container name.

Create or select a Datadog API key and identify the Datadog site for the organization. Set them as environment variables without adding the key to configuration files or source control:

export DD_API_KEY=replace-with-datadog-api-key
export DD_SITE=datadoghq.com

The Agent deployments below are intended for evaluation. Follow the Datadog Agent container guidance and the organization's secret-management requirements for production deployments.

Set GATEWAY_CONTAINER to the running APISIX or API7 Gateway container. Create a dedicated network and connect the gateway to it:

export GATEWAY_CONTAINER=replace-with-gateway-container-name

docker network create gateway-datadog-net
docker network connect gateway-datadog-net "$GATEWAY_CONTAINER"

Start the standalone DogStatsD Agent on the same network:

docker run -d \
--name dogstatsd-agent \
--network gateway-datadog-net \
-e DD_API_KEY \
-e DD_SITE \
-e DD_HOSTNAME=apisix-docs-datadog \
-e DD_DOGSTATSD_NON_LOCAL_TRAFFIC=true \
registry.datadoghq.com/dogstatsd:7.83.1

Wait for the Agent health check to pass:

until [ "$(docker inspect -f '{{.State.Health.Status}}' dogstatsd-agent)" = "healthy" ]; do
sleep 2
done

Configure the DogStatsD Destination​

The plugin metadata defines the DogStatsD endpoint, metric namespace, and tags shared by every route that enables the plugin. Configure the metadata for the selected environment:

curl "http://127.0.0.1:9180/apisix/admin/plugin_metadata/datadog" -X PUT \
-H "X-API-KEY: ${ADMIN_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"host": "dogstatsd-agent",
"port": 8125,
"namespace": "apisix_docs",
"constant_tags": [
"source:apisix",
"docs_example:datadog"
]
}'

The endpoint must be reachable from the gateway. The namespace prefixes every metric, and the constant tags make the example metrics easy to identify in Datadog.

Monitor Route Metrics​

Create a route that sends request metrics to DogStatsD. The example includes the matched path, HTTP method, and a route-specific tag, and sends each metric entry to the Agent immediately for verification.

curl "http://127.0.0.1:9180/apisix/admin/routes/datadog-route" -X PUT \
-H "X-API-KEY: ${ADMIN_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"name": "datadog-docs",
"uri": "/anything/datadog",
"plugins": {
"datadog": {
"batch_max_size": 1,
"include_path": true,
"include_method": true,
"constant_tags": [
"scenario:plugin-hub"
]
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"httpbin.org:80": 1
}
}
}'

Send several requests to generate metrics:

for request_number in $(seq 1 5); do
curl -fsS "http://127.0.0.1:9080/anything/datadog?request=${request_number}" > /dev/null
done

DogStatsD aggregates metrics on a short interval before forwarding them. In Datadog, open Metrics → Explorer, select apisix_docs.request.counter, and filter by docs_example:datadog. The metric can take a few minutes to become available in a new organization.

Datadog Metrics Explorer displaying the APISIX request counter emitted by the datadog plugin