Datadog + Spring Boot QuickStart

First things first, we can generate the starter project using Select these dependencies:

  • Spring Boot Actuator
  • Datadog
  • Spring Web

Then, using documentation here we should set API Key, Application Key and Datadog URI in file:


You can get your API Key and Datadog URI from startup Datadog screen:

By the way, Datadog has a trial period.

Application Key can be generated under Organization Settings -> Application Keys under your profile section:

Next, let’s create a controller:

public class TestController {
    public ResponseEntity<Void> light() {
        return new ResponseEntity<>(HttpStatus.OK);

    public ResponseEntity<Void> heavy() throws InterruptedException {
        return new ResponseEntity<>(HttpStatus.OK);

Notice @Timed annotation. In order to make it work, we should add a Spring Aspects dependency:


And create a bean of type TimedAspect:

TimedAspect timedAspect(MeterRegistry reg) {
    return new TimedAspect(reg);

Temporarily switch logging level to TRACE:


And find the following in Spring logs (number can vary):

successfully sent 84 metrics to datadog

If you interested what metrics actually being sent to Datadog, you can add a breakpoint to DatadogMeterRegistry class from micrometer-registry-datadog-<version>.jar to this line:

sending metrics batch to datadog:{}{}

It’s time to check metrics in Datadog UI. These are two handy pages:

Give it few minutes, if you don’t see your metrics (keeping in mind that there are no errors in Spring app).

You see, that in our case lightAPI works really fast, but heavyAPI works slower (because of Thread.sleep):

Alright, now let’s add tracing collection. Download Datadog agent:

wget -O dd-java-agent.jar ''

Build fat jar from Spring application simply running clean + package Maven actions from IntelliJ IDEA.

Run Docker container with agent. Remember to add your API Key and Datadog URI (not Application Key!) as we did in

docker run -d --cgroupns host --pid host --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 \
  -e \
  -e DD_API_KEY=your-api-key \
  -p 8126:8126 \

Run Spring app using this command. You can choose your own service name and environment:

java -javaagent:/path/to/dd-java-agent.jar \
  -Ddd.logs.injection=true \
  -Ddd.service=spring-test \
  -Ddd.env=dev \
  -jar /path/to/fat/spring/app.jar

Double check that you have no logs in Spring app and Datadog Agent container either.

Give them few mins to be uploaded to the server, and go to APM -> Traces page:

Eureka! It works!

Telegram channel

If you still have any questions, feel free to ask me in the comments under this article or write me at

If I saved your day, you can support me 🤝

Leave a Reply

Your email address will not be published. Required fields are marked *