observe

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package observe provides observability integration for OmniRetrieve. It supports Phoenix, Opik, and Langfuse through a unified interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToContext

func ToContext(ctx context.Context, sc *SpanContext) context.Context

ToContext stores SpanContext in context.

Types

type NoOpObserver

type NoOpObserver struct{}

NoOpObserver is a no-op implementation of retrieve.Observer.

func (*NoOpObserver) OnGraphTraverse

func (n *NoOpObserver) OnGraphTraverse(_ context.Context, _ string, _ int, _ int, _ int64)

OnGraphTraverse implements retrieve.Observer.

func (*NoOpObserver) OnRerank

func (n *NoOpObserver) OnRerank(_ context.Context, _ string, _ int, _ int, _ int64)

OnRerank implements retrieve.Observer.

func (*NoOpObserver) OnRetrieveEnd

func (n *NoOpObserver) OnRetrieveEnd(_ context.Context, _ *retrieve.Result, _ error)

OnRetrieveEnd implements retrieve.Observer.

func (*NoOpObserver) OnRetrieveStart

func (n *NoOpObserver) OnRetrieveStart(ctx context.Context, _ retrieve.Query) context.Context

OnRetrieveStart implements retrieve.Observer.

func (*NoOpObserver) OnVectorSearch

func (n *NoOpObserver) OnVectorSearch(_ context.Context, _ string, _ int, _ int, _ int64)

OnVectorSearch implements retrieve.Observer.

type Observer

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

Observer implements retrieve.Observer with full tracing support.

func NewObserver

func NewObserver(cfg ObserverConfig) *Observer

NewObserver creates a new Observer.

func (*Observer) OnGraphTraverse

func (o *Observer) OnGraphTraverse(ctx context.Context, backend string, depth int, nodeCount int, latencyMS int64)

OnGraphTraverse implements retrieve.Observer.

func (*Observer) OnRerank

func (o *Observer) OnRerank(ctx context.Context, model string, inputCount int, outputCount int, latencyMS int64)

OnRerank implements retrieve.Observer.

func (*Observer) OnRetrieveEnd

func (o *Observer) OnRetrieveEnd(ctx context.Context, r *retrieve.Result, err error)

OnRetrieveEnd implements retrieve.Observer.

func (*Observer) OnRetrieveStart

func (o *Observer) OnRetrieveStart(ctx context.Context, q retrieve.Query) context.Context

OnRetrieveStart implements retrieve.Observer.

func (*Observer) OnVectorSearch

func (o *Observer) OnVectorSearch(ctx context.Context, backend string, topK int, resultCount int, latencyMS int64)

OnVectorSearch implements retrieve.Observer.

type ObserverConfig

type ObserverConfig struct {
	// Exporters to send spans to.
	Exporters []SpanExporter
	// Logger for observer errors.
	Logger *slog.Logger
}

ObserverConfig configures the Observer.

type Span

type Span struct {
	// ID is the unique span identifier.
	ID string
	// TraceID links spans in the same trace.
	TraceID string
	// ParentID is the parent span ID (empty for root).
	ParentID string
	// Type identifies the operation type.
	Type SpanType
	// Name is the human-readable span name.
	Name string
	// StartTime is when the span started.
	StartTime time.Time
	// EndTime is when the span ended.
	EndTime time.Time
	// Attributes are key-value pairs for this span.
	Attributes map[string]any
	// Artifacts are larger objects attached to this span.
	Artifacts map[string]any
	// Status indicates success or failure.
	Status SpanStatus
	// Error contains error details if Status is Error.
	Error string
}

Span represents a traced operation.

type SpanContext

type SpanContext struct {
	TraceID  string
	SpanID   string
	ParentID string
}

SpanContext holds the current span information in context.

func FromContext

func FromContext(ctx context.Context) *SpanContext

FromContext extracts SpanContext from context.

type SpanExporter

type SpanExporter interface {
	// Export sends spans to the backend.
	Export(ctx context.Context, spans []Span) error
	// Name returns the exporter name.
	Name() string
}

SpanExporter exports spans to an observability backend.

type SpanStatus

type SpanStatus string

SpanStatus indicates the outcome of a span.

const (
	SpanStatusOK    SpanStatus = "ok"
	SpanStatusError SpanStatus = "error"
)

type SpanType

type SpanType string

SpanType identifies the type of operation being traced.

const (
	SpanTypeRetrieval     SpanType = "retrieval"
	SpanTypeVectorSearch  SpanType = "retrieve.vector.search"
	SpanTypeGraphTraverse SpanType = "retrieve.graph.traverse"
	SpanTypeHybridMerge   SpanType = "retrieve.hybrid.merge"
	SpanTypeRerank        SpanType = "retrieve.rerank"
)

Jump to

Keyboard shortcuts

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