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.
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:
- Adding some security headers in all the outgoing call.
- Distributed tracing
- Adding some information in MDC logging like tenant, etc.
How about performance implications? TODO
If you are further interested in learning more please see the below articles:
- Dynatrace has a really good article on this topic: https://www.dynatrace.com/resources/ebooks/javabook/collecting-performance-data/
- The Datadog documentation itself is good: https://docs.datadoghq.com/tracing/setup_overview/setup/java/
- Java Junit coverage tool such as Jacoco works on the same technology https://www.jacoco.org/jacoco/trunk/doc/implementation.html