Agent Environment Variables

For Agent v5, reference the Docker Agent GitHub repo.

Overview

For Agent v6, most of the configuration options in the Agent’s main configuration file (datadog.yaml) can be set through environment variables.

Recommendations

As a best practice, 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, see the unified service tagging documentation.

General use

In general, use the following rules:

  • Option names should be uppercase with the DD_ prefix: hostname -> DD_HOSTNAME

  • List values should be separated by spaces (Include rules support regexes, and are defined as a list of comma-separated strings):

       container_include:
         - "image:cp-kafka"
         - "image:k8szk"
       # DD_CONTAINER_INCLUDE="image:cp-kafka image:k8szk"
    
  • The nesting of config options with predefined keys should be separated with an underscore:

       cluster_agent:
         cmd_port: 5005
       # DD_CLUSTER_AGENT_CMD_PORT=5005
    
  • The nesting of config options with user-defined keys must be JSON-formatted:

       container_env_as_tags:
         ENVVAR_NAME: tag_name
       # DD_CONTAINER_ENV_AS_TAGS='{"ENVVAR_NAME": "tag_name"}'
    

Note: Specifying a nested option with an environment variable overrides all the nested options specified under the config option. The exception to this rule is the proxy config option. Reference the Agent proxy documentation for more details.

Exceptions

  • Not all datadog.yaml options are available with environment variables. See config.go in the Datadog Agent GitHub repo. Options with environment variables start with config.BindEnv*.

  • Component-specific environment variables not listed in config.go may also be supported.

Using environment variables in systemd units

In operating systems that uses systemd to manage services, environment variables—global (for example, /etc/environment) or session-based (for example, export VAR=value)—are not generally made available to services unless configured to do so. See systemd Exec manual page for more details.

From Datadog Agent 7.45, the Datadog Agent service (datadog-agent.service unit) can optionally load environment variables assignments from a file (<ETC_DIR>/environment).

  1. Create /etc/datadog-agent/environment if it does not exist.
  2. Define newline-separated environment variable assignments. Example:
GODEBUG=x509ignoreCN=0,x509sha1=1
DD_HOSTNAME=myhost.local
DD_TAGS=env:dev service:foo
  1. Restart the service for changes to take effect

Further Reading

PREVIEWING: esther/docs-9478-fix-split-after-example