Durable.OpenTelemetry (Durable v2.0.2)
View SourceReports each step attempt as an OpenTelemetry span.
Setup
Add the SDK, point its id generator at Durable, and attach the handlers when your application starts:
# mix.exs
{:opentelemetry, "~> 1.5"}
# config/config.exs
config :opentelemetry, id_generator: Durable.OpenTelemetry.IdGenerator
# application.ex
Durable.OpenTelemetry.setup()What you get
- The top run's id is the trace id, so a run and every child and parallel run under it are one trace, across sleeps, retries and nodes.
- Each step attempt is a span, its id taken from the attempt's row. The log lines saved on that row carry the same two ids.
- While a step runs, its span is current, so your own spans nest under
it and OpenTelemetry adds
otel_trace_idandotel_span_idto its Logger lines. In aTask, wrap the function inDurable.Context.bind/1to keep them. - A compensation is one span covering all its attempts, in the same trace, with an id of its own.
- An attempt that dies still gets a span, recorded by whoever finds out, marked as an error unless it was cancelled or handed back.
Durable doesn't export anything itself: your SDK configuration decides where spans and logs go.
The SDK drops a span still open after 30 minutes. For longer steps, raise
its span_ttl: config :opentelemetry, sweeper: %{span_ttl: :timer.hours(4)}.
Summary
Functions
@spec setup() :: :ok | {:error, :id_generator_not_configured | :already_exists}
Attaches the telemetry handlers. Call it once, when your application starts.
Returns {:error, :id_generator_not_configured}, and logs why, if the SDK
isn't using Durable.OpenTelemetry.IdGenerator: without it a run's attempts
wouldn't share a trace.