Skip to content

Azure Log Analytics

Run KQL queries against Azure Monitor Log Analytics workspaces

Connector software
Free and open source
Service credentials
Required
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/azure-loganalytics/index.md to help me query Azure Log Analytics with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Count sign-in outcomes over the last hour

Uses your connected account. Set up the connector and credentials to run it with your data.

SELECT result
FROM azure.main.loganalytics_query('SigninLogs | summarize count() by ResultType', '<workspace-guid>', timespan := 'PT1H')
WHERE _row_kind IS NULL

Quick start

Choose where to run Azure Log Analytics, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach the release directly

Downloads the latest release for your platform and caches it locally.

ATTACH 'azure' AS azure (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/vgi-azure-loganalytics'
);

3. Add service credentials

After attaching, create the secret for the service you want to query in the same SQL session. Replace the placeholders with your service settings.

azure_graph credentials

Microsoft Entra app-only (client-credentials) credentials for Azure Monitor / Log Analytics

Get these credentials →
secret.sql
CREATE SECRET azure_graph (
    TYPE azure_graph,
    tenant_id     '<tenant_id>',
    client_id     '<client_id>',
    client_secret '<AZURE_GRAPH_CLIENT_SECRET>'  -- secret
);
Credential fields and requirements →

4. Run a query

query.sql
SELECT result
FROM azure.main.loganalytics_query('SigninLogs | summarize count() by ResultType', '<workspace-guid>', timespan := 'PT1H')
WHERE _row_kind IS NULL
More example queries →
Technical details
Verified connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach the release directly

Uses the verified release each time you attach the connector.

ATTACH 'azure' AS azure (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/[email protected]'
);

Overview

Azure Monitor / Log Analytics KQL passthrough (loganalytics_query) — vgi-azure-loganalytics

Catalog

Everything azure exposes once attached — read straight from the worker's released build.

azure 1 schema
main 1 view · 1 function

Azure Monitor / Log Analytics KQL passthrough query surface (loganalytics_query).

Schema examples (6)
Examples (6)

Snapshot: the 100 most recent audit-log entries over the last day

SELECT result
FROM azure.main.loganalytics_query('AuditLogs | take 100', '<workspace-guid>')
WHERE _row_kind IS NULL;

Last-day ingested GB per table from the Usage table, joined to loganalytics_tables for each table's category (NULL for tables outside the curated index), largest first

SELECT u.result->>'DataType' AS table_name, t.category,
  CAST(u.result->>'IngestedGB' AS DOUBLE) AS ingested_gb
FROM azure.main.loganalytics_query('Usage | summarize IngestedGB = sum(Quantity) / 1000 by DataType', '<workspace-guid>') u
LEFT JOIN azure.main.loganalytics_tables t ON t.table_name = u.result->>'DataType'
WHERE u._row_kind IS NULL
ORDER BY ingested_gb DESC, table_name;

Curated tables from loganalytics_tables (other than Usage itself) with no ingestion recorded in the workspace's Usage table over the last day (e.g. a diagnostic setting or agent that is not sending data)

SELECT t.table_name, t.category
FROM azure.main.loganalytics_tables t
WHERE t.table_name <> 'Usage' AND NOT EXISTS (SELECT 1 FROM azure.main.loganalytics_query('Usage | summarize IngestedGB = sum(Quantity) / 1000 by DataType', '<workspace-guid>') u WHERE u._row_kind IS NULL AND u.result->>'DataType' = t.table_name)
ORDER BY t.category, t.table_name;

Count sign-in events by result type over the last hour

SELECT result
FROM azure.main.loganalytics_query('SigninLogs | summarize count() by ResultType', '<workspace-guid>', timespan := 'PT1H')
WHERE _row_kind IS NULL;
2 more examples

Incremental pull replaying a saved TimeGenerated watermark

SELECT result
FROM azure.main.loganalytics_query('SigninLogs | project TimeGenerated, UserPrincipalName', '<workspace-guid>', since := '<prior _watermark_next>')
WHERE _row_kind IS NULL;

Read the watermark cursor to persist for the next incremental scan

SELECT _watermark_next
FROM azure.main.loganalytics_query('SigninLogs | project TimeGenerated', '<workspace-guid>', since := '2026-01-01T00:00:00Z')
WHERE _row_kind = 'marker';
Views
loganalytics_tables 3 examples5 cols

A curated, credential-free registry of common Azure Monitor / Log Analytics tables and a starter KQL for each. Browsable without an azure_graph secret; feed a table's sample_kql to loganalytics_query.

