这是 Application Insight/Azure Functions 错误吗?或者我的理解不正确 [英] Is this Application Insight / Azure Functions Bug? or My understanding is incorrect

查看:12
本文介绍了这是 Application Insight/Azure Functions 错误吗?或者我的理解不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我将我的 Azure 功能与应用程序洞察力集成以进行应用程序日志记录,尤其是捕获错误堆栈跟踪.

Today I integrate my Azure function with Application insight for application logging, especially to capture error stack-trace.

首先我编写了没有 try-catch 块的 Azure 函数,因此它在 Monitor 部分和应用程序洞察力中显示了正确的状态/信息.

First I have written Azure function without try-catch block so It was showing correct status/Information in Monitor section and application insight as well.

后来我添加了 try-catch 块并记录了更多数据,例如

Later I added try-catch block and logged some more data like

catch(Exception ex)
{
    log.Error(inputData);
    log.Error(ex.Message);
    return req.CreateResponse(HttpStatusCode.InternalServerError);
}

您可以在下面的附件中看到,ResultCode 是 500,绿色状态...为什么?我认为由于这个问题,Application Insight 没有在错误/失败请求查询中显示此数据.

You can see in below attachment, ResultCode is 500 with Green Status... Why? I think because of this issue Application Insight not showing this data in Error/Failed request query.

在 Application Insight 中找不到记录

No record found in Application Insight

exceptions
|where operation_Id == "c5b5a345-fa11-4356-b769-b34d1c6619e5" 
| order by timestamp desc 
| project operation_Id , timestamp 

推荐答案

成功检查表示您的 Azure Function 调用是成功(= 未引发异常)还是失败(= 引发异常).

Success check denotes whether your Azure Function call succeeded (= no exception thrown) or failed (= exception thrown).

在您第一次调用时,发生了异常,因此函数调用没有正常终止,因此红色勾号.

At your first invocation, an exception occurred, so function invocation didn't terminate normally, thus red checkmark.

当您手动捕获并返回 500 时,就函数调用而言仍然可以 - 它完成并返回结果.

When you catch and return 500 manually, that's still OK in terms of function invocation - it finished and returned the result back.

函数运行时不遵循 HTTP 语义,规则对所有触发器类型都是通用的.

Functions runtime doesn't follow HTTP semantics, the rules are universal for all trigger types.

Application Insight 默认指标不会在失败的请求图中显示已处理的异常,开发人员需要为已处理的异常构建查询,例如

Application Insight Default metrics won't show handled exception in failed request graph, Developer need build query for handled exception e.g.

requests
| where success == "False" and timestamp >= ago(7d) 
| join kind= inner traces on operation_Id  
| project operation_Id , timestamp, message, severityLevel  
| order  by timestamp, operation_Id

severityLevel :- 1 = Info and 3 = Error

这篇关于这是 Application Insight/Azure Functions 错误吗?或者我的理解不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