Class LogsIngestionAsyncClient
This class provides an asynchronous 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 asynchronous 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 an asynchronous Logs ingestion client
LogsIngestionAsyncClient logsIngestionAsyncClient = new LogsIngestionClientBuilder()
.credential(tokenCredential)
.endpoint("<data-collection-endpoint>")
.buildAsyncClient();
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 TypeMethodDescriptionUploads logs to Azure Monitor with specified data collection rule id and stream name.Uploads logs to Azure Monitor with specified data collection rule id and stream name.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.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(); logsIngestionAsyncClient.upload("<data-collection-rule-id>", "<stream-name>", logs) .subscribe();- 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.- Returns:
- the
Monothat completes on completion of the upload request. - Throws:
NullPointerException- if any ofruleId,streamNameorlogsare null.IllegalArgumentException- iflogsis empty.
-
upload
public Mono<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. If anerror handleris set, then the service errors are surfaced to the error handler and the subscriber of this method won't receive an error signal.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); logsIngestionAsyncClient.upload("<data-collection-rule-id>", "<stream-name>", logs, logsUploadOptions) .subscribe();- 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.- Returns:
- the
Monothat completes on completion of the upload request. - Throws:
NullPointerException- if any ofruleId,streamNameorlogsare null.IllegalArgumentException- iflogsis empty.
-
uploadWithResponse
public Mono<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
Responseon successful completion ofMono. - 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.
-