Monitor, troubleshoot, and optimize Azure solutions
Observe, then fix
Application Insights is the app-side telemetry store: requests, dependencies, exceptions, traces, custom events, and metrics, correlated by operation_Id for distributed tracing. The SDK is configured with a connection string (instrumentation keys are legacy). Sampling is frequently on by default, so counts are approximate - never treat them as billing or exact-volume metrics. Add custom telemetry with TelemetryClient; enrich context with ITelemetryInitializer. Availability tests give synthetic uptime checks from outside.
Log Analytics holds logs queried with KQL. Know the table names and that ago(), summarize, bin(), and join cover most questions. Always bound the time window.
Performance: cache read-heavy data in Azure Cache for Redis using cache-aside (read cache; on miss load from source and populate; invalidate on write) with an explicit TTL. Avoid caching per-user data under a shared key, and remember eviction happens under memory pressure. Use CDN or Front Door for static assets. Handle transient faults with retries plus exponential backoff (Polly, Microsoft.Extensions.Http.Resilience) and a circuit breaker - retries are only safe if the operation is idempotent, because the first attempt may have succeeded. Autoscale rules combine metrics with cool-down periods and instance limits.
Traps
Assuming telemetry is complete while sampling runs; querying the wrong table or an unbounded time range; retrying non-idempotent writes; no TTL so stale data creeps in; autoscale with no minimum instance count.
Worked example
"Dependency calls fail intermittently." Query dependencies | where success == false | summarize count() by name, resultCode, then filter slow ones with where duration > 1000.
Rule of thumb
Measure with Application Insights, change one thing, and compare the same time window.