How to configure Azure Function App notifications for errors
Below are the steps to enable error notifications on Azure Function Apps
Follows on from my previous blog post How you can store All your Power BI Audit Logs easily and indefinitely in Azure, where every day it extracts the Audit logs into Azure Blob storage. One of the key things when working with any job that runs, is that I want to know when the job fails. If I do not have this and I assume that the data is always where, I could fall into a situation where there is missing data that I cannot get back.
Below explains how to create an alert with a notification email if an Azure Function App fails.
- Log into the Azure Portal
I then navigated to my Azure Function App
I made sure that I had selected the Name of my Azure Function App
In the right-hand pane, I then clicked on Application Insights
- This brought up all the Application Insights for my Azure Function App.
I under the Monitoring section, I clicked on Alerts
Now in the Alerts section I clicked on New alert rule
- I then configured my rule in the Create rule screen
Under Resource, this will automatically be configured and there is nothing to do. This is shown below.
Where it says Condition, this is where I want to configure the condition for my alert.
- I clicked on Add
- This then brought up the Configure signal logic screen
I then selected Custom Log Search
In the Search Query I pasted the following code below which will look for errors
union (traces), (requests), (pageViews), (dependencies), (customEvents), (availabilityResults), (exceptions) | extend itemType = iif(itemType == 'availabilityResult',itemType,iif(itemType == 'customEvent',itemType,iif(itemType == 'dependency',itemType,iif(itemType == 'pageView',itemType,iif(itemType == 'request',itemType,iif(itemType == 'trace',itemType,iif(itemType == 'exception',itemType,""))))))) | where ((itemType == 'trace' or (itemType == 'request' or (itemType == 'pageView' or (itemType == 'customEvent' or (itemType == 'exception' or (itemType == 'dependency' or itemType == 'availabilityResult')))))) ) | where * has 'error' | where timestamp > ago(1d) | top 101 by timestamp desc
The above code will search for errors
I then configured the Alert Logic with the following below
Then for the Evaluated Based on I changes this to be one day which would be 1440 minutes
- I then clicked Done
- Once completed I could then see my Condition as shown below
Next I needed to select an action group if an alert is triggered. An action is where it will do something based on an alert.
- I then clicked on Create
This then brought up the Add action group screen which I configure with the following below.
- I put in the required naming details as shown below.
I also selected the Action Type
I gave it the name of Email for the Action group name.
- This brought up the Email/SMS/Push/Voice window where I put in the details for the email address for the alerts to be sent to
- I then clicked Ok
- And then I clicked Ok on the Add Action Group
- I could then see my action group as shown below
I also got an email notifying me that I was added to an Azure Monitor Action Group
- I could then see my Action Group Selected
Next I enabled the tick under Customize Actions and Email Subject which I put in the following below, which allows me to set the subject.
I then had to configure the Alert Details with the following as shown below.
I then clicked Create alert Rule
- Now the process is complete for creating the Alert.
Finally, I could then see my Rules when I went under Manage Rules
In this blog post I have given you the steps on how to configure your Azure Function app to notify you if there is an error when it runs. This allows you to be aware of any issues if your audit logs are not extracted.
As always if you have any questions or suggestions please leave them in the comments section below.
Thanks for reading!