OpenTelemetry Instrumentation Java Auto-Instrumentation for Java with Java Agent
Open source

Automatic Instrumentation of Java applications with the OpenTelemetry Java Agent

Java applications can be instrumented without changing the source code1.

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.

curl -OL

Enable the instrumentation agent using the -javaagent flag to the JVM.

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.resource.attributes=deployment.environment=production,service.namespace=shop,service.version=1.1, \
  -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, and shopping-cart-66b6c48dd5-hprdn as explained here.
  • Note that service name can also be set in otel.resource.attributes using the key service_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.

JVM Dashboard

  1. The Java agent dynamically injects bytecode to capture telemetry from a number of popular libraries and frameworks. ↩︎