Skip to main content
Pass an IStreamObserver via NexusConfig.Observer 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 INexusLogger output by substring match. The observer is opt-in. When NexusConfig.Observer is null the SDK uses the internal no-op observer at zero overhead.

The interface

Inherit NoopStreamObserver to override only the hooks you care about:

Hook semantics

OnFallback reasons

RateLimited - active recovery vs terminate (v0.3.1+)

As of v0.3.1, FallbackReason.RateLimited no longer implies the stream is dead. It fires in both of these cases:
  1. Active recovery - 429 with a parseable Retry-After header. The SDK fires OnFallback(FallbackReason.RateLimited), await Task.Delay-s the indicated duration (clamped [5 s, 5 min]), then reconnects automatically on the next loop iteration in RunStreamAsync. The episode does NOT increment the transport-failure counter. No action is required from the observer; a subsequent OnConnected() confirms the stream has resumed.
  2. Terminate (legacy) - 429 with no parseable Retry-After. The SDK fires OnFallback(FallbackReason.RateLimited), closes the stream, and returns from RunStreamAsync. TTL polling takes over.

Threading contract

Observer methods are called synchronously from the SDK’s stream-reader Task. They MUST return promptly. The SDK does not protect against blocking observers and does not wrap the calls in Task.Run.
If your observer does anything substantial (network I/O, lock contention, disk writes), copy the argument and dispatch the work to your own pipeline before returning:

Counter pattern

Active-connection gauge pattern

OnFallback is included because after a MaxErrors fallback the SDK will not reconnect - the gauge should stay false until you call ConnectStream() again on a new client. For RateLimited with Retry-After (v0.3.1+) the SDK reconnects on its own; the subsequent OnConnected() re-arms the gauge to true automatically.

Per-event-type counter