If you deployed the Datadog Cluster Agent with Admission Controller enabled, the Admission Controller mutates the pod manifests and injects all required environment variables (based on configured mutation conditions). In that case, manual configuration of DD_
environment variables in pod manifests is unnecessary. For more information, see the Admission Controller documentation.
Full configuration
To get the full range of unified service tagging when using Kubernetes, add environment variables to both the deployment object level and the pod template spec level:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
tags.datadoghq.com/env: "<ENV>"
tags.datadoghq.com/service: "<SERVICE>"
tags.datadoghq.com/version: "<VERSION>"
...
template:
metadata:
labels:
tags.datadoghq.com/env: "<ENV>"
tags.datadoghq.com/service: "<SERVICE>"
tags.datadoghq.com/version: "<VERSION>"
containers:
- ...
env:
- name: DD_ENV
valueFrom:
fieldRef:
fieldPath: metadata.labels['tags.datadoghq.com/env']
- name: DD_SERVICE
valueFrom:
fieldRef:
fieldPath: metadata.labels['tags.datadoghq.com/service']
- name: DD_VERSION
valueFrom:
fieldRef:
fieldPath: metadata.labels['tags.datadoghq.com/version']
You can also use the OpenTelemetry Resource Attributes environment variables to set the env
, service
, and version
tags:
containers:
- ...
env:
- name: OTEL_RESOURCE_ATTRIBUTES
value: "service.name=<SERVICE>,service.version=<VERSION>,deployment.environment=<ENV>"
- name: OTEL_SERVICE_NAME
value: "<SERVICE>"
Note: The OTEL_SERVICE_NAME
environment variable takes precedence over the service.name
attribute in the OTEL_RESOURCE_ATTRIBUTES
environment variable.
Partial configuration
Pod-level metrics
To configure pod-level metrics, add the following standard labels (tags.datadoghq.com
) to the pod spec of a Deployment, StatefulSet, or Job:
template:
metadata:
labels:
tags.datadoghq.com/env: "<ENV>"
tags.datadoghq.com/service: "<SERVICE>"
tags.datadoghq.com/version: "<VERSION>"
These labels cover pod-level Kubernetes CPU, memory, network, and disk metrics, and can be used for injecting DD_ENV
, DD_SERVICE
, and DD_VERSION
into your service’s container through Kubernetes’s downward API.
If you have multiple containers per pod, you can specify standard labels by container:
tags.datadoghq.com/<container-name>.env
tags.datadoghq.com/<container-name>.service
tags.datadoghq.com/<container-name>.version
State metrics
To configure Kubernetes State Metrics:
Set join_standard_tags
to true
in your configuration file. See this example configuration file for the setting location.
Add the same standard labels to the collection of labels for the parent resource, for example: Deployment
.
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
tags.datadoghq.com/env: "<ENV>"
tags.datadoghq.com/service: "<SERVICE>"
tags.datadoghq.com/version: "<VERSION>"
spec:
template:
metadata:
labels:
tags.datadoghq.com/env: "<ENV>"
tags.datadoghq.com/service: "<SERVICE>"
tags.datadoghq.com/version: "<VERSION>"
APM tracer and StatsD client
To configure APM tracer and StatsD client environment variables, use the Kubernetes’s downward API in the format below:
containers:
- ...
env:
- name: DD_ENV
valueFrom:
fieldRef:
fieldPath: metadata.labels['tags.datadoghq.com/env']
- name: DD_SERVICE
valueFrom:
fieldRef:
fieldPath: metadata.labels['tags.datadoghq.com/service']
- name: DD_VERSION
valueFrom:
fieldRef:
fieldPath: metadata.labels['tags.datadoghq.com/version']
Automatic version tagging for APM data in containerized environments
You can use the version
tag in APM to monitor deployments and to identify faulty code deployments through Automatic Faulty Deployment Detection.
For APM data, Datadog sets the version
tag for you in the following priority order. If you manually set version
, Datadog does not override your version
value.
Priority | Version Value |
---|
1 | {your version value} |
2 | {image_tag}_{first_7_digits_of_git_commit_sha} |
3 | {image_tag} or {first_7_digits_of_git_commit_sha} if only one is available |
Requirements:
- Datadog Agent Version 7.52.0 or greater
- If your services run in a containerized environment and
image_tag
is sufficient for tracking new version deployments, no further configuration is needed - If your services are not running in a containerized environment, or if you’d also like to have the git SHA included, embed Git information in your build artifacts
Full configuration
Set the DD_ENV
, DD_SERVICE
, and DD_VERSION
environment variables and corresponding Docker labels for your container to get the full range of unified service tagging.
The values for service
and version
can be provided in the Dockerfile:
ENV DD_SERVICE <SERVICE>
ENV DD_VERSION <VERSION>
LABEL com.datadoghq.tags.service="<SERVICE>"
LABEL com.datadoghq.tags.version="<VERSION>"
Since env
is likely determined at deploy time, you can inject the environment variable and label later:
docker run -e DD_ENV=<ENV> -l com.datadoghq.tags.env=<ENV> ...
You may also prefer to set everything at deploy time:
docker run -e DD_ENV="<ENV>" \
-e DD_SERVICE="<SERVICE>" \
-e DD_VERSION="<VERSION>" \
-l com.datadoghq.tags.env="<ENV>" \
-l com.datadoghq.tags.service="<SERVICE>" \
-l com.datadoghq.tags.version="<VERSION>" \
...
Partial configuration
If your service has no need for the Datadog environment variables (for example, third party software like Redis, PostgreSQL, NGINX, and applications not traced by APM) you can use the Docker labels:
com.datadoghq.tags.env
com.datadoghq.tags.service
com.datadoghq.tags.version
As explained in the full configuration, these labels can be set in a Dockerfile or as arguments for launching the container.
Automatic version tagging for APM data in containerized environments
You can use the version
tag in APM to monitor deployments and to identify faulty code deployments through Automatic Faulty Deployment Detection.
For APM data, Datadog sets the version
tag for you in the following priority order. If you manually set version
, Datadog does not override your version
value.
Priority | Version Value |
---|
1 | {your version value} |
2 | {image_tag}_{first_7_digits_of_git_commit_sha} |
3 | {image_tag} or {first_7_digits_of_git_commit_sha} if only one is available |
Requirements:
- Datadog Agent Version 7.52.0 or greater
- If your services run in a containerized environment and
image_tag
is sufficient for tracking new version deployments, no further configuration is needed - If your services are not running in a containerized environment, or if you’d also like to have the git SHA included, embed Git information in your build artifacts
On ECS Fargate using Fluent Bit or FireLens, unified service tagging is only available for metrics and traces, not log collection.
Full configuration
Set the DD_ENV
, DD_SERVICE
, and DD_VERSION
(optional with automatic version tagging) environment variables and corresponding Docker labels in the runtime environment of each service’s container to get the full range of unified service tagging. For instance, you can set all of this configuration in one place through your ECS task definition:
"environment": [
{
"name": "DD_ENV",
"value": "<ENV>"
},
{
"name": "DD_SERVICE",
"value": "<SERVICE>"
},
{
"name": "DD_VERSION",
"value": "<VERSION>"
}
],
"dockerLabels": {
"com.datadoghq.tags.env": "<ENV>",
"com.datadoghq.tags.service": "<SERVICE>",
"com.datadoghq.tags.version": "<VERSION>"
}
Partial configuration
If your service has no need for the Datadog environment variables (for example, third party software like Redis, PostgreSQL, NGINX, and applications not traced by APM) you can use the Docker labels in your ECS task definition:
"dockerLabels": {
"com.datadoghq.tags.env": "<ENV>",
"com.datadoghq.tags.service": "<SERVICE>",
"com.datadoghq.tags.version": "<VERSION>"
}
Automatic version tagging for APM data in containerized environments
You can use the version
tag in APM to monitor deployments and to identify faulty code deployments through Automatic Faulty Deployment Detection.
For APM data, Datadog sets the version
tag for you in the following priority order. If you manually set version
, Datadog does not override your version
value.
Priority | Version Value |
---|
1 | {your version value} |
2 | {image_tag}_{first_7_digits_of_git_commit_sha} |
3 | {image_tag} or {first_7_digits_of_git_commit_sha} if only one is available |
Requirements:
- Datadog Agent Version 7.52.0 or greater
- If your services run in a containerized environment and
image_tag
is sufficient for tracking new version deployments, no further configuration is needed - If your services are not running in a containerized environment, or if you’d also like to have the git SHA included, embed Git information in your build artifacts