Home > Mobile >  How do I register 400 errors in Azure Function Apps as failures in Application Insights?
How do I register 400 errors in Azure Function Apps as failures in Application Insights?

Time:09-01

I want to treat 4xx HTTP responses from a function app (e.g. a 400 response after sending a HTTP request to my function app) as failures in application insights. The function app is being called by another service I control so a 4xx response probably means an implementation error and so I'd like to capture that to ultimately run an alert on it (so I can get an email instead of checking into Azure everytime).

If possible, I'd like it to appear here:

enter image description here

If not, are there any alternative approaches that might fit my use case?

CodePudding user response:

Unless an unhandled exception occurs the function runtime will mark the invocation as succesful, whether the status code is actually denoting an error or not. Since this behavior is defined by the runtime there are 2 things you can do: throw an exception in the code of the function and/or remove exception handling so the invocation is marked as not succesful.

Since you ultimately want to create an alert, you better alert on this specific http status code using a "Custom log search" alert

requests
| where toint(resultCode) >= 400
  • Related