Class LogsIngestionClient
- All Implemented Interfaces:
AutoCloseable
This class provides a synchronous client for uploading custom logs to an Azure Monitor Log Analytics workspace. This client encapsulates REST API calls, used to send data to a Log Analytics workspace, into a set of synchronous operations.
Getting Started
To create an instance of the LogsIngestionClient, use the LogsIngestionClientBuilder and configure
the various options provided by the builder to customize the client as per your requirements. There are two required
properties that should be set to build a client:
endpoint- The data collection endpoint. Seeendpointmethod for more details.credential- The AAD authentication credential that has the "Monitoring Metrics Publisher" role assigned to it. Azure Identity provides a variety of AAD credential types that can be used. Seecredentialmethod for more details.
Instantiating a synchronous Logs ingestion client
LogsIngestionClient logsIngestionClient = new LogsIngestionClientBuilder()
.credential(tokenCredential)
.endpoint("<data-collection-endpoint>")
.buildClient();
Client Usage
For additional information on how to use this client, see the following method documentation:
-
upload(String, String, Iterable)- Uploads logs to a Log Analytics workspace. -
upload(String, String, Iterable, LogsUploadOptions)- Uploads logs to a Log Analytics workspace with options to configure the upload request. -
uploadWithResponse(String, String, BinaryData, RequestOptions)- Uploads logs to a Log Analytics workspace with options to configure the HTTP request.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidUploads logs to Azure Monitor with specified data collection rule id and stream name.voidUploads logs to Azure Monitor with specified data collection rule id and stream name.voidupload(String ruleId, String streamName, Iterable<Object> logs, LogsUploadOptions options, com.azure.core.util.Context context) Uploads logs to Azure Monitor with specified data collection rule id and stream name.com.azure.core.http.rest.Response<Void> uploadWithResponse(String ruleId, String streamName, com.azure.core.util.BinaryData logs, com.azure.core.http.rest.RequestOptions requestOptions) This method is used to upload logs to Azure Monitor Log Analytics with specified data collection rule id and stream name.
-
Method Details
-
upload
Uploads logs to Azure Monitor with specified data collection rule id and stream name. The input logs may be too large to be sent as a single request to the Azure Monitor service. In such cases, this method will split the input logs into multiple smaller requests before sending to the service. This method will block until all the logs are uploaded or an error occurs.Each log in the input collection must be a valid JSON object. The JSON object should match the schema defined by the stream name. The stream's schema can be found in the Azure portal.
Upload logs to Azure Monitor
List<Object> logs = getLogs(); logsIngestionClient.upload("<data-collection-rule-id>", "<stream-name>", logs); System.out.println("Logs uploaded successfully");- Parameters:
ruleId- the data collection rule id that is configured to collect and transform the logs.streamName- the stream name configured in data collection rule that matches defines the structure of the logs sent in this request.logs- the collection of logs to be uploaded.- Throws:
NullPointerException- if any ofruleId,streamNameorlogsare null.IllegalArgumentException- iflogsis empty.
-
upload
public void upload(String ruleId, String streamName, Iterable<Object> logs, LogsUploadOptions options) Uploads logs to Azure Monitor with specified data collection rule id and stream name. The input logs may be too large to be sent as a single request to the Azure Monitor service. In such cases, this method will split the input logs into multiple smaller requests before sending to the service. This method will block until all the logs are uploaded or an error occurs. If anerror handleris set, then the service errors are surfaced to the error handler and this method won't throw an exception.Each log in the input collection must be a valid JSON object. The JSON object should match the schema defined by the stream name. The stream's schema can be found in the Azure portal.
Upload logs to Azure Monitor
List<Object> logs = getLogs(); LogsUploadOptions logsUploadOptions = new LogsUploadOptions().setMaxConcurrency(4); logsIngestionClient.upload("<data-collection-rule-id>", "<stream-name>", logs, logsUploadOptions, Context.NONE); System.out.println("Logs uploaded successfully");- Parameters:
ruleId- the data collection rule id that is configured to collect and transform the logs.streamName- the stream name configured in data collection rule that matches defines the structure of the logs sent in this request.logs- the collection of logs to be uploaded.options- the options to configure the upload request.- Throws:
NullPointerException- if any ofruleId,streamNameorlogsare null.IllegalArgumentException- iflogsis empty.
-
upload
public void upload(String ruleId, String streamName, Iterable<Object> logs, LogsUploadOptions options, com.azure.core.util.Context context) Uploads logs to Azure Monitor with specified data collection rule id and stream name. The input logs may be too large to be sent as a single request to the Azure Monitor service. In such cases, this method will split the input logs into multiple smaller requests before sending to the service. This method will block until all the logs are uploaded or an error occurs. If anerror handleris set, then the service errors are surfaced to the error handler and this method won't throw an exception.Each log in the input collection must be a valid JSON object. The JSON object should match the schema defined by the stream name. The stream's schema can be found in the Azure portal.
- Parameters:
ruleId- the data collection rule id that is configured to collect and transform the logs.streamName- the stream name configured in data collection rule that matches defines the structure of the logs sent in this request.logs- the collection of logs to be uploaded.options- the options to configure the upload request.context- additional context that is passed through the Http pipeline during the service call. If no additional context is required, passContext.NONEinstead.- Throws:
NullPointerException- if any ofruleId,streamNameorlogsare null.IllegalArgumentException- iflogsis empty.
-
uploadWithResponse
public com.azure.core.http.rest.Response<Void> uploadWithResponse(String ruleId, String streamName, com.azure.core.util.BinaryData logs, com.azure.core.http.rest.RequestOptions requestOptions) This method is used to upload logs to Azure Monitor Log Analytics with specified data collection rule id and stream name. This upload method provides a more granular control of the HTTP request sent to the service. UseRequestOptionsto configure the HTTP request.The input logs should be a JSON array with each element in the array matching the schema defined by the stream name. The stream's schema can be found in the Azure portal. This content will be gzipped before sending to the service. If the content is already gzipped, then set the
Content-Encodingheader togzipusingrequestOptionsand pass the content as is.Header Parameters
Header Parameters Name Type Required Description Content-Encoding String No gzip x-ms-client-request-id String No Client request Id Request Body Schema
[ Object ]- Parameters:
ruleId- The immutable Id of the Data Collection Rule resource.streamName- The streamDeclaration name as defined in the Data Collection Rule.logs- An array of objects matching the schema defined by the provided stream.requestOptions- The options to configure the HTTP request before HTTP client sends it.- Returns:
- the
Response. - Throws:
com.azure.core.exception.HttpResponseException- thrown if the request is rejected by server.com.azure.core.exception.ClientAuthenticationException- thrown if the request is rejected by server on status code 401.com.azure.core.exception.ResourceNotFoundException- thrown if the request is rejected by server on status code 404.com.azure.core.exception.ResourceModifiedException- thrown if the request is rejected by server on status code 409.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-