Columns
table_name VARCHAR
The Log Analytics table name to reference at the start of a KQL query.
category VARCHAR
A coarse grouping (identity, platform, infrastructure, operations) for navigation.
time_column VARCHAR
The datetime column to project for incremental (watermark) pulls — TimeGenerated for these tables.
description VARCHAR
A one-line description of what the table records.
sample_kql VARCHAR
A ready-to-run starter KQL string to pass as loganalytics_query's kql argument.
Examples (3)

List every curated table and its category

SELECT table_name, category
FROM azure.main.loganalytics_tables
ORDER BY category, table_name;

Get the starter KQL for the identity tables

SELECT table_name, sample_kql
FROM azure.main.loganalytics_tables
WHERE category = 'identity'
ORDER BY table_name;

Curated tables from loganalytics_tables (other than Usage itself) with no ingestion recorded in the workspace's Usage table over the last day (e.g. a diagnostic setting or agent that is not sending data)

SELECT t.table_name, t.category
FROM azure.main.loganalytics_tables t
WHERE t.table_name <> 'Usage' AND NOT EXISTS (SELECT 1 FROM azure.main.loganalytics_query('Usage | summarize IngestedGB = sum(Quantity) / 1000 by DataType', '<workspace-guid>') u WHERE u._row_kind IS NULL AND u.result->>'DataType' = t.table_name)
ORDER BY t.category, t.table_name;
Link
Table functions
loganalytics_query (kql VARCHAR, workspace VARCHAR, since := VARCHAR, timespan := VARCHAR) 5 examples

Azure Monitor / Log Analytics KQL passthrough: KQL in, one JSON result string per row. Optional TimeGenerated watermark (since := ) for incremental pulls (at-least-once within the safety lag). Large pulls (>~500k rows / 64MB) must be time-sliced by the caller.

Positional arguments
kql VARCHAR
The Kusto (KQL) query text, sent to Log Analytics verbatim — the worker never parses or rewrites it (passthrough). Required. For incremental (watermark) use, project `TimeGenerated` in the query so a cursor can be synthesized.
workspace VARCHAR
The Log Analytics workspace ID (GUID) to query — the `{workspaceId}` path segment. Required.
Named arguments
since := VARCHAR
Incremental cursor: an ISO-8601 instant, typically a prior scan's `_watermark_next` value. When set, the function fetches only rows newer than this watermark (at-least-once within a safety lag) and emits the next cursor on the marker row. Empty (the default) performs a full `timespan` pull with no marker row. · default ""
timespan := VARCHAR
The scan window as an ISO-8601 duration (e.g. `PT1H`, `P1D`) or an absolute `start/end` range. Ignored when `since` is set (incremental use derives its own range). Defaults to `P1D` (last day). · default "P1D"
Returns columns
result VARCHAR
One Kusto result row encoded as a JSON object string, keyed by the KQL query's projected column names. NULL on the marker row.
_row_kind VARCHAR
NULL for business data rows; the literal 'marker' for the single trailing cursor row (present only on an incremental `since` pull).
_watermark_next VARCHAR
On the marker row, the clamped ISO-8601 `TimeGenerated` watermark to persist and replay via the `since` argument; NULL on data rows (and no marker row is emitted at all on a non-incremental full pull).
Examples (5)

Snapshot of the 100 most recent audit-log entries over the default P1D window

SELECT result
FROM azure.main.loganalytics_query('AuditLogs | take 100', '<workspace-guid>')
WHERE _row_kind IS NULL;

Last-day ingested GB per table from the Usage table, joined to loganalytics_tables for each table's category (NULL for tables outside the curated index), largest first

SELECT u.result->>'DataType' AS table_name, t.category,
  CAST(u.result->>'IngestedGB' AS DOUBLE) AS ingested_gb
FROM azure.main.loganalytics_query('Usage | summarize IngestedGB = sum(Quantity) / 1000 by DataType', '<workspace-guid>') u
LEFT JOIN azure.main.loganalytics_tables t ON t.table_name = u.result->>'DataType'
WHERE u._row_kind IS NULL
ORDER BY ingested_gb DESC, table_name;

Aggregate sign-in events by result type over the last hour

SELECT result
FROM azure.main.loganalytics_query('SigninLogs | summarize count() by ResultType', '<workspace-guid>', timespan := 'PT1H')
WHERE _row_kind IS NULL;
2 more examples

Incremental pull of new sign-ins replaying a saved TimeGenerated watermark

SELECT result
FROM azure.main.loganalytics_query('SigninLogs | project TimeGenerated, UserPrincipalName', '<workspace-guid>', since := '<prior _watermark_next>')
WHERE _row_kind IS NULL;

