ENG-13802: every workflow step attempt that lands writes one structured log record, so a log pipeline can follow workflows without tracing
Stacked on #8115 (ENG-13801, the reflex logger bridge). Once that merges, this PR retargets to main.
What
A log pipeline that reads an event stream rather than spans (no sampling) got nothing from the workflow engine. Now every attempt whose result landed writes one record:
- logger
reflex_workflow.attempts, levelINFO - message
<table>.<step> attempt <n>: <outcome>, for exampleexpense.submit attempt 2: retry extra={"fields": {...}, "otel.event.name": "reflex.workflow.attempt", "console_level": logging.DEBUG}, wherefieldsholds the attempt span's attributes:reflex.workflow.table,.step,.attempt,.lane,.outcomeand, on a failure,error.type.- The reflex CLI's terminal and
--jsonsinks treat it asDEBUG, so a plainreflex runprints no line per attempt (--loglevel debugdoes), while the reflex-otel bridge exports it atINFOwhatever--loglevelis (#8115 decouples the export level).
Change
reflex_workflow/otel.py:attempt_attributes()builds the attributes for both the span (step_spannow uses it) and the record.log_attempt()writes the record and is guarded byisEnabledFor(INFO), so a worker below INFO builds nothing. It runs after the commit landed, so whatever a logging filter or handler raises is logged onreflex_workflow.otelinstead of failing the attempt (the same rule as_harmlessin #8113/#8118). It is plain stdlib logging, so it runs with or without tracing, and the disabled path still imports nothing fromopentelemetry.
engine/execute.py:run_attemptwrites the record once its commit has landed.abandonwrites it for the failure it records in place of a commit that could not land. Both calls happen inside the attempt's span, so a bridged record carries that span's ids.wake_on_schedulenow returns the exception a schedule raised rather than its text, so a schedule failure's record carrieserror.typethe way its span already did.reflex_base.utils.logdefines the record extras its sinks read once:FIELDS_EXTRA("fields"),EVENT_NAME_EXTRA("otel.event.name") andCONSOLE_LEVEL_EXTRA("console_level", new: the level the terminal and--jsonsinks treat a record as).reflex_otel/logs.pyimports them, which moves reflex-otel's reflex-base floor to0.11.1.dev0. reflex-workflow depends on no Reflex package, so it restates them asFIELDS_KEY,EVENT_NAME_KEY,CONSOLE_LEVEL_KEY, and a test holds them equal.reflex_base.utils.log.JsonHandlermerges a record'sfieldsdict into the JSON line. Canonical keys win over a field of the same name, the same rule asemit_json_print. It also writes a record'sotel.event.nameas a key, beside the other semantic extras it already lists (kind,feature_name, ...).reflex_otel/logs.py(from #8115): flattensfieldsinto top-level attributes rather than one kvlist, exportsotel.event.nameas the OTLPevent_name, and dropsconsole_levellike the other terminal hints.- The reflex-workflow README and
docs/api-reference/observability.mddescribe the record, when the terminal shows it, and thefields/otel.event.name/console_levelextras as a contract any record can use. News fragments for reflex-workflow, reflex-base and reflex-otel.
Design choices the ticket left open
-
"Landed" means
ok,retryorfailed. Afencedattempt left nothing behind (its commit was refused), andstale/missingnever ran a step, so none of these write a record. -
ENG-13795's transition attributes are not here yet. That ticket adds
reflex.workflow.next.*,.schedule.*,.children,.finishedand.retriesto the span and is still in progress, sorecord_transitiondoes not exist onmain. This PR shares the attribute builder rather than duplicating it. Once 13795 lands, its attributes need to go intofieldsat the same two call sites (run_attemptafter the commit lands, andabandon) so the record keeps matching the span. Whichever PR lands second should mergemainand add them. -
No run identifier yet. The run's primary key is an identifier, and exporting identifiers becomes an opt-in in #8118 (
_identifiers/identify()). Whichever of #8117 and #8118 lands second adds the run key tolog_attempt's fields under that opt-in. With tracing on, the record carries the attempt span's ids. -
A
console_levelextra rather than a logger the console filters by name, so reflex-base knows no reflex-workflow logger names and any record can use it.
Tests
tests/units/reflex_workflow/engine/test_runner.py, against Postgres, on both the session-factory and theDatabaseengine. Each assertion compares logger, level, message,fieldsand event name exactly:- a step that fails twice, then succeeds: three records (
retrywitherror.type=ConnectionError,retry,ok); - a commit that cannot land:
retrythenfailedfromabandon, with the driver's exception type; - a schedule that raises: one
failedrecord witherror.type=RuntimeError; - a fenced attempt: no record;
- with tracing on, the record carries the attempt span's trace and span ids;
- a logging filter that raises on the record:
executestill returnsok, the attempt is in the history, and the failure is logged.
- a step that fails twice, then succeeds: three records (
tests/units/reflex_base/utils/test_log.py: the JSON line carriesfieldsand canonical keys win (exact object); aconsole_level=DEBUGrecord is hidden from the rich and JSON sinks atINFO, shown atDEBUG, and reaches another handler either way.tests/units/reflex_workflow/test_otel.py: the record's extras, a raising filter logged rather than raised, and the restated extras equal to reflex-base's.tests/units/reflex_otel/test_logs.py:fieldsflattened into the exported attributes (exact set) andevent_nameexported.- Locally:
REFLEX_TEST_POSTGRES=... uv run pytest tests/units(Postgres 16) 17686 passed, 63 skipped; pre-commit clean on the changed files;scripts/check_min_deps.py reflex-otelPASS.
Linear: ENG-13802
š¤ Generated with Claude Code