Datadog implementation - Part 1

Implementation of DD-agent on a virtual Linux machine (EC2)

Running docker containers on virtual machines like EC2 with a single docker run ... command, require certain configurations, you will need to run the Datadog Agent container as a container (you can do it with a host install, but that require other skills and infrastructure, packer.io, Ansible comes to mind)

With that in mind, we will delve into the configuration of Datadog agent with one of our newly acquired products, and this is the story.

Bear in mind this configuration is for the Datadog Agent version 7.0 and this is written 2020-12-01.

What is required

We require certain changes to the application container listed below

docker run \
  -e DD_ENV=<environment> \
  -e DD_VERSION=<version of application, release, etc> \
  -e DD_AGENT_HOST="" \
  # TCP PORT Below
  -e DD_TRACE_AGENT_PORT=8126 \
  ... 

We also require to configure the dd-agent container listed below

DOCKER_CONTENT_TRUST=1 \
  docker run -d --name dd-agent \
  -v /var/run/docker.sock:/var/run/docker.sock:ro \
  -v /proc/:/host/proc/:ro \
  -v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro \
  -v /opt/datadog-agent/run:/opt/datadog-agent/run:rw \
  -v /etc/passwd:/etc/passwd:ro \
  -p 8126:8126 \
  -p 8125:8125/udp \
  -e DD_API_KEY=7f76b4a8b46afe55bf39ccbcbd17854b \
  -e DD_SITE=datadoghq.eu \
  -e DD_APM_ENABLED=true \
  -e DD_APM_NON_LOCAL_TRAFFIC=true \
  -e DD_LOGS_ENABLED=true \
  -e DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL=true \
  -e DD_CONTAINER_EXCLUDE="name:dd-agent" \
  -e DD_PROCESS_AGENT_ENABLED=true \
  -e DD_DOGSTATSD_NON_LOCAL_TRAFFIC=true \
  datadog/agent

Changes to Dockerfile to enable APM

Listed below, which could be extracted to its own page, is the Dockerfile changes needed.

# Only shown the stuff added to a regular application Dockerfile

RUN yum install -y wget && wget -O /data/dd-java-agent.jar https://dtdg.co/latest-java-tracer
LABEL com.datadoghq.ad.logs = '[{"source": "java", "service": "<serviceName>"}]'

CMD java -javaagent:/data/dd-java-agent.jar -Ddd.profiling.enabled=true <insert rest of your JAVA_OPTS and application>


References