New announcements for Serverless, Network, RUM, and more from Dash! New announcements from Dash!

Tag Assignment and Extraction

The Datadog Agent can create and assign tags to all metrics, traces, and logs emitted by a container based on its labels or environment variables. If you are working with a Kubernetes environment, the Agent can create and assign tags to all metrics, traces, and logs emitted by a Pod, based on its labels or annotations.

If running the Agent as a binary on a host, configure your tag extractions with the Agent tab instructions. If running the Agent as a container configure your tag extraction with the Containerized Agent tab instructions.

Kubernetes

Tag Autodiscovery

Starting 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.

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_IDENTIFIER> within a pod, use the following annotation on your pod:

annotations:
  ad.datadoghq.com/<CONTAINER_IDENTIFIER>.tags: '{"<TAG_KEY>": "<TAG_VALUE>","<TAG_KEY_1>": "<TAG_VALUE_1>"}'

Extract Node Labels as Tags

Starting with Agent v6.0+, the Agent can collect labels for a given node and use them as tags to attach to all metrics emitted by all pods on this node:

To extract a given node label <NODE_LABEL> and transform it as a tag key <TAG_KEY> within Datadog, add the following configuration block in the Agent datadog.yaml configuration file:

kubernetes_node_labels_as_tags:
  <NODE_LABEL>: <TAG_KEY>

For example, you could set up:

kubernetes_node_labels_as_tags:
  app: kube_app

To extract a given node label <NODE_LABEL> and transform it as a tag key <TAG_KEY> within Datadog, add the following environment variable to the Datadog Agent:

DD_KUBERNETES_NODE_LABELS_AS_TAGS='{"<NODE_LABEL>": "<TAG_KEY>"}'

For example, you could set up:

DD_KUBERNETES_NODE_LABELS_AS_TAGS='{"app":"kube_app"}'

Extract Pod Labels as Tags

Starting with Agent v6.0+, the Agent can collect labels for a given pod and use them as tags to attach to all metrics emitted by this pod:

To extract a given pod label <POD_LABEL> and transform it as a Tag Key <TAG_KEY> within Datadog, add the following configuration block in the Agent datadog.yaml configuration file:

kubernetes_pod_labels_as_tags:
  <POD_LABEL>: <TAG_KEY>

For example, you could set up:

kubernetes_pod_labels_as_tags:
  app: kube_app

For Agent v6.8.0+, use the following environment variable configuration to add all pod labels as tags to your metrics. In this example, the tag names are prefixed by <PREFIX>_:

kubernetes_pod_labels_as_tags:
  *: <PREFIX>_%%label%%

Note: Using this method may increase the number of metrics for your organization and impact your billing.

To extract a given pod label <POD_LABEL> and transform it as a tag key <TAG_KEY> within Datadog, add the following environment variable to the Datadog Agent:

DD_KUBERNETES_POD_LABELS_AS_TAGS='{"<POD_LABEL>": "<TAG_KEY>"}'

For example, you could set up:

DD_KUBERNETES_POD_LABELS_AS_TAGS='{"app":"kube_app"}'

For Agent v6.8.0+, use the following environment variable configuration to add all pod labels as tags to your metrics. In this example, the tags names are prefixed by <PREFIX>_:

DD_KUBERNETES_POD_LABELS_AS_TAGS='{"*":"<PREFIX>_%%label%%"}'

Note: Using this method may increase the number of custom metrics for your organization and impact your billing.

Extract Pod Annotations as Tags

Starting with Agent v6.0+, the Agent can collect annotations for a given pod and use them as tags to attach to all metrics emitted by this pod:

To extract a given pod annotation <POD_ANNOTATION> and transform it as a tag key <TAG_KEY> within Datadog, add the following configuration block in the Agent datadog.yaml configuration file:

kubernetes_pod_annotations_as_tags:
  <POD_ANNOTATION>: <TAG_KEY>

For example, you could set up:

kubernetes_pod_annotations_as_tags:
  app: kube_app

To extract a given pod label <POD_ANNOTATION> and transform it as a tag key <TAG_KEY> within Datadog, add the following environment variable to the Datadog Agent:

DD_KUBERNETES_POD_ANNOTATIONS_AS_TAGS='{"<POD_ANNOTATION>": "<TAG_KEY>"}'

For example, you could set up:

DD_KUBERNETES_POD_ANNOTATIONS_AS_TAGS='{"app":"kube_app"}'

Docker

Extract Labels as Tags

Starting with Agent v6.0+, the Agent can collect labels for a given container and use them as tags to attach to all data emitted by this container.

To extract a given docker label <LABEL_NAME> and transform it as a tag key <TAG_KEY> within Datadog, add the following configuration block in the Agent datadog.yaml configuration file:

docker_labels_as_tags:
  <LABEL_NAME>: <TAG_KEY>

For example, you could set up:

docker_labels_as_tags:
  com.docker.compose.service: service_name

To extract a given docker label <LABEL_NAME> and transform it as a tag key <TAG_KEY> within Datadog, add the following environment variable to the Datadog Agent:

DD_DOCKER_LABELS_AS_TAGS='{"<LABEL_NAME>": "<TAG_KEY>"}'

For example, you could set up:

DD_DOCKER_LABELS_AS_TAGS='{"com.docker.compose.service":"service_name"}'

Extract Environment Variables as Tags

Starting with Agent v6.0+, the Agent can collect environment variables for a given container and use them as tags to attach to all data emitted by this container.

To extract a given Docker environment variable <ENVVAR_NAME> and transform it as a tag key <TAG_KEY> within Datadog, add the following configuration block in the Agent datadog.yaml configuration file:

docker_env_as_tags:
  <ENVVAR_NAME>: <TAG_KEY>

For example, you could set up:

docker_env_as_tags:
  ENVIRONMENT: env

To extract a given Docker environment variable <ENVVAR_NAME> and transform it as a tag key <TAG_KEY> within Datadog, add the following environment variable to the Datadog Agent:

DD_DOCKER_ENV_AS_TAGS='{"<ENVVAR_NAME>": "<TAG_KEY>"}'

For example, you could set up:

DD_DOCKER_ENV_AS_TAGS='{"ENVIRONMENT":"env"}'

Further Reading