Autodiscovery

Autodiscovery is the mechanism by which the Datadog Agent detects a container starting up, automatically applies a monitoring configuration template that matches the service running inside it, and begins collection. Because the configuration is removed when the container disappears, nobody has to rewrite IPs or ports by hand.

Overview

Autodiscovery is the mechanism by which the Datadog Agent watches for container creation / deletion / start / stop, generates the check configuration corresponding to a started container, and begins collection. The configuration is written not for individual containers but in templates, placed in Pod annotations, Docker labels, and the like. Inside the templates, %%host%% and %%port%% are called template variables, and they are filled in at runtime with that container's values. You care about it when "I wrote the template but no monitoring is attached"; checking in turn the identifier it targets, how the variables are filled in, and the precedence when configurations overlap gets you to the cause.

Write the configuration in a template, not on the container

Autodiscovery is the mechanism by which the Datadog Agent watches for container creation / deletion / start / stop and generates the check configuration that matches the service running inside a container that has come up. The official documentation explains it as a feature that lets you define configuration templates and specify which containers to apply them to (as of September 2026, Source: Basic Agent Autodiscovery). With host-oriented Integrations you write the IP and port of the monitoring target directly in the configuration file, but with containers those values change every time one starts. So instead of values, you write only the rule of "what to apply to what kind of container" and leave filling in the blanks to the Agent. When the container stops, the generated configuration becomes invalid too. Why it is needed is left to the Container Monitoring entry; here we focus on the mechanism as seen from the Agent's side.

Where templates can be written

Pod annotations, Docker labels, configuration files inside the Agent, ConfigMaps, and key-value stores can be used (as of September 2026, Source: Basic Agent Autodiscovery). The key for a Pod annotation takes the form ad.datadoghq.com/<CONTAINER_NAME>.checks, and the value is the check name and instances written as JSON (the v2 format, Agent 7.36 and later). Log collection is just as simple: list source and service in the same place as ad.datadoghq.com/<CONTAINER_NAME>.logs. What is easy to mix up is the meaning of "container name." The official documentation states explicitly that it is something to match against spec.containers[i].name, not the image name (as of September 2026, Source: Kubernetes and Integrations).

Template variables - what gets filled with which value

Notation such as %%host%% written inside a template is a template variable. When the Agent applies the template, it replaces this part with that container's actual value. In the official documentation's Redis example, %%host%% becomes the container's IP and %%env_REDIS_PASSWORD%% becomes the value of the environment variable.

Main template variables and the values they take (as of September 2026)
VariableValue filled inNotes
%%host%%The container's network IPThe bridge network IP if none is found
%%port%%The highest of the exposed ports sorted in ascending orderFor 80 / 443 / 8443, it is 8443
%%port_<NUMBER>%% / %%port_<NAME>%%The Nth port in ascending order / the port with that nameIn the example above, %%port_0%% is 80
%%env_<VARIABLE_NAME>%%The contents of the environment variableThe value as visible from the Agent process
%%kube_namespace%% / %%kube_pod_name%%The Kubernetes namespace / Pod nameKubernetes only
Source: Datadog official documentation Autodiscovery Template Variables (as of September 2026)

The one that is easy to get wrong is %%port%%. When there are multiple exposed ports, the highest number is chosen, so if you have opened 8443 for administration, that becomes the monitoring target. To point at a specific port, specify it by position or by name. %%env_…%% reads the Agent's own environment variables, so a value passed only to the monitored container cannot be retrieved. The available variables differ by platform, and %%port%% cannot be used on ECS Fargate (as of September 2026).

When configurations overlap on the same container, which one wins

Some services, such as Redis and Apache, have default auto-configuration templates (as of September 2026, Source: Basic Agent Autodiscovery). If you also write an annotation yourself, which one takes effect? The official documentation states the precedence explicitly (as of September 2026, Source: Kubernetes and Integrations). The order is that Kubernetes annotations are stronger than the DatadogInstrumentation resource, which in turn is stronger than auto-configuration and static configuration through the Datadog Operator / Helm. DatadogInstrumentation is a custom resource that lets you declare checks without touching the Pod spec. You will not go wrong if you remember that the closer to the Pod, the stronger. If the defaults suffice, write nothing, and override only the items you want to change with annotations.

Where to look when you wrote the template but no monitoring is attached

What you care about is when the configuration did not take effect. The first thing is detection on the Agent side. The Agent automatically finds reachable endpoints such as Docker and containerd. When it does not work, check the detected features with agent status (as of September 2026, Source: Basic Agent Autodiscovery). To be explicit, use autoconfig_include_features / autoconfig_exclude_features in datadog.yaml. The second is the target: check whether the container name has been set to the image name. The third is variables: suspect whether %%port%% is the intended number and whether %%env_…%% is a value visible from the Agent. The env / service / version you attach with the Pod labels tags.datadoghq.com/… become Tags and can be used directly for filtering in the Host Map.

Share