Reputation: 1189
I'm running following simple function to check how does monitoring work in Function App. If my function returns "400" status code, in Monitoring part (and subsequently Application insight), it marks the execution as successful. Also, If it throws and catches the error, still marks as successful. If it throws the error but doesn't catch it, then it detects and count it as error (but this case is not common, as in real application, possible errors always needs to get caught).
Is this how monitoring in Azure functions work? So the only way to mark the execution as faulty is to throw an uncaught error?!?!
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?
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"
};
}
};
Upvotes: 3
Views: 925
Reputation: 29940
Is this how monitoring in Azure functions work? So the only way to mark the execution as faulty is to throw an uncaught error?
Yes, you are right, For details you can refer to this 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?
You can use application insights analytics to archive your goal, write a simple query like below:
requests
| where name ="your function app name"
| where resultCode =="500 or other status code"
| count
Result like below:
Note: If you don't know how to nav to application insights analytics, follow the step below:
1.Nav to your application insights(associated with the function app) in azure portal -> overview blade -> on the top bar, click Analytics option.
Upvotes: 3