Skip to content

Commit 02bd90e

Browse files
authored
Merge pull request #259891 from guywi-ms/combine-cross-resource-queries
Combine cross resource queries
2 parents a6ed6d1 + cbaef40 commit 02bd90e

10 files changed

+144
-241
lines changed

.openpublishing.redirection.azure-monitor.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6433,6 +6433,21 @@
64336433
"source_path_from_root": "/articles/azure-monitor/faq.yml",
64346434
"redirect_url": "/azure/azure-monitor/overview#frequently-asked-questions",
64356435
"redirect_document_id": false
6436+
},
6437+
{
6438+
"source_path_from_root": "/articles/azure-monitor/logs/app-expression.md",
6439+
"redirect_url": "/azure/azure-monitor/logs/cross-workspace-query",
6440+
"redirect_document_id": false
6441+
},
6442+
{
6443+
"source_path_from_root": "/articles/azure-monitor/logs/workspace-expression.md",
6444+
"redirect_url": "/azure/azure-monitor/logs/cross-workspace-query",
6445+
"redirect_document_id": false
6446+
},
6447+
{
6448+
"source_path_from_root": "/articles/azure-monitor/logs/resource-expression.md",
6449+
"redirect_url": "/azure/azure-monitor/logs/cross-workspace-query",
6450+
"redirect_document_id": false
64366451
}
64376452
]
64386453
}

articles/azure-monitor/logs/app-expression.md

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 120 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,51 @@
11
---
2-
title: Query across resources with Azure Monitor | Microsoft Docs
3-
description: This article describes how you can query against resources from multiple workspaces and an Application Insights app in your subscription.
4-
ms.topic: conceptual
2+
title: Query across resources with Azure Monitor
3+
description: Query and correlated data from multiple Log Analytics workspaces, applications, or resources using the `workspace()`, `app()`, and `resource()` Kusto Query Language (KQL) expressions.
4+
ms.topic: how-to
55
author: guywi-ms
66
ms.author: guywild
77
ms.date: 05/30/2023
8+
# Customer intent: As a data analyst, I want to write KQL queries that correlate data from multiple Log Analytics workspaces, applications, or resources, to enable my analysis.
89

910
---
1011

11-
# Create a log query across multiple workspaces and apps in Azure Monitor
12+
# Query data across Log Analytics workspaces, applications, and resources in Azure Monitor
1213

13-
Azure Monitor Logs support querying across multiple Log Analytics workspaces and Application Insights apps in the same resource group, another resource group, or another subscription. This capability provides you with a systemwide view of your data.
14+
There are two ways to query data from multiple workspaces, applications, and resources:
1415

