Skip to main content
skill

azure-monitor-opentelemetry-exporter-java — Claude Code skill: setup

This skill guides Java developers through sending OpenTelemetry traces, metrics, and logs to Azure Monitor and Application Insights. The exporter package is deprecated, with autoconfigure recommended as its replacement.

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

What azure-monitor-opentelemetry-exporter-java does

The skill covers OpenTelemetry integration for Java applications that send telemetry to Azure Monitor and Application Insights. Its examples show how to create spans, attach custom attributes, record exceptions, and collect HTTP request metrics. A custom SpanProcessor can add attributes when spans start, while OpenTelemetry context links nested operations.

The setup uses an Application Insights connection string and the OpenTelemetry SDK. The connection string can come from APPLICATIONINSIGHTS_CONNECTION_STRING or be passed directly during SDK configuration. The examples also cover a request counter and a latency histogram, giving developers concrete patterns for instrumenting application code.

The com.azure:azure-monitor-opentelemetry-exporter package is deprecated. The recommended alternative is com.azure:azure-monitor-opentelemetry-autoconfigure, which simplifies configuration and supports automatic instrumentation for common libraries. Existing Java projects should account for this migration before adopting the older exporter examples.

What it helps with

  • Send Java application telemetry to Azure Monitor
  • Trace operations with OpenTelemetry spans
  • Attach custom attributes to recorded spans
  • Capture exceptions and mark failed operations
  • Measure HTTP request counts and latency

Example prompts for the agent

  • Help me configure OpenTelemetry for my Java application and send telemetry to Application Insights.
  • Add spans around processOrder and attach order attributes.
  • Set up an HTTP request counter and latency histogram with OpenTelemetry.

How to install azure-monitor-opentelemetry-exporter-java

1Skills CLI (Vercel)

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

2Manually: put the files in place

~/.claude/skills/azure-monitor-opentelemetry-exporter-java/SKILL.md

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

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

Questions about azure-monitor-opentelemetry-exporter-java

How do I install azure-monitor-opentelemetry-exporter-java in Claude Code?

Run npx skills add microsoft/skills --skill azure-monitor-opentelemetry-exporter-java -a claude-code. The installed skill file is located at ~/.claude/skills/azure-monitor-opentelemetry-exporter-java/SKILL.md.

What does azure-monitor-opentelemetry-exporter-java do?

It guides OpenTelemetry setup for exporting Java application traces, metrics, and logs to Azure Monitor and Application Insights. Its examples cover span creation, custom attributes, exception recording, and HTTP metrics.

What should replace the deprecated exporter package?

Use com.azure:azure-monitor-opentelemetry-autoconfigure. It simplifies OpenTelemetry configuration and supports automatic instrumentation of common libraries.

Source text

SKILL.md · MIT
---
name: azure-monitor-opentelemetry-exporter-java
description: |
  Azure Monitor OpenTelemetry Exporter for Java. Export OpenTelemetry traces, metrics, and logs to Azure Monitor/Application Insights.
  Triggers: "AzureMonitorExporter java", "opentelemetry azure java", "application insights java otel", "azure monitor tracing java".
  Note: This package is DEPRECATED. Migrate to azure-monitor-opentelemetry-autoconfigure.
license: MIT
metadata:
  author: Microsoft
  version: "1.0.0"
  package: com.azure:azure-monitor-opentelemetry-exporter
---

# Azure Monitor OpenTelemetry Exporter for Java

> **⚠️ DEPRECATION NOTICE**: This package is deprecated. Migrate to `azure-monitor-opentelemetry-autoconfigure`.
>
> See [Migration Guide](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor/azure-monitor-opentelemetry-exporter/MIGRATION.md) for detailed instructions.

Export OpenTelemetry telemetry data to Azure Monitor / Application Insights.

## Installation (Deprecated)

```xml
<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-monitor-opentelemetry-exporter</artifactId>
    <version>1.0.0-beta.x</version>
</dependency>
```

## Recommended: Use Autoconfigure Instead

```xml
<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-monitor-opentelemetry-autoconfigure</artifactId>
    <version>LATEST</version>
</dependency>
```

## Environment Variables

```bash
APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=xxx;IngestionEndpoint=https://xxx.in.applicationinsights.azure.com/
```

## Basic Setup with Autoconfigure (Recommended)

### Using Environment Variable

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

```java
AutoConfiguredOpenTelemetrySdkBuilder sdkBuilder = AutoConfiguredOpenTelemetrySdk.builder();
AzureMonitorExporter.customize(sdkBuilder, "{connection-string}");
OpenTelemetry openTelemetry = sdkBuilder.build().getOpenTelemetrySdk();
```

## Creating Spans

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

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

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

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

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

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

1. Replace dependency:
   ```xml
   <!-- 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>
   ```

2. Update initialization code per [Migration Guide](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor/azure-monitor-opentelemetry-exporter/MIGRATION.md)

## Best Practices

1. **Use autoconfigure** — Migrate to `azure-monitor-opentelemetry-autoconfigure`
2. **Set meaningful span names** — Use descriptive operation names
3. **Add relevant attributes** — Include contextual data for debugging
4. **Handle exceptions** — Always record exceptions on spans
5. **Use semantic conventions** — Follow OpenTelemetry semantic conventions
6. **End spans in finally** — Ensure spans are always ended
7. **Use try-with-resources** — Scope management with try-with-resources pattern

## Reference Links

| Resource | URL |
|----------|-----|
| Maven Package | https://central.sonatype.com/artifact/com.azure/azure-monitor-opentelemetry-exporter |
| GitHub | https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/monitor/azure-monitor-opentelemetry-exporter |
| 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 |

© Microsoft · MIT · microsoft/skills

Similar skills

All skills for Cloud: AWS, Azure, GCP →

From the same set242

The whole set →
azure-storage-blob-java Supplies ready-to-use patterns for the Azure Storage Blob Java SDK, covering authentication, container administration, and file uploads. ★ 3,149repo stars azure-security-keyvault-secrets-java This skill guides Java work with Azure Key Vault secrets, from client setup and retrieval to versioning, deletion, recovery, and backups. ★ 3,149repo stars azure-security-keyvault-keys-java A skill for managing Azure Key Vault keys from Java: RSA and EC creation, encrypt, sign, HSM-backed keys. Useful when the agent writes Azure SDK code. ★ 3,149repo stars azure-monitor-query-java Provides Java patterns for KQL queries in Log Analytics and Azure resource metrics. Helpful when maintaining projects on the com.azure:azure-monitor-query library. ★ 3,149repo stars azure-monitor-ingestion-java Tells the agent how to ship custom logs to Azure Monitor from Java using the Logs Ingestion API, DCR and DCE. ★ 3,149repo stars azure-messaging-webpubsub-java Provides patterns for building real-time WebSocket applications in Java with the Azure Web PubSub SDK, including message filtering and token creation. ★ 3,149repo stars azure-identity-java Get guidance for authenticating Java applications to Azure with Microsoft Entra ID. Useful when wiring credentials into Azure SDK clients. ★ 3,149repo 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,149repo 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