Microsoft Docs

Monitoring Azure Functions

Azure Functions provides robust monitoring capabilities to help you understand the health, performance, and behavior of your serverless applications. This guide covers the key tools and techniques for monitoring your functions, including Application Insights, logging, and alerts.

Getting Started with Application Insights

Application Insights is the primary monitoring service for Azure Functions. It automatically collects a wealth of data about your function app's operations.

Key Telemetry Data:

To integrate Application Insights:

  1. When creating a new Function App, select Application Insights as the monitoring service.
  2. For existing Function Apps, configure the APPINSIGHTS_INSTRUMENTATIONKEY or APPLICATIONINSIGHTS_CONNECTION_STRING application setting.

Viewing Telemetry:

Navigate to your Function App in the Azure portal, then select "Application Insights" from the left-hand menu. You can explore:

Logging with Azure Monitor Logs

Azure Functions integrates with Azure Monitor Logs, allowing you to query rich log data using Kusto Query Language (KQL).

Log Categories:

Example KQL Queries:

// Find all function executions that failed in the last hour traces | where severityLevel >= 3 // Error or Critical | where timestamp > ago(1h) | project timestamp, message, operation_Name, invocationId
// Get average execution time for a specific function requests | where name == "MyHttpTriggerFunction" | summarize avg(duration) by bin(timestamp, 5m) | render timechart

Access Logs by navigating to your Function App -> "Logs" under the "Monitoring" section in the Azure portal.

Configuring Alerts

Proactive alerting helps you respond quickly to issues. You can create alerts based on metrics or log queries.

Common Alert Scenarios:

To set up alerts:

  1. Navigate to "Alerts" in the Azure portal.
  2. Click "+ Create" > "Alert rule".
  3. Define the scope (your Function App).
  4. Configure the condition (e.g., Metric: Function Execution Count, Threshold: Greater than 1000 in 5 minutes).
  5. Choose an action group to specify how to be notified (e.g., email, SMS, webhook).

Best Practices for Monitoring