telemetry

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package telemetry is the single registry of span names, metric instruments, attribute keys, log keys and histogram boundaries used by the event-sourcing, scheduler, inbox, notify and lease packages.

The instrumentation scope name is always the import path of the package that records. Providers default to the OTel globals, so everything is a no-op until otel.Setup installs real providers.

Index

Constants

View Source
const (
	AttrTenantID   attribute.Key = "eventsourcing.tenant_id"
	AttrStreamType attribute.Key = "eventsourcing.stream_type"
	AttrStreamID   attribute.Key = "eventsourcing.stream_id"
	AttrEventID    attribute.Key = "eventsourcing.event_id"
	AttrEventType  attribute.Key = "eventsourcing.event_type"
	AttrEventTypes attribute.Key = "eventsourcing.event_types"
	AttrConsumer   attribute.Key = "eventsourcing.consumer"
	AttrPosition   attribute.Key = "eventsourcing.position"
	AttrBatchSize  attribute.Key = "eventsourcing.batch.size"
	AttrAttempt    attribute.Key = "eventsourcing.attempt"
	AttrJob        attribute.Key = "eventsourcing.job"
	AttrSource     attribute.Key = "eventsourcing.source"
	AttrOutcome    attribute.Key = "eventsourcing.outcome"
	AttrStatus     attribute.Key = "eventsourcing.status"
	AttrErrorType  attribute.Key = "error.type"
	// AttrCommandReplayed marks a Command that repeated a Command ID.
	AttrCommandReplayed attribute.Key = "eventsourcing.command.replayed"
)

Span and metric attribute keys. Metric attributes are limited to AttrConsumer, AttrJob, AttrSource and AttrStreamType, plus the bounded AttrCommandReplayed, AttrOutcome and AttrStatus; tenants and IDs never become metric labels.

View Source
const (
	LogTenantID   = "tenant_id"
	LogConsumer   = "consumer"
	LogStreamType = "stream_type"
	LogStreamID   = "stream_id"
	LogEventID    = "event_id"
	LogEventType  = "event_type"
	LogPosition   = "position"
	LogAttempt    = "attempt"
	LogJob        = "job"
	LogSource     = "source"
	LogError      = "error"
)

Log keys, the fixed slog vocabulary of every runner.

View Source
const (
	LogMessageID = "message_id"
	LogOutcome   = "outcome"
	LogReason    = "reason"
	LogRetryAt   = "retry_at"
	LogStack     = "stack"
	LogCandidate = "candidate"
	LogReplayed  = "replayed"
	LogRemaining = "remaining"
	LogLease     = "lease"
)

Detail log keys, used by single runners next to the fixed vocabulary.

View Source
const MaxLinks = 128

MaxLinks caps the links from a consumer batch span to the stored event contexts.

Variables

View Source
var (
	AggregateLoadDuration = Instrument{
		Name: "eventsourcing.aggregate.load.duration", Unit: "s",
		Description: "Duration of loading an Aggregate from its Stream.",
		Boundaries:  DurationBoundaries,
	}
	AggregateLoadEvents = Instrument{
		Name: "eventsourcing.aggregate.load.events", Unit: "{event}",
		Description: "Events read to load an Aggregate.",
		Boundaries:  EventCountBoundaries,
	}
	CommandDuration = Instrument{
		Name: "eventsourcing.command.duration", Unit: "s",
		Description: "Duration of a Command transaction.",
		Boundaries:  DurationBoundaries,
	}
	ConsumerBatchDuration = Instrument{
		Name: "eventsourcing.consumer.batch.duration", Unit: "s",
		Description: "Duration of one Consumer batch.",
		Boundaries:  DurationBoundaries,
	}
	ConsumerProcessDuration = Instrument{
		Name: "eventsourcing.consumer.process.duration", Unit: "s",
		Description: "Duration of handling one event in a Consumer.",
		Boundaries:  DurationBoundaries,
	}
	InboxHandleDuration = Instrument{
		Name: "inbox.handle.duration", Unit: "s",
		Description: "Duration of handling one inbox message.",
		Boundaries:  DurationBoundaries,
	}
	SchedulerRunDuration = Instrument{
		Name: "scheduler.run.duration", Unit: "s",
		Description: "Duration of one scheduler job run.",
		Boundaries:  DurationBoundaries,
	}
)

Histograms.

View Source
var (
	InboxMessagesHandled = Instrument{
		Name: "inbox.messages.handled", Unit: "{message}",
		Description: "Inbox messages handled, by outcome.",
	}
	SchedulerRunCandidateFailures = Instrument{
		Name: "scheduler.run.candidate_failures", Unit: "{failure}",
		Description: "Failed runs of a scheduler job candidate.",
	}
	NotifyReconnects = Instrument{
		Name: "notify.reconnects", Unit: "{reconnect}",
		Description: "Reconnects of the LISTEN connection.",
	}
	NotifyGaps = Instrument{
		Name: "notify.gaps", Unit: "{gap}",
		Description: "Gaps delivered to subscriptions after overflow or reconnect.",
	}
	LeaseReconnects = Instrument{
		Name: "lease.reconnects", Unit: "{reconnect}",
		Description: "Reconnects of the advisory-lock connection.",
	}
	LeaseLost = Instrument{
		Name: "lease.lost", Unit: "{lease}",
		Description: "Leases lost while held.",
	}
	LeaseHeld = Instrument{
		Name: "lease.held", Unit: "{lease}",
		Description: "Leases currently held.",
	}
)

