0Pricing
Spring Boot 4 Complete Guide · บทเรียน

การติดตามแบบกระจายด้วย Sleuth และ Zipkin

นำการติดตามแบบกระจายมาใช้โดยใช้ Spring Cloud Sleuth และ Zipkin เพื่อให้มองเห็นการโต้ตอบระหว่างไมโครเซอร์วิส

การติดตามแบบกระจายด้วย Sleuth และ Zipkin เป็นบทเรียน Spring Boot 4 Complete Guide ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Spring Boot 4 Complete Guide และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Spring Boot 4 Complete Guide มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Tracing Microservices Flow

In microservices architectures, a single user request might travel through many different services. This makes debugging and understanding performance bottlenecks very challenging.

Distributed tracing helps by tracking the full path of a request as it moves across these services, providing end-to-end visibility.

Spring Cloud Sleuth's Role

Spring Cloud Sleuth is a powerful tool that integrates distributed tracing capabilities into your Spring Boot applications. It automatically instruments your services to generate and propagate tracing information.

Sleuth works by adding unique identifiers to every request, allowing you to follow its journey across different service boundaries.

Core Concepts: Trace & Span

Sleuth relies on two fundamental concepts:

  • Trace: Represents a single, complete request or workflow across all participating services. Think of it as the entire story of a request.
  • Span: A single operation within a trace. Each service call, database query, or method execution can be a span. Spans have parent-child relationships, forming a tree structure for the trace.

Every span has a unique ID, and all spans belonging to the same trace share a common trace ID.

Adding Sleuth Dependency

To enable Sleuth in your Spring Boot application, you simply need to add the spring-cloud-starter-sleuth dependency to your project's pom.xml (for Maven) or build.gradle (for Gradle).

This starter pulls in all necessary components for Sleuth to auto-configure itself.

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>

Basic Sleuth in Action

Once spring-cloud-starter-sleuth is on your classpath, Spring Boot automatically instruments your application. Trace and Span IDs will appear in your logs!

Try running this simple Spring Boot app and observe the console output (though without a full server setup, you won't see actual requests, but the app structure is runnable):

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class MyTracedApplication {

  public static void main(String[] args) {
    SpringApplication.run(MyTracedApplication.class, args);
  }

  @GetMapping("/hello")
  public String hello() {
    // Sleuth would automatically add trace/span IDs to logs here
    System.out.println("Processing /hello request...");
    return "Hello from Traced Service!";
  }
}

Visualize Traces with Zipkin

While Sleuth adds tracing information to your application's logs, visualizing these traces across multiple services can be complex.

This is where Zipkin comes in! Zipkin is a distributed tracing system that collects and visualizes the trace data generated by Sleuth. It provides a user interface to search and analyze traces.

Launching Zipkin Server

To use Zipkin, you first need to run a Zipkin server. The easiest way is often with Docker:

  • docker run -p 9411:9411 openzipkin/zipkin

Once running, you can access the Zipkin UI in your browser at http://localhost:9411. This UI will display all the traces sent by your Sleuth-enabled applications.

Connecting Sleuth to Zipkin

To send trace data from your Sleuth-enabled application to the Zipkin server, you need to add the spring-cloud-starter-zipkin dependency and configure the Zipkin server's URL.

Add this dependency:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>

Configuring Zipkin URL

Then, specify the Zipkin server's base URL in your application.properties:

spring.zipkin.base-url=http://localhost:9411

Now, your Spring Boot app will send its trace information to the running Zipkin server for collection and visualization.

Sleuth & Zipkin Check

Let's check your understanding of Spring Cloud Sleuth and Zipkin.

Lesson Summary

In this lesson, you learned about distributed tracing and how Spring Cloud Sleuth and Zipkin provide powerful tools for observability in microservices.

  • Sleuth instruments your applications, generating unique trace and span IDs.
  • Zipkin collects and visualizes this data, offering a clear view of request flows.

Understanding these tools is crucial for debugging, monitoring, and optimizing complex distributed systems.

คำถามที่พบบ่อย

บทเรียน “การติดตามแบบกระจายด้วย Sleuth และ Zipkin” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การติดตามแบบกระจายด้วย Sleuth และ Zipkin” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Spring Boot 4 Complete Guide ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Spring Boot 4 Complete Guide มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การติดตามแบบกระจายด้วย Sleuth และ Zipkin”

นำการติดตามแบบกระจายมาใช้โดยใช้ Spring Cloud Sleuth และ Zipkin เพื่อให้มองเห็นการโต้ตอบระหว่างไมโครเซอร์วิส คุณปฏิบัติ Spring Boot 4 Complete Guide ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Spring Boot 4 Complete Guide หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Spring Boot 4 Complete Guide บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน

บทเรียน “การติดตามแบบกระจายด้วย Sleuth และ Zipkin” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Spring Boot 4 Complete Guide นี้ได้ไหม

ได้ บทเรียน Spring Boot 4 Complete Guide ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. พื้นฐานการจัดการคลัสเตอร์ด้วย Kubernetes
  2. การติดตามแบบกระจายด้วย Sleuth และ Zipkin
  3. การตรวจสอบสถานะและรูปแบบความทนทาน
  4. เมตริกและแดชบอร์ดด้วย Micrometer และ Prometheus
← กลับไปที่ Spring Boot 4 Complete Guide