c# - Application Insights 异常和故障

标签 c# asp.net azure visual-studio-2015 azure-application-insights

我正在尝试在 Azure 预览门户和 Visual Studio 2015 社区版中使用 Application Insights。我遇到了三个不同的问题,我怀疑它们都是相关的。我想知道其他人是否遇到这些问题。

在我的一个测试 Web 应用程序中,App-Insight 工具部分工作。在另一个中,我收到有关无法检索的数据的错误。在第三个中,当我将 App-Insight 与新资源组中的资源一起使用时,我遇到了部署失败。

我将在这个问题中介绍所有三个,因为我怀疑它们可能都有相同的根本原因。

部分结果

我尝试用 app-insight 改造的第一个应用程序确实可以工作并显示 app-insight 遥测……或者至少它大部分都可以工作。一半的遥测数据显示,其余的没有。

telemetry

设置顺序如下:

我从安装 sample Mobile-MVC app that came with this MSDN Magazine article 开始,从 2015 年 6 月开始。在摆弄添加 bootstrap 以制作响应式页面之后,我决定将代码提交到 VS 在线 GIT,然后部署为 Azure Web 应用程序。

然后我按照说明操作 View logs in Application Insights并运行成功启动浏览器并允许我与站点交互的应用程序。但是,在本练习中,我在 Visual Studio 输出窗口中看到了大量异常。我在这里包含了一个小片段,其中我将最有趣的两部分加粗:

Exception thrown: 'System.MethodAccessException' in Microsoft.ApplicationInsights.Extensibility.DependencyCollector.dll Exception thrown: 'System.TypeInitializationException' in Microsoft.ApplicationInsights.Extensibility.DependencyCollector.dll Exception thrown: 'System.TypeInitializationException' in Microsoft.ApplicationInsights.Extensibility.DependencyCollector.dll ApplicationInsightsHttpModule failed at initialization with exception: System.TypeInitializationException: The type initializer for 'Microsoft.ApplicationInsights.Extensibility.DependencyCollector.Tracing.DependencyCollectorEventSource' threw an exception. ---> System.MethodAccessException: Attempt by method 'Microsoft.ApplicationInsights.Extensibility.DependencyCollector.Tracing.DependencyCollectorEventSource..ctor()' to access method 'Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing.ApplicationNameProvider..ctor()' failed.
at Microsoft.ApplicationInsights.Extensibility.DependencyCollector.Tracing.DependencyCollectorEventSource..ctor() at Microsoft.ApplicationInsights.Extensibility.DependencyCollector.Tracing.DependencyCollectorEventSource..cctor() --- End of inner exception stack trace --- at Microsoft.ApplicationInsights.Extensibility.DependencyCollector.DependencyTrackingTelemetryModule.Initialize(TelemetryConfiguration configuration) at Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryConfigurationFactory.InitializeComponents(IEnumerable components, TelemetryConfiguration configuration) at Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryConfigurationFactory.InitializeComponents(TelemetryConfiguration configuration) at Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryConfigurationFactory.Initialize(TelemetryConfiguration configuration) at Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.get_Active() at Microsoft.ApplicationInsights.Extensibility.Web.ApplicationInsightsHttpModule..ctor()

[msg=Log Error];[msg=System.TypeLoadException: Could not load type 'Microsoft.ApplicationInsights.Channel.JsonSerializer' from assembly 'Microsoft.ApplicationInsights, Version=1.2.0.5639, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. at Microsoft.ApplicationInsights.Extensibility.Web.Implementation.TelemetrySerializer.d__0.MoveNext() at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine) at Microsoft.ApplicationInsights.Extensibility.Web.Implementation.TelemetrySerializer.SerializeAsync(IEnumerable1 items) at Microsoft.ApplicationInsights.Extensibility.Web.Implementation.TelemetryBuffer.<>c__DisplayClass5.<FlushAsync>b__3() at System.Threading.Tasks.Task1.InnerInvoke() at System.Threading.Tasks.Task.Execute() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.ApplicationInsights.Extensibility.Web.Implementation.TelemetryBuffer.d__7.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.ApplicationInsights.Extensibility.Implementation.TaskTimer.<>c__DisplayClass1.<b__0>d__3.MoveNext()]



我的 Azure 门户正在接收有关某些事物的遥测数据,但不会接收其他事物的遥测数据。简而言之,正如上述异常(exception)所表明的那样,产生遥测的能力被削弱了。

现在解决下一个问题。

新资源组

使用预览门户,我创建了一个名为“SandBox”的全新资源组。再次使用预览门户,然后我创建了一个名为“ScratchWeb”的全新 Web 应用程序,我将其分配给了“沙盒”资源组。

Web 资源的部署最终完成,但有一个名为“Microsoft.WebSite3cb98c31-893c”的关联应用程序洞察资源会自动创建,该资源在最终被声明为部署失败之前会遇到十几个超时错误.下面我展示了一个超时错误的示例,以及提供一些关键信息的最终错误。
Operation Id
1E2094CECE6531F1
Tracking Id
31283062-9061-4dcf-bd42-f9885abbf596
Status
GatewayTimeout
Provisioning State
Running
Timestamp
‎9‎/‎28‎/‎2015‎ ‎10‎:‎37‎:‎59‎ ‎PM
Duration
PT30.7117477S
Type
microsoft.insights/components
Resource Id
/subscriptions/da769a1f-78d8-4d45-b9b3-c15ea0c89ca2/resourceGroups/SandBox/providers/microsoft.insights/components/ScratchWeb
StatusMessage
{"code":"GatewayTimeout","message":"Request timed out","innererror":{"diagnosticcontext":"034b642f-aece-494b-9ede-f8b015f5bfeb","time":"2015-09-29T05:37:59.8355234Z","data":"d0fe44bb-8317-4359-bf2c-160f1eb00433"}}
Resource
ScratchWeb

这是最终的失败错误消息:
Operation Id
1E2094CECE6531F1
Tracking Id
08dbbf0a-0d4a-4692-9b1a-3603a984d40d
Status
Conflict
Provisioning State
Failed
Timestamp
‎9‎/‎28‎/‎2015‎ ‎10‎:‎48‎:‎16‎ ‎PM
Duration
PT10M47.5300298S
Type
microsoft.insights/components
Resource Id
/subscriptions/da769a1f-78d8-4d45-b9b3-c15ea0c89ca2/resourceGroups/SandBox/providers/microsoft.insights/components/ScratchWeb
StatusMessage
{"code":"The component already existed in a different resource group.","message":"The component already existed in a different resource group.","innererror":{"diagnosticcontext":"9ea42d3d-4dbf-46e8-a188-eac09a4ddb09","time":"2015-09-29T05:48:15.7282268Z"}}
Resource
ScratchWeb

这是因为“Application Insights”预览无法在多个资源组中运行,还是因为我的订阅不允许?

最奇怪的是,一旦 app-insights 资源的部署最终失败,它似乎已经创建并且在我的 Application Insights 资源集合中不可见。

现在最后一个问题...

原始资源组

如果我尝试在我现有的默认 Web 应用程序资源组中创建一个新网站...那么上述问题都不会发生。不幸的是,我遇到了另一个问题。 “应用程序洞察”资源 Blade 在尝试向我显示图表时告诉我“检索数据时出错”。另一方面,Visual Studio 告诉我一切都很好......它说的是“恭喜你,你已经发布了你的第一个应用洞察数据”。

no data
no data

所以,最后,我只有一个具有可查看 App-Insight 结果的 Web 应用程序,而这些结果是残缺的。无论我是使用现有资源组还是尝试新的资源组,我尝试使用 app-insight 创建第二个可运行的 Web 应用程序均未成功。

在 Visual Studio 2015 中,我使用了两种不同的方法来尝试添加 App-Insight SDK。我尝试在事后将它添加到我的 Web 项目中,并且我还尝试从新的项目模板中添加它。唯一能让我工作的场景是当我“事后”使用 App-Insight SDK 检测我的第一个 Web 应用程序时。不幸的是(1)这些结果被削弱了,(2)正如我上面描述的那样,我第二次甚至无法获得“削弱”的结果。因此,现在 App-Insight 功能对我来说是行不通的。

最佳答案

尝试删除对 Application Insights 的所有引用,清理项目。然后添加 NuGet 包 Microsoft.ApplicationInsights.Web ,当前版本为 1.2.1。

PM> Install-Package Microsoft.ApplicationInsights.Web

这将安装所有必需的依赖项。安装后,在您的订阅中创建 Application Insights 资源(按照 Add Application Insights SDK to monitor your ASP.NET app 中的说明进行操作)并将 Instrumentation key 添加到您的应用程序。我建议将检测 key 放在您的 web.config 设置中:
  <appSettings>
    <add key="AppInsightsInstrumentationKey" value="your-key-value" />
  </appSettings>

并将其添加到您的应用程序 Application_Start喜欢:
TelemetryConfiguration.Active.InstrumentationKey = ConfigurationManager.AppSettings["AppInsightsInstrumentationKey"] ?? "some-default-key";

更新 ---

更多故障排除信息here .
  • 如果未记录浏览器事件:
  • 如果您的浏览器客户端前面有防火墙,您可能必须打开 TCP 端口 80 和 443 才能将流量传到 dc.services.visualstudio.com 和 f5.services.visualstudio.com。
  • 在您的浏览器开发人员工具中,查找网络选项卡上的“跟踪”条目 - 它应该将数据发布到 https://dc.services.visualstudio.com/v2/track (或 fc...)
  • 如果服务器数据未记录:
  • 通过 Azure Portal 安装 Application Insights :浏览到您的 WebApp >> 工具 >> 扩展,然后安装 Application Insights 扩展。
  • 关于c# - Application Insights 异常和故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32854509/

    相关文章:

    .net - 从头开始 Azure .NET 后端?

    c# - 更改 FirstPersonController MouseLook 灵敏度

    C#正则表达式提取一个div的内容

    javascript - 如何将 JavaScript 结果绑定(bind)到我页面上的 div?

    c# - 如果是第一个或最后一个,则更改转发器 li 项目类

    javascript - D3 折线图不清晰

    azure - 为什么 Azure 计算机视觉服务对为图像生成的标题给出的置信度分数较低?

    azure - 在 Azure B2C 自定义策略中使用策略 key

    c# - 使用 System.Uri 附加多个段

    c# - asp.net 中的 View 状态和自定义控件