Question

Difficulty: HardQuery and Analyze Application Insights Telemetry

An administrator reports that querying telemetry data in Log Analytics for an Azure App Service web application is frequently timing out and exceeding workspace query scan limits.

The `dependencies` table contains the following sample schema and records:

timestampnametargettypesuccessduration
2026-07-17T12:00:00ZGET /api/v1/orderssqlserver.database.windows.netSQLtrue120.0
2026-07-17T13:15:00ZPOST /paymentapi.stripe.comHTTPfalse2500.0
2026-07-17T14:30:00ZGET /user/profileapi.github.comHTTPfalse1800.0

You need to write an optimized Kusto Query Language (KQL) query that identifies the 95th percentile of the duration of all failed external HTTP dependency calls over the last 24 hours, grouped by the target of the dependency.

Which Kusto Query Language (KQL) query should you use to retrieve the required data while minimizing resource utilization?

  1. A
    dependencies
    | where success == false and type == "HTTP"
    | summarize percentiles(duration, 95) by target
  2. B
    dependencies
    | where success == false and type == "HTTP"
    | summarize percentiles(duration, 95) by target, timestamp
    | where timestamp > ago(24h)
  3. dependencies
    | where timestamp > ago(24h)
    | where success == false and type == "HTTP"
    | summarize percentiles(duration, 95) by target
    Answer
  4. D
    dependencies
    | where success == false and type == "HTTP"
    | project target, duration, type
    | summarize avg(duration) by target

Answer

The query that filters by timestamp > ago(24h) first, then filters by success and type, and aggregates using percentiles(duration, 95) by target.
The correct query filters the telemetry by timestamp at the very beginning of the pipeline using `where timestamp > ago(24h)`. In Kusto Query Language (KQL), filtering by time range as early as possible is a best practice because it limits the volume of data scanned by the query engine. It then filters for failed HTTP dependencies (`success == false and type == 'HTTP'`) before performing the `summarize percentiles(duration, 95) by target` aggregation, ensuring optimal performance and avoiding query timeouts or scan limit errors.

Step-by-Step Solution

1
Identify the target table and initial optimization step.
The target table is dependencies. To optimize KQL query performance and avoid exceeding scan limits or causing timeouts, the time range filter must be applied immediately using `where timestamp > ago(24h)`.
Applying the time-range filter first ensures that only the relevant data partition is scanned by the query engine.
2
Apply the metric status and type filters.
Add the filters `where success == false and type == 'HTTP'` to isolate failed external HTTP dependency calls.
Filtering rows before aggregation reduces the dataset size and improves query execution speed.
3
Aggregate the data to calculate the 95th percentile.
Use `summarize percentiles(duration, 95) by target` to calculate the 95th percentile of duration for each target.
The percentiles function calculates the specified percentile value, which satisfies the requirement to find the 95th percentile rather than the average.

Key Concept

Optimizing KQL queries in Azure Application Insights by placing time-range filters as early as possible in the query pipeline to minimize scanned data volume and avoid query limits.
Rate this question