IntelliJ + Open Telemetry + Jaeger



How to run your application from IntelliJ with the 🔭 Open Telemetry Java agent and a local Jaeger instance.

📝 Quick Summary

  1. 📥 Download the latest Open Telemetry Java agent to your home directory.
  2. 🛠️ Add IntelliJ VM argument -javaagent:${HOME}/opentelemetry-javaagent.jar
  3. 🛠️ Add IntelliJ environment variable: OTEL_SERVICE_NAME=your-service-name
  4. 🐳 Start the Jaeger all-in-one Docker image.
  5. 💻 Open http://localhost:16686 to see the Jaeger UI.

☕ Deep Dive: IntelliJ Java Agent Configuration

First of all, we must download the 🔭 Open Telemetry Java agent.

As described on https://github.com/open-telemetry/opentelemetry-java-instrumentation#getting-started this link will always give you the latest opentelemetry-javaagent.jar: https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar

I propose that you place it in your 🏠 home directory (aka ~). You can of course place it elsewhere.

Next, we must edit the run configuration for the application in IntelliJ. There are two changes to be made:

  1. 🛠️ Add VM argument -javaagent:${HOME}/opentelemetry-javaagent.jar
  2. 🛠️ Add environment variable: OTEL_SERVICE_NAME=your-service-name

📸 See this example screenshot for an application called "foo":

IntelliJ Run Configuration

👀 You can verify that the agent was successfully added by looking for a line like this one in the console when you start your application:

[otel.javaagent 2023-07-03 14:10:04:421 +0200] [main] INFO io.opentelemetry.javaagent.tooling.VersionLogger - opentelemetry-javaagent - version: 1.27.0

🐳 Deep Dive: Jaeger

🐳 Just start the all-in-one Docker image:

docker run -d --name jaeger \
  -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \
  -e COLLECTOR_OTLP_ENABLED=true \
  -p 6831:6831/udp \
  -p 6832:6832/udp \
  -p 5778:5778 \
  -p 16686:16686 \
  -p 4317:4317 \
  -p 4318:4318 \
  -p 14250:14250 \
  -p 14268:14268 \
  -p 14269:14269 \
  -p 9411:9411 \
  jaegertracing/all-in-one:latest

That docker command is taken from: https://www.jaegertracing.io/docs/1.46/getting-started/#all-in-one

It will run in the background without occupying a terminal window. To stop it you can use docker stop jaeger.

🛠️ Deep Dive: Configuration

The configuration options for the Java agent can be found here: https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk-extensions/autoconfigure/README.md#otlp-exporter-both-span-and-metric-exporters

But honestly OTEL_SERVICE_NAME=your-service-name is all that you need.

The 🔭 Open Telemetry Java agent will by default export to the default port on localhost, and Jaeger provides that.

📸 Jaeger Tracing Example Image

Jaeger UI Example

😊 Oh, would you look at that. It looks awfully sequential. Time to run some requests in parallel!