0Pricing
Spring Boot 4 Complete Guide · Lekcja

Śledzenie rozproszone z użyciem Sleuth i Zipkin

Proszę implementować śledzenie rozproszone za pomocą Spring Cloud Sleuth i Zipkin, aby uzyskać wgląd w interakcje mikrousług.

Śledzenie rozproszone z użyciem Sleuth i Zipkin to bezpłatna lekcja Spring Boot 4 Complete Guide na CoddyKit. To lekcja 2 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Spring Boot 4 Complete Guide, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Spring Boot 4 Complete Guide zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

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.

Często zadawane pytania

Czy lekcja „Śledzenie rozproszone z użyciem Sleuth i Zipkin” jest bezpłatna?

Tak — pełny tekst „Śledzenie rozproszone z użyciem Sleuth i Zipkin” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Spring Boot 4 Complete Guide, przejdź na CoddyKit PRO. Kurs Spring Boot 4 Complete Guide zawiera 4 lekcji w sumie.

Co nauczysz się w „Śledzenie rozproszone z użyciem Sleuth i Zipkin”?

Proszę implementować śledzenie rozproszone za pomocą Spring Cloud Sleuth i Zipkin, aby uzyskać wgląd w interakcje mikrousług. Ćwiczysz Spring Boot 4 Complete Guide z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć Spring Boot 4 Complete Guide?

Nie wymagamy żadnego doświadczenia. Spring Boot 4 Complete Guide w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 2 z 4.

Ile czasu zajmuje lekcja „Śledzenie rozproszone z użyciem Sleuth i Zipkin”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji Spring Boot 4 Complete Guide?

Tak. Każda lekcja Spring Boot 4 Complete Guide zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Podstawy orkiestracji Kubernetes
  2. Śledzenie rozproszone z użyciem Sleuth i Zipkin
  3. Kontrole stanu i wzorce odporności
  4. Metryki i pulpity nawigacyjne z Micrometer i Prometheus
← Powrót do Spring Boot 4 Complete Guide