Query multiple Application Insights instances with KQL (Kusto Query Language)
Posted
1 min read
Let's say you have multiple different Application Insights instances across different regions, resource groups or whatever. Quite recently, I had the need to query multiple application insights instances to be able to count the number of a certain custom event I had. There was at least two different application insights instances that I needed to query, and here is a simple example of how you can achieve the same.
You can query across workspaces, and across AI instances, and in this sample I'll show you how you can query by just using the name of you Application Insights instance (used in the "app" function).
Go to your application insights instance, and copy the name of it so it can be used in the query.
The example query below shows how you can use two different application insights instances in the same query and counting the total number of custom events for the past 31 days across both instances.
union
app("myFirstInstance").customEvents,
app("mySecondInstance").customEvents
| where timestamp > ago(31d)
| summarize NumberOfEvents=sum(itemCount)
You can read more about querying across workspaces, applications and resources here https://learn.microsoft.com/en-us/azure/azure-monitor/logs/cross-workspace-query.