Java Auto-instrumentation
The Java auto-instrumentation provides comprehensive telemetry collection for Java applications using the OpenTelemetry Java agent. This instrumentation automatically captures traces, metrics, and logs from Java applications and popular frameworks without requiring code modifications.
TOC
How Java Auto-instrumentation WorksEnabling Java InstrumentationJava Agent Environment VariablesInstrumentation ControlSpecific Instrumentation ControlExtension ConfigurationAdvanced ConfigurationCustom Agent ImageVolume MountsContainer-specific InjectionSupported Java VersionsTroubleshootingVerifying Agent InjectionEnabling Debug LoggingCommon IssuesExample ConfigurationConfiguration ReferenceHow Java Auto-instrumentation Works
The Operator injects the OpenTelemetry Java agent into Java application containers as a Java agent JAR file. The agent uses bytecode instrumentation to automatically instrument Java classes at runtime, capturing telemetry data from:
- HTTP servers and clients (Servlet, Spring MVC, JAX-RS, etc.)
- Database clients (JDBC, Hibernate, etc.)
- Messaging systems (JMS, Kafka, RabbitMQ, etc.)
- RPC frameworks (gRPC, etc.)
- Caching libraries (Redis, Memcached, etc.)
- And many other popular Java libraries and frameworks
Enabling Java Instrumentation
To enable auto-instrumentation for Java applications, annotate your pod or namespace:
The Operator automatically injects the Java agent and configures the JVM to load it at startup by setting the JAVA_TOOL_OPTIONS environment variable with the -javaagent flag.
Java Agent Environment Variables
The following environment variables control Java agent behavior:
Instrumentation Control
OTEL_JAVAAGENT_ENABLED- Enable or disable the Java agent (default:true)OTEL_JAVAAGENT_DEBUG- Enable debug logging for the agent (default:false)OTEL_INSTRUMENTATION_COMMON_DEFAULT_ENABLED- Enable all instrumentations by default (default:true)
Specific Instrumentation Control
You can enable or disable specific instrumentations:
OTEL_INSTRUMENTATION_JDBC_ENABLED- JDBC instrumentationOTEL_INSTRUMENTATION_SPRING_WEB_ENABLED- Spring Web instrumentationOTEL_INSTRUMENTATION_KAFKA_ENABLED- Kafka instrumentationOTEL_INSTRUMENTATION_REDIS_ENABLED- Redis instrumentation
Example configuration:
Extension Configuration
Configure additional agent extensions:
OTEL_JAVAAGENT_EXTENSIONS- Path to additional agent extensionsOTEL_JAVAAGENT_CONFIGURATION_FILE- Path to agent configuration file
Advanced Configuration
Custom Agent Image
You can specify a custom Java agent image:
Volume Mounts
The agent is mounted into the application container at /otel-auto-instrumentation-java-<container-name>/.
Container-specific Injection
For multi-container pods, specify which containers should be instrumented:
Supported Java Versions
The OpenTelemetry Java agent supports:
- Java 8 and later
Troubleshooting
Verifying Agent Injection
Check that the agent was injected successfully:
Look for the -javaagent argument in the container command.
Enabling Debug Logging
Enable debug logging to troubleshoot issues:
Common Issues
Agent not loading: Verify that the init container completed successfully and the agent JAR is present in the shared volume.
Missing traces: Check that the exporter endpoint is correct and accessible from the application pod.
High memory usage: Reduce the number of enabled instrumentations or adjust JVM heap settings.
Example Configuration
Complete example for Java application instrumentation:
Configuration Reference
For detailed configuration options, supported libraries, and advanced usage scenarios, refer to the official OpenTelemetry Operator documentation: