Monitoring Azure Functions

When you have critical applications and business processes relying on Azure resources, you want to monitor those resources for their availability, performance, and operation.

This article describes the monitoring data generated by apps hosted in Azure Functions. Azure Functions uses Azure Monitor to monitor the health of your function apps. If you're unfamiliar with the features of Azure Monitor common to all Azure services that use it, see Monitoring Azure resources with Azure Monitor.

Azure Functions uses Application Insights to collect and analyze log data from individual function executions in your function app. For more information, see Monitor functions in Azure.

Monitoring data

Azure Functions collects the same kinds of monitoring data as other Azure resources that are described in Azure Monitor data collection.

See Monitoring Azure Functions data reference for detailed information on the metrics and logs metrics created by Azure Functions.

Collection and routing

Platform metrics and the Activity log are collected and stored automatically, but can be routed to other locations by using a diagnostic setting.

Resource Logs aren't collected and stored until you create a diagnostic setting and route them to one or more locations.

See Create diagnostic setting to collect platform logs and metrics in Azure for the detailed process for creating a diagnostic setting using the Azure portal, CLI, or PowerShell. When you create a diagnostic setting, you specify which categories of logs to collect. The categories for Azure Functions are listed in Azure Functions monitoring data reference.

The metrics and logs you can collect are discussed in the following sections.

Analyzing metrics

You can analyze metrics for Azure Functions with metrics from other Azure services using metrics explorer by opening Metrics from the Azure Monitor menu. See Getting started with Azure Metrics Explorer for details on using this tool.

For a list of the platform metrics collected for Azure Functions, see Monitoring Azure Functions data reference metrics.

For reference, you can see a list of all resource metrics supported in Azure Monitor.

The following examples use Monitor Metrics to help estimate the cost of running your function app on a Consumption plan. To learn more about estimating Consumption plan costs, see Estimating Consumption plan costs.

Use Azure Monitor metrics explorer to view cost-related data for your Consumption plan function apps in a graphical format.

  1. In the Azure portal, navigate to your function app.

  2. In the left panel, scroll down to Monitoring and choose Metrics.

  3. From Metric, choose Function Execution Count and Sum for Aggregation. This adds the sum of the execution counts during chosen period to the chart.

    Define a functions app metric to add to the chart

  4. Select Add metric and repeat steps 2-4 to add Function Execution Units to the chart.

The resulting chart contains the totals for both execution metrics in the chosen time range, which in this case is two hours.

Graph of function execution counts and execution units

As the number of execution units is so much greater than the execution count, the chart just shows execution units.

This chart shows a total of 1.11 billion Function Execution Units consumed in a two-hour period, measured in MB-milliseconds. To convert to GB-seconds, divide by 1024000. In this example, the function app consumed 1110000000 / 1024000 = 1083.98 GB-seconds. You can take this value and multiply by the current price of execution time on the Functions pricing page, which gives you the cost of these two hours, assuming you've already used any free grants of execution time.

Analyzing logs

Data in Azure Monitor Logs is stored in tables where each table has its own set of unique properties.

All resource logs in Azure Monitor have the same fields followed by service-specific fields. The common schema is outlined in Azure Monitor resource log schema.

The Activity log is a type of platform log in Azure that provides insight into subscription-level events. You can view it independently or route it to Azure Monitor Logs, where you can do much more complex queries using Log Analytics.

For a list of the types of resource logs collected for Azure Functions, see Monitoring Azure Functions data reference

For a list of the tables used by Azure Monitor Logs and queryable by Log Analytics, see Monitoring Azure Functions data reference

Sample Kusto queries

Important

When you select Logs from the Azure Functions menu, Log Analytics is opened with the query scope set to the current resource. This means that log queries will only include data from that resource. If you want to run a query that includes data from other resources or data from other Azure services, select Logs from the Azure Monitor menu. See Log query scope and time range in Azure Monitor Log Analytics for details.

Following are queries that you can use to help you monitor your Azure Function.

The following sample query can help you monitor all your functions app logs:

FunctionAppLogs
| project TimeGenerated, HostInstanceId, Message, _ResourceId
| order by TimeGenerated desc

The following sample query can help you monitor a specific functions app's logs:

FunctionAppLogs
| where FunctionName == "<Function name>" 
| order by TimeGenerated desc

The following sample query can help you monitor exceptions on a specific functions app's logs:

FunctionAppLogs
| where ExceptionDetails != ""  
| where FunctionName == "<Function name>" 
| order by TimeGenerated desc

Alerts

Azure Monitor alerts proactively notify you when important conditions are found in your monitoring data. They allow you to identify and address issues in your system before your customers notice them. You can set alerts on metrics, logs, and the activity log. Different types of alerts have benefits and drawbacks.

If you're creating or running an application that run on Functions Azure Monitor Application Insights may offer other types of alerts.

The following table lists common and recommended alert rules for Functions.

Alert type Condition Examples
Metric Average connections When number of connections exceed a set value
Metric HTTP 404 When HTTP 404 responses exceed a set value
Metric HTTP Server Errors When HTTP 5xx errors exceed a set value
Activity Log Create or Update Web App When app is created or updated
Activity Log Delete Web App When app is deleted
Activity Log Restart Web App When app is restarted
Activity Log Stop Web App When app is stopped

Next steps

For more information about monitoring Azure Functions, see the following articles: