启用 Application Insights 会使 Web 应用程序挂起

Enabling Application Insights makes the Web App hang

在我的 Web 项目上启用 Application Insights 后,它对几个请求运行正常,但随后所有请求都无限期挂起。这是 运行 在本地使用 Visual Studio 调试器。使用提琴手我可以看到一个请求正在等待一个永远不会到来的响应。没有错误。最终 Visual Studio 也挂起,我需要杀死它。

我正在使用 Visual Studio 2013 更新 4。 我确实右键单击了我的 Web 项目,然后单击添加 Application Insights 遥测。 接下来,我从 ApplicationInsights.config 中删除了 Instrumentation Key,因为我不想将遥测用于本地开发。 Instrumentation Key 将在实时应用程序的 Azure 应用程序设置中设置。

如果我在没有 Application Insights 的情况下恢复原状,我不会挂起。

有什么想法吗? 谢谢!

[编辑]

之前的修复程序起初似乎有效,但真正起作用的是从 ApplicationInsights.config.

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

[旧答案]

如果未提供仪器密钥,则禁用遥测确实可以解决问题。

我有点期待这是在幕后完成的,但似乎不是。

我把这段代码放在 global.asax Application_Start 方法中:

if (string.IsNullOrEmpty(WebConfigurationManager.AppSettings["APPINSIGHTS_INSTRUMENTATIONKEY"]))
{
    Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.DisableTelemetry = true;
}

我不想窃取其他答案的任何功劳,但我想详细说明我的评论。我重新安装了 Visual Studio(我知道这是不可能的)但问题仍然存在。似乎当将 AI 的 HTTP 模块加载到 IIS Express 中时,事情进展得很快,所以我不得不求助于仅在 运行 发布配置时加载这些模块。

这意味着更新您的 web.config 以删除 AI 语句,并将它们移动到 Web.Release.config 作为转换,以便在构建发布配置时加载它们:

但是请注意,自该答案发布以来,程序集已更改。这是我需要添加的内容:

  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
    <httpModules>
      <!-- Enable application insights when running in release mode (it don't work right locally...) -->
      <!--  -->
      <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...) -->
      <!--  -->
      <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>

我是 运行 2.0.0-rc1 并且遇到了这个问题。在 ApplicationInsights.config 中注释这行代码也解决了这个问题。

<Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.PerformanceCollectorModule, Microsoft.AI.PerfCounterCollector">

将 Application Insights 升级到 2.0.0 也解决了我的问题。谢谢阿纳斯塔西娅和艾伦!