Measurement

The Observer seam and what it receives.

Observer

Observer receives client-side measurements. Set Options.Observer to one; the SDK ships no metrics stack of its own, so this is the seam where a caller attaches whatever they already run.

The measurement that exists nowhere else is IngestStat.Attempts. A shed batch never reaches the server, so a producer riding out constant backpressure is invisible to every server-side counter — it looks exactly like a producer with nothing to send.

Every method runs synchronously on the goroutine doing the work: increment and return, do not block.

type Observer interface {
	// IngestCompleted is called once per ingest call that returned, whether it
	// succeeded or not.
	IngestCompleted(IngestStat)
	// StreamDelivered is called once per subscription delivery handed to the
	// caller.
	StreamDelivered(StreamStat)
	// ConnectionChanged is called on every ResilientClient state transition:
	// connected, disconnected, breaker opened. Plain Client never calls it —
	// it has one connection and no lifecycle to report.
	ConnectionChanged(ConnStat)
}

Observer receives client-side measurements. Implement it with whatever metrics system the calling program already uses; the SDK deliberately ships none.

Both methods are called SYNCHRONOUSLY on the goroutine doing the work, so an implementation must not block — increment a counter and return. A slow Observer slows ingest, and one that panics takes the caller’s goroutine with it.

IngestStat

IngestStat describes one completed ingest call — one per call, not one per retried attempt.

type IngestStat struct {
	StreamID StreamID
	// Ticks distinguishes the two record kinds sharing this struct.
	Ticks bool
	// Records is how many were in the batch.
	Records int
	// Attempts is 1 when nothing was retried. Anything higher means the server
	// shed the batch and the client absorbed it — the signal that exists
	// nowhere else, because a shed batch never reaches the node's own counters.
	Attempts int
	// Duration covers the whole call INCLUDING the backoff waits, which is
	// what a caller's latency budget actually experiences.
	Duration time.Duration
	// Err is nil when the batch was accepted. A non-nil Err with Attempts > 1
	// is the exhausted-budget case (ErrRetriesExhausted).
	Err error
}

IngestStat describes one completed ingest CALL — not one attempt. A call that was shed twice and then landed is one IngestStat with Attempts 3 and a nil Err.

StreamStat

StreamStat describes one subscription delivery, with the wire’s flags already interpreted.

type StreamStat struct {
	StreamID StreamID
	Ticks    bool
	// Records carried by this delivery; zero is legal for a state-change-only
	// batch.
	Records int
	// Backfill marks stored history, Live the first batch after it drained.
	Backfill bool
	Live     bool
	// Dropped is how many batches the server discarded before this one. These
	// records are GONE — the counter that turns a silent data hole into an
	// alertable event.
	Dropped uint64
}

StreamStat describes one subscription delivery, after the wire’s flags have been interpreted.

ConnStat

ConnStat describes a connection lifecycle transition, delivered to an Observer. Reconnect counts and breaker state exist nowhere else — a server cannot count the clients that failed to reach it.

type ConnStat struct {
	Addr string
	// State is the state just entered.
	State ConnState
	// Reconnects is the running total of connections that replaced a dead
	// one, excluding the first.
	Reconnects int
	// Failures is the CONSECUTIVE connection-failure count driving the
	// breaker; it resets to zero on a successful connect.
	Failures int
	// Err is the failure that caused the transition, nil on success.
	Err error
}

ConnStat describes a connection lifecycle transition seen by ResilientClient. It is the resilience half of client-side measurement: reconnect counts and breaker state exist nowhere else, because a server cannot count the clients that failed to reach it.