trace

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Exporter

type Exporter interface {
	// Export writes a trace record to the configured destination.
	// Returns error if export fails.
	Export(ctx context.Context, record *TraceRecord) error

	// Close flushes any buffered records and releases resources.
	// Should be called during graceful shutdown.
	Close() error
}

Exporter defines the interface for exporting operation traces. Implementations must be safe for concurrent use.

func NewFileExporter

func NewFileExporter(filePath string, opts ...FileExporterOption) (Exporter, error)

NewFileExporter creates a file-based trace exporter. If filePath is empty, returns a no-op exporter that silently discards traces. The file is opened immediately and rotation is checked on each Export.

type FileExporter added in v1.3.0

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

FileExporter exports traces to a JSON Lines file with automatic rotation.

func (*FileExporter) Close added in v1.3.0

func (fe *FileExporter) Close() error

Close flushes and closes the trace file.

func (*FileExporter) Export added in v1.3.0

func (fe *FileExporter) Export(ctx context.Context, record *TraceRecord) error

Export writes a trace record as a JSON Lines entry. Checks for rotation after write.

type FileExporterOption

type FileExporterOption func(interface{})

FileExporterOption configures a FileExporter. This type is available in both tracing and non-tracing builds to maintain API compatibility.

func WithMaxRotatedFiles added in v1.3.0

func WithMaxRotatedFiles(count int) FileExporterOption

WithMaxRotatedFiles sets how many rotated files to keep (default: 5).

func WithMaxSize added in v1.3.0

func WithMaxSize(bytes int64) FileExporterOption

WithMaxSize sets the maximum file size before rotation (default: 10MB).

type NoopExporter

type NoopExporter struct{}

NoopExporter is used when filePath is empty - silently discards traces

func (*NoopExporter) Close

func (n *NoopExporter) Close() error

Close does nothing for noop exporter

func (*NoopExporter) Export

func (n *NoopExporter) Export(ctx context.Context, record *TraceRecord) error

Export does nothing for noop exporter

type SpanRecord

type SpanRecord struct {
	// Name is the stage name (chunk, embed, extract, write-graph, write-vector, search-vector, search-expand)
	Name string `json:"name"`

	// DurationMs is the stage duration in milliseconds
	DurationMs int64 `json:"durationMs"`

	// OK indicates success (true) or failure (false)
	OK bool `json:"ok"`

	// ErrorType classifies the error (if OK == false)
	ErrorType string `json:"errorType,omitempty"`

	// Counters provides stage-specific metrics (e.g., chunkCount, nodeUpserts)
	Counters map[string]int64 `json:"counters,omitempty"`
}

SpanRecord represents a single stage within an operation.

type TraceRecord

type TraceRecord struct {
	// Timestamp is the operation start time
	Timestamp time.Time `json:"timestamp"`

	// OperationID uniquely identifies this operation (for correlation)
	OperationID string `json:"operationId"`

	// Operation is the operation type: "cognify", "search", "add_memory"
	Operation string `json:"operation"`

	// DurationMs is the total operation duration in milliseconds
	DurationMs int64 `json:"durationMs"`

	// Status is "success" or "error"
	Status string `json:"status"`

	// Spans contains per-stage timing and status
	Spans []SpanRecord `json:"spans"`

	// ErrorType classifies the error (if Status == "error")
	// Values: network, timeout, llm, database, validation, unknown
	ErrorType string `json:"errorType,omitempty"`

	// IDs contains operation-specific identifiers (no content)
	IDs map[string]interface{} `json:"ids,omitempty"`
}

TraceRecord represents a sanitized operation trace ready for export. This structure contains NO sensitive data (no user payloads, API keys, memory content).

Jump to

Keyboard shortcuts

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