Question

Difficulty: MediumQuery and Analyze Application Insights Telemetry

You are analyzing application performance issues for an Azure Web App by using Application Insights. You need to write a Kusto Query Language (KQL) query that retrieves the top 5 external dependency calls with the longest average duration over the last 24 hours. The query must execute efficiently and avoid scanning unnecessary historical data.

Which two of the following queries should you use?

  1. dependencies
    | where timestamp > ago(24h)
    | summarize AvgDuration = avg(duration) by name
    | top 5 by AvgDuration desc
    Answer
  2. dependencies
    | where timestamp > ago(24h)
    | summarize AvgDuration = avg(duration) by name
    | order by AvgDuration desc
    | take 5
    Answer
  3. C
    dependencies
    | summarize AvgDuration = avg(duration) by name, timestamp
    | where timestamp > ago(24h)
    | top 5 by AvgDuration desc
  4. D
    dependencies
    | summarize AvgDuration = avg(duration) by name
    | top 5 by AvgDuration desc

Answer

The queries that first filter dependencies by timestamp > ago(24h) and then summarize duration by name using either 'top 5 by AvgDuration desc' or 'order by AvgDuration desc | take 5' are correct.
The correct queries apply the time filter (where timestamp > ago(24h)) immediately after referencing the dependencies table. This ensures the query engine only scans the last 24 hours of data. The aggregation calculates the average duration grouped by name. Finally, the top 5 or order by and take 5 operators are functionally equivalent ways to retrieve the 5 slowest dependencies.

Step-by-Step Solution

1
Apply a time-range filter as the very first step in the query pipeline.
Limits the input dataset to dependency telemetry from the last 24 hours, preventing a full scan of historical data.
KQL is most efficient when the dataset is reduced early in the execution plan, especially for timestamp-based partitions.
2
Aggregate the duration of the filtered dependencies using the avg function, grouping by the dependency name.
Calculates the average duration for each unique dependency name over the last 24 hours.
Grouping by name allows us to identify which external dependencies are causing bottlenecks.
3
Sort and limit the results to the top 5 records.
Returns the 5 dependencies with the highest average duration.
Using either 'top 5 by AvgDuration desc' or 'order by AvgDuration desc | take 5' achieves the same output.

Key Concept

Efficient telemetry querying in Application Insights using Kusto Query Language (KQL) by filtering on timestamp first.
Rate this question