Auto Instrumenting Java Apps with OpenTelemetry
This guide shows you how to auto instrument your Java application using the OpenTelemetry Java agent and send data to our service.
Prerequisites
- A VMware Aria Operations for Applications (formerly known as Tanzu Observability by Wavefront) account to visualize and monitor your application health. If you don’t have one already, you can sign up on our website.
- Java 11 or later.
- Maven
Install the Wavefront Proxy
Note: When running the Wavefront proxy:
- Make sure that the
WAVEFRONT_PROXY_ARGS
environment variable contains--otlpGrpcListenerPorts 4317
. - and expose the OpenTelemetry port via
-p 4317:4317
.
Run the Auto-Instrumented Application
For instrumentation, you use the Java agent provided by OpenTelemetry, which can be attached to any Java application. This agent dynamically injects bytecode to collect telemetry data, and developers can avoid manual instrumentation.
- Clone the Spring Petclinic application and navigate to the directory.
git clone https://github.com/spring-projects/spring-petclinic.git cd spring-petclinic
- Run
./mvnw package
from the root directory of the project. - Download the OpenTelemetry Java agent.
curl -L https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar --output otelagent.jar
- Assign the file path to the
JAVA_AGENT
variable.JAVA_AGENT=./otelagent.jar
- Attach the Java agent and start the Spring Petclinic application.
java -javaagent:$JAVA_AGENT -Dotel.service.name=petclinic -Dotel.resource.attributes=application=demo-petclinic -Dotel.exporter.otlp.metrics.temporality.preference=DELTA -Dotel.exporter.otlp.metrics.default.histogram.aggregation=BASE2_EXPONENTIAL_BUCKET_HISTOGRAM -jar target/*.jar
- Navigate to http://localhost:8080 and interact with the Petclinic application to generate telemetry data.
View the Metrics and Distributed Traces
You can see the traces on the Traces Browser and the Application Map, and metrics on charts.
View Traces
- Traces Browser: On the toolbar, click Applications > Traces. You see the traces sent by the Petclinic application. Example:
- Application Map: On the toolbar, click Applications > Application Status. You see the Petclinic application and the services it communicates with when sending data to our service. Example:
Create Charts with Metrics
When the metrics data collected from the Wavefront proxy are sent to our service, you can examine them in our user interface.
Example:
The query ts(jvm.threads.live)
shows the total number of live threads in the Petclinic application.
Learn More!
To manually configure your application and send data to our service, see Instrumenting Java Apps with OpenTelemetry.