Skip to main content
Version: 2.0.x

OpenTelemetry Automatic Instrumentation Example

You can find the source code here.

Firstly, we need to start the observability backends (Jaeger and Seq)

Start Jaeger by running the following command:

docker run --rm -it \
-d \
-p 14250:14250 \
-p 16686:16686 \
-p 4317:4317 \

To run Seq, you also need to specify an admin password (user is admin):

PH=$(echo 'admin123' | docker run --rm -i datalust/seq config hash)

docker run \
-d \
--restart unless-stopped \
-p 80:80 \
-p 5341:5341 \

After this, we can kick off our application to generate some metrics.

For this, we have to download OpenTelemetry JVM agent JAR:

OTEL_AGENT_PATH=$(cs fetch --classpath "io.opentelemetry.javaagent:opentelemetry-javaagent:latest.release")

Then start the server application

sbt -J-javaagent:$OTEL_AGENT_PATH \ \
-J-Dotel.traces.sampler=always_on \
-J-Dotel.traces.exporter=otlp \
-J-Dotel.logs.exporter=otlp \
-J-Dotel.exporter.otlp.logs.protocol="http/protobuf" \
-J-Dotel.exporter.otlp.logs.endpoint="http://localhost:5341/ingest/otlp/v1/logs" \
-J-Dotel.metrics.exporter=none \
"opentelemetryInstrumentationExample/runMain zio.telemetry.opentelemetry.instrumentation.example.ServerApp"

and the client application which will send one request to the server application

sbt -J-javaagent:$OTEL_AGENT_PATH \ \
-J-Dotel.traces.sampler=always_on \
-J-Dotel.traces.exporter=otlp \
-J-Dotel.metrics.exporter=none \
"opentelemetryInstrumentationExample/runMain zio.telemetry.opentelemetry.instrumentation.example.ClientApp"

Head over to Jaeger UI and Seq UI to see the result.