Add this skill
npx mdskills install sickn33/azure-monitor-ingestion-javaComprehensive Azure SDK documentation with excellent code examples and error handling patterns
Client library for sending custom logs to Azure Monitor using the Logs Ingestion API via Data Collection Rules.
com.azure
azure-monitor-ingestion
1.2.11
Or use Azure SDK BOM:
com.azure
azure-sdk-bom
{bom_version}
pom
import
com.azure
azure-monitor-ingestion
DATA_COLLECTION_ENDPOINT=https://..ingest.monitor.azure.com
DATA_COLLECTION_RULE_ID=dcr-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
STREAM_NAME=Custom-MyTable_CL
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("")
.credential(credential)
.buildClient();
import com.azure.monitor.ingestion.LogsIngestionAsyncClient;
LogsIngestionAsyncClient asyncClient = new LogsIngestionClientBuilder()
.endpoint("")
.credential(new DefaultAzureCredentialBuilder().build())
.buildAsyncClient();
| 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 |
import java.util.List;
import java.util.ArrayList;
List 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("", "", logs);
System.out.println("Logs uploaded successfully");
For large log collections, enable concurrent uploads:
import com.azure.monitor.ingestion.models.LogsUploadOptions;
import com.azure.core.util.Context;
List logs = getLargeLogs(); // Large collection
LogsUploadOptions options = new LogsUploadOptions()
.setMaxConcurrency(3);
client.upload("", "", logs, options, Context.NONE);
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("", "", logs, options, Context.NONE);
import reactor.core.publisher.Mono;
List logs = getLogs();
asyncClient.upload("", "", logs)
.doOnSuccess(v -> System.out.println("Upload completed"))
.doOnError(e -> System.err.println("Upload failed: " + e.getMessage()))
.subscribe();
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; }
}
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");
}
}
maxConcurrency for large uploadsLogsIngestionAsyncClient for reactive patternsUse 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";
Install via CLI
npx mdskills install sickn33/azure-monitor-ingestion-javaAzure Monitor Ingestion Java is a free, open-source AI agent skill. |
Install Azure Monitor Ingestion Java with a single command:
npx mdskills install sickn33/azure-monitor-ingestion-javaThis downloads the skill files into your project and your AI agent picks them up automatically.
Azure Monitor Ingestion Java works with Claude Code, Claude Desktop, Cursor, Vscode Copilot, Windsurf, Continue Dev, Codex, Gemini Cli, Amp, Roo Code, Goose, Opencode, Trae, Qodo, Command Code. Skills use the open SKILL.md format which is compatible with any AI coding agent that reads markdown instructions.