otel4s-oteljava modules provide implementation of the otel4s API interfaces using OpenTelemetry Java under the hood.
Why OTel Java?
There are several advantages of using theotel4s-oteljava backend:
- Low memory overhead - Leverages the battle-tested Java SDK implementation
- Extensive instrumentation ecosystem - Access to the rich Java instrumentation libraries
- Easy integration with Java libraries - Seamless interoperability with Java-based systems
- Well-tested implementation - Benefits from the maturity of the upstream project
This is the recommended backend to use on the JVM.
Installation
- Add the
otel4s-oteljavalibrary - Add an OpenTelemetry exporter. Without the exporter, the application will crash
- Add an OpenTelemetry autoconfigure extension
- Enable OpenTelemetry SDK autoconfigure mode
Creating an Autoconfigured Instance
You can useOtelJava.autoConfigured to autoconfigure the SDK:
OtelJava.autoConfigured(...) relies on environment variables and system properties to configure the SDK. For example, use export OTEL_SERVICE_NAME=auth-service to configure the name of the service.
See the full set of supported configuration options.
Accessing the Global Instance
There are several reasons to use the global instance:- You are using the Java Agent
- You must reuse the global instance to interoperate with Java libraries
- You have no control over the entry point
OtelJava.global to use the global OpenTelemetry instance:
API Reference
TheOtelJava class provides access to all telemetry providers:
Factory Methods
| Method | Description |
|---|---|
autoConfigured[F[_]]() | Creates an autoconfigured instance from environment variables |
global[F[_]] | Accesses the global OpenTelemetry instance |
fromJOpenTelemetry[F[_]](JOpenTelemetry) | Creates an instance from a Java OpenTelemetry instance |
noop[F[_]] | Creates a no-op implementation |
Next Steps
Configuration
Learn how to configure the SDK using environment variables
Context Propagation
Understand how context propagation works with Cats Effect
Java Interop
Integrate with Java-instrumented libraries
Java Agent
Use zero-code instrumentation with the Java Agent