0Pricing
Elixir & Phoenix: Scalable Backend Development · Lezione

Distributed tracing con OpenTelemetry

Tracci le richieste mentre attraversano processi e servizi usando OpenTelemetry, trasformando log sparsi in un'unica cronologia collegata.

Distributed tracing con OpenTelemetry è una lezione Elixir & Phoenix: Scalable Backend Development gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Elixir & Phoenix: Scalable Backend Development, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Elixir & Phoenix: Scalable Backend Development include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

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.

Domande Frequenti

La lezione «Distributed tracing con OpenTelemetry» è gratuita?

Sì — il testo completo di «Distributed tracing con OpenTelemetry» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Elixir & Phoenix: Scalable Backend Development, passa a CoddyKit PRO. Il corso Elixir & Phoenix: Scalable Backend Development include 4 lezioni in totale.

Cosa imparerò in «Distributed tracing con OpenTelemetry»?

Tracci le richieste mentre attraversano processi e servizi usando OpenTelemetry, trasformando log sparsi in un'unica cronologia collegata. Eserciti Elixir & Phoenix: Scalable Backend Development con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Elixir & Phoenix: Scalable Backend Development?

Non è richiesta alcuna esperienza precedente. Elixir & Phoenix: Scalable Backend Development su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.

Quanto tempo richiede la lezione «Distributed tracing con OpenTelemetry»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Elixir & Phoenix: Scalable Backend Development?

Sì. Ogni lezione Elixir & Phoenix: Scalable Backend Development include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Benchmarking e profiling di Elixir
  2. Monitoraggio con Telemetry e metriche
  3. Gestione degli errori e logging strutturato
  4. Distributed tracing con OpenTelemetry
← Torna a Elixir & Phoenix: Scalable Backend Development