observability

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package observability owns logging, metrics, and tracing setup.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(cfg LogConfig) *slog.Logger

func LoggerFrom

func LoggerFrom(ctx context.Context) *slog.Logger

func RequestIDFromContext

func RequestIDFromContext(ctx context.Context) (string, bool)

func WithLogger

func WithLogger(ctx context.Context, logger *slog.Logger) context.Context

func WithRequestID

func WithRequestID(ctx context.Context, id string) context.Context

Types

type LogConfig

type LogConfig struct {
	Level  slog.Level
	Format string // "auto" | "tty" | "json"
	Output io.Writer
}

type Metrics

type Metrics struct {
	Registry *prometheus.Registry

	// Append path
	EventsAppended *prometheus.CounterVec
	AppendDuration prometheus.Histogram
	AppendRetries  prometheus.Counter
	AppendFailures *prometheus.CounterVec

	// Projectors
	ProjectorApplyDuration *prometheus.HistogramVec
	ProjectorFailures      *prometheus.CounterVec
	ProjectorLag           *prometheus.GaugeVec
	ProjectorCatchup       *prometheus.GaugeVec

	// Tailer
	TailerLag       prometheus.Gauge
	TailerBatchSize prometheus.Histogram

	// Subscriptions
	SubscriptionActive    *prometheus.GaugeVec
	SubscriptionDelivered *prometheus.CounterVec
	SubscriptionDropped   *prometheus.CounterVec
	SubscriptionBuffered  *prometheus.GaugeVec
	SubscriptionCatchup   *prometheus.HistogramVec

	// Snapshots
	SnapshotDuration   *prometheus.HistogramVec
	SnapshotSize       *prometheus.GaugeVec
	SnapshotLastPos    *prometheus.GaugeVec
	SnapshotCorruption *prometheus.CounterVec

	// Storage
	SQLiteWALBytes    prometheus.Gauge
	SQLiteEventsTotal prometheus.Gauge
	SQLiteBusyRetries prometheus.Counter

	// Startup
	StartupPhase          prometheus.Gauge
	StartupDuration       prometheus.Histogram
	ReplayEventsProcessed prometheus.Counter
	RecoveryModeEntered   prometheus.Counter

	// Health
	BuildInfo *prometheus.GaugeVec
	Uptime    prometheus.GaugeFunc

	// Carport (driver subsystem)
	CarportDriverInstances        *prometheus.GaugeVec
	CarportHandshakesTotal        *prometheus.CounterVec
	CarportCommandDispatchTotal   *prometheus.CounterVec
	CarportCommandDispatchSeconds *prometheus.HistogramVec
	CarportEventsIngestedTotal    *prometheus.CounterVec
	CarportDriverRestartsTotal    *prometheus.CounterVec
	CarportHealthProbeSeconds     *prometheus.HistogramVec
	CarportStreamMessagesTotal    *prometheus.CounterVec
	CarportPendingCommands        *prometheus.GaugeVec

	// Automation + script (C6)
	AutomationTriggersTotal       *prometheus.CounterVec
	AutomationRunsTotal           *prometheus.CounterVec
	AutomationConditionsTotal     *prometheus.CounterVec
	AutomationActionsTotal        *prometheus.CounterVec
	AutomationReloadFailuresTotal prometheus.Counter
	ScriptInvocationsTotal        *prometheus.CounterVec

	AutomationRunDurationSeconds *prometheus.HistogramVec
	AutomationStarlarkSteps      *prometheus.HistogramVec
	ScriptDurationSeconds        *prometheus.HistogramVec

	AutomationInflight   *prometheus.GaugeVec
	AutomationRegistered prometheus.Gauge
	ScriptRegistered     prometheus.Gauge

	// API (C7)
	APIRequestsTotal                 *prometheus.CounterVec
	APIRequestDurationSeconds        *prometheus.HistogramVec
	APIStreamEventsSentTotal         *prometheus.CounterVec
	APIStreamHeartbeatsSentTotal     *prometheus.CounterVec
	APIStreamBackpressureClosesTotal *prometheus.CounterVec
	APIWebhookReceivedTotal          *prometheus.CounterVec
	APIActiveStreams                 *prometheus.GaugeVec

	// MCP (C8)
	MCPToolCallsTotal              *prometheus.CounterVec
	MCPToolCallDuration            *prometheus.HistogramVec
	MCPResourceSubscriptionsActive *prometheus.GaugeVec
	MCPResourceUpdatesSent         *prometheus.CounterVec
	MCPResourceOverflowCloses      *prometheus.CounterVec
	MCPEvalStarlarkTruncated       prometheus.Counter
	MCPConfigFileWrites            *prometheus.CounterVec

	// Auth + Policy (C9)
	AuthLoginAttemptsTotal   *prometheus.CounterVec
	AuthLoginDurationSeconds *prometheus.HistogramVec
	// AuthActiveSessions counts active cookie sessions; wired by sessions.Store on issue/expire.
	AuthActiveSessions prometheus.Gauge
	// AuthActiveTokens counts non-revoked, non-expired tokens; wired by credentials.Tokens on issue/revoke.
	AuthActiveTokens               prometheus.Gauge
	AuthThrottleBlocksTotal        *prometheus.CounterVec
	PolicyCompileDurationSeconds   prometheus.Histogram
	PolicyCompileGeneration        prometheus.Gauge
	PolicyAuthorizeTotal           *prometheus.CounterVec
	PolicyAuthorizeDurationSeconds prometheus.Histogram
}

func NewMetrics

func NewMetrics() *Metrics

func (*Metrics) HTTPHandler

func (m *Metrics) HTTPHandler() http.Handler

func (*Metrics) ServeMetrics

func (m *Metrics) ServeMetrics(ctx context.Context, addr string, healthFn func() (string, int)) error

ServeMetrics runs an HTTP server exposing /metrics and /health until ctx is cancelled. healthFn returns (status, httpCode).

func (*Metrics) SetBuildInfo

func (m *Metrics) SetBuildInfo(version, commit, goVersion string)

type Span

type Span interface {
	End()
	SetAttr(key string, value any)
	RecordError(err error)
}

Span is the minimal tracing surface. C1 ships a no-op implementation; C13 replaces this with an OpenTelemetry bridge — call sites do not change.

func StartSpan

func StartSpan(ctx context.Context, _ string) (context.Context, Span)

Jump to

Keyboard shortcuts

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