Skip to main content

Module subscribers

Module subscribers 

Source
Expand description

Connects best-effort runtime events to application observers.

Register Subscribe implementations through SupervisorBuilder::with_subscribers. Implement the trait for metrics, alerts, or application-specific output. Enable the logging feature for LogWriter, or the tracing feature for TracingBridge. Every configured subscriber receives its own bounded, serial callback lane.

ordinary runtime components
     │ Event
     ▼
bounded event bus
     ▼
runtime event relay
     ▼
SubscriberSet
     ├── queue A ──► serial lane A ──► subscriber A::on_event
     └── queue B ──► serial lane B ──► subscriber B::on_event

internal diagnostics ──► event relay or subscriber lane ──► callbacks

Internal subscriber diagnostics can bypass the shared bus. All delivery is for logs, metrics, alerts, and diagnostics. It does not own registry state or watched task outcomes. Publishing an ordinary event never calls subscriber code. Events can be lost at the shared bus or at an individual subscriber queue. A slow subscriber cannot fill another subscriber’s queue.

Each lane preserves FIFO callback order. Different lanes may run at the same time on a supervisor-local callback executor. Shutdown gives all lanes one shared drain deadline. With no configured subscribers, the event bus stays disabled and no event relay or callback worker starts.

Shared ingress and subscriber queues have separate capacities. Use SupervisorConfig::with_bus_capacity for bursts before fan-out. Override Subscribe::queue_capacity for bursts in one observer, and keep its callback short. Larger queues absorb longer bursts but consume more memory.

§Choosing an observer

NeedObserver
Quick human-readable console outputLogWriter with logging
Structured fields in tracingTracingBridge with tracing
Metrics, alerts, or another transportA custom Subscribe type

Use TaskWaiter instead when application logic needs a watched task’s final result. Subscriber delivery is intentionally lossy.

Structs§

LogWriterlogging
Prints each received event as one readable line on standard output.
TracingBridgetracing
Sends runtime events to tracing without free-form reason text.
TracingBridgeWithReasonstracing
Sends runtime events to tracing and includes free-form reason text.

Traits§

Subscribe
Synchronous observer for best-effort Event values.