ENG-13795: workflow step traces say what each attempt scheduled next (step, wait, schedule, fan-out, retry or stop)

AD
11h ago
+716-39

What a trace consumer gets

Until now a <table>.<step> attempt span said only ok, retry, failed or fenced, so nobody reading the traces could tell whether a run had finished, was parked on a wait, sleeping until a timer, fanned out, or due for a retry. Once an attempt's commit lands, its span now records:

  • reflex.workflow.next.kind: step, wake, wait, repeat, fan_out, retry or stop. If the event a wait is armed for is already held, the run is due now and runs that event's step, so the span records step with the event's step as next.step.
  • reflex.workflow.next.step, reflex.workflow.next.delay (seconds), reflex.workflow.next.at (ISO 8601 in UTC, cron and custom schedules only)
  • reflex.workflow.wait.step for waits
  • reflex.workflow.schedule.kind (interval, cron, custom) and reflex.workflow.schedule.expression (cron only)
  • reflex.workflow.children for fan-outs

A fenced attempt records none of these, because what it asked for did not stand. Only values declared in code are recorded (step names, counts, durations, schedules), never arguments or row columns.

How

  • Scheduled carries the transition kind that resolve() decides. otel.record_transition(outcome, scheduled, values, started, holding, spec) reads that kind instead of re-deriving it.
  • commit_attempt also returns whether the committed row holds an event (RETURNING pending_event IS NOT NULL, which costs nothing extra). For a wait the step just armed, that means its event arrived first.
  • record_transition It returns at once when tracing is off, and the disabled path still imports nothing from opentelemetry.
  • run_attempt calls it after a landed commit. abandon calls it for the failure it writes when a commit could not land.
  • The recording trace points (record_failure, record_outcome, record_transition) log anything they raise instead of raising it: they run after the commit, and an exception there would turn a landed attempt into a failed execute().
  • The README's "Tracing" section is now "Telemetry", and docs/workflows/inspecting_runs.md lists the same attributes. It lists the attributes and adds the sampling note: attempt spans are trace roots, so a ratio sampler drops a share of them, and workers that feed run reconstruction should set OTEL_TRACES_SAMPLER=always_on.

Choices the ticket left open

  • No finished or retries attribute. finished would always equal next.kind == "stop", and retries is static step configuration repeated on every span.
  • next.delay on an interval repeat is the interval. The exact wake time is computed in SQL on the run's grid, so it is not known in Python.
  • schedule.expression is the cron expression only, without its timezone. next.at already gives the resolved time.
  • next.at is rendered from what the schedule returned: an aware time converted to UTC, so spans compare as strings; a naive time as returned, since the driver and the Postgres session timezone decide which instant it is stored as; any other value a custom schedule returns (an ISO string Postgres casts) as its string; None (which parks the row) as no attribute.

Tests

  • tests/units/reflex_workflow/test_otel.py: one case per next.kind (step, wake, wait with and without timeout, both with the event already held, interval/cron/custom repeat, fan-out, stop, refused schedule), plus retry and failed with a retrying step. Each compares the span's full attribute set.
  • tests/units/reflex_workflow/engine/test_runner.py (Postgres): the chain/flaky trace test checks step → stop and the retry backoffs; the cron test checks that next.at is the same instant as the row's wake_at; a schedule answering in another timezone records UTC; a custom schedule returning a string or None still commits with execute() returning ok under tracing; a wait whose event is already held records step and its row is due and runs the event; a fenced attempt has no transition attributes; a commit that could not land records retry and then stop.
  • uv run pytest tests/units/reflex_workflow tests/units/reflex_otel against Postgres 16, with the session timezone UTC and again with America/Los_Angeles: all pass (after the review changes: 1290 passed, 2 skipped, UTC). pre-commit passes on the changed files.

Linear: ENG-13795

šŸ¤– Generated with Claude Code