无法查看应用服务功能的调用日志

问题描述 投票:0回答:5
当我将函数代码(运行时版本:3.0.14287.0 (~3))发布到应用服务时,一切似乎都在运行,但我在门户中任何函数的“监控”页面中看不到任何调用日志 - 它始终是空白的。我有计时器触发的功能,应该会显示出来。

我正在使用 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" } } }
    
azure-functions
5个回答
2
投票
在文件

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 中进行跟踪。

有关更多详细信息,请参阅这篇

文章,了解如何设置函数 v1 或 v2 的日志级别。

注意:app Insight 和 Monitor 中的调用日志有延迟时间。操作完成后,等待5分钟再检查。您可以先去应用程序洞察检查。如果app Insight没有日志,Monitor就不会有。


2
投票
我相信这个配置:

"Host.Results": "Error"
您的 host.json logLevel 设置是问题所在。

此设置控制请求的日志记录。

“这些运行时生成的日志指示功能的成功或失败。所有这些日志都是在信息级别写入的。如果您在警告或更高级别进行过滤,您将不会看到任何此类数据。”

请参阅:

https://learn.microsoft.com/en-us/azure/azure-functions/configure-monitoring?tabs=v2

尝试将其设置为“跟踪”,我希望您会看到所有请求的调用日志(而不仅仅是错误)。


0
投票
我发现在

host.json 中显式禁用应用程序洞察采样设置可以修复此问题

{ "version": "2.0", "logging": { "fileLoggingMode": "always", "applicationInsights": { "samplingSettings": { "isEnabled": false } }, "logLevel": { "default": "Debug", "Host.Results": "Error", "Function": "Trace", "Host.Aggregator": "Trace", } } }
    

0
投票
就我而言,此问题是在清理天蓝色服务后开始的。洞察服务需要具有

Log Analytics 工作区 类型的第二种资源。在我的例子中,重新创建分析服务并连接到函数(替换新的连接字符串和密钥)后,调用跟踪显示正常。

Insights required type img


0
投票
如果一切看起来都配置正确,则原因可能出在其他地方。就我而言,一些 Application Insights

域被我的广告拦截器拦截了。这导致对 Application Insights API 的请求失败,使得调用看起来好像未在监视器页面上加载。

将这些域列入白名单后,调用日志再次在 Azure 门户中可见:

*.applicationinsights.io *.loganalytics.io
    
© www.soinside.com 2019 - 2024. All rights reserved.