Counters and up-down counters.

View Source
var (
	ConsumerPending = Instrument{
		Name: "eventsourcing.consumer.pending", Unit: "{event}",
		Description: "Matching events after the Consumer's Cursor.",
	}
	ConsumerLag = Instrument{
		Name: "eventsourcing.consumer.lag", Unit: "s",
		Description: "Age of the oldest pending event of the Consumer.",
	}
	ConsumerStopped = Instrument{
		Name: "eventsourcing.consumer.stopped", Unit: "1",
		Description: "1 when the Consumer is Stopped, else 0.",
	}
	ReactorParkedStreams = Instrument{
		Name: "eventsourcing.reactor.parked.streams", Unit: "{stream}",
		Description: "Parked Streams of the Reactor.",
	}
	ReactorParkedEvents = Instrument{
		Name: "eventsourcing.reactor.parked.events", Unit: "{event}",
		Description: "Events held for Parked Streams of the Reactor.",
	}
	ReactorParkedExhausted = Instrument{
		Name: "eventsourcing.reactor.parked.exhausted", Unit: "{stream}",
		Description: "Parked Streams whose auto-redrive schedule is exhausted.",
	}
	InboxMessages = Instrument{
		Name: "inbox.messages", Unit: "{message}",
		Description: "Inbox messages, by status.",
	}
	InboxPendingOldestAge = Instrument{
		Name: "inbox.pending.oldest_age", Unit: "s",
		Description: "Age of the oldest pending inbox message.",
	}
	SchedulerJobLastSuccess = Instrument{
		Name: "scheduler.job.last_success", Unit: "s",
		Description: "Unix time of the job's last successful run.",
	}
	XminAge = Instrument{
		Name: "eventsourcing.xmin.age", Unit: "{transaction}",
		Description: "Age of the database's oldest running transaction ID.",
	}
)

Polled gauges, reported only by the lock or lease owner, except XminAge, which each process reports once.

AttributeKeys lists every registered attribute key.

View Source
var DurationBoundaries = []float64{
	0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30, 60, 120, 300,
}

DurationBoundaries are the explicit buckets, in seconds, for duration histograms.

View Source
var EventCountBoundaries = []float64{1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 5000}

EventCountBoundaries are the explicit buckets for event-count histograms.

Instruments lists every registered instrument.

LogKeys lists every key of the fixed vocabulary.

Functions

func SpanCreate

func SpanCreate(streamType string) string

SpanCreate names the INTERNAL span of a Command that creates a Stream.

func SpanHandle

func SpanHandle(eventType string) string

SpanHandle names the INTERNAL span of one event within a batch.

func SpanInboxProcess

func SpanInboxProcess(source string) string

SpanInboxProcess names the CONSUMER span of one inbox message.

func SpanProcess

func SpanProcess(consumer string) string

SpanProcess names the CONSUMER root span of a consumer batch.

func SpanSchedulerRun

func SpanSchedulerRun(job string) string

SpanSchedulerRun names the root span of one scheduler job run.

func SpanSend

func SpanSend(streamType string) string

SpanSend names the PRODUCER span whose traceparent is stored on events.

func SpanUpdate

func SpanUpdate(streamType string) string

SpanUpdate names the INTERNAL span of a Command that updates a Stream.

Types

type Instrument

type Instrument struct {
	Name        string
	Unit        string
	Description string
	Boundaries  []float64
}

Instrument describes one metric instrument. Its methods create the instrument on a meter with the registered name, unit, description and, for histograms, explicit bucket boundaries. The boundaries only apply when the SDK is configured for explicit histograms.

func (Instrument) Float64Histogram

func (i Instrument) Float64Histogram(m metric.Meter) (metric.Float64Histogram, error)

Float64Histogram creates the instrument as a float64 histogram.

func (Instrument) Float64ObservableGauge

Float64ObservableGauge creates the instrument as an asynchronous float64 gauge. An owner-only gauge registers its callback only while the lock or lease is held, so a pod that loses it stops reporting the series.

func (Instrument) Int64Counter

func (i Instrument) Int64Counter(m metric.Meter) (metric.Int64Counter, error)

Int64Counter creates the instrument as an int64 counter.

func (Instrument) Int64Histogram

func (i Instrument) Int64Histogram(m metric.Meter) (metric.Int64Histogram, error)

Int64Histogram creates the instrument as an int64 histogram.

func (Instrument) Int64ObservableGauge

Int64ObservableGauge creates the instrument as an asynchronous int64 gauge. An owner-only gauge registers its callback only while the lock or lease is held, so a pod that loses it stops reporting the series.

func (Instrument) Int64UpDownCounter

func (i Instrument) Int64UpDownCounter(m metric.Meter) (metric.Int64UpDownCounter, error)

Int64UpDownCounter creates the instrument as an int64 up-down counter.

type Providers

type Providers struct {
	TracerProvider trace.TracerProvider
	MeterProvider  metric.MeterProvider
}

Providers holds the providers a package records with. A nil field falls back to the corresponding OTel global, resolved on every call. Public packages back their WithTracerProvider/WithMeterProvider options with it.

func (Providers) Meter

func (p Providers) Meter(scope string) metric.Meter

Meter returns the meter for scope, which must be the caller's package import path.

func (Providers) Tracer

func (p Providers) Tracer(scope string) trace.Tracer

Tracer returns the tracer for scope, which must be the caller's package import path.

Jump to

Keyboard shortcuts

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