Docker Tag Extraction
Security Monitoring is now available Security Monitoring is now available

Docker Tag Extraction

Overview

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 running the Agent as a binary on a host, configure your tag extractions with the Agent tab instructions. If you are running the Agent as a container, configure your tag extraction with the Containerized Agent tab instructions.

Unified service tagging

As a best practice in containerized environments, Datadog recommends using unified service tagging when assigning 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.

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 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"}'

Note: <LABEL_NAME> is not case-sensitive. For example, if you have labels named foo and FOO, and you set DD_DOCKER_LABELS_AS_TAGS='{"foo": "bar"}', both foo and FOO are mapped to bar.

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

Extract Environment Variables as Tags

Starting with Agent v7.20+, a containerized 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 datadog.yaml file.

Tags should be added using the following format:

com.datadoghq.ad.tags: '["<TAG_KEY_1>:<TAG_VALUE_1>", "<TAG_KEY_2>:<TAG_VALUE_2>"]'

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 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"}'

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

Further Reading