1

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

  1. Azure 函数中的监控是这样工作的吗?因此,将执行标记为错误的唯一方法是抛出未捕获的错误?!?!

  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"
        };

    }
};
4

1 回答 1

2

Azure 函数中的监控是这样工作的吗?那么将执行标记为错误的唯一方法是抛出未捕获的错误?

是的,你是对的,具体可以参考这个问题

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

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

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

结果如下:

在此处输入图像描述

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

1.在 azure 门户 -> 概览刀片 -> 顶部栏上导航到您的应用程序见解(与函数应用关联),单击分析选项。

在此处输入图像描述

于 2019-01-28T07:01:25.250 回答