Help us shape the future of Go! Take the 2026 Go Developer Survey

trace

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Now

func Now() time.Time

Types

type Collector

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

Collector captures trace events and optionally forwards them to another Writer.

func NewCollector

func NewCollector(next Writer) *Collector

NewCollector returns a Collector that forwards events to next.

func (*Collector) Events

func (c *Collector) Events() []Event

Events returns all captured events.

func (*Collector) Write

func (c *Collector) Write(ctx context.Context, e Event)

Write appends the event and forwards it.

type Event

type Event struct {
	Timestamp time.Time   `json:"ts"`
	Type      EventType   `json:"type"`
	AgentID   string      `json:"agent_id"`
	Data      interface{} `json:"data,omitempty"`
}

func ParseLog

func ParseLog(r io.Reader) ([]Event, error)

ParseLog decodes newline-delimited JSON trace events from r.

type EventType

type EventType string
const (
	EventStepStart EventType = "step_start"
	// EventToolStart captures a tool invocation including parameters.
	EventToolStart  EventType = "tool_start"
	EventToolEnd    EventType = "tool_end"
	EventFinal      EventType = "final"
	EventModelStart EventType = "model_start"
	// EventToken represents a streaming token from the AI response
	EventToken EventType = "token"
	// EventYield is reserved; not used by default since agents run without iteration caps.
	EventYield EventType = "yield"
	// EventSummary indicates a run summary with token and cost statistics.
	EventSummary EventType = "summary"
)

type JSONLWriter

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

func NewJSONL

func NewJSONL(w io.Writer) *JSONLWriter

func (*JSONLWriter) Write

func (j *JSONLWriter) Write(_ context.Context, e Event)

type MultiWriter

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

MultiWriter dispatches events to multiple writers.

func NewMulti

func NewMulti(w ...Writer) *MultiWriter

func (*MultiWriter) Write

func (m *MultiWriter) Write(ctx context.Context, e Event)

type SSEWriter

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

func NewSSE

func NewSSE(w http.ResponseWriter) *SSEWriter

func (*SSEWriter) Write

func (s *SSEWriter) Write(_ context.Context, e Event)

type Summary

type Summary struct {
	InputTokens  int                        `json:"input_tokens"`
	OutputTokens int                        `json:"output_tokens"`
	TotalTokens  int                        `json:"total_tokens"`
	Cost         float64                    `json:"cost"`
	ModelUsage   map[string]cost.TokenUsage `json:"model_usage"`
}

Summary holds token usage and estimated cost for a run.

func Analyze

func Analyze(input string, events []Event) Summary

Analyze returns the token count and cost for an input and its trace events.

func AnalyzeFile

func AnalyzeFile(path string) (Summary, error)

AnalyzeFile loads a newline-delimited JSON trace log and returns the token usage summary. The input text is assumed to be empty.

type Writer

type Writer interface {
	Write(ctx context.Context, e Event)
}

Jump to

Keyboard shortcuts

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