Azure Log Analytics Data Collector API Client

raw JSON →
0.4.0 verified Fri May 01 auth: no python

Unofficial Python client for the Azure Log Analytics Data Collector API (HTTP Data Collector API). Version 0.4.0 adds configurable endpoint. Infrequently updated; use for custom log ingestion where the official Azure Monitor SDK is not required.

pip install azure-log-analytics-data-collector-api==0.4.0
error from azure_log_analytics_data_collector_api import LogAnalyticsDataCollectorClient ModuleNotFoundError: No module named 'azure_log_analytics_data_collector_api'
cause Package not installed or wrong import path.
fix
Install: pip install azure-log-analytics-data-collector-api. Then import: from azure_log_analytics_data_collector_api import LogAnalyticsDataCollectorClient
error requests.exceptions.HTTPError: 403 Client Error: Forbidden
cause Incorrect workspace ID or shared key, or missing permissions.
fix
Verify workspace ID and shared key from Azure Portal. Ensure the log type is correctly configured (custom log must be created in Azure Portal).
gotcha Log type name must be alphanumeric plus underscore, max 100 characters. It is automatically suffixed with '_CL' by Azure, but DO NOT include '_CL' yourself in the parameter.
fix Use log_type='MyLog' (not 'MyLog_CL'). The client does NOT add the suffix automatically; Azure adds it server-side.
gotcha The client does not validate the endpoint URL. If you pass an incorrect or non-Azure endpoint, the request will silently fail with a non-descriptive error.
fix Always use the default endpoint for public Azure ('https://<workspace-id>.ods.opinsights.azure.com') or explicitly verify your custom endpoint.
deprecated This library is based on the deprecated Azure Log Analytics Data Collector API. Microsoft recommends using the official azure-monitor-ingestion library for new projects.
fix Consider migrating to `azure-monitor-ingestion` (package: azure-monitor-ingestion) which is actively maintained.

Creates client and sends custom log data. Remember to configure retention and custom log fields in Azure Portal.

import os
from azure_log_analytics_data_collector_api import LogAnalyticsDataCollectorClient

workspace_id = os.environ.get('AZURE_WORKSPACE_ID', '')
shared_key = os.environ.get('AZURE_SHARED_KEY', '')
client = LogAnalyticsDataCollectorClient(workspace_id, shared_key)

records = [{"name": "test", "value": 1}]
response = client.send(records, log_type='MyCustomLog_CL')
print(response.status_code)