Skip to content

Advanced KQL Queries for Logic Apps in Application Insights: A Practical Guide

Logic app kql performance queries

Azure Logic Apps are powerful tools for building integration workflows, but their performance can sometimes be affected by external dependencies. Observability is crucial for identifying bottlenecks and ensuring robust solutions.

In this post, we will explore how to use Application Insights KQL to investigate performance issues and conduct deeper analysis. We will also look at specific log levels, connectivity, and some of my favourite KQL performance Logic Apps queries to help you spot potential problems more quickly.

Why Observability Matters in Logic Apps Performance

Observability is important when dealing with external systems. Logic Apps often depend on APIs, SaaS services, or other cloud components. If a particular step in your workflow takes too long or fails, it can have a knock-on effect on other processes. By leveraging Application Insights and KQL, you gain clarity on where these performance issues occur.

Logging Setup for Application Insights with Logic App Standard

Enable Application Insights

Before you can begin using advanced KQL queries for Logic Apps in Application Insights, ensure that your Logic App Standard is correctly configured to send logs to Application Insights.

JSON
{
  "name": "APPLICATIONINSIGHTS_CONNECTION_STRING",
  "value": "InstrumentationKey=xxx;IngestionEndpoint=https://westeurope-3.in.applicationinsights.azure.com/;LiveEndpoint=https://xxx.livediagnostics.monitor.azure.com/;ApplicationId=xxx",
  "slotSetting": false
}

Enabling Debug-Level Logs

To capture the data necessary for detailed queries, enable debug logging. Be aware that this will increase log size since every action will report its status:

JSON
{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request",
        "enableDependencyTracking": false,
        "enablePerformanceCountersCollection": false
      }
    },
    "logLevel": {
      "default": "Information",
      "Host.Results": "Error",
      "Function": "Error",
      "Host.Aggregator": "Error"
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle.Workflows",
    "version": "[1.*, 2.0.0)"
  }
}

Accessing Logs in Application Insights

  1. Go to your Application Insights resource.
  2. Select Monitoring > Logs.
  3. Switch from the simple query mode to the KQL editor to run KQL performance Logic Apps queries.

Essential KQL Queries for Logic Apps Performance

Below are some of my favourite Azure Logic Apps performance queries. Each one targets a specific angle, from pinpointing slow-running actions to monitoring daily counts.

Workflow Executions over Time with Average Duration

This query shows you the total count of Logic App runs and the average duration over the past 30 days. It’s a good starting point for high-level trends.

logic app kql Workflow Executions over Time with Average Duration chart
logic app kql Workflow Executions over Time with Average Duration
Kusto
requests
| where isnotempty(parse_json(tostring(customDimensions.resource)).runId) and timestamp >= ago(30d)  // Last 30 days
| extend DurationSeconds = duration / 1000
| summarize
    CountRuns = count(),
    AvgRunDuration = avg(DurationSeconds)
  by operation_Name, bin(timestamp, 1d)
| order by timestamp asc
| render columnchart

Top 10 Slowest Action Executions by Action Name

If you need to focus on a particular action, this query helps you zoom in on specific names and find out which ones are the slowest or most resource-intensive.

logic app Top 10 Slowest Action Executions by Action Name kql
preview
Kusto
requests
| where isnotempty(parse_json(tostring(customDimensions.resource)).runId)and success == true  
| extend DurationSeconds = duration / 1000
| project timestamp, operation_Name, name, DurationSeconds, RunId = parse_json(tostring(customDimensions.resource)).runId
| order by DurationSeconds desc
| top 10 by DurationSeconds

Top 10 Slowest Executions by Specific Action or Workflow

Uncomment or adjust the where clauses to filter by specific actions or workflow names. This lets you zoom in on trouble spots within a single workflow.

Kusto
requests
| where success == true
// | where name == "YOUR_ACTION_NAME"
// | where operation_Name == "YOUR_WORKFLOW_NAME"
| extend DurationSeconds = duration / 1000
| project timestamp, operation_Name, name, duration, DurationSeconds, RunId = parse_json(tostring(customDimensions.resource)).runId
| order by duration desc
| top 10 by DurationSeconds

Top 10 Workflows by Total Duration

This query surfaces the ten workflows consuming the most total execution time. It’s excellent for spotting resource-heavy workflows that might need optimisation.

logic app Top 10 Workflows by Total Duration kql kusto
Kusto
requests
| where success == true
| extend DurationSeconds = duration / 1000
| summarize TotalDuration = sum(DurationSeconds), TotalExecutions = count() by operation_Name
| order by TotalDuration desc
| top 10 by TotalDuration

Top 10 Slowest API Calls by URL

For this query to work, ensure the target service or API is also logging to Application Insights. It reveals which external calls might be slowing your Logic Apps.

kql Top 10 Slowest API Calls by URL kusto query
Kusto
requests
| project url, duration
| extend DurationSeconds = duration / 1000
| where isnotempty(url) and not(url contains "runtime/webhooks")
| summarize
    TotalDuration = sum(DurationSeconds),
    AvgDuration = avg(DurationSeconds),
    MaxDuration = max(DurationSeconds),
    RequestCount = count()
  by url
| order by MaxDuration desc
| top 10 by MaxDuration

Conclusion

By using these advanced KQL queries in Application Insights, you can quickly spot any bottlenecks in your Logic Apps and address them before they become major issues.

This approach not only helps improve performance but also saves money. Instead of jumping straight to a more expensive hosting plan, you can focus on optimising your existing workflows. Through careful monitoring and targeted improvements, you’ll keep costs down and ensure smooth, reliable Logic Apps that deliver value without unnecessary upgrades.