I am sure, you must be aware of Datadog. Datadog is infrastructure monitoring as a service. Read more here: datadog.com

Ever wondered how Datadog agent works? We use Datadog in SAS CI360 to monitor our infrastructure. It provides quite a lot of features like APN, distributed tracing, etc.

But, how Datadog knows all the information about your service without adding any code to our microservices? We need to include a Datadog agent in our JVM startup. But how does it work?

There is a concept called “Java instrumentation” that lets you modify the bytecode on the fly! It is quite a powerful utility to achieve a lot of work. Feel free to take a look at the Java documentation on this topic.

Datadog agent code is available on GitHub, you can see how they can intercept the calls to AWS and get the information about it from this source file.

The aim of this post is just to make you aware of how these things work, and we usually don’t care. I was discussing this with one of my colleagues and we were curious to know how it is able to intercept all our calls. So decided to find out. Hope this is helpful.

There can be many use cases:

  1. Adding some security headers in all the outgoing call.
  2. Distributed tracing
  3. Adding some information in MDC logging like tenant, etc.
  4. Mocking

How about performance implications? TODO

If you are further interested in learning more please see the below articles:

  1. Dynatrace has a really good article on this topic: https://www.dynatrace.com/resources/ebooks/javabook/collecting-performance-data/
  2. The Datadog documentation itself is good: https://docs.datadoghq.com/tracing/setup_overview/setup/java/
  3. Java Junit coverage tool such as Jacoco works on the same technology https://www.jacoco.org/jacoco/trunk/doc/implementation.html