Durable.Telemetry (Durable v2.0.2)

View Source

The :telemetry events Durable emits. This list is a contract: names, measurements and metadata keys only change in a major version.

Spans follow :telemetry.span/3: a :start event, then one of :stop or :exception (never both), with duration in native time units — the same shape as Phoenix, Ecto and Oban, so existing tooling reads them as-is.

Run, step, compensation and schedule events include :durable (the instance name) in their metadata.

Runs

A run executes in segments: it starts, runs until it finishes or suspends (sleep, wait for an event or input, parallel fan-out), and later resumes as a new segment, possibly on another node. Each segment is one span.

  • [:durable, :workflow, :start] — %{system_time, monotonic_time}; metadata :workflow_id, :root_workflow_id (the run at the top of its tree), :workflow, :workflow_module, :queue, :key, :tags, :trigger, :resumed (false on a run's first segment)
  • [:durable, :workflow, :stop] — %{duration, monotonic_time}; adds :status: :completed, :failed, :compensated, :compensation_failed, :waiting (suspended: a wait, or a retry or snooze that parked the run) or :superseded (cancelled, reclaimed by another node, or its process died mid-segment)
  • [:durable, :workflow, :exception] — the executor itself crashed; adds :kind, :reason, :stacktrace

Steps

One span per attempt. A step that raises or returns an error is a normal :stop with result: :error — :exception means Durable itself failed.

  • [:durable, :step, :start] — metadata :workflow_id, :root_workflow_id, :step_execution_id (the attempt's row), :workflow, :key, :tags, :step, :step_type, :attempt, :max_attempts
  • [:durable, :step, :stop] — adds :result (:ok, :error, :suspended, :snoozed or :cancelled) and, for errors, :error (%{type, message})
  • [:durable, :step, :exception]
  • [:durable, :step, :retry] — %{backoff_ms}; the step metadata plus :error, emitted as the run parks until the next attempt
  • [:durable, :step, :snooze] — %{snooze_ms}; the step metadata plus :reason (nil for {:snooze, ms})

Compensations

  • [:durable, :compensation, :start | :stop | :exception] — metadata :workflow_id, :root_workflow_id, :workflow, :key, :tags, :compensation, :step (the step it undoes); :stop adds :result (:ok or :error)

Attempts that die

An attempt's end event comes from whoever closes its row. That's one atomic update, so each attempt gets at most one. A worker killed between closing its row and leaving the span sends none. When its process dies, its node is lost or its run is cancelled, that's the worker, a sweep or the cancel, possibly on another node, which sends:

  • [:durable, :step, :stop] with result: :error (and :error), :cancelled or :snoozed, or [:durable, :compensation, :stop] with result: :error. duration runs from the attempt's start
  • [:durable, :step, :retry] if another attempt follows; backoff_ms is 0 after a lost worker, which uses no attempt
  • [:durable, :workflow, :stop] with status: :superseded. Its duration also runs from the attempt's start, not the segment's, and :resumed is nil

So a handler can't assume the process that saw :start sees the end. :telemetry_span_context matches them up: it's the row id for a step, the run id for a segment. A node that dies between two steps has no attempt to close, so that segment gets no end event.

Queue, scheduler and waits

  • [:durable, :queue, :job_claimed] — %{count}; :job_id, :queue, :node_id
  • [:durable, :queue, :job_completed] — %{duration}; :job_id, :queue, :workflow_module, :workflow_name, :status
  • [:durable, :queue, :poll] — %{jobs_fetched}; :queue, :available_slots
  • [:durable, :queue, :claim_failed] — %{count}; a poll's claim query failed. :queue, :reason
  • [:durable, :queue, :heartbeat] — %{count}; :job_id, :queue
  • [:durable, :queue, :stale_recovered], [:durable, :queue, :zombie_recovered] — %{count}
  • [:durable, :queue, :worker_fenced] — %{count, duration}; :job_id, :queue
  • [:durable, :queue, :ack_failed] — %{count, attempts}; :job_id, :reason
  • [:durable, :node, :drain, :start | :stop | :exception] — a span around a node stopping work; metadata :durable, :node_id; :stop adds :result (:ok or {:error, :timeout})

  • [:durable, :schedule, :trigger] — %{count}; :schedule, :workflow_id, :workflow_module, :workflow, :queue
  • [:durable, :wait, :sleep_woken] — %{count}
  • [:durable, :pruner, :pruned] — %{count}; :group (:completed, :failed or :cancelled), once per deleted batch

Workflow keys

  • [:durable, :key, :duplicate] — %{count}; a start found its key taken. :workflow, :key, :holder_id, :outcome (:use_existing, :error, :cancel_existing, :send_event or :debounced), :input_changed
  • [:durable, :key, :handoff] — %{count}; a start took the key from a finished run. :workflow, :key, :from, :to
  • [:durable, :key, :release] — %{count}; Durable.release_key/2. :workflow, :key, :workflow_id, :by

Logs

Before each attempt of a step or compensation, Logger.metadata/1 gets :workflow, :workflow_id, :step and :attempt, plus whatever the workflow's log_metadata: function returns for the step's data. Add the ones you want to your Logger formatter's :metadata. Durable.LogCapture describes what's saved on the step's row.

Durable.OpenTelemetry turns attempts into spans.

Reporting

metrics/0 returns Telemetry.Metrics definitions for any reporter (Prometheus, StatsD, LiveDashboard) when :telemetry_metrics is installed:

def metrics, do: my_metrics() ++ Durable.Telemetry.metrics()

attach_default_logger/1 logs one line per finished run and per failed step.

Summary

Functions

Logs one line per finished run (level, default :info) and one warning per failed step attempt. Detach with :telemetry.detach("durable-default-logger").

Every event name Durable emits, for :telemetry.attach_many/4.

Telemetry.Metrics definitions for Durable's events. Tags are bounded — workflow, step, queue and schedule names, never run ids.

Functions

attach_default_logger(opts \\ [])

@spec attach_default_logger(keyword()) :: :ok | {:error, :already_exists}

Logs one line per finished run (level, default :info) and one warning per failed step attempt. Detach with :telemetry.detach("durable-default-logger").

events()

@spec events() :: [[atom()]]

Every event name Durable emits, for :telemetry.attach_many/4.

metrics()

@spec metrics() :: [Telemetry.Metrics.t()]

Telemetry.Metrics definitions for Durable's events. Tags are bounded — workflow, step, queue and schedule names, never run ids.