You are troubleshooting a high-volume Azure App Service application. You need to write an optimized Kusto Query Language (KQL) query in Application Insights to analyze dependencies associated with slow requests. Specifically, you want to identify the percentile duration of dependency calls that occurred during requests that took longer than () within the last .
Which KQL query should you use to retrieve this data with the best query performance?
- let timeLimit = ago(24h);
let slowRequests = requests
| where timestamp > timeLimit and duration > 3000
| project operation_Id;
dependencies
| where timestamp > timeLimit
| join kind=inner slowRequests on operation_Id
| summarize p95 = percentile(duration, 95) by name
| order by p95 descAnswer - Blet slowRequests = requests
| where duration > 3000
| project operation_Id;
dependencies
| where timestamp > ago(24h)
| join kind=inner slowRequests on operation_Id
| summarize p95 = percentile(duration, 95) by name
| order by p95 desc - Clet timeLimit = ago(24h);
let slowRequests = requests
| where timestamp > timeLimit and duration > 3000
| project operation_Id;
dependencies
| join kind=inner slowRequests on operation_Id
| summarize p95 = percentile(duration, 95) by name
| order by p95 desc - Ddependencies
| join kind=inner requests on operation_Id
| where timestamp > ago(24h) and requests.duration > 3000
| summarize p95 = percentile(duration, 95) by name
| order by p95 desc
Answer
The correct query is the one that filters both the requests and dependencies tables by the 24-hour time range before joining them.
The correct query applies the time range filter to both the requests and dependencies tables before executing the join. In KQL, when joining two telemetry tables, it is critical to filter both datasets by time range. If one table is left unfiltered, the query optimizer cannot prune partitions effectively, resulting in a scan of all historical logs. Filtering first reduces the volume of data that needs to be loaded into memory and joined, ensuring optimal performance on large datasets.
Step-by-Step Solution
Key Concept
To maintain high query performance on Application Insights telemetry, KQL queries must filter all joined tables by time-range before executing the join operation.