ENG-13795: workflow step traces say what each attempt scheduled next (step, wait, schedule, fan-out, retry or stop)
Ā
AD
11h ago+716+716+012345678901234567890123456789-39-39-01234567890123456789
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,retryorstop. 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 recordsstepwith the event's step asnext.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.stepfor waitsreflex.workflow.schedule.kind(interval,cron,custom) andreflex.workflow.schedule.expression(cron only)reflex.workflow.childrenfor 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
Scheduledcarries the transitionkindthatresolve()decides.otel.record_transition(outcome, scheduled, values, started, holding, spec)reads that kind instead of re-deriving it.commit_attemptalso 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_transitionIt returns at once when tracing is off, and the disabled path still imports nothing fromopentelemetry.run_attemptcalls it after a landed commit.abandoncalls 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 failedexecute(). - The README's "Tracing" section is now "Telemetry", and
docs/workflows/inspecting_runs.mdlists 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 setOTEL_TRACES_SAMPLER=always_on.
Choices the ticket left open
- No
finishedorretriesattribute.finishedwould always equalnext.kind == "stop", andretriesis static step configuration repeated on every span. next.delayon 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.expressionis the cron expression only, without its timezone.next.atalready gives the resolved time.next.atis 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 pernext.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 thatnext.atis the same instant as the row'swake_at; a schedule answering in another timezone records UTC; a custom schedule returning a string orNonestill commits withexecute()returning ok under tracing; a wait whose event is already held recordsstepand 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_otelagainst Postgres 16, with the session timezone UTC and again withAmerica/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