Read the watermark cursor to persist for the next incremental scan

SELECT _watermark_next
FROM azure.main.loganalytics_query('SigninLogs | project TimeGenerated', '<workspace-guid>', since := '2026-01-01T00:00:00Z')
WHERE _row_kind = 'marker';
Link

Credentials

The secret type azure declares, as reported by the worker itself.

azure_graph

How to get these credentials

Microsoft Entra app-only (client-credentials) credentials for Azure Monitor / Log Analytics

secret.sql
CREATE SECRET azure_graph (
    TYPE azure_graph,
    tenant_id     '<tenant_id>',
    client_id     '<client_id>',
    client_secret '<AZURE_GRAPH_CLIENT_SECRET>'  -- secret
);
Key Type Required Description
tenant_id VARCHAR — Directory (tenant) ID of the Microsoft Entra tenant, from the app registration's Overview page
client_id VARCHAR — Application (client) ID of the Microsoft Entra app registration, from its Overview page
client_secret secret VARCHAR — Client secret value created under the app registration's Certificates & secrets page (shown once, at creation)

The worker doesn't mark which keys are required.

Needed by loganalytics_query

Create the secret in the same session, after attaching azure — the worker registers its secret types at ATTACH. Keys marked secret are masked in duckdb_secrets(); angle-bracket values are placeholders. Read credentials from your environment or secret store in your application and pass them through your SQL client’s parameter bindings. Keep real values out of saved SQL and history. Native DuckDB and Haybarn do not provide a SQL getenv() function.

Try these queries

query_bind_probe — Bind loganalytics_query and expose its result columns (credential-free; drop LIMIT 0 and attach an azure_graph secret to run the KQL against a real workspace)

SELECT result, _row_kind, _watermark_next
FROM azure.main.loganalytics_query('AzureActivity | take 1', '00000000-0000-0000-0000-000000000000')
LIMIT 0;

Uses loganalytics_query

Snapshot: the 100 most recent audit-log entries over the last day

SELECT result
FROM azure.main.loganalytics_query('AuditLogs | take 100', '<workspace-guid>')
WHERE _row_kind IS NULL

Uses loganalytics_query

Last-day ingested GB per table from the Usage table, joined to loganalytics_tables for each table's category (NULL for tables outside the curated index), largest first

SELECT u.result->>'DataType' AS table_name, t.category,
  CAST(u.result->>'IngestedGB' AS DOUBLE) AS ingested_gb
FROM azure.main.loganalytics_query('Usage | summarize IngestedGB = sum(Quantity) / 1000 by DataType', '<workspace-guid>') u
LEFT JOIN azure.main.loganalytics_tables t ON t.table_name = u.result->>'DataType'
WHERE u._row_kind IS NULL
ORDER BY ingested_gb DESC, table_name

Uses loganalytics_queryloganalytics_tables

Curated tables from loganalytics_tables (other than Usage itself) with no ingestion recorded in the workspace's Usage table over the last day (e.g. a diagnostic setting or agent that is not sending data)

SELECT t.table_name, t.category
FROM azure.main.loganalytics_tables t
WHERE t.table_name <> 'Usage' AND NOT EXISTS (SELECT 1 FROM azure.main.loganalytics_query('Usage | summarize IngestedGB = sum(Quantity) / 1000 by DataType', '<workspace-guid>') u WHERE u._row_kind IS NULL AND u.result->>'DataType' = t.table_name)
ORDER BY t.category, t.table_name

Uses loganalytics_tablesloganalytics_query

Incremental pull replaying a saved TimeGenerated watermark

SELECT result
FROM azure.main.loganalytics_query('SigninLogs | project TimeGenerated, UserPrincipalName', '<workspace-guid>', since := '<prior _watermark_next>')
WHERE _row_kind IS NULL

Uses loganalytics_query

Read the watermark cursor to persist for the next incremental scan

SELECT _watermark_next
FROM azure.main.loganalytics_query('SigninLogs | project TimeGenerated', '<workspace-guid>', since := '2026-01-01T00:00:00Z')
WHERE _row_kind = 'marker'

Uses loganalytics_query

2 more examples in the Catalog, each listed under the table or function it uses.

Questions it can answer

Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.

  • Before I attach any credentials, which Log Analytics tables can I query here, and what is a good starting KQL for the sign-in table?
  • Using the Azure Log Analytics workspace, list the 50 most recent sign-in events with their user principal name and time.
  • I already pulled sign-in logs once. How do I fetch only the rows that are new since my last pull?
  • Over the last day in the workspace, how many audit-log entries occurred, and can you break it down by operation name?

Azure Log Analytics is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.