Menu
Open source
Automatic Instrumentation of Java applications with the OpenTelemetry Java Agent
Java applications can be instrumented without changing the source code1.
- Supports Java 8+
- Supports a large number libraries, frameworks and application servers
- Project Website
- If you are using Spring Boot 3.x, we recommend to use the Grafana OpenTelemetry Starter.
Getting Started
Note: If you use Grafana Cloud, follow the OpenTelemetry Integration, which creates a Grafana Agent configuration for you.
Download opentelemetry-javaagent.jar
from the Github releases.
shell
curl -OL https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.27.0/opentelemetry-javaagent.jar
Enable the instrumentation agent using the -javaagent
flag to the JVM.
shell
java -javaagent:path/to/opentelemetry-javaagent.jar \
-Dotel.logs.exporter=otlp \
-Dotel.semconv-stability.opt-in=http \
-Dotel.instrumentation.micrometer.base-time-unit=s \
-Dotel.instrumentation.log4j-appender.experimental-log-attributes=true \
-Dotel.instrumentation.logback-appender.experimental-log-attributes=true \
-Dotel.exporter.otlp.endpoint=http://localhost:4317 \
-Dotel.exporter.otlp.protocol=grpc \
-Dotel.service.name=shopping-cart \
-Dotel.resource.attributes=deployment.environment=production,service.namespace=shop,service.version=1.1,service.instance.id=shopping-cart-66b6c48dd5-hprdn \
-jar myapp.jar
The application will send data to the Grafana Agent. Please follow the Grafana Agent configuration for OpenTelemetry guide.
- If the grafana agent is not running locally with the default gRPC endpoint (localhost:4317), then you need to adjust endpoint and protocol.
- Please replace
demo
,1.1
, andshopping-cart-66b6c48dd5-hprdn
as explained here. - Note that service name can also be set in
otel.resource.attributes
using the keyservice_name
(ex.service_name=demo
). - Also note that you can use environment variables instead of system properties for all configuration options.
Grafana Dashboard
You can use this dashboard to get and overview about the most important JVM metrics: CPU, memory, classes, threads, and garbage collection.
The Java agent dynamically injects bytecode to capture telemetry from a number of popular libraries and frameworks. ↩︎