【Azure 应用程序见解】通过Azure Funciton的门户启用Application Insights后,Application Insights无法收到监控数据 - LuBu0505/My-Code GitHub Wiki

问题描述

比较早期创建的Azure Funciton服务,近期发现在门户中已经启用了Application Insights功能,但是正确配置Applicaiton Insights后,却无法获取关联的Azure Function的监控数据?

问题分析

到目前为止,Azure Function已经经历了三个版本的发展,可以通过 FUNCTIONS_EXTENSION_VERSION 查看当前Azure Funciton的版本:

https://img2020.cnblogs.com/blog/2127802/202104/2127802-20210428133821565-1091706031.png

从官方的文档中,发现Application Insights已经在 Function V1.x, V2.x及V3.x的版本支持了。但是经过实测,V2.x, V3.x都能成功发送监控数据到Application Insights中,而最早的V1.x版本却无法发送监控数据。这与本文问题匹配。

最后经过咨询确认, 在中国区Function V1.X的集成除了要在门户中配置Applcation Insights外,还需要再Funciton的host.json中的applicationInsights一节修改endpoint并指向中国区的终结点:

https://img2020.cnblogs.com/blog/2127802/202104/2127802-20210428134425292-959601714.png

Function host.json示例内容:

{
  "version": "2.0",
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[1.*, 2.0.0)"
  },
  "applicationInsights": {
    "ingestionEndpoint": "https://dc.applicationinsights.azure.cn/v2/track",
    "liveEndpoint": "https://live.applicationinsights.azure.cn/QuickPulseService.svc"
  }
}

问题解决

1) Azure Function 页面中启用Application Insights

https://img2020.cnblogs.com/blog/2127802/202104/2127802-20210428134744232-1262683843.png

2) 修改Funciton的host.json文件,添加applicationInsights,ingestionEndpoint和liveEndpoint

https://img2020.cnblogs.com/blog/2127802/202104/2127802-20210428135249168-1073421166.png

参考资料

如何为 Azure Functions 配置监视: https://docs.azure.cn/zh-cn/azure-functions/configure-monitoring?tabs=v1

Azure Functions 运行时版本概述: https://docs.azure.cn/zh-cn/azure-functions/functions-versions

Application Insights Regions that require endpoint modification: https://docs.microsoft.com/en-us/azure/azure-monitor/app/custom-endpoints?tabs=net#regions-that-require-endpoint-modification