Java Setup
Setup OpenTelemetry on a Java setup, with special instructions for SpringBoot.
Java Agent
Most Java applications can be auto-instrumented using the OpenTelemetry Java agent. If you’re using SpringBoot, the autoinstrumentation may look slightly different (see below).
Configurations may be provided via Java Properties (the -D
flags on the JVM) or via a properties/yml configuration file.
The following example will demonstrate using the properties configuration approach as the baseline configuration.
Then setting an ENV variable to that file will enable the javaagent to reference the configuration settings appropriately.
How it works
The javaagent is built on top of opentelemetry-java
and provides a Java agent JAR that can be attached to any
Java 8+ application and dynamically injects bytecode to capture telemetry from a number of popular libraries and frameworks.
Out of the box, the Java Agent Instrumentation automatically handles most things. There are a few things we have learned that require additional instrumentations in order to correctly handle complex scenarios such as microservices calling other microservices via http clients. For those cases, you need to add additional dependencies appropriate for the requested capabilities and register it.
For example, if using Jetty and Java HttpClient, you need to add the following in order to correctly enable the jetty platform to handle traceIds from the PlayerZero Web SDK as well as propagating that trace id to subsequent microservice calls to other instrumented systems within your stack. :
You can find the right .jar
files
Running with the javaagent
Run the Java Application with a JVM parameter:
Java with SpringBoot
When working with spring boot, you need to add settings to the application.properties
the same way as the otel.properties
from the Java Agent approach plus a few other changes.
The auto instrumentation is a little more limited in the case of Spring Boot seeming to auto instrument only the webmvc and logging layers.
In order to instrument the JDBC, Mongo, or anything else, additional dependencies and some manual Configuration adjustments are required.
Core Instrumentation
Add the following dependencies to the maven pom.xml
.
JDBC Instrumentation
In order to instrument the JDBC calls, you must add additional dependencies and make configuration code adjustments.
Add the following to the pom.xml
file:
And then add or create a Configuration component similar to:
Mongo Instrumentation
In order to instrument the Mongo Client, you must add additional dependencies and make configuration code adjustments. Add the following to the pom.xml
file
And then add or create a Configuration component similar to:
Was this page helpful?