apm-agent-dotnet
apm-agent-dotnet copied to clipboard
[BUG] Not able to track current Subscribed Listeners in APM Agent
APM Agent version
1.16.0.0
Environment
All environments
Operating system and version: Windows
.NET Framework/Core name and version (e.g. .NET 4.6.1, NET Core 3.1.100) : NET 4.8
Application Target Framework(s) (e.g. net461, netcoreapp3.1): Web App, WCF
Describe the bug
There is no problem or bug in the behavior but I think there is a lack of functionality of the agent itself. We are using many legacy projects with multiple services where we have to explicitly subscribe to SqlClientDiagnosticSubscriber on each project or webservice. This exposes us to duplicate subscriptions that will cause repeating logging records in APM. Is there a way to track the current subscribed listeners? If not, is there an elegant way to implement such tracking?
To Reproduce
Steps to reproduce the behavior:
Using public API subscribe to SqlClientDiagnosticSubscriber in multiple different webservices/projects. See duplicate logging records in APM service log Determine ways to see if Agent is already subscribed to SqlClientDiagnosticSubscriber
Expected behavior
Every time you subscribe to SqlClientDiagnosticSubscriber it will create another span in transaction. We either need to avoid duplication (like with HttpDiagnosticSubscriber) or have ability to track what Agent is currently subscribed to.
@gregkalapos any thoughts on that?
Hi @luchkax
thanks for reporting.
tldr: at this point there isn't an out-of-the-box way to track the list of subscribed listeners. What you can do is to just introduce a flag in your code and set it once you subscribed and check on that flag in the next time. That's currently the only way to keep track of this.
Having said that, there is actually handling of this in the agent code already - by default each listener can only subscribe once - the second try will just skip the subscription. Here is the flag for it. The unfortunate thing in your specific case is that SqlClientDiagnosticSubscriber
allows multiple subscription, that is because there are multiple events it tracks.
I will leave this issue open, we can tackle this long term. This will happen in the future, so far we have lots of other issues with higher priority.