Autodiscovery Container Identifiers

This document explains how to apply an Autodiscovery configuration template to a specific container. The ad_identifiers parameter can match a container image name or a custom identifier.

Container image name

To apply the following Autodiscovery configuration template to a given container, replace <AUTODISCOVERY_IDENTIFIER> with the short container image name:

ad_identifiers:
  <AUTODISCOVERY_IDENTIFIER>

init_config:
  <INIT_CONFIG>

instances:
  <INSTANCES_CONFIG>

Example: The following Apache Autodiscovery configuration template applies to a container image named httpd:

ad_identifiers:
  - httpd
init_config:
instances:
  - apache_status_url: http://%%host%%/server-status?auto
logs:
  source: apache
  service: webapp

This matches any httpd container image on your host. If you have one container running foo/httpd:latest and another running bar/httpd:v2, the Agent applies the above template to both containers.

When using short image names as Autodiscovery container identifiers, the Agent cannot distinguish between identically named images from different sources or with different tags.

Multiple identifiers

Specify multiple image names by adding to the ad_identifiers list, for example:

ad_identifiers:
  - httpd
  - my-custom-httpd-image

This matches any container images on your host that match httpd or my-custom-httpd-image.

Custom Autodiscovery container identifiers

If you want to apply different configuration templates to containers running the same image, use custom container identifiers.

  1. Supply a custom container identifier to your container using a Docker label or Kubernetes annotation.

    Example: Apply a Docker label or Kubernetes annotation to identify your container as foo:

    LABEL com.datadoghq.ad.check.id="foo"
    

    Note: The com.datadoghq.ad.check.id label takes precedence over the image name.

    ad.datadoghq.com/<CONTAINER_NAME>.check.id: 'foo'
    

    Replace <CONTAINER_NAME> with the container name within the pod.

    Note: Supported in Datadog Agent v6.25+ and v7.25. The ad.datadoghq.com/<CONTAINER_NAME>.check.id label takes precedence over the image name.

  2. Reference this custom value in your Autodiscovery configuration template.

    Example: The following Apache Autodiscovery configuration template designates a container image with the custom name foo:

    ad_identifiers:
      - foo
    init_config:
    instances:
      - apache_status_url: http://%%host%%/server-status?auto
    logs:
      source: apache
      service: webapp
    

Advanced container identifiers

For use cases which require further granularity on Agent v7.73.0+, you can use the cel_selector check configuration option to target specific containers based on additional container attributes. These rules are based on the Common Expression Language syntax.

Note: To be a valid Autodiscovery configuration, the check configuration must either include an ad_identifier or cel_selector container rule with the container.image.reference parameter.

Example: The following NGINX Autodiscovery configuration template designates a container image with the name nginx on two selected namespaces. Separately listed conditions are joined together through an OR operation.

ad_identifiers:
  - nginx
cel_selector:
  containers:
    - container.pod.namespace == "target-ns-1"
    - container.pod.namespace == "target-ns-2"
AttributeDescription
container.nameThe name of the container.
container.image.referenceThe full reference of the container image (registry, repo, tag/digest).
container.pod.nameThe name of the pod running the container.
container.pod.namespaceThe Kubernetes namespace of the pod.
container.pod.annotationsThe annotations applied to the pod (key-value map).

These attributes can be used with the CEL syntax to define rules to select specific containers for check scheduling. Below is a list of example rules that could be defined:

Examples

To select the container running the image nginx with a specific pod annotation:

ad_identifiers:
  - nginx
cel_selector:
  containers:
    - container.pod.annotations["monitoring"] == "true"

To select the container running the image nginx in namespaces without the substring -dev:

ad_identifiers:
  - nginx
cel_selector:
  containers:
    - !container.pod.namespace.matches("-dev")

To select the container running the image nginx with the container name nginx-server only in the namespace prod:

ad_identifiers:
  - nginx
cel_selector:
  containers:
    - container.name == "nginx-server" && container.pod.namespace == "prod"

To select the container running an image with the substring nginx:

cel_selector:
  containers:
    - container.image.reference.matches("nginx")

To select containers using grouped logic (for example, a specific container name in either of two namespaces):

ad_identifiers:
  - nginx
cel_selector:
  containers:
    - container.name == "my-app" && (container.pod.namespace == "production" || container.pod.namespace == "staging")

Broad conditions can unintentionally target containers on your host. For example, using a containers cel_selector like !container.image.reference.matches("nginx") selects every container on the host except nginx, including system components and likely unrelated applications. This can lead to additional telemetry collection which can impact billing.

To globally exclude particular workloads from being collected regardless of the check integration, see the Container Discovery Management documentation.

Further Reading