How does an APM work?
I am looking for the technical nitty-gritty. How does, for example, NewRelic able to tell you how much time a request took and then give a breakup as well about which component took how much time.
for e.g this image gives you a breakup about the Application(Java) along with Redis, MySQL, and the time time taken by the web server as well.
How does a language application agent get all this information?
2
Answers
For anyone who is looking for more details, here is how (in general) an APM agent works. https://www.elastic.co/guide/en/apm/agent/python/current/how-the-agent-works.html
The New Relic Java agent instruments the application classes, that is, it modifies the bytecode of those classes. The code that is added gathers the data and sends it to some background services that the agent spawns. Then there is a periodical harvest of that data which sends it to the New Relic backend.
It uses the javaagent functionality of the JVM (check the package java.lang.instrument). To make the bytecode manipulation simpler, it uses the ASM library.
It is open source, though it is not a trivial read. Check it out on the Github repo.
Note that other languages’ agents may work differently.