繁体   English   中英

如何使用 Kusto 访问 Azure Function 应用程序代码 logging() 消息?

[英]How to use Kusto to access Azure Function app code logging() message?

I have a Python Azure Function that has a bunch of Python logging.error()/logging.info() messages. 我喜欢这种方法(我对 Python 还很陌生),因为我可以查看运行历史记录并查看有关运行的关键信息。

Azure Function 运行历史如下所示: 在此处输入图像描述

示例 1:

这个 Kusto 查询让我了解了有关给定运行的基础知识,但没有任何细节

requests
| project timestamp, id, operation_Name, success, resultCode, duration, operation_Id, cloud_RoleName, invocationId=customDimensions['InvocationId']
| where timestamp > ago(6d)
| where cloud_RoleName =~ 'functionAppName' and operation_Name =~ 'functionName'
| order by timestamp asc

Output:

在此处输入图像描述

示例 2:

此查询为我提供了我需要的所有详细信息,但我必须定义operation_idInvocationId

union traces
| union exceptions
| where timestamp > ago(30d)
| where operation_Id == '<biglongstring>'
| where customDimensions['InvocationId'] == '<biglongstring1>'
| order by timestamp asc
| project timestamp, message = iff(message != '', message, iff(innermostMessage != '', innermostMessage, customDimensions.['prop__{OriginalFormat}'])), logLevel = customDimensions.['LogLevel']

Output:

在此处输入图像描述

我需要查询在这些logging()消息中找到的特定关键字。

如何使用 Kusto 查询执行此操作?

您可以使用任何字符串搜索运算符,例如“has”。 如果您的日志消息遵循某种约定,您可以使用parse运算符将相关数据提取到列中。

以下是最终为我工作的内容。

| where message contains "specific string in logging" | where message contains "specific string in logging"是关键。 这里的message有我正在寻找的日志记录字符串。

union traces
| union exceptions
| where timestamp > ago(30d)
| where message contains "specific string in logging"
| order by timestamp asc
| project timestamp, message = iff(message != '', message, iff(innermostMessage != '', innermostMessage, customDimensions.['prop__{OriginalFormat}'])), logLevel = customDimensions.['LogLevel']

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM