Lesson 1 of 2 Analyzing Telemetry with KQL

Understanding KQL

This lesson explains where KQL runs and the operators and functions for filtering, shaping, time handling, aggregation and charting.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe the structure of a KQL query.
  • Choose operators for filtering and shaping.
  • Explain string comparison operators.
  • Explain why percentiles are used for latency.

Where KQL runs

Kusto Query Language (KQL) is a read-only query language for large volumes of log and telemetry data. In Azure Monitor it queries Log Analytics workspaces, which store Application Insights data (for workspace-based resources), Container Apps and Container insights logs, resource logs sent by diagnostic settings and many other sources. Queries are written on the Logs page of a workspace, an Application Insights resource or another resource, and the same queries drive log search alerts, workbooks and dashboards.

A query starts with a table name and passes rows through a sequence of operators separated by the pipe character |. Each operator takes the rows from the previous step and produces new rows, so a query reads from top to bottom like a recipe.

Filtering and shaping

The most frequently used operators filter rows and shape columns.

OperatorPurposeExample
whereKeep rows that match a conditionwhere Success == false and DurationMs > 1000
projectChoose, rename and compute columnsproject TimeGenerated, Name, DurationMs
extendAdd calculated columns, keeping existing onesextend Seconds = DurationMs / 1000
take or limitReturn a number of arbitrary rowstake 10
sort by / order bySort rowsorder by DurationMs desc
topSort and keep the first Ntop 5 by DurationMs desc
distinctUnique combinations of columnsdistinct ResultCode

String comparisons follow precise rules. == is case-sensitive and =~ is case-insensitive. has matches whole terms using the index and is fast, while contains matches any substring and is slower; startswith, endswith, in and matches regex cover other cases. Dynamic (JSON) columns, such as custom dimensions, are accessed with dot or bracket notation and usually converted with tostring() or toint().

The following diagram shows a KQL query as a pipeline of operators.

The KQL query as a pipeline. It starts from AppRequests, filters early on time and failure, summarizes a count and a median duration by operation name, keeps groups with at least 20 failures, and sorts by the median. The second where clause works on the aggregated rows, which a filter before summarize could not do.
Each operator works on the rows produced by the one before it.
Match the pairs

KQL operators

Exam skills 4.2.2

Match each KQL operator with what it does.

Log in to try this activity Interactive activities are free with an account.

Time

Every log table has a time column, TimeGenerated in Log Analytics tables (timestamp in the classic Application Insights tables). Filtering on time early in the query is the most important performance practice, because the engine can skip data outside the range. ago(1h) returns the time one hour before now; timespans are written as 30s, 5m, 2h or 7d; between (datetime(2026-11-01) .. datetime(2026-11-02)) selects a range; and startofday() and similar functions round times.

True or false

Working with time

Exam skills 4.2.2

Decide whether each statement about time in KQL is true.

Log in to try this activity Interactive activities are free with an account.

Aggregation and charts

summarize groups rows and computes aggregates for each group. Common aggregation functions include count(), countif(), sum(), avg(), min(), max(), dcount() (approximate distinct count), percentile() and percentiles(), and make_set(). Grouping by bin(TimeGenerated, 5m) buckets rows into five-minute intervals, which produces a time series that render timechart draws.

AppRequests
| where TimeGenerated > ago(24h)
| summarize Requests = count(), Failures = countif(Success == false),
            P95 = percentile(DurationMs, 95) by bin(TimeGenerated, 15m)
| extend FailureRate = round(100.0 * Failures / Requests, 2)
| render timechart

Averages can hide problems: a service with most requests at 100 ms and a few at 10 seconds has a reasonable average but unhappy users. Percentiles, such as the 95th or 99th, describe what most users experience and are the right measure for latency objectives. let statements name values or sub-queries for reuse, which keeps longer queries readable.

Put in order

Building a latency chart

Exam skills 4.2.2

Put the parts of a query that charts failures and p95 latency in order.

Log in to try this activity Interactive activities are free with an account.
Worked example

Reading a query

An engineer must find which API operations had the slowest typical latency for failed requests in the last six hours, considering only operations with at least 20 failures.

The query starts from AppRequests, filters early on time and failure, groups by operation name with a count and a median (50th percentile) of duration, keeps groups with at least 20 failures, and sorts.

AppRequests
| where TimeGenerated > ago(6h) and Success == false
| summarize Failures = count(), MedianMs = percentile(DurationMs, 50) by Name
| where Failures >= 20
| order by MedianMs desc

Filtering with where Failures >= 20 after summarize works on the aggregated rows, which a filter before summarize could not do. Using avg() would let a few extreme failures dominate. Omitting the time filter would scan the whole retention period.

Check yourself

What is the difference between has and contains in KQL?

Show answer

has matches whole terms using the index and is fast; contains matches any substring and is slower.

Exam Tips

Remember for the exam

  • A query is a table followed by operators joined with |; filter on time first.
  • where filters, project selects, extend adds, summarize aggregates by groups.
  • == is case-sensitive, =~ is not; has matches whole terms faster than contains.
  • Use percentile() for latency, bin() for time series and render timechart to chart.