Configure customized notification for Function App

  • Thread starter Thread starter Marina_Liu
  • Start date Start date
M

Marina_Liu

For configuring customized notification of function app, Application Insight alter with custom log search is a suitable way to achieve the goal.
In this blog, I will take two senarios (function invocation is under long time running and function fails due to timeout) as examples for how to set the customized notifications. Below is one situation which might need customized notification:
Function invocations' time duration might span with a wide range (such as function which handles uploaded files whose size might be a few KB or more than tens GB), notification is needed if a function invocation persists for a long time or it fails with timeout.

Detailed steps for creating a customized notification as below:

Step 1: Create Alert rule
First, please go to the Application Insight which is linked with the function app -> Alerts -> Create Alert rule.

large?v=v2&px=999.png

Step 2: Alert rule - Condition Tab
In the "Condition" Tab, please select "Custon log search" as the signal name. Then you can write your own customized query and config measurement option and alert logic.
large?v=v2&px=999.png


For "Search query", you can query any needed data. Such as below are the sample Kusto queries which get the long time running function invocation and timeout exception separately.
  • Get long time running function invocation

let currentfnstate=
(traces
| where message startswith "Execut"
| order by timestamp desc
| take 1
| extend exest=iff(message startswith "Executing", "incomplete", "completed")
|extend duration=datetime_diff('minute', ago(1s), timestamp) //check the function invocation duration with the time unit minute. The unit can be hour, day and week etc
|extend overmylimit=iff(duration>=4, "yes","no") //the limit canbe set based on own need
| project timestamp, message, exest, duration, overmylimit
);
currentfnstate
| where exest =='incomplete'
|where overmylimit =='yes'




  • Get timeout exception

exceptions
| where type == 'Microsoft.Azure.WebJobs.Host.FunctionTimeoutException'




For "Aggregation granularity", it's used to set the look back time of the Kusto query. Such as the value 15 minutes means executing the Kusto query within the latest 15 minutes data.
For "Frequency of evaluation", it means how frequently the alert logic will be evaluated.

Step 3: Alert rule - Actions Tab
For the actions, you can create/select the action group for how you want to be notified, such as via email or SMS etc.
large?v=v2&px=999.png

Step 4: Alert rule - Details Tab
Then you can set alert rule details with severity and name.

large?v=v2&px=999.png

The Alter rule is configured completely now. And you will receive the related notifications if the alert rules are hitted. Below are the exmaple of the email notifications which function invocation is persisting for a long time and function failed due to timeout separately.
large?v=v2&px=999.png

Continue reading...
 
Back
Top