Getting Started with OpenTelemetry Java
Snippets that will guide you through instrumenting Java applications with OpenTelemetry Java SDK. You'll learn how to implement both manual and automatic instrumentation to emit traces, metrics, and logs to console/OTLP backends.
OpenTelemetry Java in a nutshell
- opentelemetry-java main repository which implements and delivers the core packages:
- io.opentelemetry:opentelemetry-api - Core API for creating telemetry data
- io.opentelemetry:opentelemetry-sdk - Default SDK implementation
- io.opentelemetry:opentelemetry-semconv - Standard attribute keys and values
- io.opentelemetry:opentelemetry-exporter-otlp - OTLP protocol exporters
- opentelemetry-java-instrumentation Java agent for automatic instrumentation:
- opentelemetry-javaagent - Java agent for zero-code instrumentation
- library instrumentations - Manual instrumentation for popular Java libraries
Prerequisites
Before starting with this tutorial, ensure you have the following tools installed on your system:
- Java - Java Development Kit (JDK 17 or later)
-
Install via package manager:
brew install openjdk
(macOS) orapt install openjdk-17-jdk
(Ubuntu) -
Gradle - Build automation tool (optional, as projects include Gradle wrapper)
- Download from gradle.org
-
Or install via package manager:
brew install gradle
(macOS) -
Docker - For running OpenTelemetry Collector and observability backends
- Download from docker.com
List of snippets
Following is a list of all available OpenTelemetry Java snippets:
basics
Congratulations! You now have a solid foundation for instrumenting Java applications with OpenTelemetry. Start with the simple examples and gradually add more sophisticated instrumentation as your observability needs grow.