0Pricing
Elixir & Phoenix: Scalable Backend Development · Aula

Rastreio Distribuído com OpenTelemetry

Rastreie pedidos à medida que atravessam processos e serviços usando OpenTelemetry, transformando registos dispersos numa única linha temporal conectada.

Rastreio Distribuído com OpenTelemetry é uma aula grátis de Elixir & Phoenix: Scalable Backend Development no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Elixir & Phoenix: Scalable Backend Development, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Elixir & Phoenix: Scalable Backend Development inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

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.

Perguntas Frequentes

A aula “Rastreio Distribuído com OpenTelemetry” é grátis?

Sim — o texto completo de “Rastreio Distribuído com OpenTelemetry” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Elixir & Phoenix: Scalable Backend Development, atualize para CoddyKit PRO. O curso de Elixir & Phoenix: Scalable Backend Development inclui 4 aulas no total.

O que vou aprender em “Rastreio Distribuído com OpenTelemetry”?

Rastreie pedidos à medida que atravessam processos e serviços usando OpenTelemetry, transformando registos dispersos numa única linha temporal conectada. Você pratica Elixir & Phoenix: Scalable Backend Development com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Elixir & Phoenix: Scalable Backend Development?

Nenhuma experiência prévia é necessária. Elixir & Phoenix: Scalable Backend Development no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.

Quanto tempo leva a aula “Rastreio Distribuído com OpenTelemetry”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Elixir & Phoenix: Scalable Backend Development?

Sim. Cada aula de Elixir & Phoenix: Scalable Backend Development inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Benchmarking e Criação de Perfis no Elixir
  2. Monitoramento com Telemetry e Métricas
  3. Tratamento de Erros e Registro Estruturado
  4. Rastreio Distribuído com OpenTelemetry
← Voltar para Elixir & Phoenix: Scalable Backend Development