0Pricing
API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) · درس

التتبّع الموزّع باستخدام Sleuth وZipkin

ادمجوا Spring Cloud Sleuth وZipkin لإجراء التتبّع الموزّع والحصول على رؤية واضحة لتدفقات الطلبات عبر الخدمات المصغّرة.

التتبّع الموزّع باستخدام Sleuth وZipkin درس مجاني في API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

What is Distributed Tracing?

In microservices, a single user request often travels through many different services. This makes it hard to follow the request's journey!

Distributed tracing is a technique that helps you track the path of a request as it moves across various services in your system.

Why Trace Microservices?

Without tracing, debugging issues in microservices is like finding a needle in a haystack. You don't know which service failed or where the delay occurred.

  • Debugging: Pinpoint errors faster.
  • Performance: Identify bottlenecks in the request flow.
  • Visibility: Understand how services interact.

Sleuth: The Tracing Enabler

Spring Cloud Sleuth integrates with Spring applications to automatically add tracing information to requests and logs.

It injects unique identifiers into HTTP headers and logging contexts, allowing you to link related operations across services.

Trace & Span IDs Explained

Sleuth uses two main IDs:

  • Trace ID: A unique ID for the entire request, from start to finish, across all services it touches.
  • Span ID: A unique ID for a single operation or unit of work within a service (e.g., an HTTP request or a method call). Spans form a tree structure within a trace.

Add Sleuth Dependency

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

For Maven:

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

For Gradle:

implementation 'org.springframework.cloud:spring-cloud-starter-sleuth'

Zipkin: The Tracing UI

While Sleuth adds tracing info, you need a way to collect and visualize it. That's where Zipkin comes in!

Zipkin is a distributed tracing system that collects and stores trace data, then provides a web UI to search and view these traces.

Run Zipkin Server

The easiest way to get Zipkin running locally is using Docker. This command pulls the Zipkin image and starts it on port 9411.

docker run -d -p 9411:9411 openzipkin/zipkin

You can then access the Zipkin UI at http://localhost:9411 in your browser.

Configure Sleuth for Zipkin

Once Zipkin is running, tell your Sleuth-enabled Spring Boot application where to send its trace data. Add this to your application.properties or application.yml.

application.properties:

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

Now, your application will send trace data to the local Zipkin server.

Tracing a Service Call

Let's see how a simple Spring Boot service logs trace IDs. With Sleuth, your logs will automatically include [appName,traceId,spanId,exportable].

Run this simple app, then make a request to /hello. Check the console logs for the added IDs.

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 TracingApp {

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

  @GetMapping("/hello")
  public String hello() {
    System.out.println("Hello endpoint called!");
    return "Hello from TracingApp!";
  }
}

Quick Check

Which of the following statements correctly describe the roles of Spring Cloud Sleuth and Zipkin in distributed tracing? (Select all that apply)

Recap & Next Steps

You've learned how distributed tracing helps in microservices, especially with Spring Cloud Sleuth and Zipkin.

  • Sleuth: Integrates with Spring apps to inject traceId and spanId.
  • Zipkin: Collects these traces and provides a UI for visualization and analysis.

These tools are crucial for understanding and debugging complex distributed systems.

الأسئلة الشائعة

هل درس «التتبّع الموزّع باستخدام Sleuth وZipkin» مجاني؟

نعم — نص درس «التتبّع الموزّع باستخدام Sleuth وZipkin» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)، انتقل إلى CoddyKit PRO. تتضمن دورة API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 4 دروس في المجموع.

ماذا ستتعلم في «التتبّع الموزّع باستخدام Sleuth وZipkin»؟

ادمجوا Spring Cloud Sleuth وZipkin لإجراء التتبّع الموزّع والحصول على رؤية واضحة لتدفقات الطلبات عبر الخدمات المصغّرة. تتمرن على API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)؟

لا تُشترط خبرة سابقة. API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.

كم من الوقت يستغرق درس «التتبّع الموزّع باستخدام Sleuth وZipkin»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) هذا؟

نعم. كل درس في API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. المصادقة والتفويض باستخدام JWT
  2. التتبّع الموزّع باستخدام Sleuth وZipkin
  3. الإعداد المركزي باستخدام Config Server
  4. إتاحة المقاييس باستخدام Actuator وPrometheus
← العودة إلى API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)