Distributed Tracing ?
Distributed tracing is a technique used to monitor and debug microservices by tracking requests as they propagate across different services in a distributed system. It provides visibility into the entire lifecycle of a request, including its entry, processing, and exit from various microservices. This helps identify bottlenecks, latency issues, and failures within the system.
In a Spring Boot microservice architecture, distributed tracing is achieved by instrumenting the application to generate trace data, such as trace IDs, span IDs, and timing information, for each request. These traces are then sent to a centralized tracing system for analysis.
How Zipkin Achieves Distributed Tracing?
Zipkin is a popular open-source distributed tracing system that helps monitor and visualize the flow of requests across microservices.
Here's how it works:
- Instrumentation: Each Spring Boot microservice is configured with tracing libraries (e.g., Spring Cloud Sleuth, Spring Cloud Micrometer) that generate Trace and span IDs for incoming and outgoing requests.
- Trace Context Propagation: Trace IDs and Span IDs are passed between services through headers in HTTP or messaging protocols. This ensures that all parts of a single request are linked together in the same trace.
- Data Collection: Each service collects trace data (such as service name, span start/end times, and annotations) and sends it to a Zipkin server.
- Storage and Visualization: The Zipkin Server aggregates trace data, stores it in a backend database, and provides a web UI to visualize the hierarchical flow of requests. Users can view trace timelines, dependency graphs, and latency details for each span.
By using Zipkin, developers can easily identify performance issues, understand service dependencies, and improve the overall reliability of their Spring Boot microservices.
Zipkin Server by default runs on this URL (http://localhost:9411/zipkin/).
Development Steps:
- Install Docker on PC: We can get Zipkin Server in a few ways. For example, Download the Zipkin Server jar file from the official website or Use the Docker command to pull and run the Zipkin Server. We will pull the Zipkin Server from Docker and run it using a single command.
- Install Docker: Require to install Docker on PC.
- Pull & Run Zipkin Server from Docker: Use the Docker command to pull and run the Zipkin Server in CMD or Terminal of IntelliJ Idea IDE.
- Open Zipkin UI in Browser: After successfully run the Zipkin Server, Open the Zipkin UI in the browser. (URL - http://localhost:9411/zipkin/).
- Mapped Zipkin Server with Microservices: Add Required Dependency and Configuration (application.properties) from API-Gateway to all microservices except Config-Server and Service-Registry.
- Trace the Request: Request an API from the Client (Postman) and test in Zipkin UI (URL: http://localhost:9411/zipkin/)
0 Comments