com.azure.monitor.ingestion
The Azure Monitor Ingestion client library is used to send custom logs to an Azure Monitor Log Analytics workspace.
Getting Started
Prerequisites
The client library requires the following:
- Java 8 or later
- An Azure subscription
- An existing Azure Monitor Data Collection Rule
- An existing Azure Monitor Data Collection Endpoint
- An existing Azure Monitor Log Analytics workspace
Authenticate a Client
The LogsIngestionClient and LogsIngestionAsyncClient can be authenticated using Microsoft Entra ID. To authenticate with Microsoft Entra ID, create a TokenCredential that can be passed to the LogsIngestionClientBuilder. The Azure Identity library provides implementations of TokenCredential for multiple authentication flows. See TokenCredential for multiple authentication flows. See Azure Identity Azure Identity for more information. See LogsIngestionClientBuilder for more examples on authenticating a client.
The following sample demonstrates how to create a LogsIngestionClient using LogsIngestionClientBuilder and TokenCredential authentication.
LogsIngestionClient logsIngestionClient = new LogsIngestionClientBuilder()
.credential(tokenCredential)
.endpoint("<data-collection-endpoint>")
.buildClient();
Overview
The Logs Ingestion REST API in Azure Monitor lets you send data to a Log Analytics workspace. The API allows you to send data to supported tables or to custom tables that you create. You can also extend the schema of Azure tables with custom columns to accept additional data.
The Azure Monitor Ingestion client library provides both synchronous and asynchronous client implementations, providing you the capability to send custom logs to an Azure Monitor Log Analytics workspace.
Key Concepts
Data Collection Endpoint
Data Collection Endpoints (DCEs) allow you to uniquely configure ingestion settings for Azure Monitor. This article provides an overview of data collection endpoints including their contents and structure and how you can create and work with them.
Data Collection Rule
Data collection rules (DCR) define data collected by Azure Monitor and specify how and where that data should be sent or stored. The REST API call must specify a DCR to use. A single DCE can support multiple DCRs, so you can specify a different DCR for different sources and target tables.
The DCR must understand the structure of the input data and the structure of the target table. If the two don't match, it can use a transformation to convert the source data to match the target table. You may also use the transform to filter source data and perform any other calculations or conversions.
For more details, see Data collection rules in Azure Monitor. For information on how to retrieve a DCR ID, see this tutorial.
Log Analytics Workspace Tables
Custom logs can send data to any custom table that you create and to certain built-in tables in your Log Analytics workspace. The target table must exist before you can send data to it.
Logs retrieval
The logs that were uploaded using this library can be queried using the Azure Monitor Query client library.
Client Usage
Uploading logs to Azure Monitor
The following sample demonstrates how to upload logs to Azure Monitor using LogsIngestionClient.
List<Object> logs = getLogs();
logsIngestionClient.upload("<data-collection-rule-id>", "<stream-name>", logs);
System.out.println("Logs uploaded successfully");
For more synchronous and asynchronous client usage information, see LogsIngestionClient and LogsIngestionAsyncClient, respectively.
Logs |
This class provides an asynchronous client for uploading custom logs to an Azure Monitor Log Analytics workspace. |
Logs |
This class provides a synchronous client for uploading custom logs to an Azure Monitor Log Analytics workspace. |
Logs |
Fluent builder for creating instances of LogsIngestionClient and LogsIngestionAsyncClient. |
Logs |
The service version of the Azure Monitor service to upload logs. |