elastic / apm-agent-dotnet

https://www.elastic.co/guide/en/apm/agent/dotnet/current/index.html
Apache License 2.0
581 stars 207 forks source link

Support for .net WCF using .net Standard IServiceProvider #933

Open no1ross opened 4 years ago

no1ross commented 4 years ago

Is your feature request related to a problem? Please describe. I'm designing a framework that serves both .net Core and .net Framework WCF services. The base framework is designed with .net Standard 2.0/2.1, and has 2 host libraries, 1 for .net Core and 1 for .net Framework WCF, they both share at least 20 modules/clients that do various tasks. The framework works great, we have data/rule/content/mongo/elastic etc. clients, also many modules that do logging/caching/proccessing/interception etc.

I have started to integrate APM into the WCF project and have had many issues. First issue is that for some reason the APM agent is always initialized no matter how i try to initialize it. We need to be able to specify the IApmLogger and IConfigurationReader, as even though this is a WCF service we use the application.json files to load configuration. I have pretty much removed the need to read from a web.config as our CI process prefers tokenized json files rather xpaths in a config file.

Describe the solution you'd like A way to start APM with the specific configuration and logger while creating the IServiceProvider in a WCF project. We don't have access to IApplicationBuilder like in a .net core app, all have access to is new IServiceCollection. There needs to be a more .net standard friendly way of initializing the apm agent for .net framework wcf application. For some reason even when using the web.config, the agent was always trying to initialize from env varaiables, why can't we tell the .net framework agent that i want to use the IConfiguration for the configuration at all time and never look at env or web.config...

Describe alternatives you've considered As above i tried to create my own agent, but that was a no go :(.

Additional context Consumers of this agent need the ability to customize it to their needs, I was planning to go to production with this in October, but now things are delayed due to the fact that the current implementation does not support our needs.

no1ross commented 4 years ago

To add I would prefer to add the IHttpModule to the IServiceCollection in the Application_Start(), then in the Init() of the HttpApplication do module.Init(this); LIke I said i want to remove the need for web.config. I think the bottom line is we need more flexibility in how we use this agent.

russcam commented 2 years ago

@no1ross instrumenting WCF more generally is something that we could tackle with profiler auto instrumentation: #1534, instrumenting around ChannelHandler's HandleRequest method