Skip to content
Visual explainer 3h 30m to learn 5 steps

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.

Topic 23 of 33

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.

FlowFrom a symptom to an alert
  1. 1
    Collect

    Diagnostic settings and Application Insights send data to a workspace

  2. 2
    Notice

    A metric chart shows failed requests rising

  3. 3
    Query

    KQL narrows it to one operation and one dependency

  4. 4
    Correlate

    The operation ID links the request to the failing database call

  5. 5
    Alert

    An alert rule fires an action group next time

CompareThree kinds of telemetry
Metrics
  • Numbers over time
  • Cheap and near real time
  • Good for alerts on thresholds
  • Little context about why
Logs
  • Structured records with many fields
  • Queried with KQL
  • Explain what happened
  • Cost grows with volume
Traces
  • One request across services
  • Spans share an operation ID
  • Show where time was spent
  • Come from app instrumentation
MapWhere telemetry lands in the workspace
Log Analytics workspace
  • 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.

FlowHow a KQL pipeline narrows data
  1. 1
    AppDependencies

    Every outgoing call in the workspace

  2. 2
    where TimeGenerated > ago(1h)

    Only the last hour

  3. 3
    where Success == false

    Only failed calls

  4. 4
    summarize count() by Target

    Failures per downstream system

  5. 5
    order 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.

SequenceOne trace across two services
Browser
API
Worker API
PostgreSQL
  1. 1GET /orders (new operation ID)
    Browser to API: GET /orders (new operation ID)
  2. 2HTTP call with traceparent header
    API to Worker API: HTTP call with traceparent header
  3. 3SQL query, recorded as dependency
    Worker API to PostgreSQL: SQL query, recorded as dependency
  4. 4Result after 2.4 s
    PostgreSQL to Worker API: Result after 2.4 s
  5. 5200 OK, same operation ID
    Worker API to API: 200 OK, same operation ID
  6. 6Slow response, trace shows why
    API to Browser: Slow response, trace shows why

Learn it in 5 short steps

About 40m each. Track them with a timer in your plan.

  1. 1
    Send diagnostics to Log Analytics~40m
  2. 2
    Instrument the app with Application Insights~40m
  3. 3
    Write a KQL query~40m
  4. 4
    Create an alert rule~40m
  5. 5
    Correlate 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

kusto
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 desc

Failure 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.

kusto
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 desc

Turning 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.

bash
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.

Question 1

1You enabled nothing yet. Which data from a storage account can you already see in Azure Monitor?

Question 2

2Which KQL operator groups rows and calculates aggregates such as count() and percentile()?

Question 3

3How do two services end up in the same Application Insights trace?

Question 4

4Which alert type suits 'more than 5 percent of requests failed in 10 minutes' best?

Question 5

5What does an action group define?

0/5 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Send a storage account's blob logs and all metrics to a Log Analytics workspace, then confirm data arrives.

  2. Exercise 2medium

    Write a KQL query that shows the five slowest operations by 95th percentile latency in the last 24 hours, with request counts.

  3. 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.

Go deeper

ShareXLinkedInWhatsApp