System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) · บทเรียน

ทำความเข้าใจสแปนและรหัสประจำแทรซ

เรียนรู้ส่วนประกอบพื้นฐานของแทรซ ได้แก่ สแปน รหัสแทรซ และรหัสสแปน ทำความเข้าใจว่าข้อมูลเหล่านี้เชื่อมโยงกันเพื่อสร้างเส้นทางคำขอที่สมบูรณ์อย่างไร

บทเรียน 1 จาก 411 ขั้นตอน

ทำความเข้าใจสแปนและรหัสประจำแทรซ เป็นบทเรียน System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) มีบทเรียนทั้งหมด 4 บทเรียน

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

Tracing Your System's Story

Welcome to Distributed Tracing! Ever wonder exactly what happens when a user clicks a button, and that request travels through many services?

Traditional monitoring struggles with this. Distributed tracing is your solution to understand the full journey of a request across complex systems.

What is a Trace?

Think of a trace as the complete story of a single request or operation as it flows through all the services in your application.

  • It starts when a request enters your system.
  • It ends when the final response is sent.
  • It captures every step in between, no matter how many services are involved.

Introducing Spans: The Chapters

A trace is made up of smaller units called spans. Each span represents a single, distinct operation or unit of work within the trace.

For example, fetching data from a database, calling another microservice, or executing a specific function could each be a span.

Anatomy of a Span

Every span holds important information about the operation it represents:

  • Operation Name: What happened (e.g., authenticateUser).
  • Start/End Time: When the operation began and finished.
  • Duration: How long it took.
  • Attributes (Tags): Key-value pairs providing context (e.g., http.method: GET, user.id: 123).

Trace ID: The Story's Title

The Trace ID is a unique identifier assigned to the entire request journey. All spans that belong to the same request share the exact same Trace ID.

This ID is crucial for linking all related operations together, allowing you to reconstruct the full story of a request.

Span ID: Chapter Number

While the Trace ID identifies the whole story, the Span ID uniquely identifies a specific operation (span) within that story.

Each span gets its own unique Span ID. This helps distinguish individual steps in the trace, even if they happen concurrently.

Parent-Child Span Relationships

Spans aren't just a flat list; they form a hierarchy. When one operation triggers another, they become parent-child spans.

A child span will typically reference its parent's Span ID. This creates a tree-like structure, showing causality and nested operations.

Visualizing the Trace Tree

These IDs and relationships allow observability tools to visualize a trace as a waterfall diagram or a tree. You can see:

  • The total time taken for the request.
  • Which services were called.
  • How long each step took.
  • Any errors that occurred at a specific step.

Simulating Trace & Span IDs

Let's look at a conceptual Java example. Imagine a request being handled, which then calls an authentication service and a database service. Notice how the Trace ID is constant, but Span IDs change, and parent-child relationships are indicated.

public class TraceExample {
  public static void main(String[] args) {
    String traceId = generateId(); // Unique ID for the whole request
    System.out.println("Trace Started. Trace ID: " + traceId);

    // Span 1: Main operation
    String span1Id = generateId();
    System.out.println("  Span 1: handleRequest (ID: " + span1Id + ", Parent: none)");

    // Span 2: Sub-operation of Span 1
    String span2Id = generateId();
    System.out.println("    Span 2: authenticateUser (ID: " + span2Id + ", Parent: " + span1Id + ")");

    // Span 3: Another sub-operation of Span 1
    String span3Id = generateId();
    System.out.println("    Span 3: fetchDataFromDB (ID: " + span3Id + ", Parent: " + span1Id + ")");

    System.out.println("Trace Finished.");
  }

  // Helper to simulate ID generation
  private static String generateId() {
    return Long.toHexString(System.nanoTime()); // Simple, unique-ish ID
  }
}

Quick Check: Trace Components

You've learned about the core components of a distributed trace. Let's see if you can identify their roles!

Recap: Tracing's Core Concepts

Great job! You've learned the fundamental building blocks of distributed tracing:

  • A Trace is the complete journey of a request.
  • Spans are individual operations within a trace.
  • The Trace ID uniquely identifies the entire request.
  • The Span ID uniquely identifies an individual operation.
  • Spans form parent-child relationships to show causality.

These concepts are key to understanding how distributed tracing provides deep visibility into your complex systems. Next, we'll explore how tracing actually works!

เริ่มต้นได้ฟรี

เรียนรู้ System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
12
บทเรียน
48

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

บทเรียน “ทำความเข้าใจสแปนและรหัสประจำแทรซ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “ทำความเข้าใจสแปนและรหัสประจำแทรซ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) ให้อัปเกรดเป็น CoddyKit PRO คอร์ส System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “ทำความเข้าใจสแปนและรหัสประจำแทรซ”

เรียนรู้ส่วนประกอบพื้นฐานของแทรซ ได้แก่ สแปน รหัสแทรซ และรหัสสแปน ทำความเข้าใจว่าข้อมูลเหล่านี้เชื่อมโยงกันเพื่อสร้างเส้นทางคำขอที่สมบูรณ์อย่างไร คุณปฏิบัติ System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน

บทเรียน “ทำความเข้าใจสแปนและรหัสประจำแทรซ” ใช้เวลานานแค่ไหน

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

ฉันเขียนและรันโค้ดในบทเรียน System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) นี้ได้ไหม

ได้ บทเรียน System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

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

  1. ทำความเข้าใจสแปนและรหัสประจำแทรซ
  2. การทำงานของการติดตามแบบกระจาย
  3. การติดตามเทียบกับการบันทึกล็อกและตัวชี้วัด
  4. กลยุทธ์การสุ่มตัวอย่างสำหรับร่องรอย
← กลับไปที่ System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)