Generated banner for Azure Monitor Ingestion Java
Generated logo for Azure Monitor Ingestion Java

Azure Monitor Ingestion Java

MicrosoftOfficialCreated by Microsoft

  • Skill
  • Tool integration
  • Cloud and DevOps
  • MIT
  • No issues found

From the author

Azure Monitor Ingestion SDK for Java. Send custom logs to Azure Monitor via Data Collection Rules (DCR) and Data Collection Endpoints (DCE). Triggers: "LogsIngestionClient java", "azure monitor ingestion java", "custom logs java", "DCR java", "data collection rule java".
— the description by Microsoft

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

The Azure Monitor Ingestion SDK for Java provides a client library for developers to send custom log data to Azure Monitor. It utilizes Data Collection Rules (DCR) and Data Collection Endpoints (DCE) to route and ingest logs into Log Analytics workspaces. The library supports both synchronous and asynchronous operations, allowing for flexible integration into Java applications.

What it does

  • Provides a client for interacting with the Azure Monitor Logs Ingestion API.
  • Supports uploading custom log entries to specified DCR streams.
  • Offers both synchronous and asynchronous client implementations.
  • Enables configuration of concurrent uploads for log collections.
  • Includes error handling mechanisms for partial upload failures.
  • Integrates with Azure Identity for authentication.

When to use it

  • When you need to send custom application logs to Azure Monitor.
  • When your architecture requires routing logs through Data Collection Rules.
  • When building Java applications that need to ingest data into Log Analytics workspaces.
  • When you need to manage log ingestion programmatically within a Java environment.

Advantages

  • Native Java support for the Azure Monitor Logs Ingestion API.
  • Flexible authentication options via Azure Identity.
  • Built-in support for batching and concurrency.
  • Provides structured error handling for log upload operations.

Usage examples

“How do I initialize the LogsIngestionClient in Java?”
You use the LogsIngestionClientBuilder, providing the data collection endpoint and a credential object, such as DefaultAzureCredential.
“How can I upload a list of custom logs to Azure Monitor?”
You call the upload method on the client, passing the DCR ID, the target stream name, and the list of log objects.
“How do I handle errors during log ingestion?”
You can use LogsUploadOptions to set a logsUploadErrorConsumer, which allows you to process failed log entries during the upload process.
“Can I perform log uploads asynchronously?”
Yes, by using the LogsIngestionAsyncClient, which supports reactive patterns for non-blocking log ingestion.

Install

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/microsoft/azure-monitor-ingestion-java/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip azure-monitor-ingestion-java.zip -d .agents/skills

Documentation by Microsoft

Azure Monitor Ingestion SDK for Java

Client library for sending custom logs to Azure Monitor using the Logs Ingestion API via Data Collection Rules.

Installation

<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-monitor-ingestion</artifactId>
    <version>1.2.11</version>
</dependency>

