Agent Skillsmicrosoft/skills › azure-monitor-ingestion-java

azure-monitor-ingestion-java

GitHub

Azure Monitor Java SDK,用于通过DCR和DCE将自定义日志发送至Azure Monitor。提供同步/异步客户端创建、依赖安装及环境变量配置说明。

.github/plugins/azure-sdk-java/skills/azure-monitor-ingestion-java/SKILL.md microsoft/skills

Trigger Scenarios

LogsIngestionClient java azure monitor ingestion java custom logs java DCR java data collection rule java

Install

npx skills add microsoft/skills --skill azure-monitor-ingestion-java -g -y
More Options

Non-standard path

npx skills add https://github.com/microsoft/skills/tree/main/.github/plugins/azure-sdk-java/skills/azure-monitor-ingestion-java -g -y

Use without installing

npx skills use microsoft/skills@azure-monitor-ingestion-java

指定 Agent (Claude Code)

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

安装 repo 全部 skill

npx skills add microsoft/skills --all -g -y

预览 repo 内 skill

npx skills add microsoft/skills --list

SKILL.md

Frontmatter
{
    "name": "azure-monitor-ingestion-java",
    "license": "MIT",
    "metadata": {
        "author": "Microsoft",
        "package": "com.azure:azure-monitor-ingestion",
        "version": "1.0.0"
    },
    "description": "Azure Monitor Ingestion SDK for Java. Send custom logs to Azure Monitor via Data Collection Rules (DCR) and Data Collection Endpoints (DCE).\nTriggers: \"LogsIngestionClient java\", \"azure monitor ingestion java\", \"custom logs java\", \"DCR java\", \"data collection rule java\".\n"
}

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

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

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 throughputLogsIngestionAsyncClient 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";

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

Version History

  • 4f1db7e Current 2026-07-25 06:28

Same Skill Collection

.github/plugins/azure-kusto-graph-skills/skills/azure-kusto-irql/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-ai-agents-persistent-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-ai-document-intelligence-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-ai-openai-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-ai-projects-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-ai-voicelive-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-eventgrid-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-eventhub-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-identity-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-maps-search-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-mgmt-apicenter-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-mgmt-apimanagement-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-mgmt-applicationinsights-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-mgmt-arizeaiobservabilityeval-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-mgmt-botservice-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-mgmt-fabric-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-mgmt-mongodbatlas-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-mgmt-weightsandbiases-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-resource-manager-cosmosdb-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-resource-manager-durabletask-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-resource-manager-mysql-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-resource-manager-postgresql-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-resource-manager-redis-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-resource-manager-sql-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-search-documents-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-security-keyvault-keys-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-servicebus-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/m365-agents-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/microsoft-azure-webjobs-extensions-authentication-events-dotnet/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-ai-agents-persistent-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-ai-anomalydetector-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-ai-contentsafety-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-ai-formrecognizer-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-ai-projects-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-ai-vision-imageanalysis-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-ai-voicelive-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-appconfiguration-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-communication-callautomation-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-communication-callingserver-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-communication-chat-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-communication-common-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-communication-sms-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-compute-batch-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-cosmos-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-data-tables-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-eventgrid-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-eventhub-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-identity-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-messaging-webpubsub-java/SKILL.md

Metadata

Files
0
Version
a3d788b
Hash
edc52c6a
Indexed
2026-07-25 06:28

Главная - Вики-сайт
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-20 10:39
浙ICP备14020137号-1 $Гость$