Search and commands

↑ ↓ to select · Enter to open · Esc to close

Type to search packages.

otel

v9.24.1
github.com/redis/go-redis/v9/internal/otel

Documentation

pkg.go.dev ↗

Table of contents

↓ to select · Enter to jump· Shift+Enter for source

14 matches

Top ↑

Functions

Enabled

func Enabled(r Recorder) bool

Enabled reports whether r records anything: false for the noop recorder (or a view of a global that is noop) and for a recorder whose own Enabled says so. Callers use it to skip metric work whose INPUTS are expensive to obtain, e.g. reading a command's result, which on the async autopipeline face blocks until the command executes.

PoolCallbacks

func PoolCallbacks(r Recorder) *pool.MetricCallbacks

PoolCallbacks returns the pool metric callback table that records to r. Every callback captures r, so a -1 reaches the recorder that saw the +1.

RegisterPools

func RegisterPools(r Recorder, connPool pool.Pooler, pubSubPool PubSubPooler, pipelinePool pool.Pooler)

RegisterPools registers a client's connection pools with r when it is a PoolRegistrar, under each pool's own name. pipelinePool is the optional dedicated pipeline connection pool (nil when not configured).

SetGlobalRecorder

func SetGlobalRecorder(r Recorder)

SetGlobalRecorder installs r as the global recorder and binds the global pool metric callbacks to it. nil uninstalls both. Pools created before r was installed are registered with r, so they are observed too.

UnregisterPools

func UnregisterPools(r Recorder, connPool pool.Pooler, pubSubPool PubSubPooler, pipelinePool pool.Pooler)

UnregisterPools removes a client's connection pools from r (see RegisterPools). Call it after the pools are closed: a closed pool is no longer handed to a recorder installed later.

Types

Cmder

type Cmder interface {
	Name() string
	FullName() string
	Args() []interface{}
	Err() error
}

Cmder is a minimal interface for command information needed for metrics. This avoids circular dependencies with the main redis package.

PendingDeltaFilter

type PendingDeltaFilter interface {
	WantsPendingDeltas() bool
}

PendingDeltaFilter is implemented by recorders that may not use the pending request +1/-1 events, e.g. one that reads the pools at collection time. When WantsPendingDeltas returns false, the pool skips RecordPendingRequests.

PoolRegistrar

type PoolRegistrar interface {
	// RegisterPool is called when a new client is created with its connection pools,
	// and for every live pool when the recorder becomes the global one.
	// poolName: the pool's own name, the one its connections carry (Conn.PoolName)
	// pool: the connection pool
	RegisterPool(poolName string, pool pool.Pooler)
	// UnregisterPool is called when a client is closed to remove its pool from the registry.
	// pool: the connection pool to unregister
	UnregisterPool(pool pool.Pooler)
	// RegisterPubSubPool is called when a new client is created with a PubSub pool.
	// poolName: the pool's own name (e.g., "localhost:6379_1_pubsub")
	// pool: the PubSub connection pool
	RegisterPubSubPool(poolName string, pool PubSubPooler)
	// UnregisterPubSubPool is called when a PubSub client is closed to remove its pool.
	// pool: the PubSub connection pool to unregister
	UnregisterPubSubPool(pool PubSubPooler)
}

PoolRegistrar is implemented by recorders that read pool state at collection time (connection count, pending requests). Register may be called more than once for the same pool and must be idempotent.

PubSubPooler

type PubSubPooler interface {
	Stats() *pool.PubSubStats
	Name() string
}

PubSubPooler is a PubSub pool as RegisterPools sees it.

Recorder

