ENG-13802: every workflow step attempt that lands writes one structured log record, so a log pipeline can follow workflows without tracing

AD
10h ago
+682-33

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, level INFO
  • message <table>.<step> attempt <n>: <outcome>, for example expense.submit attempt 2: retry
  • extra={"fields": {...}, "otel.event.name": "reflex.workflow.attempt", "console_level": logging.DEBUG}, where fields holds the attempt span's attributes: reflex.workflow.table, .step, .attempt, .lane, .outcome and, on a failure, error.type.
  • The reflex CLI's terminal and --json sinks treat it as DEBUG, so a plain reflex run prints no line per attempt (--loglevel debug does), while the reflex-otel bridge exports it at INFO whatever --loglevel is (#8115 decouples the export level).

Change

  • reflex_workflow/otel.py:
    • attempt_attributes() builds the attributes for both the span (step_span now uses it) and the record.
    • log_attempt() writes the record and is guarded by isEnabledFor(INFO), so a worker below INFO builds nothing. It runs after the commit landed, so whatever a logging filter or handler raises is logged on reflex_workflow.otel instead of failing the attempt (the same rule as _harmless in #8113/#8118). It is plain stdlib logging, so it runs with or without tracing, and the disabled path still imports nothing from opentelemetry.
  • engine/execute.py: run_attempt writes the record once its commit has landed. abandon writes 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_schedule now returns the exception a schedule raised rather than its text, so a schedule failure's record carries error.type the way its span already did.
  • reflex_base.utils.log defines the record extras its sinks read once: FIELDS_EXTRA ("fields"), EVENT_NAME_EXTRA ("otel.event.name") and CONSOLE_LEVEL_EXTRA ("console_level", new: the level the terminal and --json sinks treat a record as). reflex_otel/logs.py imports them, which moves reflex-otel's reflex-base floor to 0.11.1.dev0. reflex-workflow depends on no Reflex package, so it restates them as FIELDS_KEY, EVENT_NAME_KEY, CONSOLE_LEVEL_KEY, and a test holds them equal.
  • reflex_base.utils.log.JsonHandler merges a record's fields dict into the JSON line. Canonical keys win over a field of the same name, the same rule as emit_json_print. It also writes a record's otel.event.name as a key, beside the other semantic extras it already lists (kind, feature_name, ...).
  • reflex_otel/logs.py (from #8115): flattens fields into top-level attributes rather than one kvlist, exports otel.event.name as the OTLP event_name, and drops console_level like the other terminal hints.
  • The reflex-workflow README and docs/api-reference/observability.md describe the record, when the terminal shows it, and the fields / otel.event.name / console_level extras 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, retry or failed. A fenced attempt left nothing behind (its commit was refused), and stale/missing never 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, .finished and .retries to the span and is still in progress, so record_transition does not exist on main. This PR shares the attribute builder rather than duplicating it. Once 13795 lands, its attributes need to go into fields at the same two call sites (run_attempt after the commit lands, and abandon) so the record keeps matching the span. Whichever PR lands second should merge main and 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 to log_attempt's fields under that opt-in. With tracing on, the record carries the attempt span's ids.

  • A console_level extra 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 the Database engine. Each assertion compares logger, level, message, fields and event name exactly:
    • a step that fails twice, then succeeds: three records (retry with error.type=ConnectionError, retry, ok);
    • a commit that cannot land: retry then failed from abandon, with the driver's exception type;
    • a schedule that raises: one failed record with error.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: execute still returns ok, the attempt is in the history, and the failure is logged.
  • tests/units/reflex_base/utils/test_log.py: the JSON line carries fields and canonical keys win (exact object); a console_level=DEBUG record is hidden from the rich and JSON sinks at INFO, shown at DEBUG, 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: fields flattened into the exported attributes (exact set) and event_name exported.
  • 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-otel PASS.

Linear: ENG-13802

šŸ¤– Generated with Claude Code