Skip to main content
skill

azure-monitor-ingestion-java — Claude Code skill: logs to Azure

Tells the agent how to ship custom logs to Azure Monitor from Java using the Logs Ingestion API, DCR and DCE.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add microsoft/skills --skill azure-monitor-ingestion-java -a claude-code
Open on GitHub

What azure-monitor-ingestion-java does

The skill covers the com.azure:azure-monitor-ingestion client library for Java. Your agent gets ready-made patterns: building LogsIngestionClient and LogsIngestionAsyncClient, calling upload with a data collection rule ID and stream name, and a log entry model with getters for JSON serialization.

It also documents concurrent uploads with LogsUploadOptions.setMaxConcurrency, partial failure handling through setLogsUploadErrorConsumer, and sorting HttpResponseException by status code 403 or 404. The async path uses Reactor with doOnSuccess and doOnError.

You need a Data Collection Endpoint, a Data Collection Rule, a Log Analytics workspace and a target table before any of this runs. Without DATA_COLLECTION_ENDPOINT and DATA_COLLECTION_RULE_ID the client cannot be built, so check the environment first. Log entry fields must match the DCR transformation schema or the upload fails.

What it helps with

  • send application logs to Azure Monitor from Java code
  • route logs through a Data Collection Rule and stream
  • speed up large log batches with concurrency
  • handle partial upload failures without losing the rest
  • tell a 403 apart from a 404 when hitting the DCE

Example prompts for the agent

  • Show me how to build a LogsIngestionClient with DefaultAzureCredential and upload a list of logs to the Custom-MyTable_CL stream
  • Add concurrent log upload with LogsUploadOptions and maxConcurrency 3
  • Catch HttpResponseException on upload and explain what to check on a 403

How to install azure-monitor-ingestion-java

1Skills CLI (Vercel)

npx skills add microsoft/skills --skill azure-monitor-ingestion-java -a claude-code

2Manually: put the files in place

~/.claude/skills/azure-monitor-ingestion-java/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/azure-monitor-ingestion-java/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about azure-monitor-ingestion-java

How do I install azure-monitor-ingestion-java in GitHub Copilot?

Run gh skill install microsoft/skills azure-monitor-ingestion-java. The skill lands in .github/skills/azure-monitor-ingestion-java/SKILL.md.

What does azure-monitor-ingestion-java do?

It gives the agent a reference for the Java SDK that sends custom logs to Azure Monitor. Client setup, upload calls, concurrency and error handling are all covered.

What do I need before using the skill?

A Data Collection Endpoint, a Data Collection Rule, a Log Analytics workspace and a target table. Set DATA_COLLECTION_ENDPOINT, DATA_COLLECTION_RULE_ID and STREAM_NAME as well.

Source text

SKILL.md · MIT
---
name: azure-monitor-ingestion-java
description: |
  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".
license: MIT
metadata:
  author: Microsoft
  version: "1.0.0"
  package: com.azure:azure-monitor-ingestion
---

# 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

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

Or use Azure SDK BOM:

```xml
<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

```bash
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

```java
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

```java
import com.azure.monitor.ingestion.LogsIngestionAsyncClient;

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

## Key Concepts

| Concept | Description |
|---------|-------------|
| Data Collection Endpoint (DCE) | Ingestion endpoint URL for your region |
| Data Collection Rule (DCR) | Defines data transformation and routing to tables |
| Stream Name | Target stream in the DCR (e.g., `Custom-MyTable_CL`) |
| Log Analytics Workspace | Destination for ingested logs |

## Core Operations

### Upload Custom Logs

```java
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:

```java
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:

```java
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

```java
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

```java
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

```java
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](../query/SKILL.md) to query ingested logs:

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

## Reference Links

| Resource | URL |
|----------|-----|
| Maven Package | https://central.sonatype.com/artifact/com.azure/azure-monitor-ingestion |
| GitHub | https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/monitor/azure-monitor-ingestion |
| Product Docs | https://learn.microsoft.com/azure/azure-monitor/logs/logs-ingestion-api-overview |
| DCE Overview | https://learn.microsoft.com/azure/azure-monitor/essentials/data-collection-endpoint-overview |
| DCR Overview | https://learn.microsoft.com/azure/azure-monitor/essentials/data-collection-rule-overview |
| Troubleshooting | https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor/azure-monitor-ingestion/TROUBLESHOOTING.md |

© Microsoft · MIT · microsoft/skills

Similar skills

Everything for Cloud: AWS, Azure, GCP →

From the same set64

The whole set →
research Runs a five-iteration investigation of one topic in your codebase, tracing real code paths and citing a source for every claim. ★ 3,148repo stars azure-kubernetes-automatic-readiness Checks Kubernetes workloads and cluster config against AKS Automatic rules, flags migration blockers and drafts fixes as diffs. ★ 3,148repo stars azure-enterprise-infra-planner The skill plans enterprise Azure infrastructure from a workload description and generates Bicep or Terraform. Useful when you need a landing zone, hub-spoke network or DR topology. ★ 3,148repo stars azure-app-onboard Takes a business idea or existing codebase to a running Azure deployment: picks services, estimates cost, writes IaC. ★ 3,148repo stars azure-eventhub-java A skill for the Azure Event Hubs SDK for Java: producers, consumers, batching, partitions, checkpoints. Useful when you build event streaming apps. ★ 3,148repo stars azure-communication-callautomation-java Java SDK skill for Azure Communication Services Call Automation: outbound calls, IVR, recording, DTMF and speech recognition. ★ 3,148repo stars azure-ai-vision-imageanalysis-java A skill for the Azure AI Vision SDK for Java. It feeds the agent ready code for captions, OCR, object detection, tagging and smart cropping. ★ 3,148repo stars azure-resource-manager-redis-dotnet A skill for provisioning and managing Azure Cache for Redis through Azure Resource Manager in .NET: caches, firewall rules, access keys, geo-replication. ★ 3,148repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor