Let’s start with “why” should one even bother with setting up Datadog on the local machine. I can share my motivation to set it up

My strong ‘why’:trying to make sense of the flaky tests:

We had an extensive end-to-end test suite with high coverage. But sadly, the tests grew flakier and flakier over time. To my dismay, when the tests were run in isolation, they’d pass. When we ran the entire test suite, many tests would start failing. The application logs corresponding to the tests should help us debug. But I couldn’t even understand where the logs for a particular test started and ended, let alone make sense of them.

Datadog to the rescue 🦸!

We have been using Datadog in our project to visualize the production logs and we found it super useful. That’s when I had an epiphany! What if I set up Datadog locally to dissect these logs? And that’s what triggered the contents of this blog post.

Our application is written in Java and my local machine runs on MacOS. You could tweak the below steps to suit your need.

What do you need to set up:

  1. Sign up for Datadog here. Our scope here is only local debugging, so a free trial should suffice.
  2. Datadog Agent is the software that monitors the host on which it runs. Settings like service name, environment, etc. can be made in the agent.
  3. dd-trace-java, Datadog's APM (App Performance Monitoring) client Java library. dd-trace-java is a jar that contains APIs to automatically or manually trace and profile Java applications.

Step 1 — Sign up process:

Step 2— Datadog Agent Installation:

For MacOS, you could install via brew (package manager for MacOS). Use the commands given here for installation. ¹

Step 3 — Install Datadog tracer:

Running your application:

-javaagent:"/Users/home/Downloads/dd-java-agent.jar" -Ddd.profiling.enabled=true -Ddd.logs.injection=true -Ddd.agent.port=8126 -Ddd.service=ecommerce-service -Ddd.env=local -XX:FlightRecorderOptions=stackdepth=256

jvmArgs = ["-javaagent:/Users/home/Downloads/dd-java-agent.jar", "-XX:FlightRecorderOptions=stackdepth=256", "-Ddd.profiling.enabled=true", "-Ddd.logs.injection=true", "-Ddd.agent.port=8126", "-Ddd.service=ecommerce-service", "-Ddd.env=local"]

Logging in Datadog:

Some Tips:

Conclusion:

Once I had the Datadog agent up and running locally, I was able to view all the requests contextually.

And voila! All of my end-to-end tests are passing now 🙂 Happy logging!

Additional Info: