XenonStack Recommends

Service Design

Distributed Tracing with Jaeger and OpenTracing

Navdeep Singh Gill | 08 February 2022

Distributed Tracing with Jaeger and OpenTracing

What is Jaeger and OpenTracing?

Jaeger and OpenTracing is a way to do profiling and tracing in a distributed way. As it works on the concept of a distributed context propagation, that associates specific metadata for every request which is made by the user, distributed tracing requires instrumentation of application code. With the help of this instrumentation based code, different profiling parameters include so that distributed context propagation can be made possible by various parameters. You can also explore our use case based on  Java Microservices for Scalable Applications. All the parameters need to be defined in the form of an instrumented code so that these help in monitoring of a code. Understanding a distributed tracing model helps to define instrumentation effectively, explained as follows -

A tool that enables end users, administrators and organizations to gauge and evaluate the performance of a given system. Click to explore about, Performance Monitoring Tools and Management

Distributed Tracing Model/Architecture

Different components of distributed tracing -
  • Trace - It mainly contains a description of the transaction as it moves through a distributed system.
  • Span - A operation that represents a piece of the workflow.Spans key: value tags as well as fine-grained.
  • Span-context - It is mainly used to represent a process when moving from one service to another service over a network. Span-context mainly contains trace identifier, tree identifier, and any other data which is specified to identify a service.

How Tracing Works?

  • Firstly, there is a requirement to do tracing for instrumentation of endpoints.
  • Write code to Go Lang endpoint using some libraries explained below.
  • Do get the specific libraries required for operating refer to the tool section, mentioned below.
  • Then hit endpoint in a browser.
  • The results for an endpoint in the form of tracing obtained from a Jaeger dashboard.
  • Jaeger UI dashboard gives a result in the form of a tracing format.
  • Here from this dashboard, various things analyzed like checking HTTP Request Latency.
Performance Tracing is important to check how all cores of the processor are used to execute a function. Click to explore about, Performance Tracing Tools

What are the best practises of Jaeger and OpenTracing?

  • Log-structured Data
  • Logging Events
  • Trace Client Calls
  • Distributed Context Propagation
  • Trace function
  • Trace Server Endpoints
  • Active Span Management
  • Out -of -Band Trace Data Encoding
  • In-Band Context Encoding
  • Distributed Tracing
  • Instrumentation
  • Cross Process Propagation
  • Sampling

What are the benefits of adapting Distributed Tracing?

  • To check the performance of an application that how much time it takes during page loading.
  • To check the availability of specific endpoint of application whether that endpoint is available or not while making request hit from the client side.
  • To track the resources used.
  • To track the workload for a specific endpoint.
  • To track the HTTP Latency of request.
  • To track how much time is taken to access the database resources.


A way to get insights into the whole infrastructure. It is essential for the operations team. Click to explore about, Observability Best Practices and its Benefits

Why Jaeger and OpenTracing Matters?

To make the tracing possible in a distributed way it is necessary to make instrumentation for the code. To instrument a code there is a library available which is helpful to make tracing possible for the code. Mainly this library useful in providing the following features -

  • It helps in instrumentation of code to make tracing possible.
  • Helps in defining span tags for each endpoint.
  • Help in the execution of instrumentation of every component in an isolated way.
  • Setting span tags in application to do the tracing of the application by a span in a Jaeger UI Dashboard.
  • To get the code for instrumentation in a practical way, there is a need to work on the following content.
  • Standardized Span management.
  • Standardized Inter-process propagation.
  • Standardized Active Span Management.
  • Standardized in-band context encoding.
  • Standardized out-of-band trace data encoding.

If things mentioned above handled expertly in code, then it will also help to do the tracing of code effectively.

How to adopt Jaeger and OpenTracing?

Different commands needed to get the result explained as follows along with the process -
  • Firstly, write a Golang code along with tracing parameters are defined for this. Code instrumented for tracing can be obtained from a git link.
  • Then after writing code, there is a need to run a code, the code will start executing at a specific port.
  • There will also a message at the top after command execution as "Initializing logging reporter" means tracing for this enabled at a defined Jaeger's defined port. Tracing result obtained from a Jaeger dashboard.
  • Then after this, the next step is to do tracing using a Jaeger UI dashboard.
  • Get the tracing dashboard, enter a specific endpoint at which Jaeger dashboard is running.

Jaeger dashboard access

  • This dashboard helps in tracing of a specific application.
  • It also provides a feature to make tracing possible only for specific endpoints.
  • As from a service drop down, service selected for which tracing required.
  • As from an Operation drop down, service selected for a specific endpoint which is required by a user.
  • In the same way, the number of results which need to be displayed can be limited by selected the amount from a Limit Results field.

Integration of results with a Prometheus Time-Series database

A direct result of the application's metrics integrated into a Prometheus dashboard. Mention the Jaeger based instrumentation result into a node exporter so that Prometheus can read the metrics from this endpoint. How to specify the endpoint in node exporters so that metrics read from an end required endpoint? This endpoint is helpful to get the metrics integration with Prometheus dashboard and to make monitoring possible in a Prometheus Time-Series database.
Observability and Monitoring have become a relevant term, importantly when you’re discussing software development.. Click to explore about, Observability vs Monitoring

What are the key Jaeger and OpenTracing Tools/Libraries?

The key Jaeger and OpenTracing Tools/Libraries are listed below:

Golang Library 

To make tracing possible for different HTTP requests for Go Lang based code. There is a need to use some libraries. The libraries which are used to make tracing possible for code which obtained in a reference written as follows -

"github.com/gin-gonic/gin"
"github.com/opentracing/opentracing-go"
"github.com/uber/jaeger-client-go"
"github.com/uber/jaeger-client-go/config"

Browser

Is there any requirement of a browser? Yes, to demonstrate an end to end testing there is a need to run a mentioned endpoints in a code at the browser. To hit an endpoint from a browser for which tracing or instrumentation defined. Then get the tracing results for the same endpoint in the form of a tracing from a dashboard.

Jaeger

To get results in the form of tracing for endpoints which will be hit by the user in a browser, there is a need of Jaeger dashboard. This will get the results for the endpoints which is hit by the user. But, this dashboard will give the result in the form of spans. So, there is a requirement that there should be different spans for each endpoint while making instrumentation of code.


Conclusion

In a nutshell, Jaeger and OpenTracing are helpful in Tracing of instrumented endpoints in the form of span and span context. It helps to find an issue whether at time of spanning or at time of spanning context. Along with this, it is also helpful to check how much resources each endpoint is taking, but this thing is only possible if instrumentation defined for these endpoints.