我正在使用 ARM 脚本来部署包含应用服务的资源组。该部署包含以下资源:
Microsoft.Insights/components
Microsoft.KeyVault/vaults
Microsoft.Storage/storageAccounts
Microsoft.Web/serverfarms
Microsoft.Web/sites
我可以使用类似以下查询的方式在 Application Insights 中查看函数跟踪:
traces
| order by timestamp desc
| where message contains 'telemetry'
我不知道是否相关,但在应用服务概述页面中,我确实看到以下警告:
Storage is not configured properly, Function scaling will be limited. Click to learn more.
我使用以下应用服务应用程序设置将其连接到 App Insights:
APPINSIGHT_INSTRUMENTATIONKEY: <instrumentation key from app insights>
AzureWebJobsDashboard: <storage acct connect string>
AzureWebJobsStorage: <storage acct connect string>
FUNCTIONS_EXTENSION_VERSION ~3
FUNCTIONS_WORKER_RUNTIME dotnet
存储帐户具有以下自动创建的对象。
BLOB <name>-leases
BLOB azure-webjobs-hosts
BLOB azure-webjobs-secrets
QUEUES <name>-control-[00,01,02,03]
QUEUES <name>-workitems
TABLE <name>History
TABLE <name>Instances
TABLE AzureWebJobsHostLogs202008
TABLE AzureWebJobsHostLogscommon
这是我的hosts.json:
{
"version": "2.0",
"logging": {
"fileLoggingMode": "always",
"logLevel": {
"default": "Debug",
"Host.Results": "Error",
"Function": "Trace",
"Host.Aggregator": "Trace"
}
}
}
host.json
中,对于字段“Function”,将其值设置为Trace。然后就可以登录应用洞察了。Azure function v2 的示例
host.json
,可以将跟踪消息记录到 Application Insights:
{
"version": "2.0",
"logging": {
"fileLoggingMode": "always",
"logLevel": {
"default": "Information",
"Host.Results": "Error",
"Function": "Trace",
"Host.Aggregator": "Trace"
}
}
}
在 Azure 门户中,导航到函数应用 -> 在函数应用设置中,然后将日志级别更改为在 host.json 中进行跟踪。有关更多详细信息,请参阅这篇
注意:app Insight 和 Monitor 中的调用日志有延迟时间。操作完成后,等待5分钟再检查。您可以先去应用程序洞察检查。如果app Insight没有日志,Monitor就不会有。
host.json 中显式禁用应用程序洞察采样设置可以修复此问题
{
"version": "2.0",
"logging": {
"fileLoggingMode": "always",
"applicationInsights": {
"samplingSettings": {
"isEnabled": false
}
},
"logLevel": {
"default": "Debug",
"Host.Results": "Error",
"Function": "Trace",
"Host.Aggregator": "Trace",
}
}
}
域被我的广告拦截器拦截了。这导致对 Application Insights API 的请求失败,使得调用看起来好像未在监视器页面上加载。
将这些域列入白名单后,调用日志再次在 Azure 门户中可见:
*.applicationinsights.io
*.loganalytics.io