Set the following parameters in the task definition for the gcr.io/datadoghq/agent container. Set the portMappings host / container port to 8126 with protocol tcp:
Assign the private IP address for each underlying instance your containers are running in your application container to the DD_AGENT_HOST environment variable. This allows your application traces to be shipped to the Agent.
The Amazon’s ECS container metadata file allows discovery of the private IP address. To get the private IP address for each host, run the following command:
Set the result as your Trace Agent hostname environment variable for each application container shipping to APM:
os.environ['DD_AGENT_HOST'] = <EC2_PRIVATE_IP>
Launch time variables
In cases where variables on your ECS application are set at launch time, you must set the hostname as an environment variable with DD_AGENT_HOST. Otherwise, you can set the hostname in your application’s source code for Python, Javascript, or Ruby. For Java and .NET, you can set the hostname in the ECS task. For example:
packagemainimport("net/http""io/ioutil""gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer")resp,err:=http.Get("http://169.254.169.254/latest/meta-data/local-ipv4")bodyBytes,err:=ioutil.ReadAll(resp.Body)host:=string(bodyBytes)iferr==nil{//set the output of the curl command to the DD_Agent_host env
os.Setenv("DD_AGENT_HOST",host)// tell the trace agent the host setting
tracer.Start(tracer.WithAgentAddr(host))defertracer.Stop()
Copy this script into the entryPoint field of your ECS task definition, updating the values with your application jar and argument flags.
For Apache and mod_php in VirtualHost or server configuration file, use PassEnv to set DD_AGENT_HOST and other environment variables, such as the variables for Unified Service Tagging like the below example:
When the ini param is set as clear_env=on, in the pool workers file www.conf you must also configure environment variables to be read from the host. Use this to also set DD_AGENT_HOST and other environment variables, such as the variables for Unified Service Tagging like the below example: