Skip navigation links

Azure SDK for Java Reference Documentation

Current version is 1.0.0-beta.4, click here for the index

Azure Monitor OpenTelemetry Exporter client library for Java

See: Description

Other Packages 
Package Description
com.azure.monitor.opentelemetry.exporter
Package containing the OpenTelemetry Exporter for Azure Monitor.
Current version is 1.0.0-beta.4, click here for the index

Azure Monitor OpenTelemetry Exporter client library for Java

This client library provides support for exporting OpenTelemetry data to Azure Monitor. This package assumes your application is already instrumented with the OpenTelemetry SDK following the OpenTelemetry Specification.

Source code | Package (Maven) | API reference documentation | Product Documentation | Samples

Getting started

Prerequisites

For more information, please read introduction to Application Insights.

Include the Package

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

Authentication

Get the instrumentation key from the portal

In order to export telemetry data to Azure Monitor, you will need the instrumentation key to your Application Insights resource. To get your instrumentation key, go to Azure Portal, search for your resource. On the overview page of your resource, you will find the instrumentation key on the top right corner.

Creating exporter for Azure Monitor

AzureMonitorTraceExporter azureMonitorTraceExporter = new AzureMonitorExporterBuilder()
    .connectionString("{connection-string}")
    .buildTraceExporter();

Exporting span data

The following example shows how to export a trace data to Azure Monitor through the AzureMonitorExporter

Setup OpenTelemetry Tracer to work with Azure Monitor exporter
// Create Azure Monitor exporter and configure OpenTelemetry tracer to use this exporter
// This should be done just once when application starts up
AzureMonitorTraceExporter exporter = new AzureMonitorExporterBuilder()
    .connectionString("{connection-string}")
    .buildTraceExporter();

SdkTracerProvider tracerProvider = SdkTracerProvider.builder()
    .addSpanProcessor(SimpleSpanProcessor.create(exporter))
    .build();

OpenTelemetrySdk openTelemetrySdk = OpenTelemetrySdk.builder()
    .setTracerProvider(tracerProvider)
    .buildAndRegisterGlobal();

Tracer tracer = openTelemetrySdk.getTracer("Sample");
Create spans
// Make service calls by adding new parent spans
ConfigurationClient client = new ConfigurationClientBuilder()
    .connectionString("{app-config-connection-string}")
    .buildClient();

Span span = tracer.spanBuilder("user-parent-span").startSpan();
final Scope scope = span.makeCurrent();
try {
    // Thread bound (sync) calls will automatically pick up the parent span and you don't need to pass it explicitly.
    client.setConfigurationSetting("hello", "text", "World");
} finally {
    span.end();
    scope.close();
}

Key concepts

Some of the key concepts for the Azure Monitor exporter include:

For more information on the OpenTelemetry project, please review the OpenTelemetry Specifications.

Examples

More examples can be found in [samples][samples_code].

Troubleshooting

Enabling Logging

Azure SDKs for Java offer a consistent logging story to help aid in troubleshooting application errors and expedite their resolution. The logs produced will capture the flow of an application before reaching the terminal state to help locate the root issue. View the logging wiki for guidance about enabling logging.

Next steps

Learn more about Open Telemetry

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a [Contributor License Agreement (CLA)][cla] declaring that you have the right to, and actually do, grant us the rights to use your contribution.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For more information see the [Code of Conduct FAQ][cocfaq] or contact [opencode@microsoft.com][coccontact] with any additional questions or comments.

Impressions

Skip navigation links
Visit the Azure for Java Developerssite for more Java documentation, including quick starts, tutorials, and code samples.

Copyright © 2021 Microsoft Corporation. All rights reserved.