Azure Diagnostics
Diagnose and troubleshoot Azure service issues with monitoring and logging
Category: development Source: microsoft/skillsAzure Diagnostics is a development skill for diagnosing and troubleshooting Azure service issues, covering monitoring, logging, metrics collection, and performance analysis
What Is This?
Overview
Azure Diagnostics is a comprehensive monitoring and logging service that collects diagnostic data from Azure resources and applications. It enables developers and operators to capture detailed information about system performance, errors, and events across virtual machines, cloud services, and other Azure components. The service stores this data in Azure Storage or sends it to Application Insights for deeper analysis and visualization.
Azure Diagnostics works by deploying diagnostic agents to your resources that continuously gather metrics, logs, and trace data. You configure what data to collect, where to send it, and how long to retain it. This centralized approach helps identify bottlenecks, debug issues, and maintain visibility into your entire Azure infrastructure without manual log collection.
Who Should Use This
Azure developers, DevOps engineers, and system administrators who need to monitor application performance, troubleshoot production issues, and maintain compliance with logging requirements should use Azure Diagnostics.
Why Use It?
Problems It Solves
Azure Diagnostics eliminates the challenge of scattered logs across multiple resources by centralizing diagnostic data collection. It reduces mean time to resolution by providing immediate access to performance metrics and error logs. Without it, troubleshooting Azure issues becomes time-consuming and incomplete, often missing critical system events that occur during failures.
Core Highlights
Azure Diagnostics collects performance counters, event logs, crash dumps, and custom trace data from your Azure resources in real-time. It integrates seamlessly with Azure Storage and Application Insights for long-term retention and advanced analytics. The service supports filtering and sampling to control costs while maintaining visibility into critical issues. Configuration can be managed through the Azure Portal, PowerShell, or infrastructure-as-code templates for consistency across environments.
How to Use It?
Basic Usage
$diagnosticsConfig = New-AzureServiceDiagnosticsExtensionConfig `
-DiagnosticsConfigurationPath "diagnostics.wadcfgx" `
-StorageAccountName "mystorageaccount" `
-StorageAccountKey $storageKey
Set-AzureServiceDiagnosticsExtension -ServiceName "myservice" `
-Slot "Production" -DiagnosticsConfiguration $diagnosticsConfig
Real-World Examples
Example 1: Collecting performance metrics from a virtual machine to monitor CPU and memory usage over time for capacity planning.
$vm = Get-AzVM -ResourceGroupName "mygroup" -Name "myvm"
$diagnosticsConfig = @{
storageAccount = "mystorageaccount"
metrics = @("PercentProcessorTime", "AvailableMemory")
interval = "PT1M"
}
Set-AzVMDiagnosticsExtension -ResourceGroupName "mygroup" `
-VMName "myvm" -DiagnosticsConfigurationPath $config
Example 2: Sending application logs and exceptions to Application Insights for real-time monitoring and alerting on production errors.
$appInsightsConfig = @{
instrumentationKey = "your-key"
samplingSettings = @{ maxTelemetryItemsPerSecond = 5 }
}
Enable-AzApplicationInsightsMonitoring -ResourceGroupName "mygroup" `
-AppServiceName "myapp" -InstrumentationKey $key
Advanced Tips
Use sampling and filtering in your diagnostics configuration to reduce storage costs while keeping critical diagnostic data, especially for high-traffic applications. Set up alerts in Application Insights based on diagnostic metrics to get notified immediately when performance degrades or error rates spike.
When to Use It?
Use Cases
Use Azure Diagnostics when deploying applications to production to maintain continuous visibility into system health and performance. Enable it during development and testing to capture detailed logs that help identify bugs before release. Use it for compliance and auditing requirements where you need to retain and analyze access logs and security events. Enable it when troubleshooting intermittent issues that are difficult to reproduce locally.
Related Topics
Azure Diagnostics works alongside Application Insights for application-level monitoring, Azure Monitor for comprehensive platform monitoring, and Log Analytics for advanced querying and analysis of diagnostic data.
Important Notes
Requirements
You need an Azure Storage account to store diagnostic data or an Application Insights resource for cloud-based analysis. The diagnostic agent must be installed on your Azure resources, which requires appropriate permissions and network connectivity. Ensure your storage account and resources are in the same region for optimal performance.
Usage Recommendations
Start with essential metrics and logs, then expand collection based on your troubleshooting needs to manage costs. Review diagnostic data regularly to identify patterns and optimize your monitoring strategy. Use role-based access control to restrict who can view sensitive diagnostic information.
Limitations
Azure Diagnostics has data retention limits in Storage accounts and may incur costs for high-volume data collection. Some legacy Azure services have limited diagnostic capabilities compared to newer services. Real-time analysis requires integration with Application Insights or Log Analytics rather than direct Storage access.