Investigate
Event Sinks
Export lifecycle facts and command output through project-owned providers.
Project event sinks live in python/event_sinks/ and are imported from sqlbuild.event_sinks.
Each sink consumes one record type. Lifecycle and command-output streams stay separate even when
they share a provider and destination.
Lifecycle event sink
Section titled “Lifecycle event sink”from python.providers.destination_client import DestinationClientfrom sqlbuild.event_sinks import ( LifecycleEvent, LifecycleEventKind, lifecycle_event_sink, lifecycle_event_to_json,)
@lifecycle_event_sink( event_kinds={ LifecycleEventKind.INVOCATION, LifecycleEventKind.RUN, LifecycleEventKind.RESOURCE, LifecycleEventKind.AUDIT, })def publish_lifecycle(event: LifecycleEvent, destination_client: DestinationClient) -> None: destination_client.publish( route="sqlbuild.lifecycle.v2", key=event.invocation_id, payload=lifecycle_event_to_json(event).encode("utf-8"), )Use invocation_id as a partition key to keep one invocation on one partition, and keep
event_id as the deduplication key. Use a non-compacted topic when complete lifecycle history must
remain replayable.
Invocation phases
Section titled “Invocation phases”Before running its first node, a command emits an invocation_phase event (kind invocation) as
each preparation step finishes:
phase |
When | Extra fields |
|---|---|---|
discovered |
Declarations and Python were read | duration_ms |
compiled |
Project compiled | duration_ms, count (models) |
matched |
Worker compile matched its published snapshot | duration_ms |
discovered_set |
Worker loaded a saved discovered set | name, count, detail |
connected |
Warehouse connections opened | duration_ms, name (adapter), count |
inspected |
Required warehouse state was read | duration_ms |
planned |
Plan generated | duration_ms, count (nodes), detail |
started_execution |
Execution begins | count (concurrency), detail |
Consumers should ignore unknown phase values.
Command-output event sink
Section titled “Command-output event sink”from sqlbuild.event_sinks import CommandOutputRecord, command_output_event_sink, command_output_to_json
@command_output_event_sink(streams={"stdout", "stderr"})def publish_output(record: CommandOutputRecord, destination_client: DestinationClient) -> None: destination_client.publish( route="sqlbuild.command_output.v1", key=record.record_id, payload=command_output_to_json(record).encode("utf-8"), )Command output groups adjacent text into bounded chunks and emits a loss record if bounded queues drop output. Use lifecycle facts—not command-output records—to build execution state and timelines.
A sink taking a parameter annotated sqlbuild.recall.RecallWriter replaces what
Recall stores for its stream
rather than acting as an external exporter.
Configuration
Section titled “Configuration”Narrow declaration filters and set the exit flush budget in sqlbuild_project.toml:
[event_sinks.lifecycle]event_kinds = ["run", "resource", "operation", "statement", "audit"]min_severity = "info"shutdown_timeout = "30s"
[event_sinks.lifecycle.named.publish_lifecycle]event_kinds = ["resource", "statement"]min_severity = "warning"shutdown_timeout (default "2s", range "0s"–"10m") controls how long a command waits at exit
for lifecycle sinks to drain queued events ("0s" drops remaining queued events). It applies under
[event_sinks.lifecycle] only, not per named sink.
SQLBuild owns envelope validation, queueing, filtering, and bounded dispatch. Your project owns destination credentials, serialization, routes, retries, and durability.
Delivery behavior
Section titled “Delivery behavior”- Ordered boundaries, prioritized middle:
invocation_startedarrives first andinvocation_completedorinvocation_failedarrives last. Between them, failures and terminal events take priority over normal events; sort byinvocation_sequencefor exact order. Run and invocation outcome events are always preserved. - Per-call timeout: Each sink call has one second to return. If it exceeds that, SQLBuild warns on stderr and drops intermediate events for that sink until the call returns, while preserving run and invocation outcomes.
- Isolation: Sink failures, drops, and provider teardown errors print a summary warning to
stderr without changing the command’s exit code or
--jsonstdout. Invalid sink declarations or provider setup errors fail before execution. - Compile exclusion:
sqb compilesends only invocation start and outcome events to lifecycle sinks, not per-phase events. - Streaming audits:
audit_completedevents publish as each audit finishes rather than in a burst at the end of a run. - Shared providers: Providers shared by multiple sinks are set up and torn down once per command; see Providers.