How to implement Zipkin in Spring Boot 3

Md Mohosin Miah
2 min readJun 16, 2023

--

Monitor your API endpoints using Zipkin in a Spring Boot 3 application

To implement Zipkin in a Spring Boot application and run it using Docker Compose, follow these steps:

Step 1: Create a docker-compose.yml file with the following contents:

services:
zipkin:
image: ghcr.io/openzipkin/zipkin-slim:${TAG:-latest}
container_name: zipkin
environment:
- STORAGE_TYPE=mem
- MYSQL_HOST=mysql
ports:
- 9411:9411

This file defines a service named “zipkin” that uses the official Zipkin Docker image and exposes port 9411 for the Zipkin UI and HTTP API.

Step 2: Add the necessary dependencies to your project’s pom.xml file:

<dependencies>
<!-- Other dependencies -->

<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-brave</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter-brave</artifactId>
</dependency>
</dependencies>

These dependencies are required for integrating Zipkin with your Spring Boot application.

Step 3: Configure your application by adding the following properties to the application.properties file:

# Zipkin configuration
spring.zipkin.base-url=http://localhost:9411/
spring.sleuth.sampler.probability=1.0

The spring.zipkin.base-url property specifies the URL where Zipkin is running (in this case, http://localhost:9411/). The spring.sleuth.sampler.probability property sets the sampling probability to 100% to ensure all requests are traced.

Step 4: Run the Zipkin server using Docker docker-compose.yml file is located, and run the following command:

docker-compose up

This will start the Zipkin server in a Docker container.

Once you have implemented and configured Zipkin in your Spring Boot application, you can run it alongside other microservices. Zipkin will collect and display distributed traces, allowing you to analyze the flow of requests across your system.

Happy coding :)

Project URL: https://github.com/MohosinMiah/Employee_Department_Organization_Microservices

GitHub Source Zipkin : https://github.com/openzipkin/zipkin/blob/master/docker/examples/docker-compose-kafka.yml

--

--

Md Mohosin Miah
Md Mohosin Miah

Responses (1)