Class LogsIngestionAsyncClient

java.lang.Object
com.azure.monitor.ingestion.LogsIngestionAsyncClient

public final class LogsIngestionAsyncClient extends Object

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:

  1. endpoint - The data collection endpoint. See endpoint method for more details.
  2. 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. See credential method 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:

See Also:
  • Method Details

    • upload

      public Mono<Void> upload(String ruleId, String streamName, Iterable<Object> logs)
      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 Mono that completes on completion of the upload request.
      Throws:
      NullPointerException - if any of ruleId, streamName or logs are null.
      IllegalArgumentException - if logs is 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 an error handler is 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 Mono that completes on completion of the upload request.
      Throws:
      NullPointerException - if any of ruleId, streamName or logs are null.
      IllegalArgumentException - if logs is 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. Use RequestOptions to 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-Encoding header to gzip using requestOptions and pass the content as is.

      Header Parameters

      Header Parameters
      NameTypeRequiredDescription
      Content-EncodingStringNogzip
      x-ms-client-request-idStringNoClient 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 on successful completion of Mono.
      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.