This page explains how to configure a Java app using the Java OpenTelemetry SDK to send telemetry data to Axiom.
DiceRollerApp.java
sample.MyProject
with a standard directory structure.
DiceRollerApp.java
is the core of the sample app. It simulates rolling a dice and demonstrates the usage of OpenTelemetry for tracing. The app includes two methods: one for a simple dice roll and another that demonstrates the usage of span links to establish relationships between spans across different traces.
Create the DiceRollerApp.java
in the src/main/java/com/example
directory with the following content:
OtelConfiguration.java
sets up the OpenTelemetry SDK and configures the exporter to send data to Axiom. It initializes the tracer provider, sets up the Axiom exporter, and configures the resource attributes.
Create the OtelConfiguration.java
file in the src/main/java/com/example
directory with the following content:
API_TOKEN
with the Axiom API token you have generated. For added security, store the API token in an environment variable.Replace DATASET_NAME
with the name of the Axiom dataset where you want to send data.Replace AXIOM_DOMAIN
with api.axiom.co
if your organization uses the US region, and with api.eu.axiom.co
if your organization uses the EU region. For more information, see Regions.pom.xml
file defines the project structure and dependencies for Maven. It includes the necessary OpenTelemetry libraries and configures the build process.
Update the pom.xml
file in the root of your project directory with the following content:
rollDice()
and rollDiceWithLink()
methods, generates telemetry data, and sends the data to Axiom.
Set up OpenTelemetry
API_TOKEN
with the Axiom API token you have generated. For added security, store the API token in an environment variable.Replace DATASET_NAME
with the name of the Axiom dataset where you want to send data.Replace AXIOM_DOMAIN
with api.axiom.co
if your organization uses the US region, and with api.eu.axiom.co
if your organization uses the EU region. For more information, see Regions.Create spans
Annotate spans
Creating span links
Set up dependencies
pom.xml
.Auto-instrument the app
Integrate and run
Field category | Field name | Description |
---|---|---|
General trace information | ||
_rowId | Unique identifier for each row in the trace data. | |
_sysTime | System timestamp when the trace data was recorded. | |
_time | Timestamp when the actual event being traced occurred. | |
trace_id | Unique identifier for the entire trace. | |
span_id | Unique identifier for the span within the trace. | |
parent_span_id | Unique identifier for the parent span within the trace. | |
Operational details | ||
duration | Time taken for the operation, typically in microseconds or milliseconds. | |
kind | Type of span. For example, server , internal . | |
name | Name of the span, often a high-level title for the operation. | |
Scope and instrumentation | ||
scope.name | Instrumentation scope, typically the Java package or app component. For example, com.example.DiceRollerApp . | |
Service attributes | ||
service.name | Name of the service generating the trace. For example, axiom-java-otel . | |
service.version | Version of the service generating the trace. For example, 0.1.0 . | |
Telemetry SDK attributes | ||
telemetry.sdk.language | Programming language of the SDK used for telemetry, typically java . | |
telemetry.sdk.name | Name of the telemetry SDK. For example, opentelemetry . | |
telemetry.sdk.version | Version of the telemetry SDK used in the tracing setup. For example, 1.18.0 . |
io.opentelemetry:opentelemetry-api
This package provides the core OpenTelemetry API for Java. It defines the interfaces and classes that developers use to instrument their apps manually. This includes the Tracer
, Span
, and Context
classes, which are fundamental to creating and managing traces in your app. The API is designed to be stable and consistent, allowing developers to instrument their code without tying it to a specific implementation.
io.opentelemetry:opentelemetry-sdk
The opentelemetry-sdk package is the reference implementation of the OpenTelemetry API for Java. It provides the actual capability behind the API interfaces, including span creation, context propagation, and resource management. This SDK is highly configurable and extensible, allowing developers to customize how telemetry data is collected, processed, and exported. It’s the core component that brings OpenTelemetry to life in a Java app.
io.opentelemetry:opentelemetry-exporter-otlp
This package provides an exporter that sends telemetry data using the OpenTelemetry Protocol (OTLP). OTLP is the standard protocol for transmitting telemetry data in the OpenTelemetry ecosystem. This exporter allows Java applications to send their collected traces, metrics, and logs to any backend that supports OTLP, such as Axiom. The use of OTLP ensures broad compatibility and a standardized way of transmitting telemetry data across different systems and platforms.
io.opentelemetry:opentelemetry-sdk-extension-autoconfigure
This extension package provides auto-configuration capabilities for the OpenTelemetry SDK. It allows developers to configure the SDK using environment variables or system properties, making it easier to set up and deploy OpenTelemetry-instrumented applications in different environments. This is particularly useful for containerized applications or those running in cloud environments where configuration through environment variables is common.
io.opentelemetry:opentelemetry-sdk-trace
This package is part of the OpenTelemetry SDK and focuses specifically on tracing capability. It includes important classes like SdkTracerProvider
and BatchSpanProcessor
. The SdkTracerProvider
is responsible for creating and managing tracers, while the BatchSpanProcessor
efficiently processes and exports spans in batches, similar to its Node.js counterpart. This batching mechanism helps optimize the performance of trace data export in OpenTelemetry-instrumented Java applications.
io.opentelemetry:opentelemetry-sdk-common
This package provides common capability used across different parts of the OpenTelemetry SDK. It includes utilities for working with attributes, resources, and other shared concepts in OpenTelemetry. This package helps ensure consistency across the SDK and simplifies the implementation of cross-cutting concerns in telemetry data collection and processing.