当我在 App insights 中打开实时指标时,为什么会出现“不可用:您的应用程序处于离线状态或使用较旧的 SDK”?

Why do i get "Not available: your app is offline or using an older SDK' when i turn on live metrics in App insights?

我在我的 Web 应用程序中打开了 Application Insights,但是当我转到 Application Insights 中的实时指标时,我收到上述错误“不可用:您的应用程序处于脱机状态或使用较旧的 SDK”。

我需要在 Azure 中打开什么? 任何帮助或指导将不胜感激

您可以使用最新的应用程序洞察包进行​​试用,或者降级。如果它不起作用,你最好提交支持票。

作为解决方法,您可以在 Azure 门户的应用程序洞察中使用日志功能或搜索功能。从那里,您还可以看到这些日志。

我在 Azure 门户中遇到了同样的问题和消息,App Insights、实时指标和应用程序地图无法正常工作。在浏览了几个解决方案描述后,我想给你我的解决方案的本质。

首先:我从头开始,直截了当。我没有防火墙问题。 但是除了 social.msdn.com 上的答案之外,我还会更详细地告诉您我的方法。 请注意:此解决方案是使用 .Net 6.0 和 EF 6.0 开发和测试的。

我需要设置使用 Azure Web 应用程序的所有先决条件!

我做到了

  1. 为 运行使用 azure cli 的网络应用程序设置必要的 azure 资源(有很多资源可以帮助您四处走动)
  2. 一个简单的 .Net 6 Web 应用程序,可以发布到 azure web 应用程序
  3. 在 Azure 中设置应用程序见解
  4. 将应用见解与 Azure 中的 Web 应用相连接
  5. dotnet 发布
  6. 运行 网络应用程序 (.azurewebsites.net)

我将以下代码添加到我的 .Net 6 Web 应用启动 Class 以启用 Application Insights 遥测

...
public void ConfigureServices(IServiceCollection services)
{
    // The following line enables Application Insights telemetry collection*
    services.AddApplicationInsightsTelemetry();
}...

因此 Nuget 包

Microsoft.ApplicationInsights.AspNetCore (for me v2.20.0)

需要安装。

在那之后仍然没有数据发送到遥测。

实时指标说: “不可用:您的应用程序处于离线状态或使用较旧的 SDK” 应用程序地图未显示任何内容

您需要更多的 Nuget 包:

Microsoft.ApplicationInsights.PerfCounterCollector (v2.20.0)

Microsoft.ApplicationInsights.Web (v2.20.0)

在那之后仍然没有数据发送到遥测。

最后但最不重要的是我的错: 在为开发人员重新部署我的 azure 设置后(全部由 Infrastructure 作为代码),Application Insights InstrumentationKey 发生了变化。 因此,请始终确保在 appsettings.json.

中正确设置了 InstrumentationKey 和 ConnectionString
{
"ApplicationInsights": {
    "InstrumentationKey": "GUID",
    "ConnectionString": "InstrumentationKey=GUID;IngestionEndpoint=https://<location>.in.applicationinsights.azure.com/"
  }...
}

您可以在 Azure 门户中的 Application Insights 的概览边栏选项卡中找到 instrumentationKey,也可以使用 azure cli

az monitor app-insights component show --app yourappinsightsname -g yourressourcegrouname --query instrumentationKey -o tsv

提示:如果您使用 Visual Studio(在我的例子中是 2022)连接 Application Insights,它会自动将 Application Insights 配置插入到您的 appsettings.json。如果你使用 appsettings.{env}.json 确保 你让他们改变也需要 id。

所有结果

ApplicationInsights 在本地工作(当在 appsetting.development.json 中设置时) 应用地图 - 现在工作 实时指标 - 正在运行

希望它对我有帮助!