Skip to main content

Kusto Query Language (KQL)

Kusto Query Language (KQL) is the query language used across Azure Monitor Log Analytics, Application Insights, and Microsoft Sentinel to search, filter, and aggregate large volumes of log and telemetry data. It uses a readable pipe-based syntax (`|`) chaining operators like `where`, `summarize`, and `project`, purpose-built for fast exploration of time-series and event data rather than relational joins.

Kusto Query Language (KQL)

KQL pipes data through a sequence of operators — filter, project, summarize — to turn raw log data into actionable answers, like "how many 500 errors occurred in the last hour."

Why It Matters in Production

Swiggy's on-call engineers use a saved KQL query to instantly surface all 5xx errors grouped by service during an incident, cutting diagnosis time from manually grepping logs to seconds.

AppRequests | where TimeGenerated > ago(1h) | where ResultCode startswith "5" | summarize ErrorCount = count() by CloudRoleName | order by ErrorCount desc

Tip

Always add a TimeGenerated filter near the top of a KQL query — without it, Log Analytics scans the entire retention window and queries run far slower.

Frequently Asked Questions

Why does Azure use a separate language like KQL instead of standard SQL for its logging services?

KQL was purpose-built for exploring large volumes of semi-structured, time-series telemetry — its pipe-based syntax (`Table | where Timestamp > ago(1h) | summarize count() by bin(Timestamp, 5m)`) reads as a left-to-right sequence of transformations rather than nested SQL clauses, which maps naturally to how engineers actually explore logs interactively. It also has native operators for time-bucketing, string parsing, and anomaly detection that plain SQL lacks without heavy extensions.

What's a common performance mistake when writing KQL queries against large Log Analytics workspaces?

Filtering on time range too late in the query, or omitting it altogether — `where Timestamp > ago(1h)` should come as early as possible (ideally first) so Kusto can prune the data it scans before applying more expensive operators, since queries are billed and throttled based on data scanned. Running unbounded `search *` queries or joining large tables without narrowing both sides by time first is the most common cause of slow or throttled Sentinel and Log Analytics queries.