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

Docker Tag 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 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.

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