Why static API for .net core agent?

Hi @Marcin_Druzgala,

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.