Or use Azure SDK BOM:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.azure</groupId>
            <artifactId>azure-sdk-bom</artifactId>
            <version>{bom_version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>com.azure</groupId>
        <artifactId>azure-monitor-ingestion</artifactId>
    </dependency>
</dependencies>

Prerequisites

  • Data Collection Endpoint (DCE)

  • Data Collection Rule (DCR)

  • Log Analytics workspace

  • Target table (custom or built-in: CommonSecurityLog, SecurityEvents, Syslog, WindowsEvents)

Environment Variables

DATA_COLLECTION_ENDPOINT=https://<dce-name>.<region>.ingest.monitor.azure.com  # Required for all auth methods
DATA_COLLECTION_RULE_ID=dcr-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  # Required for log upload routing
STREAM_NAME=Custom-MyTable_CL  # Required for the target DCR stream
AZURE_TOKEN_CREDENTIALS=prod  # Required only if DefaultAzureCredential is used in production

Client Creation

Synchronous Client
import com.azure.core.credential.TokenCredential;
import com.azure.identity.AzureIdentityEnvVars;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.identity.ManagedIdentityCredentialBuilder;
import com.azure.monitor.ingestion.LogsIngestionClient;
import com.azure.monitor.ingestion.LogsIngestionClientBuilder;

// Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential>
TokenCredential credential = new DefaultAzureCredentialBuilder()
    .requireEnvVars(AzureIdentityEnvVars.AZURE_TOKEN_CREDENTIALS)
    .build();
// Or use a specific credential directly in production:
// See https://learn.microsoft.com/java/api/overview/azure/identity-readme?view=azure-java-stable#credential-classes
// TokenCredential credential = new ManagedIdentityCredentialBuilder().build();

LogsIngestionClient client = new LogsIngestionClientBuilder()
    .endpoint("<data-collection-endpoint>")
    .credential(credential)
    .buildClient();
Asynchronous Client
import com.azure.monitor.ingestion.LogsIngestionAsyncClient;

LogsIngestionAsyncClient asyncClient = new LogsIngestionClientBuilder()
    .endpoint("<data-collection-endpoint>")
    .credential(credential)
    .buildAsyncClient();

Key Concepts

ConceptDescription
Data Collection Endpoint (DCE)Ingestion endpoint URL for your region
Data Collection Rule (DCR)Defines data transformation and routing to tables
Stream NameTarget stream in the DCR (e.g., Custom-MyTable_CL)
Log Analytics WorkspaceDestination for ingested logs

Core Operations

Upload Custom Logs
import java.util.List;
import java.util.ArrayList;

List<Object> logs = new ArrayList<>();
logs.add(new MyLogEntry("2024-01-15T10:30:00Z", "INFO", "Application started"));
logs.add(new MyLogEntry("2024-01-15T10:30:05Z", "DEBUG", "Processing request"));

client.upload("<data-collection-rule-id>", "<stream-name>", logs);
System.out.println("Logs uploaded successfully");
Upload with Concurrency

For large log collections, enable concurrent uploads:

import com.azure.monitor.ingestion.models.LogsUploadOptions;
import com.azure.core.util.Context;

List<Object> logs = getLargeLogs(); // Large collection

LogsUploadOptions options = new LogsUploadOptions()
    .setMaxConcurrency(3);

client.upload("<data-collection-rule-id>", "<stream-name>", logs, options, Context.NONE);
Upload with Error Handling

Handle partial upload failures gracefully:

LogsUploadOptions options = new LogsUploadOptions()
    .setLogsUploadErrorConsumer(uploadError -> {
        System.err.println("Upload error: " + uploadError.getResponseException().getMessage());
        System.err.println("Failed logs count: " + uploadError.getFailedLogs().size());
        
        // Option 1: Log and continue
        // Option 2: Throw to abort remaining uploads
        // throw uploadError.getResponseException();
    });

client.upload("<data-collection-rule-id>", "<stream-name>", logs, options, Context.NONE);
Async Upload with Reactor
import reactor.core.publisher.Mono;

List<Object> logs = getLogs();

asyncClient.upload("<data-collection-rule-id>", "<stream-name>", logs)
    .doOnSuccess(v -> System.out.println("Upload completed"))
    .doOnError(e -> System.err.println("Upload failed: " + e.getMessage()))
    .subscribe();

Log Entry Model Example

public class MyLogEntry {
    private String timeGenerated;
    private String level;
    private String message;
    
    public MyLogEntry(String timeGenerated, String level, String message) {
        this.timeGenerated = timeGenerated;
        this.level = level;
        this.message = message;
    }
    
    // Getters required for JSON serialization
    public String getTimeGenerated() { return timeGenerated; }
    public String getLevel() { return level; }
    public String getMessage() { return message; }
}

Error Handling

import com.azure.core.exception.HttpResponseException;

try {
    client.upload(ruleId, streamName, logs);
} catch (HttpResponseException e) {
    System.err.println("HTTP Status: " + e.getResponse().getStatusCode());
    System.err.println("Error: " + e.getMessage());
    
    if (e.getResponse().getStatusCode() == 403) {
        System.err.println("Check DCR permissions and managed identity");
    } else if (e.getResponse().getStatusCode() == 404) {
        System.err.println("Verify DCE endpoint and DCR ID");
    }
}

Best Practices

  1. Batch logs — Upload in batches rather than one at a time

  2. Use concurrency — Set maxConcurrency for large uploads

  3. Handle partial failures — Use error consumer to log failed entries

  4. Match DCR schema — Log entry fields must match DCR transformation expectations

  5. Include TimeGenerated — Most tables require a timestamp field

  6. Reuse client — Create once, reuse throughout application

  7. Use async for high throughput — LogsIngestionAsyncClient for reactive patterns

Querying Uploaded Logs

Use azure-monitor-query to query ingested logs:

// See azure-monitor-query skill for LogsQueryClient usage
String query = "MyTable_CL | where TimeGenerated > ago(1h) | limit 10";

Files

references/examples.md

Azure Monitor Ingestion SDK for Java - Examples

Comprehensive code examples for the Azure Monitor Ingestion SDK for Java.

Table of Contents

  • Maven Dependency

  • Client Creation

  • Uploading Logs

  • Batching with Concurrency

  • Error Handling

  • Async Client Patterns

Maven Dependency

<!-- Using Azure SDK BOM (recommended) -->
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.azure</groupId>
            <artifactId>azure-sdk-bom</artifactId>
            <version>1.2.29</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>com.azure</groupId>
        <artifactId>azure-monitor-ingestion</artifactId>
    </dependency>
    <dependency>
        <groupId>com.azure</groupId>
        <artifactId>azure-identity</artifactId>
    </dependency>
</dependencies>

<!-- Or direct dependencies -->
<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-monitor-ingestion</artifactId>
    <version>1.2.14</version>
</dependency>
<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-identity</artifactId>
    <version>1.15.3</version>
</dependency>

Client Creation

Synchronous Client
import com.azure.identity.DefaultAzureCredential;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.monitor.ingestion.LogsIngestionClient;
import com.azure.monitor.ingestion.LogsIngestionClientBuilder;

DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build();

LogsIngestionClient client = new LogsIngestionClientBuilder()
    .endpoint("<data-collection-endpoint>")  // e.g., "https://my-dce.eastus-1.ingest.monitor.azure.com"
    .credential(credential)
    .buildClient();
Asynchronous Client
import com.azure.monitor.ingestion.LogsIngestionAsyncClient;

LogsIngestionAsyncClient asyncClient = new LogsIngestionClientBuilder()
    .endpoint("<data-collection-endpoint>")
    .credential(new DefaultAzureCredentialBuilder().build())
    .buildAsyncClient();

Uploading Logs

Basic Upload
import com.azure.monitor.ingestion.LogsIngestionClient;
import com.azure.monitor.ingestion.models.LogsUploadException;
import java.time.OffsetDateTime;
import java.util.Arrays;
import java.util.List;

List<Object> logs = Arrays.asList(
    new Object() {
        OffsetDateTime time = OffsetDateTime.now();
        String computer = "Computer1";
        String message = "Application started";
        int level = 1;
    },
    new Object() {
        OffsetDateTime time = OffsetDateTime.now();
        String computer = "Computer2";
        String message = "Connection established";
        int level = 2;
    }
);

try {
    client.upload(
        "dcr-00000000000000000000000000000000",  // DCR immutable ID
        "Custom-MyTableRawData",                  // Stream name from DCR
        logs
    );
    System.out.println("Logs uploaded successfully");
} catch (LogsUploadException e) {
    System.out.println("Failed to upload logs");
    e.getLogsUploadErrors().forEach(error -> 
        System.out.println(error.getMessage()));
}
Using POJO Classes
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.List;

// Define log entry class
class CustomLogEntry {
    private OffsetDateTime timeGenerated;
    private String computer;
    private String message;
    private int severity;

    public CustomLogEntry(OffsetDateTime timeGenerated, String computer, 
                          String message, int severity) {
        this.timeGenerated = timeGenerated;
        this.computer = computer;
        this.message = message;
        this.severity = severity;
    }

    // Getters required for JSON serialization
    public OffsetDateTime getTimeGenerated() { return timeGenerated; }
    public String getComputer() { return computer; }
    public String getMessage() { return message; }
    public int getSeverity() { return severity; }
}

// Create and upload logs
List<Object> logs = new ArrayList<>();
logs.add(new CustomLogEntry(OffsetDateTime.now(), "Server1", "Started", 1));
logs.add(new CustomLogEntry(OffsetDateTime.now(), "Server2", "Connected", 2));

client.upload("<dcr-id>", "<stream-name>", logs);

Batching with Concurrency

When uploading large collections, the SDK automatically splits them into batches:

import com.azure.core.util.Context;
import com.azure.monitor.ingestion.models.LogsUploadOptions;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.List;

// Generate large batch
List<Object> logs = new ArrayList<>();
for (int i = 0; i < 100000; i++) {
    final int index = i;
    logs.add(new Object() {
        OffsetDateTime time = OffsetDateTime.now();
        String computer = "Computer" + (index % 10);
        String message = "Log entry " + index;
        int level = index % 5;
    });
}

// Configure concurrency
LogsUploadOptions options = new LogsUploadOptions()
    .setMaxConcurrency(3);  // Up to 3 concurrent batch uploads

client.upload("<dcr-id>", "<stream-name>", logs, options, Context.NONE);

Error Handling

Error Consumer for Partial Failures
import com.azure.core.util.Context;
import com.azure.monitor.ingestion.models.LogsUploadOptions;

LogsUploadOptions options = new LogsUploadOptions()
    .setLogsUploadErrorConsumer(error -> {
        // Log error details
        System.out.println("Error: " + error.getResponseException().getMessage());
        System.out.println("Failed logs: " + error.getFailedLogs().size());
        
        // Access failed logs for retry
        error.getFailedLogs().forEach(log -> 
            System.out.println("Failed: " + log));

        // Option 1: Continue with remaining logs (default)
        // Just return

        // Option 2: Abort remaining uploads
        // throw error.getResponseException();
    });

client.upload("<dcr-id>", "<stream-name>", logs, options, Context.NONE);
Catching LogsUploadException
import com.azure.monitor.ingestion.models.LogsUploadException;

try {
    client.upload("<dcr-id>", "<stream-name>", logs);
    System.out.println("All logs uploaded");
} catch (LogsUploadException e) {
    System.out.println("Some logs failed");
    e.getLogsUploadErrors().forEach(error -> {
        System.out.println("Error: " + error.getMessage());
        System.out.println("Status: " + 
            error.getResponseException().getResponse().getStatusCode());
    });
}

Async Client Patterns

Basic Async Upload
import java.util.concurrent.CountDownLatch;

CountDownLatch latch = new CountDownLatch(1);

asyncClient.upload("<dcr-id>", "<stream-name>", logs)
    .doOnSuccess(unused -> System.out.println("Uploaded successfully"))
    .doOnError(error -> System.err.println("Failed: " + error.getMessage()))
    .doFinally(signal -> latch.countDown())
    .subscribe();

latch.await();
Async with Options
import com.azure.monitor.ingestion.models.LogsUploadOptions;

LogsUploadOptions options = new LogsUploadOptions()
    .setMaxConcurrency(3)
    .setLogsUploadErrorConsumer(error -> {
        System.out.println("Partial failure: " + error.getFailedLogs().size());
    });

asyncClient.upload("<dcr-id>", "<stream-name>", logs, options)
    .subscribe(
        unused -> System.out.println("Success"),
        error -> System.err.println("Error: " + error.getMessage()),
        () -> System.out.println("Completed")
    );
Chaining Operations
import reactor.core.publisher.Mono;

Mono.just(generateLogs())
    .flatMap(logs -> asyncClient.upload("<dcr-id>", "<stream-name>", logs))
    .doOnSuccess(unused -> System.out.println("Upload complete"))
    .doOnError(error -> System.err.println("Upload failed: " + error))
    .subscribe();

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Created by
Microsoft
Publisher
Microsoft (Official)
Source
microsoft/skills · .github/plugins/azure-sdk-java/skills/azure-monitor-ingestion-java · commit 0696600
Licence
MIT License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced

AutoGineer is not affiliated with or endorsed by Microsoft.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download azure-monitor-ingestion-java.zip