We started working with APM agent for .net core (Elastic.Apm.NetCoreAll) and it works nice but I have couple of questions:
Why is everything static? It feels really awkward to use Singletons inside .net core app in 2020 - especially since .net core was build on top of IoC/DI.
It also makes it super hard to unit test code that uses Agent.Tracer.CaptureTransaction or Agent.Tracer.CaptureSpan (it is almost impossible to be honest - we have to refactor code to use the hack Mock an APM instance).
How will that singleton behave if we are using the APM tracing not only for http requests but also for rabbitmq events - since everything is a singleton is there a chance that by accessing agent singleton instance while we have both rabbitmq and http in progress might be problematic?
I wrote about why we need a singleton here. If we let users new up tons of agent instances then it'd open up lots of other issues.
It also makes it super hard to unit test code that uses Agent.Tracer.CaptureTransaction or Agent.Tracer.CaptureSpan (it is almost impossible to be honest - we have to refactor code to use the hack Mock an APM instance).
One suggestion I can give you is that you could just inject the ITracer instance (that's the Agent.Tracer) into the classes you test and in a test environment just set it to null and use it with ?. in your code. That way if it's not prod and the agent is not configured there won't be traces and the API won't do anything.
How will that singleton behave if we are using the APM tracing not only for http requests but also for rabbitmq events - since everything is a singleton is there a chance that by accessing agent singleton instance while we have both rabbitmq and http in progress might be problematic?
I don't think it'd be problematic, in fact in order to correlate all the spans we can't have independent agent instances. If you'd have 2 independent agent instances for the 2 libraries it'd be even harder to correlate them.
Now, having said that - there are already some issues in the agent repo around this topic to make some improvements. This one is an example.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.