Spring Cloud - Tracing Services with Zipkin
Last Updated :
10 Oct, 2025
In a Spring Boot application, Spring Cloud provides distributed tracing capabilities through its integration with Zipkin, an open-source distributed tracing system. Using Zipkin, developers can trace and visualize requests across multiple microservices to identify performance issues or bottlenecks.
Key Terminologies
- Trace: Represents the entire journey of a request as it travels through multiple services. It contains multiple spans.
- Trace ID: A unique identifier assigned to each trace.
- Span: Represents a single unit of work or operation within a trace. Each span contains details such as request metadata, start and end time, and downstream calls.
- Span ID: Unique identifier for each span. All spans within the same trace share the same Trace ID.
- Parent Span ID: Identifies the parent span to establish a hierarchy among spans.
- Trace Context: Propagates trace-related information (Trace ID, Span ID, Parent Span ID) across services.
- Sampler: Determines which requests are traced, helping control the tracing volume.
- Reporter: Sends collected span data to the Zipkin backend for storage and analysis.
- Zipkin UI Dashboard: A web-based dashboard used to visualize traces, analyze performance, and troubleshoot distributed systems.
Step-by-Step Implementation
Let’s implement a simple Employee Data Service integrated with Zipkin for distributed tracing.
Step 1: Create the Spring Boot Project
Use IntelliJ IDEA or Spring Initializr to create a new Spring Boot project with the following dependencies:
- Spring Web
- Spring Data MongoDB
- Spring Boot DevTools
- Spring Boot Actuator
- Zipkin
Add the following additional dependencies manually to the pom.xml file for Zipkin integration:
XML
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-server</artifactId>
<version>2.12.9</version>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-ui</artifactId>
<version>2.12.9</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-brave</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter-brave</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
<version>2.2.8.RELEASE</version>
</dependency>
Open src/main/resources/application.properties and add the following configurations:
spring.data.mongodb.uri=mongodb://localhost:27017/Registration
# Zipkin Configuration
spring.zipkin.base-url=http://localhost:9411
spring.sleuth.sampler.probability=1.0
- spring.zipkin.base-url: Points to the Zipkin server.
- spring.sleuth.sampler.probability: Defines the percentage of requests to be traced (1.0 = 100%).
Step 3: Run the Zipkin Server
Download the Zipkin JAR from the official Zipkin GitHub releases.
Run the following command in your terminal:
java -jar zipkin-server-3.0.6-exec.jar
The Zipkin server runs by default on port 9411.
Verify by visiting http://localhost:9411, this opens the Zipkin Dashboard.

Step 4: Create the Employee Entity
Java
package com.example.zipkindemoproject;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
@Document
public class Employee {
@Id
private String id;
private String fullName;
private String department;
private String role;
private String experience;
// Getters and Setters
public String getId() { return id; }
public void setId(String id) { this.id = id; }
public String getFullName() { return fullName; }
public void setFullName(String fullName) { this.fullName = fullName; }
public String getDepartment() { return department; }
public void setDepartment(String department) { this.department = department; }
public String getRole() { return role; }
public void setRole(String role) { this.role = role; }
public String getExperience() { return experience; }
public void setExperience(String experience) { this.experience = experience; }
}
Step 5: Create the Repository
Java
package com.example.zipkindemoproject;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface EmployeeRepo extends MongoRepository<Employee, String> {
}
Step 6: Create the Service Layer
Java
package com.example.zipkindemoproject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class EmployeeService {
@Autowired
private EmployeeRepo repository;
public List<Employee> getAllEmployees() {
return repository.findAll();
}
public Employee saveEmployee(Employee employee) {
return repository.save(employee);
}
}
Step 7: Create the Controller
Java
package com.example.zipkindemoproject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/employees")
public class EmployeeController {
@Autowired
private EmployeeService service;
@GetMapping
public List<Employee> getAllEmployees() {
return service.getAllEmployees();
}
@PostMapping("/create")
public Employee createEmployee(@RequestBody Employee employee) {
return service.saveEmployee(employee);
}
}
Step 8: Create the Main Class
Java
package com.example.zipkindemoproject;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import zipkin2.server.internal.EnableZipkinServer;
@SpringBootApplication
@EnableZipkinServer
public class ZipkinDemoProjectApplication {
public static void main(String[] args) {
SpringApplication.run(ZipkinDemoProjectApplication.class, args);
}
}
Step 9: Run the Application
Run the application as a Spring Boot App. The application starts on port 8080 and the Zipkin server runs on port 9411.

Step 10: Test the APIs
Use Postman to test the API endpoints:
POST Request:
http://localhost:8080/employees/create
GET Request:
http://localhost:8080/employees

Step 11: Check Zipkin Dashboard
After executing the requests, open http://localhost:9411 to view the traces in the Zipkin Dashboard. You’ll see details such as:

Zipkin can trace all the information of the requests and generates the service name, span name and span ID and parent ID and all the details of the request.

Explore
Java Enterprise Edition
Multithreading
Concurrency
JDBC (Java Database Connectivity)
Java Frameworks
JUnit