ENG-13798: workflow traces show each start, run, deliver and cancel call and what it did

Merged
AD
13h ago
+726-23

Until now start, run, deliver and cancel left nothing in a trace but the traceparent they stamp into the stored arguments: whether a start inserted or found the run already there, how many runs a run or cancel matched, and whether a delivery was accepted were returned to the caller only, and a step's span linked to the whole handler around the call.

Each of the four calls is now a PRODUCER span in the caller's context:

spanattributes
reflex.workflow.startreflex.workflow.table, reflex.workflow.step, reflex.workflow.started (false on a unique-constraint hit)
reflex.workflow.runtable, step, reflex.workflow.rows (runs matched)
reflex.workflow.delivertable, step, reflex.workflow.restart, reflex.workflow.rows (runs that accepted)
reflex.workflow.canceltable, reflex.workflow.rows (runs matched)

The span is current while the statement encodes its arguments, so the stored traceparent, and with it the attempt span's link, names the call that scheduled the step. A call that raises (e.g. RunConflict) ends its span with the error.

A reflex.workflow.operations counter ({operation}) on the reflex_workflow meter counts completed calls by reflex.workflow.operation, table, step and reflex.workflow.result (started/exists, matched/none, accepted/refused). otel.enable() takes a meter_provider, defaulting to the global one.

Choices the ticket left open:

  • The counter's attributes use the same reflex.workflow.* keys as the spans rather than bare table/step.
  • The ticket mentions identifiers "when that opt-in is on"; no such opt-in exists yet, so none are recorded. Whoever adds the opt-in can add them here.
  • A call that raises is not counted; its span carries the error.
  • cancel has no step, so its span and count carry none.
  • reflex-otel doesn't forward a meter provider yet, so the counter goes to the global one; a sibling ticket (ENG-13797) owns that wiring.

Tests: under the Postgres fixture (both engine backends), each call's span with the value it returned for every outcome (inserted / exists, rows matched / none, accepted / refused, restart), the stored traceparent naming the start span, a RunConflict start as an error span that counts nothing, and the existing runner test now checking the attempt links to the start span under the handler. The full tests/units/reflex_workflow and reflex_otel suites pass locally (1274 passed).

Linear: ENG-13798

šŸ¤– Generated with Claude Code