【App Service】排查App Service中发送Application Insights日志数据问题的神级脚本: Test-AppInsightsTelemetryFlow.ps1

【App Service】排查App Service中发送Application Insights日志数据问题的神级脚本: Test-AppInsightsTelemetryFlow.ps1

问题描述

在 Azure Application Insights 故障排查过程中,经常会遇到这样一类典型问题:

  • SDK 已经部署
  • Connection String 已配置
  • 应用运行正常
  • 但 App Insights Portal 中完全没有任何日志数据(指标,请求记录,应用中输出的日志)

我们通常会问一个问题:“我的代码到底有没有成功把日志数据发到 Application Insights?”

遗憾的是,而我们几乎无法确定,且没有有效的工具来帮助定位问题,到底这个问题发生在那里呢?

问题解答

非常好的消息是,微软Application Insights团队提供了一个神级脚本 (Test-AppInsightsTelemetryFlow.ps1) , 可以在你的应用环境中通过执行PowerShell脚本来监测日志收集过程中的全部环节。

它的官方介绍:https://github.com/microsoft/appinsights-telemetry-flow

适用于 Azure Application Insights 的自助诊断脚本。

直接在运行您的应用程序的机器上,验证连接性、TLS、AMPLS/Private Link、数据引入、采样、工作区健康状况以及代理安装。

支持 PowerShell(Windows)和 Bash(Linux)。

遥测流程概览

从宏观层面来看,遥测数据从您的应用程序(或此诊断脚本)出发,依次流经以下阶段:

image

每个方框代表一个层,该层可能会独立发生故障、性能下降或静默丢失数据。脚本会从上到下测试每一层。

要详细了解每一层的功能、故障原因以及脚本如何检测故障,请参阅官方文档中的架构介绍部分:https://github.com/microsoft/appinsights-telemetry-flow/blob/main/docs/architecture.md, 本文主要是通过在中国区Azure的App Service上演示如何使用这个神级脚本:Test-AppInsightsTelemetryFlow.ps1

实际演示

第一步:登录App Service的Kudu站点( https://.scm.chinacloudsites.cn ),进入Debug Console Powershell

使用脚本尝试下载脚本Test-AppInsightsTelemetryFlow.ps1

Invoke-WebRequest -Uri "https://raw.githubusercontent.com/microsoft/appinsights-telemetry-flow/main/powershell/Test-AppInsightsTelemetryFlow.ps1" -OutFile "Test-AppInsightsTelemetryFlow.ps1"

因为中国区Azure App Service的所在的环境访问github会出现连不上的情况,所以可以在一个稳定访问github的环境中下载这个脚本文件后,直接拖拽到App Service上或通过新建文件把脚本内容复制上去也可。

PS: 也可以从这里下载脚本文件:https://files.cnblogs.com/files/lulight/Test-AppInsightsTelemetryFlow.zip?t=1776861726&download=true

image

第二步:直接运行 .\Test-AppInsightsTelemetryFlow.ps1 并检查运行结果

执行  .\Test-AppInsightsTelemetryFlow.ps1  或者  .\Test-AppInsightsTelemetryFlow.ps1 -AutoApprove

然后进入Application Insights中查看 availabilityResults 中是否有数据

image

演示动画

test ai telementry flow

参考资料

Application Insights Telemetry Flow Troubleshooters :https://github.com/microsoft/appinsights-telemetry-flow

正在加载评论...