0Pricing
Elixir & Phoenix: Scalable Backend Development · درس

التتبع الموزع باستخدام OpenTelemetry

تتبّع الطلبات أثناء انتقالها بين العمليات والخدمات باستخدام OpenTelemetry، وحوّل السجلات المتناثرة إلى مخطط زمني واحد مترابط.

التتبع الموزع باستخدام OpenTelemetry درس مجاني في Elixir & Phoenix: Scalable Backend Development على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 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» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Elixir & Phoenix: Scalable Backend Development، انتقل إلى CoddyKit PRO. تتضمن دورة Elixir & Phoenix: Scalable Backend Development 4 دروس في المجموع.

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

تتبّع الطلبات أثناء انتقالها بين العمليات والخدمات باستخدام OpenTelemetry، وحوّل السجلات المتناثرة إلى مخطط زمني واحد مترابط. تتمرن على Elixir & Phoenix: Scalable Backend Development مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 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 يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

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

  1. قياس الأداء وتحليله في Elixir
  2. المراقبة باستخدام Telemetry والمقاييس
  3. معالجة الأخطاء والتسجيل المنظّم
  4. التتبع الموزع باستخدام OpenTelemetry
← العودة إلى Elixir & Phoenix: Scalable Backend Development