OpenTracing with Jaeger (Auto Instrumentation)

Sibendra Singh
3 min readJun 4, 2022

Objective

In distributed environment tracing helps teams understand more quickly how each micro-service is performing and in case of failures find out the exact point and cause of failure.

OpenTracing

OpenTracing provides the specification which different tools adopt, Jaeger is one of the tool on which we will be focusing. It offers a way for developers to follow the thread to trace requests from start to end across several applications and understand distributed systems at scale.

Implementations of OpenTracing are Jaeger, LightStep, Instana, Apache SkyWalking etc.

Common terminology of OpenTracing

Span: Primary building block of a distributed trace, representing an individual unit of work done in a distributed system. A span consists of several parameters like span-id, trace-id(explained below), name, duration of execution, start timestamp, finish timestamp, tags (key-value pair), logs (text) etc.

Trace: A trace represents the life of a request across different distributed systems. It can be visualised as a combinations of several spans coming together under one parent span. All the spans in a trace share same trace-id.

SpanContext: This acts as a carrier of tracing data across application boundaries. This helps to bind together spans across several application using under parent span.

Below screenshot is a visual representation trace and span.

Jaeger

Jaeger is one of the OpenTracing implementation supported and hosted by CNCF. It is an end to end tracing tool which the collects the traces across several application and present them on Jaeger UI with Pictorial representation and lot of details w.r.t performance.

Components of Jaeger

There are below individual of Jaeger tool:

  1. jaeger-agent — Traces are reported from application to agent nodes on using http or udp protocol
  2. jaeger-query — This is the frontend querying application.
  3. jaeger-collector — Logs are reported to collector system from agents.

Each of the above components can be installed separately using their respective docker image.

There is also an all-in-one jaeger docker image is available which consists of all the above mentioned components.

Install Jaeger Tool

jaegertracing/all-in-one docker image will be used to run the tool as a docker container. Official documentation Jaeger Tool

docker run -d — name jaeger
-p 5775:5775/udp
-p 6831:6831/udp
-p 6832:6832/udp
-p 5778:5778
-p 16686:16686
-p 14250:14250
-p 14268:14268
-p 14269:14269
-p 9411:9411
jaegertracing/all-in-one:1.32

Here we are interested in below ports:

6831 = UDP Sender Port (Span will be reported on this port to jaeger-agent. UDP protocol is most performance efficient. It is considered almost consistent in terms of span reporting.)

5778 = Http Sender Port (This is an alternative of UDP protocol. It is not as efficient as UDP in terms of performance but it is considered always consistent in terms of span reporting.)

16686 =Jaeger Frontend Port (We can access the Jaeger frontend where can see the traces along with many other performance relateds statistics)

Once the container started successfully, Below UI application should be available at http://localhost:16686/

Instrumentation of spring-boot with jaeger

Here we have three spring-boot applications:

  1. Order Service
  2. Customer Service
  3. Inventory Service

Add below dependency in pom.xml:

<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-spring-jaeger-cloud-starter</artifactId>
<version>3.2.0</version>
</dependency>

Add below configuration:

opentracing:
jaeger:
service-name: Service_name
enabled: true

Once all the three services are instrumented, if we try to access url http://localhost:8081/customer should be able to see the tracing dashboard as below:

Upcoming articles in tracing areas are: Custom Span Tracing, Tracing following opentelemetry conventions.

Please find the source code of this article in github.

--

--