Question

Difficulty: MediumQuery and Analyze Application Insights Telemetry

You are troubleshooting a performance issue in a web application. You need to identify the top 3 operations with the longest average duration over the past 12 hours by querying the Application Insights telemetry. The query must be optimized to minimize data scan limits and query execution time.

Which Kusto Query Language (KQL) query should you run to retrieve this data efficiently?

  1. requests
    | where timestamp > ago(12h)
    | summarize AvgDuration = avg(duration) by name
    | top 3 by AvgDuration desc
    Answer
  2. B
    requests
    | summarize AvgDuration = avg(duration) by name
    | top 3 by AvgDuration desc
  3. C
    requests
    | summarize AvgDuration = avg(duration) by name, timestamp
    | where timestamp > ago(12h)
    | top 3 by AvgDuration desc
  4. D
    requests
    | where timestamp > ago(12h)
    | summarize avg(duration) by name
    | top 3 by duration desc

Answer

The KQL query that filters by timestamp > ago(12h) first, aggregates the average duration using summarize AvgDuration = avg(duration) by name, and then uses top 3 by AvgDuration desc.
The correct query filters the requests table by timestamp first, ensuring only telemetry from the past 12 hours is scanned and processed. It then calculates the average duration using the summarize operator and correctly references the aggregated alias in the top operator.

Step-by-Step Solution

1
Filter incoming records by time range using a where clause.
Limits the dataset to requests from the last 12 hours.
Applying time range filters first is the primary optimization best practice in KQL queries.
2
Aggregate the data using the summarize operator to calculate the average duration grouped by operation name.
Produces a set of distinct operation names with their respective average durations.
Required to identify the performance metrics per operation.
3
Sort the results and limit the output using the top operator.
Returns the 3 operations with the highest average duration.
Extracts the top 3 bottlenecks from the summarized telemetry.

Key Concept

KQL Query Optimization with Time Range Filtering
Rate this question