Azure Monitor Opentelemetry Exporter Java
MicrosoftOfficialCreated by Microsoft
- Skill
- Tool integration
- Software development
- MIT
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides guidance on using the Azure Monitor OpenTelemetry Exporter for Java. It covers the integration of OpenTelemetry SDK with Azure Monitor, including setting up tracers, creating spans, recording exceptions, and defining metrics. Note that this specific package is deprecated; users are strongly advised to migrate to the azure-monitor-opentelemetry-autoconfigure package for automatic instrumentation and simplified configuration.
What it does
- Exports OpenTelemetry telemetry data to Azure Monitor and Application Insights.
- Demonstrates how to create and manage spans for distributed tracing.
- Shows how to record exceptions and add attributes to spans for better observability.
- Provides examples for implementing custom span processors.
- Illustrates how to define and record metrics using OpenTelemetry APIs.
- Provides migration instructions to the recommended autoconfigure package.
When to use it
- When you need to send Java application telemetry to Azure Monitor.
- When you are currently using the deprecated exporter and need to plan a migration.
- When you want to implement distributed tracing in a Java environment.
- When you need to collect custom metrics from your Java application.
Advantages
- Provides a clear path for migrating to the modern autoconfigure approach.
- Offers comprehensive examples for standard OpenTelemetry patterns.
- Includes guidance on best practices for span and metric management.
Usage examples
- “How do I configure the Azure Monitor exporter in my Java application?”
- The agent provides the setup code using AutoConfiguredOpenTelemetrySdk and explains how to use the APPLICATIONINSIGHTS_CONNECTION_STRING environment variable.
- “How can I add custom attributes to my spans for better debugging?”
- The agent shows how to use the setAttribute method on a span object to include contextual data like order IDs or customer tiers.
- “What is the recommended way to migrate from the deprecated exporter?”
- The agent provides the steps to remove the old dependency and replace it with azure-monitor-opentelemetry-autoconfigure, including links to the official migration guide.
- “How do I record an exception in a span?”
- The agent demonstrates a try-catch block pattern where span.recordException(e) and span.setStatus are used to capture and report errors.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/microsoft/azure-monitor-opentelemetry-exporter-java/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip azure-monitor-opentelemetry-exporter-java.zip -d .agents/skills
Documentation by Microsoft
Azure Monitor OpenTelemetry Exporter for Java
⚠️ DEPRECATION NOTICE: This package is deprecated. Migrate to
azure-monitor-opentelemetry-autoconfigure.See Migration Guide for detailed instructions.
Export OpenTelemetry telemetry data to Azure Monitor / Application Insights.
Installation (Deprecated)
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-monitor-opentelemetry-exporter</artifactId>
<version>1.0.0-beta.x</version>
</dependency>Recommended: Use Autoconfigure Instead
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-monitor-opentelemetry-autoconfigure</artifactId>
<version>LATEST</version>
</dependency>Environment Variables
APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=xxx;IngestionEndpoint=https://xxx.in.applicationinsights.azure.com/Basic Setup with Autoconfigure (Recommended)
Using Environment Variable
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder;
import io.opentelemetry.api.OpenTelemetry;
import com.azure.monitor.opentelemetry.exporter.AzureMonitorExporter;
// Connection string from APPLICATIONINSIGHTS_CONNECTION_STRING env var
AutoConfiguredOpenTelemetrySdkBuilder sdkBuilder = AutoConfiguredOpenTelemetrySdk.builder();
AzureMonitorExporter.customize(sdkBuilder);
OpenTelemetry openTelemetry = sdkBuilder.build().getOpenTelemetrySdk();With Explicit Connection String
AutoConfiguredOpenTelemetrySdkBuilder sdkBuilder = AutoConfiguredOpenTelemetrySdk.builder();
AzureMonitorExporter.customize(sdkBuilder, "{connection-string}");
OpenTelemetry openTelemetry = sdkBuilder.build().getOpenTelemetrySdk();Creating Spans
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.context.Scope;
// Get tracer
Tracer tracer = openTelemetry.getTracer("com.example.myapp");
// Create span
Span span = tracer.spanBuilder("myOperation").startSpan();
try (Scope scope = span.makeCurrent()) {
// Your application logic
doWork();
} catch (Throwable t) {
span.recordException(t);
throw t;
} finally {
span.end();
}Adding Span Attributes
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
Span span = tracer.spanBuilder("processOrder")
.setAttribute("order.id", "12345")
.setAttribute("customer.tier", "premium")
.startSpan();
try (Scope scope = span.makeCurrent()) {
// Add attributes during execution
span.setAttribute("items.count", 3);
span.setAttribute("total.amount", 99.99);
processOrder();
} finally {
span.end();
}Custom Span Processor
import io.opentelemetry.sdk.trace.SpanProcessor;
import io.opentelemetry.sdk.trace.ReadWriteSpan;
import io.opentelemetry.sdk.trace.ReadableSpan;
import io.opentelemetry.context.Context;
private static final AttributeKey<String> CUSTOM_ATTR = AttributeKey.stringKey("custom.attribute");
SpanProcessor customProcessor = new SpanProcessor() {
@Override
public void onStart(Context context, ReadWriteSpan span) {
// Add custom attribute to every span
span.setAttribute(CUSTOM_ATTR, "customValue");
}
@Override
public boolean isStartRequired() {
return true;
}
@Override
public void onEnd(ReadableSpan span) {
// Post-processing if needed
}
@Override
public boolean isEndRequired() {
return false;
}
};
// Register processor
AutoConfiguredOpenTelemetrySdkBuilder sdkBuilder = AutoConfiguredOpenTelemetrySdk.builder();
AzureMonitorExporter.customize(sdkBuilder);
sdkBuilder.addTracerProviderCustomizer(
(sdkTracerProviderBuilder, configProperties) ->
sdkTracerProviderBuilder.addSpanProcessor(customProcessor)
);
OpenTelemetry openTelemetry = sdkBuilder.build().getOpenTelemetrySdk();Nested Spans
public void parentOperation() {
Span parentSpan = tracer.spanBuilder("parentOperation").startSpan();
try (Scope scope = parentSpan.makeCurrent()) {
childOperation();
} finally {
parentSpan.end();
}
}
public void childOperation() {
// Automatically links to parent via Context
Span childSpan = tracer.spanBuilder("childOperation").startSpan();
try (Scope scope = childSpan.makeCurrent()) {
// Child work
} finally {
childSpan.end();
}
}Recording Exceptions
Span span = tracer.spanBuilder("riskyOperation").startSpan();
try (Scope scope = span.makeCurrent()) {
performRiskyWork();
} catch (Exception e) {
span.recordException(e);
span.setStatus(StatusCode.ERROR, e.getMessage());
throw e;
} finally {
span.end();
}Metrics (via OpenTelemetry)
import io.opentelemetry.api.metrics.Meter;
import io.opentelemetry.api.metrics.LongCounter;
import io.opentelemetry.api.metrics.LongHistogram;
Meter meter = openTelemetry.getMeter("com.example.myapp");
// Counter
LongCounter requestCounter = meter.counterBuilder("http.requests")
.setDescription("Total HTTP requests")
.setUnit("requests")
.build();
requestCounter.add(1, Attributes.of(
AttributeKey.stringKey("http.method"), "GET",
AttributeKey.longKey("http.status_code"), 200L
));
// Histogram
LongHistogram latencyHistogram = meter.histogramBuilder("http.latency")
.setDescription("Request latency")
.setUnit("ms")
.ofLongs()
.build();
latencyHistogram.record(150, Attributes.of(
AttributeKey.stringKey("http.route"), "/api/users"
));Key Concepts
| Concept | Description |
|---|---|
| Connection String | Application Insights connection string with instrumentation key |
| Tracer | Creates spans for distributed tracing |
| Span | Represents a unit of work with timing and attributes |
| SpanProcessor | Intercepts span lifecycle for customization |
| Exporter | Sends telemetry to Azure Monitor |
Migration to Autoconfigure
The azure-monitor-opentelemetry-autoconfigure package provides:
Automatic instrumentation of common libraries
Simplified configuration
Better integration with OpenTelemetry SDK
Migration Steps
Replace dependency:
<!-- Remove --> <dependency> <groupId>com.azure</groupId> <artifactId>azure-monitor-opentelemetry-exporter</artifactId> </dependency> <!-- Add --> <dependency> <groupId>com.azure</groupId> <artifactId>azure-monitor-opentelemetry-autoconfigure</artifactId> </dependency>Update initialization code per Migration Guide
Best Practices
Use autoconfigure — Migrate to
azure-monitor-opentelemetry-autoconfigureSet meaningful span names — Use descriptive operation names
Add relevant attributes — Include contextual data for debugging
Handle exceptions — Always record exceptions on spans
Use semantic conventions — Follow OpenTelemetry semantic conventions
End spans in finally — Ensure spans are always ended
Use try-with-resources — Scope management with try-with-resources pattern
Reference Links
Files
- ATTRIBUTION.mdAdded by AutoGineer1.0 KiB
- LICENSELicence file added by AutoGineer1.1 KiB
- SKILL.md8.6 KiB
- references/examples.md5.4 KiB
references/examples.md
Azure Monitor OpenTelemetry Exporter Java - Migration Guide
⚠️ DEPRECATION NOTICE: This package (
azure-monitor-opentelemetry-exporter) is deprecated.Migrate to
azure-monitor-opentelemetry-autoconfigurefor automatic instrumentation and simplified configuration.
Migration Overview
| Old Package | New Package |
|---|---|
azure-monitor-opentelemetry-exporter | azure-monitor-opentelemetry-autoconfigure |
Maven Dependency
Remove (Deprecated)
<!-- REMOVE THIS -->
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-monitor-opentelemetry-exporter</artifactId>
<version>1.0.0-beta.x</version>
</dependency>Add (Recommended)
<!-- ADD THIS -->
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-monitor-opentelemetry-autoconfigure</artifactId>
<version>1.0.0</version>
</dependency>Environment Variables
APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=xxx;IngestionEndpoint=https://xxx.in.applicationinsights.azure.com/Basic Setup with Autoconfigure
Using Environment Variable (Simplest)
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder;
import io.opentelemetry.api.OpenTelemetry;
import com.azure.monitor.opentelemetry.exporter.AzureMonitorExporter;
// Connection string from APPLICATIONINSIGHTS_CONNECTION_STRING env var
AutoConfiguredOpenTelemetrySdkBuilder sdkBuilder = AutoConfiguredOpenTelemetrySdk.builder();
AzureMonitorExporter.customize(sdkBuilder);
OpenTelemetry openTelemetry = sdkBuilder.build().getOpenTelemetrySdk();With Explicit Connection String
String connectionString = System.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING");
AutoConfiguredOpenTelemetrySdkBuilder sdkBuilder = AutoConfiguredOpenTelemetrySdk.builder();
AzureMonitorExporter.customize(sdkBuilder, connectionString);
OpenTelemetry openTelemetry = sdkBuilder.build().getOpenTelemetrySdk();Creating Traces
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.context.Scope;
// Get tracer
Tracer tracer = openTelemetry.getTracer("com.example.myapp");
// Create span
Span span = tracer.spanBuilder("processOrder").startSpan();
try (Scope scope = span.makeCurrent()) {
// Your application logic
span.setAttribute("order.id", "12345");
span.setAttribute("customer.tier", "premium");
processOrder();
} catch (Throwable t) {
span.recordException(t);
throw t;
} finally {
span.end();
}Creating Metrics
import io.opentelemetry.api.metrics.Meter;
import io.opentelemetry.api.metrics.LongCounter;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributeKey;
Meter meter = openTelemetry.getMeter("com.example.myapp");
// Counter
LongCounter requestCounter = meter.counterBuilder("http.requests")
.setDescription("Total HTTP requests")
.setUnit("requests")
.build();
requestCounter.add(1, Attributes.of(
AttributeKey.stringKey("http.method"), "GET",
AttributeKey.longKey("http.status_code"), 200L
));Custom Span Processor
import io.opentelemetry.sdk.trace.SpanProcessor;
import io.opentelemetry.sdk.trace.ReadWriteSpan;
import io.opentelemetry.sdk.trace.ReadableSpan;
import io.opentelemetry.context.Context;
SpanProcessor customProcessor = new SpanProcessor() {
@Override
public void onStart(Context context, ReadWriteSpan span) {
span.setAttribute("custom.attribute", "value");
}
@Override
public boolean isStartRequired() { return true; }
@Override
public void onEnd(ReadableSpan span) { }
@Override
public boolean isEndRequired() { return false; }
};
AutoConfiguredOpenTelemetrySdkBuilder sdkBuilder = AutoConfiguredOpenTelemetrySdk.builder();
AzureMonitorExporter.customize(sdkBuilder);
sdkBuilder.addTracerProviderCustomizer(
(sdkTracerProviderBuilder, configProperties) ->
sdkTracerProviderBuilder.addSpanProcessor(customProcessor)
);
OpenTelemetry openTelemetry = sdkBuilder.build().getOpenTelemetrySdk();Why Migrate?
The azure-monitor-opentelemetry-autoconfigure package provides:
Automatic instrumentation — Common libraries instrumented automatically
Simplified configuration — Less boilerplate code
Better integration — Native OpenTelemetry SDK integration
Active maintenance — Ongoing updates and improvements
Production ready — GA (Generally Available) status
Migration Steps Summary
Update Maven/Gradle dependency
Replace manual exporter setup with
AzureMonitorExporter.customize()Use
AutoConfiguredOpenTelemetrySdk.builder()for SDK initializationRemove manual span processor registration (unless custom processors needed)
Set
APPLICATIONINSIGHTS_CONNECTION_STRINGenvironment variable
Reference Links
| Resource | URL |
|---|---|
| Migration Guide | https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor/azure-monitor-opentelemetry-exporter/MIGRATION.md |
| Autoconfigure Package | https://central.sonatype.com/artifact/com.azure/azure-monitor-opentelemetry-autoconfigure |
| OpenTelemetry Java | https://opentelemetry.io/docs/languages/java/ |
| Application Insights | https://learn.microsoft.com/azure/azure-monitor/app/app-insights-overview |
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-opentelemetry-exporter-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-opentelemetry-exporter-java.zip