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
- Email/SMS/Push/Voice
-
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
Summary
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!
[…] Gilbert Quevauvilliers shares how to receive notification e-mails when an Azure Function App fails: […]
Hi, for this step: “In the Search Query I pasted the following code below which will look for errors”
How did you find/create that query? I’d like to understand more about how that code works. Thank you.
Hi JP, thanks for the question
I got it from learning and using Kusto which is the query language used for Log Analytics
Here is a link to get you started: https://docs.microsoft.com/en-us/azure/data-explorer/kusto/concepts/
Thank you!
traces table causes an issue
‘union’ operator: Failed to resolve table expression named ‘traces’
If the issue persists, please open a support ticket. Request id: 0f9ac284-6e3d-4336-a879-1937947d610e
Hi Tim
It does appear as the table name has changed from ‘traces’ if you could look in the log analytics and find the name?
BadArgumentError- ‘union’ operator: Failed to resolve table expression named ‘traces’
and im not finding Email in Action Group Name section
Hi Balaraju ,
You would have to look at your data in order to find the column you require.
hi Gil
thanks for response now it is showing this error
1. The query couldn’t be validated since you need permission for the logs. Contact the subscription owner to request access.
Hi Balaraju,
You would then need to contact the person who setup the azure function to give you the required permissions to see the data in log analytics.