Is this Application Insight / Azure Functions Bug? or My understanding is incorrect

佐手、 提交于 2019-12-30 14:17:18

问题


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

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.

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

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.

No record found in Application Insight

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


回答1:


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.

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

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

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


来源:https://stackoverflow.com/questions/51646904/is-this-application-insight-azure-functions-bug-or-my-understanding-is-incorr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!