![]() |
VOOZH | about |
The Datadog Agent can automatically assign tags to metrics, traces, and logs emitted by a pod (or an individual container within a pod) based on labels or annotations.
The list of automatically-assigned tags depends on the Agent’s cardinality configuration. Tag Cardinality is added before ingestion and can impact billing, as different cardinality settings impact the number of emitted metrics.
container_iddisplay_container_namepod_nameoshift_deploymentopenshift.io/deployment.namekube_ownerref_namekube_job (Orchestrator)kube_job (Low)kube_replica_setkube_servicekube_daemon_setkube_container_namekube_namespacekube_app_nameapp.kubernetes.io/namekube_app_instanceapp.kubernetes.io/instancekube_app_versionapp.kubernetes.io/versionkube_app_componentapp.kubernetes.io/componentkube_app_part_ofapp.kubernetes.io/part-ofkube_app_managed_byapp.kubernetes.io/managed-byenvtags.datadoghq.com/env or container envvar (DD_ENV or OTEL_RESOURCE_ATTRIBUTES)versiontags.datadoghq.com/version or container envvar (DD_VERSION or OTEL_RESOURCE_ATTRIBUTES)servicetags.datadoghq.com/service or container envvar (DD_SERVICE, OTEL_RESOURCE_ATTRIBUTES, or OTEL_SERVICE_NAME)pod_phaseoshift_deployment_configopenshift.io/deployment-config.namekube_ownerref_kindkube_deploymentkube_argo_rolloutkube_replication_controllerkube_stateful_setpersistentvolumeclaimkube_cronjobimage_nameshort_imageimage_tageks_fargate_nodekube_runtime_classgpu_vendorimage_idkube_autoscaler_kindkube_priority_classkube_qosThe Agent can attach Kubernetes environment information as “host tags”.
kube_cluster_nameDD_CLUSTER_NAME envvar or cloud provider integrationDD_CLUSTER_NAME envvar or cloud provider integration enabledkube_node_rolenode-role.kubernetes.io/<role>kube_nodeNodeName field in a pod’s specificationsorch_cluster_idkube_distributionStarting with Agent v6.10+, the Agent can autodiscover tags from Pod annotations. It allows the Agent to associate tags to all data emitted by the entire pods or an individual container within this pod.
As a best practice in containerized environments, Datadog recommends using unified service tagging to help unify tags. Unified service tagging ties Datadog telemetry together through the use of three standard tags: env, service, and version. To learn how to configure your environment with unified tagging, refer to the dedicated unified service tagging documentation.
To apply a <TAG_KEY>:<TAG_VALUE> tag to all data emitted by a given pod and collected by the Agent use the following annotation on your pod:
annotations:ad.datadoghq.com/tags:'{"<TAG_KEY>": "<TAG_VALUE>","<TAG_KEY_1>": "<TAG_VALUE_1>"}'If you want to apply a <TAG_KEY>:<TAG_VALUE> tag to an individual container <CONTAINER_NAME> within a pod, use the following annotation on your pod:
annotations:ad.datadoghq.com/<CONTAINER_NAME>.tags:'{"<TAG_KEY>": "<TAG_VALUE>","<TAG_KEY_1>": "<TAG_VALUE_1>"}'Starting with Agent v7.17+, the Agent can Autodiscover tags from Docker labels. This process allows the Agent to associate custom tags to all data emitted by a container, without modifying the Agent configuration.
com.datadoghq.ad.tags:'["<TAG_KEY>:TAG_VALUE", "<TAG_KEY_1>:<TAG_VALUE_1>"]'Starting with Agent v7.77+, tag annotations support Autodiscovery template variables for dynamic tagging based on runtime metadata. With the exception of %%env_<VAR>%%, all template variables are supported.
annotations:ad.datadoghq.com/tags:'{"pod_ip":"%%host%%","pod_name":"%%kube_pod_name%%","namespace":"%%kube_namespace%%"}'ad.datadoghq.com/nginx.tags:'{"container_port":"%%port_80%%"}'Starting in version 7.64+, the Agent and Cluster Agent can be configured to collect labels and annotations from Kubernetes resources and use them as tags from a common configuration. Datadog recommends using the following options to ensure consistent reporting across the Agent’s core tagging, the Cluster Agent’s KSM reporting, and both Agents’ Orchestrator Explorer reporting:
kubernetesResourcesLabelsAsTagskubernetesResourcesAnnotationsAsTagsThese options should be used instead of the legacy Agent options podLabelsAsTags, nodeLabelsAsTags, namespaceLabelsAsTags, and any KSM configuration overrides.
These configurations reference the resource type of the object from which to extract metadata. Each resource type must be specified in the format resourceType.apiGroup, where resourceType is the plural name of the resource. Resources in the empty API group (for example, pods and nodes) can be specified using only the resourceType name.
For example, run kubectl api-resources to retrieve this information:
| Name | API Version | Datadog Resource Configuration |
|---|---|---|
| pods | v1 | pods |
| nodes | v1 | nodes |
| namespaces | v1 | namespaces |
| deployments | apps/v1 | deployments.apps |
| roles | rbac.authorization.k8s.io/v1 | roles.rbac.authorization.k8s.io |
Notes:
This option is used to extract a given label on your Kubernetes resources and send that up as a Datadog tag.
To extract a given resource label <LABEL> and transform them as tag keys <TAG_KEY> within Datadog, add the following configuration to your Operator’s DatadogAgent configuration in datadog-agent.yaml:
apiVersion:datadoghq.com/v2alpha1kind:DatadogAgentmetadata:name:datadogspec:global:kubernetesResourcesLabelsAsTags:<RESOURCE>:<LABEL>:<TAG_KEY>For example, to extract resource labels from nodes, pods, and deployments:
apiVersion:datadoghq.com/v2alpha1kind:DatadogAgentmetadata:name:datadogspec:global:kubernetesResourcesLabelsAsTags:nodes:kubernetes.io/arch:archpods:role:pod_roledeployments.apps:team:kube_teamTo extract a given resource label <LABEL> and transform them as tag keys <TAG_KEY> within Datadog, add the following configuration to your Helm datadog-values.yaml file:
datadog:kubernetesResourcesLabelsAsTags:<RESOURCE>:<LABEL>:<TAG_KEY>For example, to extract resource labels from nodes, pods, and deployments:
datadog:kubernetesResourcesLabelsAsTags:nodes:kubernetes.io/arch:archpods:role:pod_roledeployments.apps:team:kube_teamTo extract a given resource label <LABEL> and transform them as tag keys <TAG_KEY> within Datadog, add the following environment variable to both your Agent and Cluster Agent containers.
- name:DD_KUBERNETES_RESOURCES_LABELS_AS_TAGSvalue:'{"<RESOURCE>":{"<LABEL>":"<TAG_KEY>"}}'For example, to extract resource labels from nodes, pods, and deployments:
- name:DD_KUBERNETES_RESOURCES_LABELS_AS_TAGSvalue:'{"deployments.apps":{"team":"kube_team"},"nodes":{"kubernetes.io/arch":"arch"},"pods":{"role":"pod_role"}}'For Agent 7.73.0+, use the following configuration to add all resource labels as tags to your metrics. In this example, the tag names are prefixed with <PREFIX>_:
#(...)kubernetesResourcesLabelsAsTags:pods:"*": <PREFIX>_%%label%%Notes: Custom metrics may impact billing. See the custom metrics billing page for more information.
This configuration option is merged with other configurations set in podLabelsAsTags, namespaceLabelsAsTags and nodeLabelsAsTags. In case of conflict, kubernetesResourcesLabelsAsTags take precedence while merging the configurations.
For example, if you have the following configurations:
datadog:kubernetesResourcesLabelsAsTags:pods:label-1:tag-alabel-2:tag-bpodLabelsAsTags:label-2:legacy-tag-clabel-3:legacy-tag-dThe following mapping is used to extract tags from pod labels:
label-1:tag-alabel-2:tag-blabel-3:legacy-tag-dThis option extracts a specified annotation from your Kubernetes resources and sends it as a Datadog tag.
To extract a given resource annotation <ANNOTATION> and transform them as tag keys <TAG_KEY> within Datadog, add the following configuration to your Operator’s DatadogAgent configuration in datadog-agent.yaml:
apiVersion:datadoghq.com/v2alpha1kind:DatadogAgentmetadata:name:datadogspec:global:kubernetesResourcesAnnotationsAsTags:<RESOURCE>:<ANNOTATION>:<TAG_KEY>For example, to extract resource annotations from nodes, pods, and deployments:
apiVersion:datadoghq.com/v2alpha1kind:DatadogAgentmetadata:name:datadogspec:global:kubernetesResourcesAnnotationsAsTags:nodes:kubernetes.io/arch:archpods:role:pod_roledeployments.apps:team:kube_teamTo extract a given resource annotation <ANNOTATION> and transform them as tag keys <TAG_KEY> within Datadog, add the following configuration to your Helm datadog-values.yaml file:
datadog:kubernetesResourcesAnnotationsAsTags:<RESOURCE>:<ANNOTATION>:<TAG_KEY>For example, to extract resource annotations from nodes, pods, and deployments:
datadog:kubernetesResourcesAnnotationsAsTags:nodes:kubernetes.io/arch:archpods:role:pod_roledeployments.apps:team:kube_teamTo extract a given resource annotation <ANNOTATION> and transform them as tag keys <TAG_KEY> within Datadog, add the following environment variable to both your Agent and Cluster Agent containers.
- name:DD_KUBERNETES_RESOURCES_ANNOTATIONS_AS_TAGSvalue:'{"<RESOURCE>":{"<ANNOTATION>":"<TAG_KEY>"}}'For example, to extract resource annotations from nodes, pods, and deployments:
- name:DD_KUBERNETES_RESOURCES_ANNOTATIONS_AS_TAGSvalue:'{"deployments.apps":{"team":"kube_team"},"nodes":{"kubernetes.io/arch":"arch"},"pods":{"role":"pod_role"}}'For Agent 7.73.0+, use the following configuration to add all resource annotations as tags to your metrics. In this example, the tag names are prefixed with <PREFIX>_:
#(...)kubernetesResourcesAnnotationsAsTags:pods:"*": <PREFIX>_%%annotation%%Notes: Custom metrics may impact billing. See the custom metrics billing page for more information.
This configuration option is merged with other configurations set in podAnnotationsAsTags. In case of conflict, kubernetesResourcesAnnotationsAsTags take precedence while merging the configurations.
For example, if you have the following configurations:
datadog:kubernetesResourcesAnnotationsAsTags:pods:annotation-1:tag-aannotation-2:tag-bpodAnnotationsAsTags:annotation-2:legacy-tag-cannotation-3:legacy-tag-dThe following mapping is used to extract tags from pod annotations:
annotation-1:tag-aannotation-2:tag-bannotation-3:legacy-tag-dStarting with Agent v7.32+, the Agent can collect container environment variables and use them as tags to attach to all metrics, traces, and logs corresponding to the container. Both docker and containerd containers are supported:
To extract a given environment variable <ENV_VAR> and transform it as a tag key <TAG_KEY> within Datadog, add the following configuration to your Operator’s DatadogAgent configuration in datadog-agent.yaml:
apiVersion:datadoghq.com/v2alpha1kind:DatadogAgentmetadata:name:datadogspec:#(...)override:nodeAgent:env:- name:DD_CONTAINER_ENV_AS_TAGSvalue:'{"<ENV_VAR>": "<TAG_KEY>"}'For example, you could set up:
apiVersion:datadoghq.com/v2alpha1kind:DatadogAgentmetadata:name:datadogspec:#(...)override:nodeAgent:env:- name:DD_CONTAINER_ENV_AS_TAGSvalue:'{"app":"kube_app"}'To extract a given environment variable <ENV_VAR> and transform it as a tag key <TAG_KEY> within Datadog, add the following configuration to your Helm datadog-values.yaml file:
datadog:env:- name:DD_CONTAINER_ENV_AS_TAGSvalue:'{"<ENV_VAR>": "<TAG_KEY>"}'For example, you could set up:
datadog:env:- name:DD_CONTAINER_ENV_AS_TAGSvalue:'{"app":"kube_app"}'To extract a given environment variable <ENV_VAR> and transform it as a tag key <TAG_KEY> within Datadog, add the following environment variable to the Datadog Agent:
DD_CONTAINER_ENV_AS_TAGS='{"<ENV_VAR>": "<TAG_KEY>"}'
For example:
DD_CONTAINER_ENV_AS_TAGS='{"app":"kube_app"}'
Note: Custom metrics may impact billing. See Custom Metrics Billing for more details.
Starting with Agent v7.33+, the Agent can collect container labels and use them as tags. The agent attaches the tags to all metrics, traces, and logs associated with the container.
The Agent can generate tags from container labels for both docker and containerd containers. In the case of containerd, the minimum supported version is v1.5.6, because previous releases do not propagate labels correctly.
To extract a given container label <CONTAINER_LABEL> and transform it as a tag key <TAG_KEY> within Datadog, add the following configuration to your Operator’s DatadogAgent configuration in datadog-agent.yaml:
apiVersion:datadoghq.com/v2alpha1kind:DatadogAgentmetadata:name:datadogspec:#(...)override:nodeAgent:env:- name:DD_CONTAINER_LABELS_AS_TAGSvalue:'{"<CONTAINER_LABEL>": "<TAG_KEY>"}'For example, you could set up:
apiVersion:datadoghq.com/v2alpha1kind:DatadogAgentmetadata:name:datadogspec:#(...)override:nodeAgent:env:- name:DD_CONTAINER_LABELS_AS_TAGSvalue:'{"app":"kube_app"}'To extract a given container label <CONTAINER_LABEL> and transform it as a tag key <TAG_KEY> within Datadog, add the following configuration to your Helm datadog-values.yaml file:
datadog:env:- name:DD_CONTAINER_LABELS_AS_TAGSvalue:'{"<CONTAINER_LABEL>": "<TAG_KEY>"}'For example, you could set up:
datadog:env:- name:DD_CONTAINER_LABELS_AS_TAGSvalue:'{"app":"kube_app"}'To extract a given container label <CONTAINER_LABEL> and transform it to a tag key <TAG_KEY>, add the following environment variable to the Datadog Agent:
DD_CONTAINER_LABELS_AS_TAGS='{"<CONTAINER_LABEL>":"<TAG_KEY>"}'
For example:
DD_CONTAINER_LABELS_AS_TAGS='{"app":"kube_app"}'
Note: Custom metrics may impact billing. See Custom Metrics Billing for more details.
Additional helpful documentation, links, and articles:
| |