telemetry

package
v1.0.27 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package telemetry provides bounded, payload-free operational events for hosts that need to observe CRDT transport boundaries.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidConfig reports a nil sink or invalid bounded queue size.
	ErrInvalidConfig = errors.New("crdt telemetry: invalid configuration")
)

Functions

This section is empty.

Types

type Event

type Event struct {
	Time      time.Time
	Component string
	Operation string
	Outcome   Outcome
	Duration  time.Duration
	ErrorCode crdt.ErrorCode
}

Event describes an operational boundary without including replica IDs, group IDs, endpoints, headers, payloads, or application values. Component and Operation should be fixed names chosen by the library or host.

type Options

type Options struct {
	QueueSize int
	Sink      Sink
}

Options configures one bounded Reporter. QueueSize defaults to 256. Sink is required so construction cannot silently create a background no-op worker.

type Outcome

type Outcome string

Outcome is the privacy-safe result category for one operational event.

const (
	OutcomeSuccess  Outcome = "success"
	OutcomeRejected Outcome = "rejected"
	OutcomeFailure  Outcome = "failure"
)

type Reporter

type Reporter struct {
	// contains filtered or unexported fields
}

Reporter asynchronously delivers a bounded stream of operational events. Record never waits for Sink and never changes application behavior. It is safe for concurrent use. Call Close during host shutdown to request delivery shutdown; Close does not wait for a blocked third-party sink.

func New

func New(options Options) (*Reporter, error)

New creates a bounded asynchronous Reporter.

func (*Reporter) Close

func (reporter *Reporter) Close()

Close stops normal event acceptance and requests that the worker exit. One event that raced with Close may still reach Sink. Close is idempotent and returns immediately even when a third-party Sink has blocked.

func (*Reporter) Done

func (reporter *Reporter) Done() <-chan struct{}

Done closes after the delivery goroutine exits. It can remain open when a third-party Sink blocks, which is why Close never waits for it.

func (*Reporter) Dropped

func (reporter *Reporter) Dropped() uint64

Dropped reports events that could not enter the bounded queue.

func (*Reporter) Record

func (reporter *Reporter) Record(event Event)

Record queues event when capacity is available. It is intentionally lossy: the caller does not wait for observation, and Dropped exposes overload to a host metric. A nil Reporter is a zero-cost no-op.

type Sink

type Sink func(Event)

Sink receives events on a Reporter-owned goroutine. It may block or panic without delaying CRDT, transport, or request paths; a blocked sink only causes the report queue to fill and later events to be dropped.

func SlogSink

func SlogSink(logger *slog.Logger) Sink

SlogSink adapts a standard-library structured logger. It records only the fields in Event; in particular, an underlying error and caller data are not attached. Failures are warnings, while successful events are debug records.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL