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

แอตทริบิวต์ เหตุการณ์ และสถานะของช่วง

เรียนรู้การเพิ่มแอตทริบิวต์ที่มีความหมายให้ช่วง การบันทึกเหตุการณ์ตามเวลา และการกำหนดสถานะช่วง เพื่อให้ร่องรอยใช้วิเคราะห์ปัญหาได้ ไม่ใช่เพียงข้อมูลเวลา

บทเรียน 4 จาก 413 ขั้นตอน

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

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

Beyond Timing

A span knows its duration automatically, but raw timing is rarely enough. Enriching spans with attributes, events, and status makes traces tell a story.

Span Attributes

Attributes are key-value pairs that add context to a span, like the route handled or the number of rows returned.

span.set_attribute("http.route", "/orders/:id")
span.set_attribute("db.rows", 42)

Use Conventions

Prefer standard semantic-convention keys for common data so backends understand them. Use custom keys only for domain-specific context.

standard: http.response.status_code
custom: order.tier

Keep Attributes Bounded

Like metric labels, avoid high-cardinality or huge values. Do not stuff entire payloads into an attribute.

  • Good: order count, region
  • Bad: full request body, raw stack trace as attribute

Span Events

An event is a timestamped annotation inside a span marking something that happened at a moment, like a retry or cache miss.

span.add_event("cache.miss", { "key": "user:42" })

Recording Exceptions

Exceptions are recorded as a special event capturing the type, message, and stack, so failures show up in the trace timeline.

try:
    do_work()
except Exception as e:
    span.record_exception(e)

Span Status

Status tells whether the operation succeeded. The default is Unset; set Error on failure so backends can highlight broken spans.

span.set_status(StatusCode.ERROR, "payment declined")

Status vs Recording Exceptions

Recording an exception adds detail but does not by itself mark the span failed. Always also set the status to Error.

span.record_exception(e)
span.set_status(StatusCode.ERROR)

Attributes vs Events

Use attributes for facts true for the whole span; use events for things that happen at a point in time within it.

Naming Spans Well

Span names should be low cardinality, describing the operation type, not the specific instance. Put the variable part in attributes.

name: "GET /orders/:id"   (good)
name: "GET /orders/48213" (bad)

A Well-Formed Span

A diagnostic span has a clean name, a few bounded attributes, events for notable moments, and an accurate status.

Quick Check

Pick the correct statement about span status.

Recap

You learned to enrich spans with bounded attributes (preferring semantic conventions), to mark point-in-time moments and failures with events and record_exception, and to set status to Error explicitly. Low-cardinality span names plus rich context turn traces into real diagnostics.

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

เรียนรู้ 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 ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 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)