Tracing a flow can be easier than we think (Image Courtesy Freepik)

Configuring tracing with Zipkin , Spring Boot, Sleuth and Gradle

When there are a series of calls happening where Service A call Service B and Service B calls Service C it would help to profile how much of time is being spent in each of these services.

This analysis helps to identify bottlenecks in a microservice application.

Spring has made it easy to achieve this with minimal configuration. This involves 2 parts

  1. Installing the zipkin server which collects and displays traces and spans across microservices in a nice GUI
  2. Adding dependencies into your Spring application so that specific tracing implementations are available.

Trust me , No Code changes required. It is that simple

Lets see each step individually

Step 1 : Download and Run Zipkin sever

Download the zipkin server with the below command on your terminal. This would download the zipkin.jar into the folder from where the command was run.

curl -sSL https://zipkin.io/quickstart.sh | bash -s io.zipkin:zipkin-server:LATEST:slim zipkin.jar

Once downloaded you can run the server using the below command from the folder where you downloaded the zipkin.jar. It should not take more than a minute to start.

java -jar zipkin.jar

You can verify that zipkin sever is running by visiting the following site

http://127.0.0.1:9411/zipkin/

Step 2: Configuring your Spring application with Spring Cloud Sleuth

There is plenty of content available on the internet on what “Sleuth” is hence I do not wish to cover it here. But for those who choose to remain on this site

Spring Cloud Sleuth allows you to aggregate and track log entries as requests move through a distributed software system. It is used to generate and attach the trace id, span id to the logs so that these can then be used by tools like Zipkin and ELK

Add the below dependencies into your build.gradle. Save and build.

https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies
runtimeOnly(group: 'org.springframework.cloud', name: 'spring-cloud-dependencies', version: '2020.0.4', ext: 'pom')
implementation(group: 'org.springframework.cloud', name: 'spring-cloud-starter-sleuth', version: '3.0.2')
implementation(group: 'org.springframework.cloud', name: 'spring-cloud-sleuth-zipkin', version: '3.0.2')

That is all required to start tracing.

Step 3: Send out a HTTP request to your service

Using Postman or similar tools send out a HTTP request to your service. Now open the zipkin sever running on your machine and click on “Run Query”

http://127.0.0.1:9411/zipkin

You should now be seeing traces of the last HTTP request that you sent.

--

--

--

Tech Enthusiast | Programmer | Architect | Likes to Travel | Interests in Technology, History, Languages, Science

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to become a web developer — 4 possible paths

Nightly and serverless builds in MS Appcenter for React Native — Async Mobile DevOps Example

Converting JSON to CSV and back again using Python

Properties of base fields cannot be altered in this manner!

📸 Taking a picture and selecting from gallery in Flutter

How to Create AWS VPC in 10 steps, less than 5 min

Autoscale on AWS with EC2, Python, Flask, and Nginx Part3

CSS Crash Course for Beginners -5

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Basavaraj V

Basavaraj V

Tech Enthusiast | Programmer | Architect | Likes to Travel | Interests in Technology, History, Languages, Science

More from Medium

Spring Events at VISO

Writing a Logging Aspect with Spring AOP

Chain of Responsibility Pattern(Behavioral Design Pattern)

Retry pattern with resilience4j and Spring boot