Monitoring Durable Functions
Effective monitoring is crucial for understanding the health, performance, and behavior of your Durable Functions orchestrations. Azure provides several tools to help you monitor your functions, including Azure Monitor, Application Insights, and the Durable Functions extension's built-in logging.
Key Monitoring Tools
- Azure Monitor: A comprehensive solution for collecting, analyzing, and acting on telemetry from your Azure and on-premises environments.
- Application Insights: An extension of Azure Monitor, specifically designed for monitoring the performance and usage of live web applications. It's invaluable for tracking requests, dependencies, exceptions, and custom events related to Durable Functions.
- Durable Functions Diagnostic Store: The extension writes detailed diagnostic information to a designated storage account, which can be queried for troubleshooting and analysis.
Using Application Insights
Application Insights is your primary tool for real-time monitoring and historical analysis of Durable Functions.
Traces and Logs
Durable Functions generate various traces and logs that are sent to Application Insights. These include:
- Orchestration lifecycle events (e.g., started, completed, failed)
- Activity function execution details
- Orchestration input and output
- Errors and exceptions
You can query these logs using Kusto Query Language (KQL) in the Application Insights Logs blade.
Example KQL Query for Orchestration Status
traces
| where customDimensions.Category == "Host.Traces" and message startswith "Durable Functions"
| extend OrchestrationId = customDimensions.OrchestrationId
| extend EventType = customDimensions.EventType
| project timestamp, OrchestrationId, EventType, message
| order by timestamp desc
| take 100
Performance Metrics
Application Insights provides metrics like request duration, success rates, and dependency call performance. By correlating these metrics with your Durable Functions, you can identify bottlenecks and performance issues.
Monitoring the Diagnostic Store
The Durable Functions extension can be configured to write its diagnostic data to a storage account. This store contains detailed information about each event in an orchestration's history.
Accessing the Diagnostic Store
You can access the diagnostic data programmatically or by using tools like Azure Storage Explorer. The data is typically stored in tables named like orchestrations, activities, and instances.
Tip: While direct querying of the diagnostic store can be powerful for deep dives, Application Insights offers a more user-friendly and integrated experience for most monitoring needs.
Common Monitoring Scenarios
1. Tracking Orchestration Progress
Use Application Insights to filter traces by OrchestrationId to see the complete history of a specific orchestration, including all activity calls and their results.
2. Identifying Failed Orchestrations
Query Application Insights for traces where the message indicates a failure or exception. Look for entries with EventType like 'Failed' or 'Exception'.
traces
| where customDimensions.Category == "Host.Traces" and message contains "Failed"
| project timestamp, message, customDimensions
| order by timestamp desc
3. Performance Analysis
Analyze the execution times of your activity functions. Long-running activities might indicate areas for optimization.
4. Debugging and Troubleshooting
When an orchestration behaves unexpectedly, examine the logs in Application Insights for the relevant OrchestrationId. The detailed traces can reveal the exact step where an issue occurred.
Alerting and Notifications
Configure alerts in Azure Monitor based on Application Insights metrics or log queries. For example, you can set up an alert for a high number of failed orchestrations or unusually long execution times.
Best Practices for Monitoring
- Ensure Application Insights is correctly configured for your Azure Functions app.
- Utilize custom telemetry within your orchestrations and activities to log important business logic events.
- Regularly review your monitoring dashboards and alerts.
- Understand the different log categories and event types generated by Durable Functions.
By leveraging these monitoring tools and techniques, you can ensure your Durable Functions applications are reliable, performant, and easy to manage.