Azure Monitoring & Logging
Observability is critical for production applications. The AZ-204 exam focuses on Application Insights, performance optimization, and diagnostic logging.Application Insights
Application Insights is Azure’s Application Performance Monitoring (APM) service.Telemetry Collection
Application Insights automatically collects and tracks various telemetry types. Auto-Collected Telemetry:- Requests (req) - HTTP requests
- Dependencies (dep) - Outgoing calls to SQL, HTTP, Blob, Service Bus
- Exceptions (exc) - Unhandled exceptions
- Traces (TRC) - Log statements
- Page Views - Client-side page loads
Use
APPLICATIONINSIGHTS_CONNECTION_STRING app setting instead of deprecated InstrumentationKey - connection strings support sovereign clouds and include endpoint information.Custom Events
Track business events and user actions with custom telemetry. Custom Event Usage:TrackEvent(name, properties, measurements)- Properties - String key-value pairs for filtering
- Measurements - Numeric values for aggregation
Dependency Tracking
Application Insights auto-tracks outgoing calls as dependency telemetry. Auto-Tracked:- HttpClient calls
- SQL (SqlClient)
- Azure SDKs (Storage, Service Bus, Cosmos)
- Redis, MongoDB
Distributed Tracing
End-to-end tracing links telemetry across microservices. Key Concepts:- Operation.Id - Root trace identifier (trace ID)
- Operation.ParentId - Parent span identifier
- W3C TraceContext -
traceparentheader standard - End-to-End Transaction - Timeline view in portal
Availability Testing
Synthetic monitoring validates uptime from multiple locations. Test Types:- Standard test - URL ping on schedule (default 5 min)
- Multi-step web test - Recorded HTTP sequence (deprecated)
- TrackAvailability() - Programmatic custom tests
Run availability tests from at least 5 locations and alert when 2+ locations fail simultaneously - single location failures are often transient network issues.
Metric Alerts
Azure Monitor alerts fire when metrics exceed thresholds. Alert Types:- Static threshold - Fixed value comparison
- Dynamic threshold - ML-based normal range
- Evaluation frequency - 1, 5, 15, 30, 60 minutes
- Aggregation - avg, min, max, total, count
Performance Optimization
Caching Strategies
Caching reduces database and API load by storing frequently accessed data. Cache Patterns:- Cache-Aside - App manages (read miss → DB fetch → cache store)
- Write-Through - Write to cache and DB together
- Write-Behind - Async write to DB
Connection Pooling
Reuse established connections to avoid expensive connection setup. Best Practices:- ADO.NET - Automatic pool per connection string
- HttpClient - Singleton via IHttpClientFactory
- Redis - Single multiplexed ConnectionMultiplexer
Timeout Configurations
Proper timeouts prevent resource exhaustion from slow dependencies. Key Timeouts:- HttpClient.Timeout - Default 100s (usually too long)
- SqlCommand.CommandTimeout - 30s default
- CancellationToken - Pass caller’s cancellation context
Use Polly’s timeout policy around HttpClient calls - Polly can combine timeout, retry, and circuit breaker in a coherent resilience strategy.
Throughput Optimization
Maximize requests per second through async patterns and parallelism. Key Techniques:- Async all I/O - Never block async code with
.Result/.Wait() - Parallel independent ops -
Task.WhenAllinstead of sequential await - Batch writes - Reduce round trips
- HTTP/2 - Multiplex requests over single connection
Latency Reduction
Minimize response time through architectural patterns. Strategies:- CDN - Serve static content from edge PoPs
- Redis cache - Sub-millisecond responses for hot data
- Read replicas - Distribute read load
- Always On - Prevents App Service cold start
- Async HTTP APIs - 202 Accepted + status polling
Diagnostic Logging
App Service diagnostic logging captures application and platform logs. Log Types:- Application logging - stdout/stderr to Storage/Blob
- Web server logging - IIS logs
- Detailed error messages - HTML error pages
- Failed request tracing - FREB logs
App Service Profiler
Automatic performance profiling when thresholds are exceeded. Features:- Auto CPU profiling on performance degradation
- Snapshot Debugger - Capture memory dumps on exceptions
- Kudu -
/api/processes,/api/dumpfor manual analysis - Near-zero overhead
Azure Dashboards
Aggregate metrics and logs across services into shared views. Dashboard Features:- Pin tiles from any portal chart
- Log Analytics query results as tiles
- JSON export/import for dashboard-as-code
- Share with portal users
- Interactive, parametrized dashboards
- Combine metrics and log queries
- Drill-down and conditional display
Use Azure Workbooks instead of static dashboards for complex observability scenarios - they support parameters, drill-down, and conditional display.
Exam Checklist
- Understand Application Insights telemetry types
- Know how to track custom events and metrics
- Understand dependency tracking and Application Map
- Know distributed tracing with Operation.Id
- Understand availability testing patterns
- Know metric alert types (static vs dynamic)
- Understand caching strategies (Cache-Aside)
- Know connection pooling best practices
- Understand timeout configuration patterns
- Know throughput optimization with async/await
- Understand latency reduction strategies
- Know diagnostic logging destinations
- Understand App Service Profiler capabilities