observability

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package observability provides Prometheus metrics and structured logging for Cortex.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(ctx context.Context, msg string, fields ...zap.Field)

Debug logs a debug message with context fields.

func Duration

func Duration(key string, value time.Duration) zap.Field

Duration creates a duration zap field.

func Err

func Err(err error) zap.Field

Err creates an error zap field.

func Error

func Error(ctx context.Context, msg string, fields ...zap.Field)

Error logs an error message with context fields.

func Fatal

func Fatal(msg string, fields ...zap.Field)

Fatal logs a fatal message and exits.

func Field

func Field(key string, value interface{}) zap.Field

Field creates a zap field. This is a convenience wrapper around zap.Any.

func Info

func Info(ctx context.Context, msg string, fields ...zap.Field)

Info logs an info message with context fields.

func InitLogger

func InitLogger(level string, structured bool) error

InitLogger initializes the default logger with the given configuration. If structured is true, logs are emitted in JSON format. Level should be one of: debug, info, warn, error.

func InitMetrics

func InitMetrics(queueStats QueueStatsProvider)

InitMetrics initializes the default metrics instance.

func InitTestLogger

func InitTestLogger()

InitTestLogger initializes a no-op logger for testing.

func Int

func Int(key string, value int) zap.Field

Int creates an int zap field.

func LogOperation

func LogOperation(ctx context.Context, primitive, action string, start time.Time, err error, fields ...zap.Field)

LogOperation logs an operation with timing and context.

func String

func String(key, value string) zap.Field

String creates a string zap field.

func Warn

func Warn(ctx context.Context, msg string, fields ...zap.Field)

Warn logs a warning message with context fields.

func WithEntityID

func WithEntityID(ctx context.Context, entityID string) context.Context

WithEntityID adds an entity ID to the context.

func WithNamespace

func WithNamespace(ctx context.Context, namespace string) context.Context

WithNamespace adds a namespace to the context.

func WithRequestID

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

WithRequestID adds a request ID to the context.

func WithRunID

func WithRunID(ctx context.Context, runID string) context.Context

WithRunID adds a run ID to the context.

func WithThreadID

func WithThreadID(ctx context.Context, threadID string) context.Context

WithThreadID adds a thread ID to the context.

Types

type Logger

type Logger struct {
	*zap.Logger
}

Logger wraps zap.Logger with context-aware logging methods.

var DefaultLogger *Logger

DefaultLogger is the global logger instance.

func (*Logger) Sync

func (l *Logger) Sync() error

Sync flushes any buffered log entries.

func (*Logger) WithContext

func (l *Logger) WithContext(ctx context.Context) *zap.Logger

WithContext returns a logger with fields extracted from the context.

func (*Logger) WithFields

func (l *Logger) WithFields(fields ...zap.Field) *Logger

WithFields returns a logger with additional fields.

type Metrics

type Metrics struct {
	// Operations metrics
	OperationsTotal   *prometheus.CounterVec
	OperationDuration *prometheus.HistogramVec

	// Search metrics
	SearchLatency     *prometheus.HistogramVec
	SearchResultCount *prometheus.HistogramVec

	// Embedding metrics
	EmbeddingLatency      *prometheus.HistogramVec
	EmbeddingRequestTotal *prometheus.CounterVec

	// Entity extraction metrics
	ExtractionQueueSize       prometheus.GaugeFunc
	ExtractionDeadLetterCount prometheus.GaugeFunc
	ExtractionProcessedTotal  *prometheus.CounterVec

	// Storage metrics
	StorageOperationDuration *prometheus.HistogramVec
}

Metrics holds all Prometheus metrics for Cortex.

var DefaultMetrics *Metrics

DefaultMetrics is the global metrics instance used when metrics are enabled.

func NewMetrics

func NewMetrics(queueStats QueueStatsProvider) *Metrics

NewMetrics creates and registers all Prometheus metrics for Cortex. If queueStats is nil, queue metrics will report 0.

func (*Metrics) RecordEmbedding

func (m *Metrics) RecordEmbedding(provider, model, status string, durationSeconds float64)

RecordEmbedding records an embedding API call metric.

func (*Metrics) RecordExtraction

func (m *Metrics) RecordExtraction(status string)

RecordExtraction records an extraction processing metric.

func (*Metrics) RecordOperation

func (m *Metrics) RecordOperation(primitive, action, namespace, status string, durationSeconds float64)

RecordOperation records an operation metric.

func (*Metrics) RecordSearch

func (m *Metrics) RecordSearch(primitive, namespace string, durationSeconds float64, resultCount int)

RecordSearch records a search operation metric.

func (*Metrics) RecordStorageOperation

func (m *Metrics) RecordStorageOperation(backend, operation string, durationSeconds float64)

RecordStorageOperation records a storage backend operation metric.

type MetricsServer

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

MetricsServer serves Prometheus metrics over HTTP.

func NewMetricsServer

func NewMetricsServer(port int) *MetricsServer

NewMetricsServer creates a new metrics server on the specified port.

func (*MetricsServer) Port

func (s *MetricsServer) Port() int

Port returns the port the metrics server is listening on.

func (*MetricsServer) Shutdown

func (s *MetricsServer) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the metrics server.

func (*MetricsServer) Start

func (s *MetricsServer) Start()

Start starts the metrics server in the background. Returns immediately after starting.

type QueueStatsProvider

type QueueStatsProvider interface {
	GetQueueSize() int64
	GetDeadLetterCount() int64
}

QueueStatsProvider is an interface for getting extraction queue statistics.

Jump to

Keyboard shortcuts

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