Azure Monitor, Log Analytics and Application Insights
Correlate metrics, traces and logs and write a KQL query and an alert for a real symptom.
By Invicly Tech, , in Microsoft Azure Cloud Engineering. About 13 minutes to read.
In short
Azure Monitor is the umbrella service that collects metrics, logs and traces from Azure resources and your own code. Resources send platform logs to a Log Analytics workspace through diagnostic settings, and Application Insights records requests, dependencies and exceptions from the app into the same workspace. You then ask questions with KQL (Kusto Query Language) and turn the useful answers into alert rules.
Think of it like this: Metrics are the car's dashboard gauges, logs are the mechanic's notebook and traces are the dashcam recording of one trip.
Explained simply
When an app misbehaves in the cloud you cannot walk over and look at the server. You need the system to tell you what happened. Azure Monitor is the Azure service that collects that information: numbers over time (metrics), detailed records (logs) and the path of single requests through your services (traces).
Azure collects basic metrics for most resources by itself, such as CPU or request counts. Detailed logs are different. You must switch them on with a diagnostic setting, which is a small rule on each resource that says which logs to send and where. The usual destination is a Log Analytics workspace, a store built for searching logs.
Your own code needs instrumentation too. Application Insights, part of Azure Monitor, records each incoming request, each call your code makes to a database or another API, and each exception. You add it with a small library and a connection string. Its data goes into the same workspace as the resource logs.
To ask questions you write KQL, the Kusto Query Language. A query reads like a pipeline: start with a table, then filter, then group, then sort. When a query reliably spots a real problem, such as too many failed requests, you save it as an alert rule so Azure tells you next time instead of a customer.
Press Play on a diagram to walk through it one step at a time.
- 1Collect
Diagnostic settings and Application Insights send data to a workspace
- 2Notice
A metric chart shows failed requests rising
- 3Query
KQL narrows it to one operation and one dependency
- 4Correlate
The operation ID links the request to the failing database call
- 5Alert
An alert rule fires an action group next time
- Numbers over time
- Cheap and near real time
- Good for alerts on thresholds
- Little context about why
- Structured records with many fields
- Queried with KQL
- Explain what happened
- Cost grows with volume
- One request across services
- Spans share an operation ID
- Show where time was spent
- Come from app instrumentation
- Application Insights
- AppRequests
- AppDependencies
- AppTraces
- AppExceptions
- Resource logs
- Resource-specific tables per service
- AzureDiagnostics for older services
- Activity log
- AzureActivity: create, delete, role changes
- Metrics
- Platform metrics store by default
- Optional export to AzureMetrics
In depth
Diagnostic settings: getting resource logs in
Each Azure resource offers log categories, such as storage read and write operations or Container Apps console output. Nothing is kept until you create a diagnostic setting that picks categories and a destination: a Log Analytics workspace for querying, a storage account for cheap archiving, or Event Hubs for streaming to another tool. A resource can have several settings. The allLogs category group is convenient but can be noisy and expensive on busy resources, so choose categories on purpose. Assign the built-in diagnostic policies at a management group to make this automatic for new resources. The activity log, which records control-plane actions like creating or deleting resources, is subscription-level and also needs its own diagnostic setting to reach the workspace.
- Workspace: query with KQL and alert
- Storage account: cheap long-term archive
- Event Hubs: stream to a third-party SIEM
- Activity log: who changed what, needs its own setting
Instrumenting the app with Application Insights
Create a workspace-based Application Insights resource and copy its connection string. In code, the Azure Monitor OpenTelemetry Distro does most of the work: in Python, install azure-monitor-opentelemetry and call configure_azure_monitor() once at start-up. It automatically records incoming HTTP requests for common frameworks, outgoing HTTP and database calls, logs and exceptions. Pass the connection string through the APPLICATIONINSIGHTS_CONNECTION_STRING setting, never in source code. Set a cloud role name per service so the application map shows the API and the worker as separate boxes. In the workspace, the data appears in tables such as AppRequests, AppDependencies, AppTraces and AppExceptions.
- One Application Insights resource per environment
- Connection string from app settings, not code
- Role name per service for the application map
- Sampling reduces volume on busy apps
Reading a KQL query
KQL is read-only and flows top to bottom. Each line after the table name starts with a pipe and an operator. where filters rows, project picks columns, extend adds calculated columns, summarize groups rows and aggregates them with functions like count(), avg() and percentile(), and order by sorts. bin(TimeGenerated, 5m) rounds timestamps into buckets, which turns raw events into a time series you can chart. Always filter on time first, because it makes queries faster and cheaper. join combines two tables on a shared column, which is how you link requests to dependencies by OperationId. Start small, run often, and add one line at a time.
- 1AppDependencies
Every outgoing call in the workspace
- 2where TimeGenerated > ago(1h)
Only the last hour
- 3where Success == false
Only failed calls
- 4summarize count() by Target
Failures per downstream system
- 5order by count_ desc
Worst target first
Alert rules that people trust
An alert rule has a scope (what to watch), a condition (a metric threshold or a log query result), an evaluation frequency and window, a severity, and one or more action groups that say who to notify by email, SMS, push, webhook or a runbook. Metric alerts are fast and cheap for simple thresholds. Log search alerts run a KQL query on a schedule and suit conditions like failure rate above 5 percent over 10 minutes. Good alerts describe user pain, include a runbook link in the description, and fire rarely enough that people still read them. Each alert should have an owner and a clear first action.
- Metric alert: threshold on a number
- Log search alert: scheduled KQL query
- Action group: who and how to notify
- Severity 0 is critical, 4 is verbose
Correlating one request across services
When the API receives a request, Application Insights starts a trace with an operation ID. Outgoing HTTP calls carry a W3C traceparent header, so the next service joins the same trace. Its request and dependency records share the operation ID, with a parent ID showing who called whom. In the portal, the end-to-end transaction view draws this as a timeline. In KQL, filter every App table by the same OperationId. Messages through Service Bus can keep the trace too when both sides use supported SDKs. This is how you move from a slow request to the exact database call that was slow.
- Browser to API: GET /orders (new operation ID)1GET /orders (new operation ID)
- API to Worker API: HTTP call with traceparent header2HTTP call with traceparent header
- Worker API to PostgreSQL: SQL query, recorded as dependency3SQL query, recorded as dependency
- PostgreSQL to Worker API: Result after 2.4 s4Result after 2.4 s
- Worker API to API: 200 OK, same operation ID5200 OK, same operation ID
- API to Browser: Slow response, trace shows why6Slow response, trace shows why
Learn it in 5 short steps
About 40m each. Track them with a timer in your plan.
- 1Send diagnostics to Log Analytics~40m
- 2Instrument the app with Application Insights~40m
- 3Write a KQL query~40m
- 4Create an alert rule~40m
- 5Correlate a request across services~40m
Key points
- Platform metrics are collected automatically; resource logs need a diagnostic setting before anything is stored.
- Application Insights should be workspace-based so app data lands in Log Analytics next to resource logs.
- The Azure Monitor OpenTelemetry Distro instruments Python, .NET, Java and Node.js apps with a connection string.
- Every request gets an operation ID that ties together its dependencies, traces and exceptions.
- Alert on symptoms users feel, such as failure rate or latency, and send them to an action group.
Key terms
Tap a card to flip it. 0/6 known
Examples
AppRequests
| where TimeGenerated > ago(1h)
| summarize total = count(),
failed = countif(Success == false),
p95_ms = percentile(DurationMs, 95)
by bin(TimeGenerated, 5m), Name
| extend failure_rate = round(100.0 * failed / total, 1)
| order by TimeGenerated descFailure rate and 95th percentile latency per operation, in 5-minute buckets.
Finding why checkout failures doubled
Step 1: the Application Insights failures view shows POST /checkout failing about 8 percent of the time since 14:00. Step 2: you query AppDependencies for failed calls in that window and group by target; nearly all failures point at the payments API. Step 3: you take one OperationId and open the end-to-end view, which shows the payments call timing out after 30 seconds. Step 4: the payments API's own requests are fine, but its container restarts appear in the Container Apps system logs at 14:00, after a deployment. You roll back and failures return to normal.
AppDependencies
| where TimeGenerated between (datetime(2026-11-30 13:30) .. datetime(2026-11-30 15:00))
| where Success == false
| summarize failures = count() by Target, ResultCode
| order by failures descTurning the query into a log search alert
You want a page when more than 5 percent of requests fail for 10 minutes. Step 1: write a query that returns the failure rate. Step 2: create a log search alert scoped to the workspace that runs every 5 minutes over a 10 minute window. Step 3: attach an action group that emails the on-call address and posts to a webhook. Step 4: put the runbook link in the description. Step 5: test it by pointing a staging app at a broken dependency and confirm the alert fires and then resolves. The scheduled-query command may prompt to install a CLI extension the first time.
az monitor scheduled-query create -g rg-lab -n checkout-failure-rate \
--scopes <workspace-resource-id> \
--condition "count 'Failed' > 20" \
--condition-query Failed="AppRequests | where Success == false" \
--evaluation-frequency 5m --window-size 10m --severity 2 \
--action-groups <action-group-resource-id> \
--description "Runbook: https://wiki.example.com/runbooks/checkout"Quick reference
- Resource logs need a diagnostic setting; platform metrics are collected automatically
- Use workspace-based Application Insights so app and resource logs share one workspace
- Python: pip install azure-monitor-opentelemetry, then call configure_azure_monitor()
- Filter on TimeGenerated first in every KQL query
- summarize count() by bin(TimeGenerated, 5m) turns events into a chart
- OperationId links requests, dependencies, traces and exceptions from one call
- Alert on failure rate and latency, attach an action group and a runbook link
Common mistakes
- Expecting resource logs to appear without creating a diagnostic setting first.
- Alerting on every error log line instead of a rate, which floods people with noise.
- Sending everything at full verbosity and discovering the ingestion bill a month later.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Send a storage account's blob logs and all metrics to a Log Analytics workspace, then confirm data arrives.
- Exercise 2medium
Write a KQL query that shows the five slowest operations by 95th percentile latency in the last 24 hours, with request counts.
- Exercise 3hard
For failed requests in the last hour, list the failing dependency behind each one using OperationId, and count by request name and dependency target.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- Is Azure Monitor free?
- Platform metrics and the activity log in the portal are free. Log ingestion into Log Analytics and Application Insights is billed per gigabyte, with a small free allowance, so a lab with a few apps costs little if you avoid verbose logging.
- Do I need one Log Analytics workspace or many?
- Start with one workspace per environment or per region. Microsoft recommends as few workspaces as your access, data residency and billing needs allow, because queries across one workspace are simpler.
- What is the difference between Application Insights and Log Analytics?
- Application Insights collects and visualises application telemetry. Log Analytics is the workspace store and query tool. Workspace-based Application Insights writes its data into a Log Analytics workspace.
- Can I practise KQL without an Azure subscription?
- Yes. Microsoft runs a public demo Log Analytics environment and the free Azure Data Explorer help cluster with sample data, both usable from a browser with a Microsoft account.