Skip to main content
Pass a NexusStreamObserver via NexusConfig.streamObserver to receive structured callbacks for every SSE lifecycle transition. The observer is the canonical way to wire SDK state into ops dashboards, custom telemetry, or load-test tooling - far more reliable than scraping NexusLogger output by substring match. The observer is opt-in. When streamObserver is undefined the SDK uses NOOP_STREAM_OBSERVER at zero overhead.

The interface

Every method is optional - the SDK calls only the ones you set. You can write { onEvent: (n) => count(n) } and ignore the rest.

Hook semantics

onFallback reasons

A 429 response with {"error":"quarantined"} body does NOT fire onFallback. It fires onQuarantined instead (v0.4.0). The stream failure counter is not incremented for quarantine reconnects.

Threading contract

Observer methods MUST return promptly. The SDK calls them synchronously from the stream reader loop on the main thread. If your observer does anything substantial (network I/O, structured logging fan-out), copy the argument and dispatch the work to a future microtask.

Counter pattern

Active-connection state pattern

Vue’s reactive primitives make this clean - wire the observer to a ref defined outside any component setup function:
In a component:
For a built-in alternative, use the existing useNexusStreamStatus() composable - it returns the same connected boolean derived from the streamConnected getter.