Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling Application Insights makes the Web App hang

After enabling Application Insights on my Web project, it runs ok for a couple of requests, but then all requests hang indefinitely. This is running locally using the Visual Studio debugger. Using fiddler I can see that a requests are waiting for a response, which never come. There is no error. Eventually Visual Studio also hangs and I need to kill it.

I'm using Visual Studio 2013 update 4. I did right-click on my web project, and click Add Application Insights Telemetry. Next I removed the Instrumentation Key from the ApplicationInsights.config, since I don't want telemetry for local development. The Instrumentation Key will be set in the Azure App Settings for the live application.

If I revert back without Application Insights, I get no hanging.

Any ideas ? Thanks!

like image 374
Guillaume Morin Avatar asked Nov 22 '15 15:11

Guillaume Morin


People also ask

Does application Insights affect performance?

The Application Insights SDK and instrumentation is designed to be extremely lightweight and have minimal impact on the performance of your application.

What is the purpose of implementing application Insights?

Application Insights is a feature of Azure Monitor that provides extensible application performance management (APM) and monitoring for live web apps. Developers and DevOps professionals can use Application Insights to: Automatically detect performance anomalies. Help diagnose issues by using powerful analytics tools.

How do I enable Insights for web app?

Select File | New Project. Select Visual C# | . NET Core | ASP.NET Core Web Application, ensure to mark the checkbox Add Application Insights to Project. Click Ok on the next screen.

How do I enable application insights on the web app?

Enabling the application insights on the web app through the portal does this in the back ground for you. App settings need to be updated with some settings that configures your web app to send its telemetry data to Application Insights. Restart the web app.

How much does application insights cost?

The basic Application Insights pricing plan has no charge until your app has substantial usage. To use Application Insights at run time, you can instrument your web app on the server. This approach is ideal for apps that are already deployed, because it avoids any updates to the app code.

How to enable application insights in powerhell?

Enable the Application Insights Extension in Portal and setup the settings. Get the app settings. Use these app settings when configuring your app settings through powerhell. Delete this webapp.

Where does applicationinsights keep its configuration file?

Application Insights will keep it’s configuration in an ApplicationInsights.config file in your web app root folder and some nuget packages in your App_Data folder and additional dlls in the bin folder. The configuration file, dlls and packages can be be lost when you redeploy.


2 Answers

[EDIT]

The previous fix seemed to work at first, but what really did the trick is to comment out the PerformanceCollectorModule from ApplicationInsights.config.

<TelemetryModules>
    ...
    <!--
    <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.PerformanceCollectorModule, Microsoft.AI.PerfCounterCollector">
    -->
    ...
</TelemetryModules>

[Old Answer]

Disabling telemetry if no Instrument Key is provided does fix the issue.

I kind of expected this was done under the hood, but it seems not.

I put this code in global.asax Application_Start method:

if (string.IsNullOrEmpty(WebConfigurationManager.AppSettings["APPINSIGHTS_INSTRUMENTATIONKEY"]))
{
    Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.DisableTelemetry = true;
}
like image 81
Guillaume Morin Avatar answered Sep 27 '22 22:09

Guillaume Morin


I don't want to steal any credit from another answer, but I wanted to elaborate on my comment. I re-installed Visual Studio (long-shot I know) and still had the issue. It seems that when the HTTP modules for AI are loaded into IIS Express things go south quickly, so I had to resort to only loading those modules when running the release configuration.

This means updating your web.config to remove the AI statements, and instead move them to Web.Release.config as transforms so they're loaded when a release configuration is built:

https://stackoverflow.com/a/27923364/571237

Note however that the assemblies have changed since that answer was posted. Here's what I needed to add:

  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
    <httpModules>
      <!-- Enable application insights when running in release mode (it don't work right locally...) -->
      <!-- https://stackoverflow.com/a/27923364/571237 -->
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
           xdt:Transform="Insert"/>
    </httpModules>
  </system.web>

  <system.webServer>
    <modules>
      <!-- Enable application insights when running in release mode (it don't work right locally...) -->
      <!-- https://stackoverflow.com/a/27923364/571237 -->
      <remove name="ApplicationInsightsWebTracking" xdt:Transform="Insert"/>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" xdt:Transform="Insert" />
    </modules>
  </system.webServer>
like image 32
Sam Storie Avatar answered Sep 27 '22 22:09

Sam Storie