ENG-13796: workflow traces can name the run, parent run and event key of each step attempt (opt-in)
Stacked on #8113 (ENG-13795). It extends the README "Telemetry" section that PR renames. Review only the commits above #8113; this retargets to main once #8113 lands.
What a trace consumer gets
An attempt span carried no run identity, so two attempts of the same step on different rows looked identical, and a run's history could not be assembled from its spans. Links only reach backwards, and they break at every wait, because a delivered event links to the request that delivered it. Behind one opt-in, an attempt span now records:
reflex.workflow.run: the primary key as a JSON array in column order, even for a single column: the text ofAttemptLog.run's jsonb (viajson_pk, so UUIDs and other non-JSON keys match), sorun = '<attribute>'::jsonbjoins a span to its attempts.reflex.workflow.parent.tableandreflex.workflow.parent.runon a fanned-out child.reflex.workflow.event.keywhen the attempt runs a keyed event.
Opt in with ReflexInstrumentor().instrument(workflow_identifiers=True) or OTEL_PYTHON_REFLEX_WORKFLOW_IDENTIFIERS=true, which is forwarded to reflex_workflow.otel.enable(identifiers=True). It is off by default, so the reflex-otel README's promise that row columns never leave the process holds unless someone asks. Both READMEs document it as "turn on when your keys are surrogate ids".
Choices the ticket left open
- Default off, as the ticket proposes. The proposal had left this open.
- Event key on both delivery paths. The ticket points at
taken, but a claim only sets that when it takes an event held for a wait that wasn't armed yet. For held events the worker reads the key from that claim, whoever delivered the event. An event delivered to a run that is already waiting is applied directly and never passes throughtaken. For that pathdeliverstamps the key into the step's stored arguments underdelivered_key, the same waytraceparentalready travels (otel.stamp_event). It is stamped only while the delivering process has tracing and identifiers on, so an app that never opts in stores nothing beyond what it stored before. The cost: a direct-applied event delivered from a process with identifiers off has noevent.keyon the worker's span. The README says to turn identifiers on in every process that delivers events. Deriving the key on the worker fromrecent_event_keyswas rejected. That list's newest entry is still there for every later step of the run, so it would attach an event's key to steps the event never ran. Steps are called with only the storedargsandkwargs, so no step ever sees the key. Dedupe semantics are unchanged. The key stays in the stored arguments for the step's retries. - A key JSON cannot hold leaves out
reflex.workflow.runrather than raising while the span opens. Such a key already fails where the engine records it. Any other error in_add_identifiersis logged by the same guard as the other recorders, and the step still runs. - Older reflex-workflow releases: reflex-otel calls
enable(..., identifiers=...)and, onTypeError, calls it again without the argument, warning if identifiers were asked for. disable()also turns identifiers off, so a laterenable()without the flag does not inherit it.
Tests
tests/units/reflex_workflow/test_otel.py: off by default even when keys are passed; on for one column, several columns (with a UUID), a child, a keyed event, and a key JSON cannot hold. Each compares the full attribute set. Also coversstamp_eventwriting the key only with identifiers on, identifiers that cannot be read (a raising key encoder, a parent without a key) never failing the span, anddisable()clearing the flag.tests/units/reflex_otel/test_init.py: the keyword and the env var (true,TRUE,1, unset, and keyword-over-env) reachreflex_workflow.otel, anduninstrument()clears it. With a reflex-workflow whoseenabletakes noidentifiers, tracing still turns on, and the warning appears only when identifiers were asked for.tests/units/reflex_workflow/engine/test_runner.py(Postgres): an event applied to a waiting run and an event held for a wait both put their key on thedecidespan, and the step still never sees the key. For {untraced, traced, identifying} deliverer Ć {held, applied}: the key is stored only by an identifying deliverer, and a held event's key is always on the worker's span. A resend is still refused. A retried event step names its event on every attempt. A fan-out's children record their parent's table and key, and the parent records its own run.uv run pytest tests/units/reflex_workflow tests/units/reflex_otelagainst Postgres 16, with the session timezone UTC and again withAmerica/Los_Angeles: 1333 passed, 2 skipped (UTC, after the review changes). pre-commit passes on the changed files.
Linear: ENG-13796
š¤ Generated with Claude Code