Try for free Book a demo

How to get alerts on Azure Functions failure?

Azure Monitoring

8 Mins Read | Last modified on February 28th, 2024

Azure Function Alert on Failure

Azure Function is an event-driven serverless computing service on Microsoft Azure. It is a cost-effective solution with less code where the user can execute their logic as event-driven, readily available blocks of code without needing infrastructure

Failures in Azure Function

There could be various reasons for which the Azure Functions could fail, like a failure in underlying resources, errors in code, resource limitations, connectivity issues, etc. Some of the common failures are listed below:

  • Timeout errors – may occur if a function runs longer than the specified timeout duration. Timeout errors could happen if the function is handling a lot of data or is awaiting a resource that isn’t immediately available.
  • Code errors – Functions can fail if there are errors in the code. Code errors happen with syntax, runtime, or logical errors in the code.
  • Resource limitations – When processing a lot of data or having too many concurrent requests, Azure Functions have resource limits that can be exceeded. The function tends to fail or can be terminated when the limits are exceeded.
  • Connectivity issues – Functions that rely on external resources, such as databases or APIs, can fail if there are any connectivity issues. Connection issues can happen if the external resource is unavailable or there are network issues.
  • Unhandled exceptions – If a function fails with an unhandled exception, the exception details are logged, and the instance completes with a Failed status.

It’s crucial to watch for errors in the Function app to address and resolve the failures in Azure Functions, which will be discussed later in this blog.

Why is it essential to monitor Azure Functions?

Azure Functions Monitoring is critical for maintaining the health and performance of your serverless architecture and ensuring that your functions meet your organization’s requirements and goals.

Think of a scenario where 100 customers need to have a payment transaction performed using Azure Functions.

The payment to a specific customer could be unsuccessful for several reasons, including network or connectivity issues, infrastructure failures, configuration errors throughout the payment process, coding errors, and security or compliance problems.

In any scenario, monitoring the Azure Function and configuring alerts to spot and address any payment system errors swiftly is critical.

Application Insights is valuable when examining any Azure function’s failures. It can help you proactively identify and resolve issues in your Azure Functions.

Tracking failures in Azure

You should monitor the availability, performance, and operation of Azure resources when critical business applications and processes rely on them. There are several ways to track down failures in Azure Functions through the Azure Monitor.

Application Insights – Application Insights is an Azure service that helps you monitor your applications’ performance and usage, including Azure Functions. It provides insights into function execution time, invocation count, failure rates, and detailed telemetry data such as logs, traces, and exceptions.

Log analytics – Azure Functions integrates with Azure Monitor Logs to monitor functions. In the Azure portal, you can create and test queries for Log Analytics and use these tools directly to analyze the data or save queries for use with visualizations or alert rules.

Metrics Explorer – You can utilize the Azure portal’s Metrics Explorer to plot charts and visually correlate patterns to detect the application’s performance and latency. The metric explorer shows the analytics results based on the filters configured on the wide range of metrics.

Alerts – Azure Functions supports Azure Alerts, which allows you to create alerts based on specific criteria, such as function failures. You can set alerts on metrics, logs, and activity logs. When an alert is triggered, you receive a notification.

Monitor functions in Azure

Application Insights is an extension of Azure Monitor and provides application performance monitoring (APM) features. Azure Functions offers built-in integration with Application Insights to monitor function executions.

Telemetry information is transmitted to your corresponding Application Insights instance from the functions when the integration with Application Insights is enabled. This information includes performance data, traces created by your functions code, and logs produced by the Functions host.

Select Monitor in the Azure function to examine the invocation logs.

Monitor functions in Azure - 1

Click on “Run query in Application insights” to troubleshoot any failures in the function.

Application Insights in Azure Functions provides an easy way to create alerts for different types of telemetry data, such as exceptions, requests, and performance counters.

Monitor functions in Azure - 2

Alerts can be used to proactively notify you when certain conditions are met, like, when the failed requests of your function exceed a specific threshold value or when the availability of your function drops below a certain level.

