trace

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package trace provides execution tracing and audit logging.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithParentSpan added in v0.3.0

func WithParentSpan(ctx context.Context, spanID string) context.Context

WithParentSpan adds a parent span ID to the context.

func WithTraceID added in v0.3.0

func WithTraceID(ctx context.Context, traceID string) context.Context

WithTraceID adds a trace ID to the context.

Types

type Collector

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

Collector records traces and audit events.

func NewCollector

func NewCollector(store storage.Storage) *Collector

func (*Collector) Audit

func (c *Collector) Audit(ctx context.Context, sessionID, actor, action, resource string) error

Audit records a security audit event.

func (*Collector) EndSpan

func (c *Collector) EndSpan(ctx context.Context, t *storage.Trace, output any, errMsg string) error

EndSpan completes a trace span.

func (*Collector) StartSpan

func (c *Collector) StartSpan(ctx context.Context, sessionID, name, kind string) (*storage.Trace, error)

StartSpan begins a new trace span.

type OTelCollector added in v0.3.0

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

OTelCollector collects OpenTelemetry-compatible spans and exports them to a configured endpoint. It supports proper parent-child relationships and attributes for agent, graph, tool, and model operations.

func NewOTelCollector added in v0.3.0

func NewOTelCollector(endpoint string) *OTelCollector

NewOTelCollector creates a new OTel-compatible span collector. endpoint is the OTLP endpoint to export spans to (empty = collect only, no export).

func (*OTelCollector) EndSpan added in v0.3.0

func (c *OTelCollector) EndSpan(span *OTelSpan, err error)

EndSpan completes a span, setting its end time and status.

func (*OTelCollector) Flush added in v0.3.0

func (c *OTelCollector) Flush() []*OTelSpan

Flush returns all spans and clears the collector.

func (*OTelCollector) SetEnabled added in v0.3.0

func (c *OTelCollector) SetEnabled(enabled bool)

SetEnabled enables or disables span collection.

func (*OTelCollector) Spans added in v0.3.0

func (c *OTelCollector) Spans() []*OTelSpan

Spans returns all collected spans.

func (*OTelCollector) StartSpan added in v0.3.0

func (c *OTelCollector) StartSpan(ctx context.Context, name, kind string, attrs map[string]any) *OTelSpan

StartSpan begins a new OTel span with the given name and kind.

type OTelSpan added in v0.3.0

type OTelSpan struct {
	TraceID    string         `json:"trace_id"`
	SpanID     string         `json:"span_id"`
	ParentID   string         `json:"parent_id,omitempty"`
	Name       string         `json:"name"`
	Kind       string         `json:"kind"` // agent, graph, tool, model
	Attributes map[string]any `json:"attributes,omitempty"`
	StartTime  time.Time      `json:"start_time"`
	EndTime    time.Time      `json:"end_time,omitempty"`
	Status     string         `json:"status"` // ok, error, unset
	Events     []SpanEvent    `json:"events,omitempty"`
}

OTelSpan represents an OpenTelemetry-compatible span.

func (*OTelSpan) AddEvent added in v0.3.0

func (span *OTelSpan) AddEvent(name string, attrs map[string]any)

AddEvent adds a timestamped event to a span.

type SpanEvent added in v0.3.0

type SpanEvent struct {
	Name       string         `json:"name"`
	Timestamp  time.Time      `json:"timestamp"`
	Attributes map[string]any `json:"attributes,omitempty"`
}

SpanEvent is a timestamped annotation on a span.

Jump to

Keyboard shortcuts

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