15-
If you manage subscriptions in other Microsoft Entra tenants through [Azure Lighthouse](../../lighthouse/overview.md), you can include [Log Analytics workspaces created in those customer tenants](../../lighthouse/how-to/monitor-at-scale.md) in your queries.
16+
* Explicitly by specifying the workspace, app, or resource information using the [workspace()](#query-across-log-analytics-workspaces-using-workspace), [app()](#query-across-classic-application-insights-applications-using-app), or [resource()](#correlate-data-between-resources-using-resource) expressions, as described in this article.
17+
* Implicitly by using [resource-context queries](manage-access.md#access-mode). When you query in the context of a specific resource, resource group, or a subscription, the query retrieves relevant data from all workspaces that contain data for these resources. Resource-context queries don't retrieve data from classic Application Insights resources.
1618

17-
There are two methods to query data that's stored in multiple workspaces and apps:
19+
This article explains how to use the `workspace()`, `app()`, and `resource()` expressions to query data from multiple Log Analytics workspaces, applications, and resources.
1820

19-
* Explicitly by specifying the workspace and app information. This technique is used in this article.
20-
* Implicitly by using [resource-context queries](manage-access.md#access-mode). When you query in the context of a specific resource, resource group, or a subscription, the relevant data will be fetched from all workspaces that contain data for these resources. Application Insights data that's stored in apps won't be fetched.
21+
If you manage subscriptions in other Microsoft Entra tenants through [Azure Lighthouse](../../lighthouse/overview.md), you can include [Log Analytics workspaces created in those customer tenants](../../lighthouse/how-to/monitor-at-scale.md) in your queries.
2122

2223
> [!IMPORTANT]
23-
> If you're using a [workspace-based Application Insights resource](../app/create-workspace-resource.md), telemetry is stored in a Log Analytics workspace with all other log data. Use the `workspace()` expression to write a query that includes applications in multiple workspaces. For multiple applications in the same workspace, you don't need a cross-workspace query.
24+
> If you're using a [workspace-based Application Insights resource](../app/create-workspace-resource.md), telemetry is stored in a Log Analytics workspace with all other log data. Use the `workspace()` expression to query data from applications in multiple workspaces. You don't need a cross-workspace query to query data from multiple applications in the same workspace.
2425
2526
## Permissions required
2627

2728
- You must have `Microsoft.OperationalInsights/workspaces/query/*/read` permissions to the Log Analytics workspaces you query, as provided by the [Log Analytics Reader built-in role](./manage-access.md#log-analytics-reader), for example.
2829
- To save a query, you must have `microsoft.operationalinsights/querypacks/queries/action` permisisons to the query pack where you want to save the query, as provided by the [Log Analytics Contributor built-in role](./manage-access.md#log-analytics-contributor), for example.
2930

30-
## Cross-resource query limits
31+
## Limitations
3132

32-
* The number of Application Insights components and Log Analytics workspaces that you can include in a single query is limited to 100.
33+
* Cross-resource and cross-service queries don’t support parameterized functions and functions whose definition includes other cross-workspace or cross-service expressions, including `adx()`, `arg()`, `resource()`, `workspace()`, and `app()`.
34+
* You can include up to 100 Log Analytics workspaces or classic Application Insights resources in a single query.
3335
* Querying across a large number of resources can substantially slow down the query.
3436
* Cross-resource queries in log alerts are only supported in the current [scheduledQueryRules API](/rest/api/monitor/scheduledqueryrule-2018-04-16/scheduled-query-rules). If you're using the legacy Log Analytics Alerts API, you'll need to [switch to the current API](../alerts/alerts-log-api-switch.md).
35-
* References to a cross resource, such as another workspace, should be explicit and can't be parameterized. See [Gather identifiers for Log Analytics workspaces](?tabs=workspace-identifier#gather-identifiers-for-log-analytics-workspaces-and-application-insights-resources) for examples.
36-
37-
## Gather identifiers for Log Analytics workspaces and Application Insights resources
38-
39-
To reference another workspace in your query, use the [workspace](../logs/workspace-expression.md) identifier. For an app from Application Insights, use the [app](./app-expression.md) identifier.
40-
41-
### [Workspace identifier](#tab/workspace-identifier)
42-
43-
You can identify a workspace using one of these IDs:
44-
45-
* **Workspace ID**: A workspace ID is the unique, immutable, identifier assigned to each workspace represented as a globally unique identifier (GUID).
46-
47-
`workspace("00000000-0000-0000-0000-000000000000").Update | count`
48-
49-
* **Azure Resource ID**: This ID is the Azure-defined unique identity of the workspace. For workspaces, the format is */subscriptions/subscriptionId/resourcegroups/resourceGroup/providers/microsoft.OperationalInsights/workspaces/workspaceName*.
50-
51-
For example:
52-
53-
```
54-
workspace("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/ContosoAzureHQ/providers/Microsoft.OperationalInsights/workspaces/contosoretail-it").Update | count
55-
```
56-
57-
### [App identifier](#tab/app-identifier)
58-
The following examples return a summarized count of requests made against an app named *fabrikamapp* in Application Insights.
59-
60-
You can identify an app using one of these IDs:
61-
62-
* **ID**: This ID is the app GUID of the application.
63-
64-
`app("00000000-0000-0000-0000-000000000000").requests | count`
65-
66-
* **Azure Resource ID**: This ID is the Azure-defined unique identity of the app. The format is */subscriptions/subscriptionId/resourcegroups/resourceGroup/providers/microsoft.OperationalInsights/components/componentName*.
67-
68-
For example:
69-
70-
```
71-
app("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/Fabrikam/providers/microsoft.insights/components/fabrikamapp").requests | count
72-
```
73-
74-
---
37+
* References to a cross resource, such as another workspace, should be explicit and can't be parameterized.
7538

76-
## Query across Log Analytics workspaces and from Application Insights
39+
## Query across workspaces, applications, and resources using functions
7740

78-
Follow the instructions in this section to query without using a function or by using a function.
41+
This section explains how to query workspaces, applications, and resources using functions with and without using a function.
7942

8043
### Query without using a function
8144
You can query multiple resources from any of your resource instances. These resources can be workspaces and apps combined.
8245

8346
Example for a query across three workspaces:
8447

85-
```
48+
```kusto
8649
union
8750
Update,
8851
workspace("00000000-0000-0000-0000-000000000001").Update,
@@ -123,6 +86,108 @@ applicationsScoping
12386
>[!NOTE]
12487
> This method can't be used with log alerts because the access validation of the alert rule resources, including workspaces and applications, is performed at alert creation time. Adding new resources to the function after the alert creation isn't supported. If you prefer to use a function for resource scoping in log alerts, you must edit the alert rule in the portal or with an Azure Resource Manager template to update the scoped resources. Alternatively, you can include the list of resources in the log alert query.
12588
89+
## Query across Log Analytics workspaces using workspace()
90+
91+
Use the `workspace()` expression to retrieve data from a specific workspace in the same resource group, another resource group, or another subscription. You can use this expression to include log data in an Application Insights query and to query data across multiple workspaces in a log query.
92+
93+
### Syntax
94+
95+
`workspace(`*Identifier*`)`
96+
97+
### Arguments
98+
99+
`*Identifier*`: Identifies the workspace by using one of the formats in the following table.
100+
101+
| Identifier | Description | Example
102+
|:---|:---|:---|
103+
| ID | GUID of the workspace | workspace("00000000-0000-0000-0000-000000000000") |
104+
| Azure Resource ID | Identifier for the Azure resource | workspace("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/Contoso/providers/Microsoft.OperationalInsights/workspaces/contosoretail") |
105+
106+
### Examples
107+
108+
```Kusto
109+
workspace("00000000-0000-0000-0000-000000000000").Update | count
110+
```
111+
```Kusto
112+
workspace("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/Contoso/providers/Microsoft.OperationalInsights/workspaces/contosoretail").Event | count
113+
```
114+
```Kusto
115+
union
116+
( workspace("00000000-0000-0000-0000-000000000000").Heartbeat | where Computer == "myComputer"),
117+
(app("00000000-0000-0000-0000-000000000000").requests | where cloud_RoleInstance == "myRoleInstance")
118+
| count
119+
```
120+
```Kusto
121+
union
122+
(workspace("00000000-0000-0000-0000-000000000000").Heartbeat), (app("00000000-0000-0000-0000-000000000000").requests) | where TimeGenerated between(todatetime("2023-03-08 15:00:00") .. todatetime("2023-04-08 15:05:00"))
123+
```
124+
125+
## Query across classic Application Insights applications using app()
126+
127+
Use the `app` expression to retrieve data from a specific classic Application Insights resource in the same resource group, another resource group, or another subscription. If you're using a [workspace-based Application Insights resource](../app/create-workspace-resource.md), telemetry is stored in a Log Analytics workspace with all other log data. Use the `workspace()` expression to query data from applications in multiple workspaces. You don't need a cross-workspace query to query data from multiple applications in the same workspace.
128+
129+
### Syntax
130+
131+
`app(`*Identifier*`)`
132+
133+
134+
### Arguments
135+
136+
`*Identifier*`: Identifies the app using one of the formats in the table below.
137+
138+
| Identifier | Description | Example
139+
|:---|:---|:---|
140+
| ID | GUID of the app | app("00000000-0000-0000-0000-000000000000") |
141+
| Azure Resource ID | Identifier for the Azure resource |app("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/Fabrikam/providers/microsoft.insights/components/fabrikamapp") |
142+
143+
### Examples
144+
145+
```Kusto
146+
app("00000000-0000-0000-0000-000000000000").requests | count
147+
```
148+
```Kusto
149+
app("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/Fabrikam/providers/microsoft.insights/components/fabrikamapp").requests | count
150+
```
151+
```Kusto
152+
union
153+
(workspace("00000000-0000-0000-0000-000000000000").Heartbeat | where Computer == "myComputer"),
154+
(app("00000000-0000-0000-0000-000000000000").requests | where cloud_RoleInstance == "myColumnInstance")
155+
| count
156+
```
157+
```Kusto
158+
union
159+
(workspace("00000000-0000-0000-0000-000000000000").Heartbeat), (app("00000000-0000-0000-0000-000000000000").requests)
160+
| where TimeGenerated between(todatetime("2023-03-08 15:00:00") .. todatetime("2023-04-08 15:05:00"))
161+
```
162+
163+
## Correlate data between resources using resource()
164+
165+
The `resource` expression is used in a Azure Monitor query [scoped to a resource](scope.md#query-scope) to retrieve data from other resources.
166+
167+
168+
### Syntax
169+
170+
`resource(`*Identifier*`)`
171+
172+
### Arguments
173+
174+
`*Identifier*`: Identifies the resource, resource group, or subscription from which to correlate data.
175+
176+
| Identifier | Description | Example
177+
|:---|:---|:---|
178+
| Resource | Includes data for the resource. | resource("/subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcesgroups/myresourcegroup/providers/microsoft.compute/virtualmachines/myvm") |
179+
| Resource Group or Subscription | Includes data for the resource and all resources that it contains. | resource("/subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcesgroups/myresourcegroup) |
180+
181+
182+
### Examples
183+
184+
```Kusto
185+
union (Heartbeat),(resource("/subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcesgroups/myresourcegroup/providers/microsoft.compute/virtualmachines/myvm").Heartbeat) | summarize count() by _ResourceId, TenantId
186+
```
187+
```Kusto
188+
union (Heartbeat),(resource("/subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcesgroups/myresourcegroup).Heartbeat) | summarize count() by _ResourceId, TenantId
189+
```
190+
126191
## Next steps
127192

128193
See [Analyze log data in Azure Monitor](./log-query-overview.md) for an overview of log queries and how Azure Monitor log data is structured.

articles/azure-monitor/logs/log-query-overview.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ Although Azure Monitor uses the same KQL as Azure Data Explorer, there are some
7272
### Other operators in Azure Monitor
7373
The following operators support specific Azure Monitor features and aren't available outside of Azure Monitor:
7474

75-
* [app()](../logs/app-expression.md)
76-
* [resource()](./resource-expression.md)
77-
* [workspace()](../logs/workspace-expression.md)
75+
* [workspace()](../logs/cross-workspace-query.md#query-across-log-analytics-workspaces-using-workspace)
76+
* [app()](../logs/cross-workspace-query.md#query-across-classic-application-insights-applications-using-app)
77+
* [resource()](../logs/cross-workspace-query.md#correlate-data-between-resources-using-resource)
78+
7879

7980
## Next steps
8081
- Walk through a [tutorial on writing queries](/azure/data-explorer/kusto/query/tutorial?pivots=azuremonitor).

articles/azure-monitor/logs/query-optimization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ A query that spans more than five workspaces is considered a query that consumes
455455

456456
> [!IMPORTANT]
457457
> - In some multi-workspace scenarios, the CPU and data measurements won't be accurate and will represent the measurement of only a few of the workspaces.
458-
> - Cross workspace queries having an explicit identifier: workspace ID, or workspace Azure Resource ID, consume less resources and are more performant. See [Gather identifiers for Log Analytics workspaces](./cross-workspace-query.md?tabs=workspace-identifier#gather-identifiers-for-log-analytics-workspaces-and-application-insights-resources)
458+
> - Cross workspace queries having an explicit identifier: workspace ID, or workspace Azure Resource ID, consume less resources and are more performant.
459459
460460
## Parallelism
461461
Azure Monitor Logs uses large clusters of Azure Data Explorer to run queries. These clusters vary in scale and potentially get up to dozens of compute nodes. The system automatically scales the clusters according to workspace placement logic and capacity.

0 commit comments

Comments
 (0)