14

I have timer-triggered Azure functions running in production, but now I want to be notified if the function fails.

In my case, access to various connected services can cause crashes, and there are many to troubleshoot. The crash is the type of error I need notification for.

When the function does fail, the log entry indicates failure, so I wonder if there is a hook in the system that would allow me to cause the system to generate a notification.

I know that blob and queue bindings, for instance, support the creation of poison queue entries, but timer trigger binding doesn't say anything about any trigger outputs of that nature.

I see that functions can pass their $return status as input to other functions, but that operation is not explained in depth in the docs. Also, in that case, I need to write another function to process the error status, and I was looking for something built-in.

I Have inquired with @AzureSupport on this, but their answer had nothing to do with Azure Functions, instead referring me to DLL notification hooks, then recommending I file on uservoice.

I'm sure there must be people here who have implemented some sort of error status notification. I prefer a solution that doesn't require code.

Leigh007
  • 201
  • 1
  • 2
  • 8

5 Answers5

7

The recommended way to monitor and alert on failures is to use AppInsights which integrates fully with Azure Functions now

https://blogs.msdn.microsoft.com/appserviceteam/2017/04/06/azure-functions-application-insights/

Since all the logs are available in AppInsights it's easy to monitor for failures and setup alerts based on your own criteria.

However, if you only care about alerting and not things like monitoring etc, you could use Azure Monitor instead: https://learn.microsoft.com/en-us/azure/monitoring-and-diagnostics/monitoring-get-started

Chris
  • 5,040
  • 3
  • 20
  • 24
  • Your first link has rotted since you posted it. This link might offer similar help: https://learn.microsoft.com/en-us/azure/azure-monitor/app/azure-functions-supported-features – Claus Appel Jan 19 '22 at 13:41
2

When the function does fail, the log entry indicates failure, so I wonder if there is a hook in the system that would allow me to cause the system to generate a notification.

...

I prefer a solution that doesn't require code.

This is a zero-code solution:

I poked @AzureFunctions once before on this topic, and a suggested response was to use Application Insights. It can handle the alerts upon failure and also can use webhooks.

See the Azure Functions App-Insights documentation on how to link your function app to App Insights. Then set up any alerts you want.

flyte
  • 1,242
  • 11
  • 18
1

Unfortunately this hook doesn't exist.

Can you switch from a timer trigger to a queue trigger?

You can get retries (if you want them), and after the specified number of attempts the message is sent to a poison queue.

To schedule executions you can add queue messages with a visibility timeout to match your schedule.

Matt Mason
  • 2,676
  • 9
  • 22
  • Thanks. Will look into it and report back. Also, will be at //BUILD next week at the serverless computing workshop – Leigh007 May 05 '17 at 21:07
  • Just got back to this. If I understand you correctly, I should 1) Create a queue 2) Write a timer function that adds a message to the queue on the schedule, using a timeout on the message so it will disappear after a while 3) Change my actual worker function that was a timer function to be a queue function. 4) Write another function that reads the poison queue with the same name 'orig-queue'-poison that then has a send grid or twilio output, or handles the message some other way. IS that about right? Thx – Leigh007 May 06 '17 at 17:22
  • That would work. You could also have each queue execution schedule the next execution. To kick it off, run the function manually or add an item to the queue. Jonny also has some good input - if you're not worried about binding errors or timeouts, a try catch could work for you. – Matt Mason May 08 '17 at 18:56
0

In order to get alerts on failure you have two options:

  1. A timer trigger than scans the execution logs (via SFTP) for failures.
  2. Wrap the whole function in a try/catch block and in the catch block write a few lines to send you an email with the error details.

Hope this helps.

Jonny Leigh
  • 125
  • 2
  • 7
-1

No code:

  1. Go to your azure cloud account

  2. From the menu select Monitor

  3. Then select Add New Rule

  4. Then Select your condition, action and add the alert details.

MarwaAhmad
  • 808
  • 9
  • 21
  • 1
    That does work, but I couldn't see how to check for execution failures. Had an error on a bad compile. It did run, but just gave errors. Looked at the different options, but I didn't see anything that included that. – Dan Parker Nov 11 '19 at 19:08
  • does your code return a 4xx response code if an execution failure happen? if yes, then you can put in the azure rule condition when "4xx happen". If no, then i think you might need to have an external log, so that you can refer to it when something happen. – MarwaAhmad Nov 16 '19 at 09:48