Reputation: 342
How NewRelic .NET agent works in its core? Is it some kind of IIS module or NewRelic agent attaches to CLR in some way?
E.g. how it knows that some request is external if it runs through HttpClient?
Upvotes: 2
Views: 1310
Reputation: 597
All of the APM tools which monitor .NET (the leaders are AppDynamics, New Relic, and Dynatrace) do essentially the same thing. In order to collect data from the CLR they use the profiling APIs https://msdn.microsoft.com/en-us/library/bb384493(v=vs.110).aspx but the trick is doing this while minimizing overhead. You must instrument in a smart way, to avoid causing performance issues. The more advanced products will also do code injection (we do this at AppDynamics for example) here is a sample app for adding your own code in at runtime. https://www.codeproject.com/Articles/463508/NET-CLR-Injection-Modify-IL-Code-during-Run-time
They also combine this with collecting data via WMI across the OS, .NET runtimes, IIS, and others.
You can see APM tools are very complex, doing this at scale in production with low overhead is a challenge. Oh yeah, remember you can't break anything either. This is the reason it takes years to build a good APM product. If you have specific questions within the APIs, I can explain more how we do it at AppDynamics at least :)
Upvotes: 3