我正在运行以下简单功能来检查功能应用程序中的监控工作方式。如果我的函数在监控部分(以及随后的应用程序洞察力)中返回“400”状态代码,它会将执行标记为成功。此外,如果它抛出并捕获错误,仍然标记为成功。如果它抛出错误但没有捕获它,那么它会检测并将其计为错误(但这种情况并不常见,因为在实际应用中,可能的错误总是需要被捕获)。
Azure 函数中的监控是这样工作的吗?因此,将执行标记为错误的唯一方法是抛出未捕获的错误?!?!
在 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"
};
}
};