There are different types of signals based on which an alert can be created.

  • Log search – Log search is the signal you may use to perform advanced logic operations on your data. Here monitoring is done by using a Log Analytics query to evaluate the function logs at a set frequency (Eg. – Failed operations, Custom log search).
  • Metrics – The Functions can be monitored, by frequently evaluating the alert rules configured using the metrics. It includes a set of platform metrics like Exceptions, Failed requests, and Application Insights custom metrics like Online transaction count, Online transaction failures.
  • Activity log – Activity log can be used when a user needs to be alerted when a specific administrative event occurs. The administrative category includes the record of all create, update, delete, and action operations like Application insights API key generate, Application Insights component delete.

Click on the “New alert rule” and choose the type of signal you want to create under the “Alert section” of an Application Insight.

Monitor functions in Azure - 1

You will be notified when the metrics meet its configured threshold. You can take necessary actions to resolve the issue to ensure the Function is running successfully. When it comes to Azure Functions, there are some restrictions like, the metrics are not available at the Azure function level and are limited to the level of the Function app; telemetry may occasionally be dropped by Application insights due to sampling, which results in inaccuracy in data.

Use Turbo360 to monitor Azure Functions failures effectively

Although Azure offers multiple monitoring tools via Azure Monitor, monitoring the Azure functions is cumbersome in the Azure portal as you have to drill down to each of the respective functions to set up alerts for the particular function.

Azure Functions monitoring tool allows users to monitor numerous entities with various metrics. One can monitor all the functions and receive a consolidated alert report for all the functions by associating all the necessary functions and their application insights in a single place (Business Application).

Firstly, create a Business Application in Turbo360 by associating the necessary Azure Functions with the Application Insights.

Please navigate to the Azure Function you’ve associated with the Business Application and get a detailed view of the function and its invocation logs. Additionally, you can use the logs’ status to filter the invocation logs.

Turbo360 to monitor Azure Functions failures effectively - 1

When no monitoring alerts are enabled, an invocation failure may occasionally go unnoticed. In such cases, you will need to investigate the cause of the failure, which may be done quickly by looking at the specific invocation log’s details.

Turbo360 to monitor Azure Functions failures effectively - 2

An option is also available to test the Functions by making an HTTP request.

Turbo360 to monitor Azure Functions failures effectively - 3

In addition, you can invoke the trigger for the specific Azure Function, for which the configuration is automatically saved for later use. Multiple trigger types are supported like HTTP, Service Bus, and Event Grid.

Turbo360 to monitor Azure Functions failures effectively - 4

Think of a situation where a developer wishes to be notified anytime there is a failure to invoke Azure Functions. Users can watch any failures in the execution of Azure Functions using Turbo360’s Query monitoring feature.

Turbo360 provides you with a set of default queries to monitor. By adding a new query rule, you may keep track of failures. To do this, choose the appropriate Application Insight, select the “Failures for the last 24 hours” query, and then provide the rule’s warning and error thresholds.

Turbo360 to monitor Azure Functions failures effectively - 5

Following the successful creation of query rules, the resources in the relevant Business Application are checked for violations and triggers a notification in case of any errors.

Here is a sample alert triggered for a Function.

Turbo360 to monitor Azure Functions failures effectively - 6

You can associate other Azure Functions or other resources within a Business Application and monitor them for violations. You will receive a consolidated alert report on the overall health of all the resources in a Business application. In contrast to Azure, Turbo360 allows you to view the status of all the resources in a Business application in a single place.

Turbo360 to monitor Azure Functions failures effectively - 7

To conclude, Azure provides many capabilities to monitor and manage Azure functions. Turbo360 has the advantage of providing better visibility if it comes to monitoring functions and other resources at a larger scale. In addition to Business Applications, there is a module called Business Activity Monitoring available in Turbo360, which is instrumental in the monitoring and management of serverless applications.

Through its advanced features, BAM offers valuable insights and enhanced visibility into the execution of serverless workflows and processes. It delivers comprehensive end-to-end visibility, real-time monitoring, and enables efficient troubleshooting and root cause analysis in case of event failures. Check out this article for more information – End-to-End tracking.

Turbo360 is an enterprise-grade cloud management platform for your Azure environment and it comes with an free trial.

This article was originally published on Jul 13, 2023. It was most recently updated on Feb 28, 2024.

Related Articles