Distributed Tracing Using Spring Sleuth

Ankit Verma
Latest posts by Ankit Verma (see all)

Microservices and distributed systems are closely linked. But to make sure you can properly trace your services, it’s key to architect your solution properly.

In this article, we will examine some best practices to follow while logging micro services and the architecture to handle distributed logging in the micro services world. As we all, know micro services run on multiple hosts. To fulfill a single business requirement, we might need to talk to multiple services running on different machines. So, the log messages generated by micro services are distributed across multiple hosts.

An Example
Flow diagrams for micro services

As we see in these we have multiple instances of gateway, services and data access layers. Consider an example if client request a service and it goes via gateway then service layer , an exception occurs at service layer and we have hundreds of pods or instances are running will we go at every instance and check what had actually happened so we need a better solution for that.

See also  Load Balancing Microservices using Zuul and Consul

So as a solution we need a following prerequisites

  • Eclipse
  • Maven
  • Java 8

Ref : https://www.elastic.co/downloads/elasticsearch

Now we have created two layers

  1. Gateway Layer
  2. Service Layer

Now as you can see that we are calling gateway layer from service layer

service layer
gateway layer

If we see a gateway layer and service layer we can see that trace Id which is same across the layers. Now using these traces we can trace the entire service request.

Ref: https://bitbucket.org/dashboard/overviewh

Next we will see how we can use ELK stack for distributed logging.