Sitemap

Using OpenTelemetry in OpenLiberty

2 min readDec 15, 2022

--

The latest betas of the OpenLiberty server have added support for the MicroProfile Telemetry specification which provides the ability to track the progress of a request through all the parts of your application.

To start we need an application to instrument so the easiest thing to do is to create a starter application using the online tool.

With that downloaded and set-up in an IDE we can start adding the functionality and start seeing what is happening while the service runs.

Turning on the functionality

Unlike the official specification, the microprofile telemetry specification is not enabled for all applications by default, so in the microprofile-config.properties file needs to have

otel.sdk.disabled=false

added. We also need to add

<feature>mpTelemetry-1.0</feature>

to the server.xml file and now otel records are being produced everytime we call the application.

Accessing the records

While having the records being produced is great, without a way to access them they’re not adding any benefit to our application.

Jaeger is an open source product for working with distributed traces which can receive OpenTelemetry records and then display them in a useful way.

Get Andrew Smithson’s stories in your inbox

Join Medium for free to get updates from this writer.

The easiest way to get an instance of Jaeger up and running is to run a container

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:1.40

We then need to configure the Liberty server to send the records to the Jaeger instance. This is done with a couple of environment variables

OTEL_TRACES_EXPORTER=jaeger
OTEL_EXPORTER_JAEGER_ENDPOINT=http://localhost:14250

The first says that we’re exporting to a Jaeger endpoint, the second specifies the endpoint the Jaeger service is listening on (which we specified in the docker command).

Now calling the service results in a record showing up in the UI.

Press enter or click to view image in full size
Jaeger UI showing an OpenTelemetry trace

So while we’re now getting the traces being stored, the service name is a bit uninspired and is likely to cause confusion as we start adding more services and applications into the Jaeger server.

To update the name a new variable can be added to the config properties

otel.service.name=HelloWorld

Now when traces are exported they show up in the UI under the name we have chosen.

Press enter or click to view image in full size
Jaeger UI for out now named service traces

With this all in place we can now add extra instrumentation through attributes, events and child spans to the code and see what is happening in our application and all the services it consumes.

--

--

Andrew Smithson
Andrew Smithson

Written by Andrew Smithson

Software Engineer, Gamer, Musician and everything in between. All opinions are my own.