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.
| Name | Type | Description |
|---|---|---|
request.counter | Counter | Number of requests received. |
request.latency | Histogram | Total request latency in milliseconds. |
upstream.latency | Histogram | Time in milliseconds from the upstream connection until the upstream response. This metric is omitted when no upstream latency is available. |
apisix.latency | Histogram | Time in milliseconds spent processing the request in the gateway. |
ingress.size | Timer | Request size in bytes. |
egress.size | Timer | Response size in bytes. |
Tags
The plugin attaches the following tags when their values are available:
| Name | Description |
|---|---|
route_name | Route name when prefer_name is true and a name is configured; otherwise, the route ID. |
service_name | Service name when prefer_name is true and a name is configured; otherwise, the service ID. |
consumer | Consumer username. |
balancer_ip | Address of the upstream node that handled the request. |
response_status | HTTP response status code, such as 200, 404, or 503. |
response_status_class | HTTP 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. |
scheme | Upstream scheme, such as http, https, or grpc. |
path | Matched route path when include_path is true. |
method | HTTP 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.
- Docker
- Kubernetes
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
Create a Kubernetes Secret from the API key:
kubectl create secret generic datadog-api-key \
--namespace aic \
--from-literal=api-key="$DD_API_KEY"
Create the DogStatsD Deployment and Service. Replace the DD_SITE value if the organization does not use the US1 site:
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: aic
name: dogstatsd-agent
spec:
replicas: 1
selector:
matchLabels:
app: dogstatsd-agent
template:
metadata:
labels:
app: dogstatsd-agent
spec:
containers:
- name: dogstatsd-agent
image: registry.datadoghq.com/dogstatsd:7.83.1
env:
- name: DD_API_KEY
valueFrom:
secretKeyRef:
name: datadog-api-key
key: api-key
- name: DD_SITE
value: datadoghq.com
- name: DD_HOSTNAME
value: apisix-docs-datadog
- name: DD_DOGSTATSD_NON_LOCAL_TRAFFIC
value: "true"
ports:
- name: dogstatsd
containerPort: 8125
protocol: UDP
readinessProbe:
exec:
command:
- /probe.sh
initialDelaySeconds: 5
periodSeconds: 10
---
apiVersion: v1
kind: Service
metadata:
namespace: aic
name: dogstatsd-agent
spec:
selector:
app: dogstatsd-agent
ports:
- name: dogstatsd
port: 8125
targetPort: dogstatsd
protocol: UDP
Apply the manifest and wait for the Agent to become ready:
kubectl apply -f dogstatsd.yaml
kubectl rollout status -n aic deployment/dogstatsd-agent
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:
- Admin API (Docker)
- ADC (Docker)
- Ingress Controller (Kubernetes)
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"
]
}'
Plugin metadata is a global collection and cannot be isolated with a label selector. Export the complete collection before changing the Datadog entry:
adc dump -o adc-metadata.yaml --with-id \
--include-resource-type plugin_metadata
Add or update the datadog entry while preserving every other plugin metadata entry:
plugin_metadata:
# Keep all other plugin metadata entries from the exported file.
datadog:
host: dogstatsd-agent
port: 8125
namespace: apisix_docs
constant_tags:
- "source:apisix"
- "docs_example:datadog"
Preview the complete collection and confirm that no unrelated changes or deletions are included:
adc diff -f adc-metadata.yaml \
--include-resource-type plugin_metadata
Synchronize the reviewed collection:
adc sync -f adc-metadata.yaml \
--include-resource-type plugin_metadata
Add the following entry under spec.pluginMetadata in the complete GatewayProxy manifest used by the deployment:
datadog:
host: dogstatsd-agent.aic.svc
port: 8125
namespace: apisix_docs
constant_tags:
- "source:apisix"
- "docs_example:datadog"
Apply the updated complete manifest through the deployment's normal Kubernetes or GitOps workflow.
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.
- Admin API (Docker)
- ADC (Docker)
- Ingress Controller (Kubernetes)
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
}
}
}'
services:
- name: datadog-example
labels:
docs-example: datadog
routes:
- name: datadog-route
uris:
- /anything/datadog
plugins:
datadog:
batch_max_size: 1
include_path: true
include_method: true
constant_tags:
- "scenario:plugin-hub"
upstream:
type: roundrobin
nodes:
- host: httpbin.org
port: 80
weight: 1
Preview the scoped service change and confirm that no unrelated changes or deletions are included:
adc diff -f adc.yaml \
--include-resource-type service \
--label-selector docs-example=datadog
Synchronize the reviewed service:
adc sync -f adc.yaml \
--include-resource-type service \
--label-selector docs-example=datadog
- Gateway API
- APISIX CRD
apiVersion: v1
kind: Service
metadata:
namespace: aic
name: httpbin-external-domain
spec:
type: ExternalName
externalName: httpbin.org
ports:
- name: http
port: 80
targetPort: 80
---
apiVersion: apisix.apache.org/v1alpha1
kind: PluginConfig
metadata:
namespace: aic
name: datadog-plugin-config
spec:
plugins:
- name: datadog
config:
batch_max_size: 1
include_path: true
include_method: true
constant_tags:
- "scenario:plugin-hub"
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
namespace: aic
name: datadog-route
spec:
parentRefs:
- name: apisix
rules:
- matches:
- path:
type: Exact
value: /anything/datadog
filters:
- type: ExtensionRef
extensionRef:
group: apisix.apache.org
kind: PluginConfig
name: datadog-plugin-config
backendRefs:
- name: httpbin-external-domain
port: 80
apiVersion: apisix.apache.org/v2
kind: ApisixUpstream
metadata:
namespace: aic
name: httpbin-external-domain
spec:
ingressClassName: apisix
externalNodes:
- type: Domain
name: httpbin.org
---
apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
namespace: aic
name: datadog-route
spec:
ingressClassName: apisix
http:
- name: datadog-route
match:
paths:
- /anything/datadog
methods:
- GET
upstreams:
- name: httpbin-external-domain
plugins:
- name: datadog
config:
batch_max_size: 1
include_path: true
include_method: true
constant_tags:
- "scenario:plugin-hub"
Apply the configuration:
kubectl apply -f datadog-ic.yaml
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.
