gpt4 book ai didi

azure - Azure 在监视功能时将什么视为错误?

转载 作者:行者123 更新时间:2023-12-02 06:08:05 25 4
gpt4 key购买 nike

我正在运行以下简单函数来检查功能应用程序中的监控如何工作。如果我的函数在监视部分(以及随后的应用程序洞察)中返回“400”状态代码,则它将标记执行成功。另外,如果它抛出并捕获错误,仍然标记为成功。如果它抛出错误但没有捕获它,那么它会检测并将其计为错误(但这种情况并不常见,因为在实际应用中,总是需要捕获可能的错误)。

  1. 这就是 Azure 函数中的监视方式吗?因此,将执行标记为错误的唯一方法是抛出 Uncaught Error ?!?!

  2. 在 Application Insight 中,是否可以根据请求的响应状态代码对请求进行排序?例如,是否可以查看单个函数返回了多少个 500 请求?

module.exports = async function (context, req) {

if (req.query.name || (req.body && req.body.name)) {
context.res = {
body: "Hello " + (req.query.name || req.body.name)
};
} else {
// only if following line is uncommented, it counts the funciton execution as error
// throw new Error('this is a test error')

try {
throw new Error('this is a test error')
} catch (e) {
// in this case, it counts the function execution as successfull
return context.res = {
status: 500,
body: "caught the internal error"
};
}
// in this case, counts the function execution as successfull
return context.res = {
status: 400,
body: "didn't catch the error. Please pass a name on the query string or in the request body"
};

}
};

最佳答案

Is this how monitoring in Azure functions work? So the only way to mark the execution as faulty is to throw an uncaught error?

是的,你说得对,具体可以引用这个issue .

In Application Insight, is there anyway to sort the requests based on their response status code? For example is there anyway to see how many 500 requests has been returned from an individual function?

您可以使用应用程序洞察分析来归档您的目标,编写如下简单查询:

requests 
| where name ="your function app name"
| where resultCode =="500 or other status code"
| count

结果如下:

enter image description here

注意:如果您不知道如何导航到应用程序洞察分析,请按照以下步骤操作:

1.在 Azure 门户中导航到您的应用程序见解(与函数应用关联) -> 概述边栏选项卡 -> 在顶部栏上,单击“分析”选项。

enter image description here

关于azure - Azure 在监视功能时将什么视为错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54371350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com