Java
StackState v6.0
Last updated
StackState v6.0
Last updated
The Java SDK supports instrumenting applications on the JVM. As a result it not only supports Java but also other JVM languages like Kotlin and Scala.
Automatic instrumentation for Java uses a Java agent JAR that can be attached to any Java 8+ application. It dynamically injects bytecode to capture telemetry from many , including several Kotlin and Scala libraries. It can be used to capture telemetry data at the โedgesโ of an app or service, such as inbound requests, outbound HTTP calls, database calls, and so on.
Automatic instrumentation does not require any modifications of the application. To set it up follow these steps:
Download from of the opentelemetry-java-instrumentation repository and include the JAR file in the docker image of your application. The JAR file contains the agent and instrumentation libraries.
Update the command that starts your application to load the Java agent, either by updating the docker image entry point or command or by updating the command
in the Kubernetes manifest for your application. Add -javaagent:/path/to/opentelemetry-javaagent.jar
:
Deploy your application with the extra environment variables .
StackState is receiving traces and/or metrics
For more details please refer to the .
Manual instrumentation can be used when you need metrics, traces or logs from parts of the code that are not supported by the auto instrumentation. For example unsupported libraries, in-house code or business-level metrics.
To capture that data you need to modify your application.
Include the Open Telemetry SDK as a dependency
Add code to your application to capture metrics, spans or logs where needed
There is detailed documentation for this on the .
Make sure you use the OTLP exporter (this is the default) and . When deploying the application the service name and exporter are .
For some Java metrics, for example, garbage collector metrics, StackState has defined charts on the related components. For Kubernetes, the charts are available on the pods. It is possible to , this works for metrics from automatic instrumentation but also for application-specific metrics from manual instrumentation.