Documentation
¶
Overview ¶
Package observability provides Prometheus metrics and structured logging for Cortex.
Index ¶
- func Debug(ctx context.Context, msg string, fields ...zap.Field)
- func Duration(key string, value time.Duration) zap.Field
- func Err(err error) zap.Field
- func Error(ctx context.Context, msg string, fields ...zap.Field)
- func Fatal(msg string, fields ...zap.Field)
- func Field(key string, value interface{}) zap.Field
- func Info(ctx context.Context, msg string, fields ...zap.Field)
- func InitLogger(level string, structured bool) error
- func InitMetrics(queueStats QueueStatsProvider)
- func InitTestLogger()
- func Int(key string, value int) zap.Field
- func LogOperation(ctx context.Context, primitive, action string, start time.Time, err error, ...)
- func String(key, value string) zap.Field
- func Warn(ctx context.Context, msg string, fields ...zap.Field)
- func WithEntityID(ctx context.Context, entityID string) context.Context
- func WithNamespace(ctx context.Context, namespace string) context.Context
- func WithRequestID(ctx context.Context, requestID string) context.Context
- func WithRunID(ctx context.Context, runID string) context.Context
- func WithThreadID(ctx context.Context, threadID string) context.Context
- type Logger
- type Metrics
- func (m *Metrics) RecordEmbedding(provider, model, status string, durationSeconds float64)
- func (m *Metrics) RecordExtraction(status string)
- func (m *Metrics) RecordOperation(primitive, action, namespace, status string, durationSeconds float64)
- func (m *Metrics) RecordSearch(primitive, namespace string, durationSeconds float64, resultCount int)
- func (m *Metrics) RecordStorageOperation(backend, operation string, durationSeconds float64)
- type MetricsServer
- type QueueStatsProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitLogger ¶
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 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 WithEntityID ¶
WithEntityID adds an entity ID to the context.
func WithNamespace ¶
WithNamespace adds a namespace to the context.
func WithRequestID ¶
WithRequestID adds a request ID to the context.
Types ¶
type Logger ¶
Logger wraps zap.Logger with context-aware logging methods.
var DefaultLogger *Logger
DefaultLogger is the global logger instance.
func (*Logger) WithContext ¶
WithContext returns a logger with fields extracted from the context.
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 ¶
RecordEmbedding records an embedding API call metric.
func (*Metrics) RecordExtraction ¶
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 ¶
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 ¶
QueueStatsProvider is an interface for getting extraction queue statistics.