type Recorder interface {
	// RecordOperationDuration records the total operation duration (including all retries)
	// dbIndex is the Redis database index (0-15)
	RecordOperationDuration(ctx context.Context, duration time.Duration, cmd Cmder, attempts int, err error, cn *pool.Conn, dbIndex int)

	// RecordPipelineOperationDuration records the total pipeline/transaction duration.
	// operationName should be "PIPELINE" for regular pipelines or "MULTI" for transactions.
	// cmdCount is the number of commands in the pipeline.
	// err is the error from the pipeline execution (can be nil).
	// dbIndex is the Redis database index (0-15)
	RecordPipelineOperationDuration(ctx context.Context, duration time.Duration, operationName string, cmdCount int, attempts int, err error, cn *pool.Conn, dbIndex int)

	// RecordConnectionCreateTime records the time it took to create a new connection
	RecordConnectionCreateTime(ctx context.Context, duration time.Duration, cn *pool.Conn)

	// RecordConnectionRelaxedTimeout records when connection timeout is relaxed/unrelaxed
	// delta: +1 for relaxed, -1 for unrelaxed
	// poolName: name of the connection pool (e.g., "main", "pubsub")
	// notificationType: the notification type that triggered the timeout relaxation (e.g., "MOVING")
	RecordConnectionRelaxedTimeout(ctx context.Context, delta int, cn *pool.Conn, poolName, notificationType string)

	// RecordConnectionHandoff records when a connection is handed off to another node
	// poolName: name of the connection pool (e.g., "main", "pubsub")
	RecordConnectionHandoff(ctx context.Context, cn *pool.Conn, poolName string)

	// RecordError records client errors (ASK, MOVED, handshake failures, etc.)
	// errorType: type of error (e.g., "ASK", "MOVED", "HANDSHAKE_FAILED")
	// statusCode: Redis response status code if available (e.g., "MOVED", "ASK")
	// isInternal: whether this is an internal error
	// retryAttempts: number of retry attempts made
	RecordError(ctx context.Context, errorType string, cn *pool.Conn, statusCode string, isInternal bool, retryAttempts int)

	// RecordMaintenanceNotification records when a maintenance notification is received
	// notificationType: the type of notification (e.g., "MOVING", "MIGRATING", etc.)
	RecordMaintenanceNotification(ctx context.Context, cn *pool.Conn, notificationType string)

	// RecordConnectionWaitTime records the time spent waiting for a connection from the pool
	RecordConnectionWaitTime(ctx context.Context, duration time.Duration, cn *pool.Conn)

	// RecordConnectionClosed records when a connection is closed
	// reason: reason for closing (e.g., "idle", "max_lifetime", "error", "pool_closed")
	// err: the error that caused the close (nil for non-error closures)
	RecordConnectionClosed(ctx context.Context, cn *pool.Conn, reason string, err error)

	// RecordPubSubMessage records a Pub/Sub message
	// direction: "sent" or "received"
	// channel: channel name (may be hidden for cardinality reduction)
	// sharded: true for sharded pub/sub (SPUBLISH/SSUBSCRIBE)
	RecordPubSubMessage(ctx context.Context, cn *pool.Conn, direction, channel string, sharded bool)

	// RecordStreamLag records the lag for stream consumer group processing
	// lag: time difference between message creation and consumption
	// streamName: name of the stream (may be hidden for cardinality reduction)
	// consumerGroup: name of the consumer group
	// consumerName: name of the consumer
	RecordStreamLag(ctx context.Context, lag time.Duration, cn *pool.Conn, streamName, consumerGroup, consumerName string)

	// RecordMultiDBFailover records a MultiDB (geo-failover) failover from one
	// member database to another. fromFQDN/toFQDN are host-only database FQDNs,
	// reason is "automatic" or "manual", and duration is the wall time of the
	// failover.
	RecordMultiDBFailover(ctx context.Context, fromFQDN, toFQDN, reason string, duration time.Duration)

	// RecordMultiDBActiveDatabaseChange records a change of the active MultiDB
	// member database (failover, fallback, or manual selection). fromFQDN/toFQDN
	// are host-only database FQDNs.
	RecordMultiDBActiveDatabaseChange(ctx context.Context, fromFQDN, toFQDN string)

	// RecordMultiDBCircuitStateChange records a MultiDB circuit breaker state
	// transition for the database identified by dbFQDN.
	RecordMultiDBCircuitStateChange(ctx context.Context, dbFQDN, fromState, toState string)

	// RecordMultiDBHealthCheck records the result of a MultiDB health-check pass
	// for the database identified by dbFQDN. duration is the wall time of the check.
	RecordMultiDBHealthCheck(ctx context.Context, dbFQDN string, success bool, duration time.Duration)

	// RecordPendingRequests records a change in pending requests (UpDownCounter)
	// delta: +1 when request starts waiting, -1 when request stops waiting
	// poolName is passed explicitly because we may not have a connection yet when request starts
	RecordPendingRequests(ctx context.Context, delta int, cn *pool.Conn, poolName string)
}

Recorder is the interface for recording metrics.

NoopRecorder

func NoopRecorder() Recorder

NoopRecorder returns the recorder that discards everything. A test that installs a partial recorder embeds it so the methods the test does not care about still have an implementation.

Scoped

func Scoped(r Recorder) Recorder

Scoped returns the recorder a client records to: r itself, or, when r is nil, a view of whatever global recorder is installed at call time. This is the only place "fall back to the global recorder" is written.

Dependency graph