Application Insight - 适用于 .NET Core,但不适用于 Service Fabric 中的网站

Application Insight - work for .NET Core, but not for website in Service Fabric

我正在尝试将来自 ServiceFabric 的请求记录到 Application Insight 中,但没有成功。

我构建了两个应用程序,一个是 .NET Core 2.1 WebApi,其中配置了 Application Insight 资源和正确的检测密钥。当我调试它时,requests/exceptions 存储在 Azure 应用程序见解中。

然后我在 ServiceFabric 有一个基本网站。它具有相同的包并配置了相同的应用程序洞察资源,但我从未在 Application Insights 中看到来自 SF 应用程序的任何 requests/exceptions。

两个应用程序都说我已 100% 配置(菜单项目->Application Insights->配置 Application Insights...)并且都在 voting-rg(资源组)中使用 jahav-voting-ai(资源)。

我已经尝试用 https://docs.microsoft.com/en-us/azure/application-insights/app-insights-asp-net-troubleshoot-no-data 但没有成功(可能是因为我对 SF 和 AI 都很陌生)。

Service Fabric 项目没有 the tutorial 中描述的 Microsoft.ApplicationInsights.ServiceFabric.Native,我试过了,但根本没有帮助。

基本上我不知道最基础的.NET Core SF项目中缺少什么才能让它记录requests/exceptions到AI。

我发现了几个使用 .NET Framework 的项目(可以工作并记录 requests/exceptions 到 AI),但没有用于 .NET Core。

The archive with both projects.

TL;DR:将 .UseApplicationInsights() 添加到 WebHost 构建中,以便将 Application Insights 集成到 OWIN 管道中。

Cloud -> ASP.NET Core Web Application 模板和 Cloud->Service Fabric Application[=27] 的方式不同=] 模板在用户添加 Application Insight 遥测时运行。

Cloud -> ASP.NET Core Web Application 模板创建的项目将 .UseApplicationInsights() 添加到 BuildWebHost() 方法中Program.cs,而从 Cloud->Service Fabric Application 模板创建的项目不会。

因此,托管在 Azure 中的 .NET Core 项目确实收集了遥测数据,而 Service Fabric 没有。不同之处在于在构建 Web 主机时缺少使用应用程序洞察力的指令。