Observability
Lifecycle events and per-step spans, both pluggable.
Two pluggable surfaces, both no-op by default.
import { createRecordingObserver, createRecordingTracer } from 'octaflow';
const observer = createRecordingObserver(); // captures FlowEvents in memory (tests/introspection)
const tracer = createRecordingTracer(); // captures spans in memory
const engine = createWorkflowEngine({ store, dispatcher, registry, partitionKey, observer, tracer });
-
FlowObserverreceives aFlowEventat every transition —workflow.started/completed/ failed/cancelled/retried/purgedandstep.started/completed/failed/defaulted/retrying/skipped/ waiting/resumed/timedOut/mapping/compensating/compensated, each with{ workflowId, stepKey, stepType, attempt, durationMs, error, partitionKey, at }. One surface powers run history (persist the events) and metrics (feed OTel counters/histograms).step.defaultedis a failure that did not end the run: the step’s budget was spent and itsonFailure: { output }completed it with a stand-in. It carries the error and counts as a completion from there on — a live-progress view shows it as the step’s outcome, an alert counts it withstep.failed.Two are worth wiring to an alert rather than a chart.
workflow.retriedmeans an operator reached forretryWorkflow— a run got far enough to fail.step.timedOutmeans a suspended step hit its wait deadline; it is always followed by the event for what the policy did,step.failed(orstep.defaulted, if the type has anonFailurestand-in) orstep.completed, so count the pair rather than assuming which. -
FlowTracerwraps each step execution in aflow.stepspan (records the error on failure). An OpenTelemetry adapter is a ~10-linestartSpanshim. -
Postgres run history:
createPgEventSink({ pool, partitionKey })is aFlowObserverthat appends toflow_step_event; read a run’s timeline back withreadFlowEvents(pool, { workflowId, partitionKey }). A step that retried/transitioned is fully reconstructable after the fact.
→ examples/11-observability.ts
From octaflow@0.44.0 in the platform repository, MIT-licensed.npm