Skip navigation links

Azure SDK for Java Reference Documentation

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

Azure OpenTelemetry Tracing plugin library for Java

See: Description

Packages 
Package Description
com.azure.core.tracing.opentelemetry
An OpenTelemetry implementation of the tracing APIs required by azure-core to enable users to effectively trace their calls and have this information submitted to an OpenTelemetry backend.
Current version is 1.0.0-beta.14, click here for the index

Azure OpenTelemetry Tracing plugin library for Java

This package enables distributed tracing across Azure SDK Java libraries through OpenTelemetry. OpenTelemetry is an open source, vendor-agnostic, single distribution of libraries to provide metrics collection and distributed tracing for services. The Azure core tracing package provides:

Source code | API reference documentation | Product documentation | Samples

Getting started

Prerequisites

Include the package

<dependency>
  <groupId>com.azure</groupId>
  <artifactId>azure-core-tracing-opentelemetry</artifactId>
  <version>1.0.0-beta.14</version>
</dependency>

Key concepts

Trace

A trace is a tree of spans showing the path of work through a system. A trace on its own is distinguishable by a unique 16 byte sequence called a TraceID.

Span

A span represents a single operation in a trace. A span could be representative of an HTTP request, a remote procedure call (RPC), a database query, or even the path that a code takes.

Examples

The following sections provides examples of using the azure-core-tracing-opentelemetry plugin with some of the Azure Java SDK libraries:

Using the plugin package with HTTP client libraries

Using the plugin package with AMQP client libraries

Send a single event/message using azure-messaging-eventhubs with tracing enabled.

Users can additionally pass the value of the current tracing span to the EventData object with key PARENTSPANKEY on the Context object:

// Get the Tracer Provider
private static TracerSdkProvider tracerProvider = OpenTelemetrySdk.getTracerProvider();
private static final Tracer TRACER = configureOpenTelemetryAndLoggingExporter();

private static void doClientWork() {
    EventHubProducerClient producer = new EventHubClientBuilder()
        .connectionString(CONNECTION_STRING)
        .buildProducerClient();

    Span span = TRACER.spanBuilder("user-parent-span").startSpan();
    try (Scope scope = TRACER.withSpan(span)) {
        EventData event1 = new EventData("1".getBytes(UTF_8));
        event1.addContext(PARENT_SPAN_KEY, span);

        EventDataBatch eventDataBatch = producer.createBatch();

        if (!eventDataBatch.tryAdd(eventData)) {
            producer.send(eventDataBatch);
            eventDataBatch = producer.createBatch();
        }
    } finally {
        span.end();
    }
}

Troubleshooting

General

For more information on OpenTelemetry Java support for tracing, see OpenTelemetry Java.

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

Samples

Several Java SDK samples are available to you in the SDKs GitHub repository. These following samples provide example code for additional scenarios commonly encountered while working with Tracing:

Additional Documentation

For more extensive documentation on OpenTelemetry, see the API reference documentation.

Contributing

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

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. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com 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.