0Pricing
Elixir & Phoenix: Scalable Backend Development · บทเรียน

การติดตามแบบกระจายด้วย OpenTelemetry

ติดตามคำขอขณะไหลผ่านกระบวนการและบริการต่าง ๆ ด้วย OpenTelemetry เปลี่ยนบันทึกที่กระจัดกระจายให้เป็นลำดับเวลาที่เชื่อมโยงกัน

การติดตามแบบกระจายด้วย OpenTelemetry เป็นบทเรียน Elixir & Phoenix: Scalable Backend Development ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Elixir & Phoenix: Scalable Backend Development และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Elixir & Phoenix: Scalable Backend Development มีบทเรียนทั้งหมด 4 บทเรียน

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

The Distributed Debugging Problem

In a system spread across services and processes, one user request touches many components. Plain logs cannot show how they connect. Distributed tracing stitches the whole journey into one timeline.

Traces and Spans

A trace represents one end-to-end request. It is made of spans — timed units of work like a DB query or an HTTP call. Spans nest to form a tree.

What is OpenTelemetry?

OpenTelemetry (OTel) is a vendor-neutral standard for traces, metrics, and logs. Elixir has first-class support via the opentelemetry packages, exporting to Jaeger, Honeycomb, Datadog, and more.

Adding the Dependencies

Add the API, SDK, and an exporter to your deps.

defp deps do
  [
    {:opentelemetry, "~> 1.3"},
    {:opentelemetry_exporter, "~> 1.6"},
    {:opentelemetry_phoenix, "~> 1.1"}
  ]
end

Auto-Instrumenting Phoenix

The opentelemetry_phoenix package hooks into Telemetry events so each request becomes a trace automatically. Set it up in your application start.

def start(_type, _args) do
  OpentelemetryPhoenix.setup()
  OpentelemetryEcto.setup([:my_app, :repo])
  Supervisor.start_link(children, opts)
end

Creating a Manual Span

For custom work, wrap it in a span with Tracer.with_span/2. It records start and end times automatically.

require OpenTelemetry.Tracer, as: Tracer
Tracer.with_span "charge_payment" do
  PaymentGateway.charge(order)
end

Adding Span Attributes

Attributes attach searchable context to a span, like the user id or order total.

Tracer.set_attributes([{"order.id", order.id}, {"order.total", order.total}])

Recording Errors

When something fails, mark the span so it stands out in your tracing UI.

Tracer.set_status(:error, "payment declined")
Tracer.record_exception(exception)

Context Propagation

The magic of tracing is context propagation: the trace id travels with the request across service boundaries via HTTP headers, so spans from different services join the same trace.

Exporting to a Backend

Configure an exporter to ship spans to your observability backend over OTLP.

config :opentelemetry,
  span_processor: :batch,
  traces_exporter: :otlp
config :opentelemetry_exporter,
  otlp_endpoint: "http://collector:4318"

Reading a Trace

In a tracing UI you see a waterfall of spans. Long bars reveal slow steps; gaps reveal waiting. This pinpoints latency far faster than scanning logs.

Quick Check

Test your tracing knowledge.

Recap

You learned distributed tracing with OpenTelemetry:

  • Traces are built from nested spans
  • Auto-instrument Phoenix and Ecto via Telemetry
  • Create manual spans with with_span and add attributes
  • Record errors on spans for visibility
  • Context propagation connects spans across services

Tracing turns multi-service requests into one readable timeline.

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

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

ใช่ — ข้อความเต็มของ “การติดตามแบบกระจายด้วย OpenTelemetry” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Elixir & Phoenix: Scalable Backend Development ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Elixir & Phoenix: Scalable Backend Development มีบทเรียนทั้งหมด 4 บทเรียน

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

ติดตามคำขอขณะไหลผ่านกระบวนการและบริการต่าง ๆ ด้วย OpenTelemetry เปลี่ยนบันทึกที่กระจัดกระจายให้เป็นลำดับเวลาที่เชื่อมโยงกัน คุณปฏิบัติ Elixir & Phoenix: Scalable Backend Development ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Elixir & Phoenix: Scalable Backend Development หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Elixir & Phoenix: Scalable Backend Development บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

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

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

ฉันเขียนและรันโค้ดในบทเรียน Elixir & Phoenix: Scalable Backend Development นี้ได้ไหม

ได้ บทเรียน Elixir & Phoenix: Scalable Backend Development ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

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

  1. การวัดประสิทธิภาพและการทำโพรไฟล์ Elixir
  2. การตรวจติดตามด้วย Telemetry และเมตริก
  3. การจัดการข้อผิดพลาดและการบันทึกล็อกแบบมีโครงสร้าง
  4. การติดตามแบบกระจายด้วย OpenTelemetry
← กลับไปที่ Elixir & Phoenix: Scalable Backend Development