async def test_logs_batch_query_additional_workspaces():
    client = LogsQueryClient(_credential())
    query = "union * | where TimeGenerated > ago(100d) | project TenantId | summarize count() by TenantId"

    requests = [
        LogsQueryRequest(
            query,
            timespan="PT1H",
            workspace_id=os.environ['LOG_WORKSPACE_ID'],
            additional_workspaces=[os.environ['SECONDARY_WORKSPACE_ID']]),
        LogsQueryRequest(
            query,
            timespan="PT1H",
            workspace_id=os.environ['LOG_WORKSPACE_ID'],
            additional_workspaces=[os.environ['SECONDARY_WORKSPACE_ID']]),
        LogsQueryRequest(
            query,
            workspace_id=os.environ['LOG_WORKSPACE_ID'],
            additional_workspaces=[os.environ['SECONDARY_WORKSPACE_ID']]),
    ]
    response = await client.batch_query(requests)

    assert len(response.responses) == 3

    for resp in response.responses:
        assert len(resp.body.tables[0].rows) == 2
    def __init__(self, arguments):
        super().__init__(arguments)

        # auth configuration
        self.workspace_id = self.get_from_env('LOG_WORKSPACE_ID')

        # Create clients
        self.logs_client = SyncLogsQueryClient(
            credential=SyncDefaultAzureCredential())
        self.async_logs_client = AsyncLogsQueryClient(
            credential=AsyncDefaultAzureCredential())

        self.requests = [
            LogsQueryRequest(query="AzureActivity | summarize count()",
                             start_time=datetime(2021,
                                                 7,
                                                 25,
                                                 0,
                                                 0,
                                                 0,
                                                 tzinfo=timezone.utc),
                             end_time=datetime(2021,
                                               7,
                                               26,
                                               0,
                                               0,
                                               0,
                                               tzinfo=timezone.utc),
                             workspace_id=self.workspace_id),
            LogsQueryRequest(query="""AppRequests | take 10  |
                    summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId""",
                             start_time=datetime(2021,
                                                 7,
                                                 25,
                                                 0,
                                                 0,
                                                 0,
                                                 tzinfo=timezone.utc),
                             end_time=datetime(2021,
                                               7,
                                               26,
                                               0,
                                               0,
                                               0,
                                               tzinfo=timezone.utc),
                             workspace_id=self.workspace_id),
            LogsQueryRequest(query="AppRequests | take 20",
                             workspace_id=self.workspace_id,
                             include_statistics=True),
        ]
async def test_logs_batch_query():
    client = LogsQueryClient(_credential())

    requests = [
        LogsQueryRequest(query="AzureActivity | summarize count()",
                         timespan="PT1H",
                         workspace=os.environ['LOG_WORKSPACE_ID']),
        LogsQueryRequest(query="""AppRequests | take 10  |
                summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId""",
                         timespan="PT1H",
                         workspace=os.environ['LOG_WORKSPACE_ID']),
        LogsQueryRequest(query="AppRequests | take 2",
                         workspace=os.environ['LOG_WORKSPACE_ID']),
    ]
    response = await client.batch_query(requests)

    assert len(response.responses) == 3
import os
import pandas as pd
from azure.monitor.query import LogsQueryClient, LogsQueryRequest
from azure.identity import ClientSecretCredential

credential = ClientSecretCredential(
    client_id=os.environ['AZURE_CLIENT_ID'],
    client_secret=os.environ['AZURE_CLIENT_SECRET'],
    tenant_id=os.environ['AZURE_TENANT_ID'])

client = LogsQueryClient(credential)

# [START send_batch_query]
requests = [
    LogsQueryRequest(query="AzureActivity | summarize count()",
                     duration="PT1H",
                     workspace=os.environ['LOG_WORKSPACE_ID']),
    LogsQueryRequest(query="""AppRequests | take 10  |
            summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId""",
                     duration="PT1H",
                     start_time=datetime(2021, 6, 2),
                     workspace=os.environ['LOG_WORKSPACE_ID']),
    LogsQueryRequest(query="AppRequests | take 2",
                     workspace=os.environ['LOG_WORKSPACE_ID']),
]
response = client.batch_query(requests)

for response in response.responses:
    body = response.body
    print(response.id)
    if not body.tables: