MiniProfiler / dotnet

A simple but effective mini-profiler for ASP.NET (and Core) websites
https://miniprofiler.com/dotnet/
MIT License
2.9k stars 597 forks source link

DiagnosticSource Compatibility Issue with Azure App Insights #574

Open mellamokb opened 2 years ago

mellamokb commented 2 years ago

Having trouble with an Azure App that broke the Application Insights. In troubleshooting, there is a requirement that the library DiagnosticSource is not included with the app because it can break the Application Insights extension. I notice that MiniProfiler includes a direct dependency on that library and so brings it into the application.

I tried updating to the latest version of DiagnosticSource (5.0.1) and it did not resolve the issue. I've tried building a PostBuild step to delete the file from publish folder and it doesn't work. Trying to remove the .dll manually from the /bin/ folder with Kudu doesn't fix it either. It appears the only way to get Application Insights working is to remove MiniProfiler completely.

Is there any way to resolve this dependency so we can use MiniProfiler in production in a Azure App without breaking Application Insights?

NickCraver commented 2 years ago

Hey @mellamokb Do you have any information on why or how it breaks? I'm a big blind here on what isn't working. This is the first report I've seen of this, so I'm not sure what the conflict is. Do you have a reference/link for that requirement if not be included for example?

mellamokb commented 2 years ago

@NickCraver I wasn't able to find out exactly how or why it broke unfortunately. We are running on Azure App Services, so we don't have full control or insight of the application startup. Also Application Insights was enabled from the Azure App portal rather than deployed manually.

All I know is that in researching the issue, I stumbled on this document which explicitly states that having System.Diagnostics.DiagnosticSource.dll present in the bin folder can cause the Application Insights to fail. I could confirm from the Kudu App Insights monitoring url /AppInsights, that it identified the presence of the dll as the cause of failure for App Insights startup.

I was able to find a workaround, which was simply to forcibly remove the System.Diagnostics.DiagnosticSource nuget from our application, ignoring the dependency for MiniProfiler. From what I can see the removal has not caused any issues in MiniProfiler in either development or production.

Hope this helps.

NickCraver commented 2 years ago

Soooooo since you opened this issue, I joined the App Services team in Azure. Lots going on, but I'll try and find time to repro this and understand what's going on - in a much better position to do so now :)