detailed_logging

package
v0.0.0-...-8ed2a29 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateDuration

func CalculateDuration(start time.Time, end *time.Time) int64

Helper function to calculate duration

func InstallGlobalInterceptor

func InstallGlobalInterceptor(logger *DetailedLogger)

InstallGlobalInterceptor replaces http.DefaultTransport

func NewID

func NewID() string

Helper function to generate IDs

func NewLoggingProvider

func NewLoggingProvider(provider provider.Provider, providerName string, logger *DetailedLogger) provider.Provider

NewLoggingProvider creates a new logging provider wrapper

Types

type DetailedLogger

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

DetailedLogger is the main coordinator for detailed logging

func NewDetailedLogger

func NewDetailedLogger(enabled bool) (*DetailedLogger, error)

NewDetailedLogger creates a new detailed logger instance

func (*DetailedLogger) Close

func (dl *DetailedLogger) Close() error

Close cleans up resources

func (*DetailedLogger) EndSession

func (dl *DetailedLogger) EndSession()

EndSession marks the session as complete

func (*DetailedLogger) EndToolCall

func (dl *DetailedLogger) EndToolCall(id string, output interface{}, err error)

EndToolCall completes tracking of a tool call

func (*DetailedLogger) GetCurrentLLMCall

func (dl *DetailedLogger) GetCurrentLLMCall() string

GetCurrentLLMCall returns the current LLM call ID

func (*DetailedLogger) GetCurrentToolCall

func (dl *DetailedLogger) GetCurrentToolCall() string

GetCurrentToolCall returns the current tool call ID

func (*DetailedLogger) GetToolTracker

func (dl *DetailedLogger) GetToolTracker() *ToolTracker

GetToolTracker returns the tool tracker instance

func (*DetailedLogger) IsEnabled

func (dl *DetailedLogger) IsEnabled() bool

IsEnabled returns whether detailed logging is enabled

func (*DetailedLogger) LogHTTP

func (dl *DetailedLogger) LogHTTP(call *HTTPLog)

LogHTTP logs an HTTP request/response

func (*DetailedLogger) LogLLMCall

func (dl *DetailedLogger) LogLLMCall(call *LLMCallLog)

LogLLMCall logs an LLM API call

func (*DetailedLogger) LogToolCall

func (dl *DetailedLogger) LogToolCall(call *ToolCallLog)

LogToolCall logs a tool invocation

func (*DetailedLogger) SetCommandArgs

func (dl *DetailedLogger) SetCommandArgs(args []string)

SetCommandArgs sets the command arguments for the session

func (*DetailedLogger) SetCurrentLLMCall

func (dl *DetailedLogger) SetCurrentLLMCall(callID string)

SetCurrentLLMCall sets the current LLM call context

func (*DetailedLogger) SetMetadata

func (dl *DetailedLogger) SetMetadata(key, value string)

SetMetadata adds metadata to the session

func (*DetailedLogger) StartToolCall

func (dl *DetailedLogger) StartToolCall(name string, input map[string]interface{}) string

StartToolCall begins tracking a tool call

type HTTPInterceptor

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

HTTPInterceptor wraps http.RoundTripper to log requests/responses

func NewHTTPInterceptor

func NewHTTPInterceptor(transport http.RoundTripper, logger *DetailedLogger) *HTTPInterceptor

NewHTTPInterceptor creates a new HTTP interceptor

func (*HTTPInterceptor) RoundTrip

func (h *HTTPInterceptor) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper

type HTTPLog

type HTTPLog struct {
	ID              string              `json:"id"`
	SessionID       string              `json:"session_id"`
	Method          string              `json:"method"`
	URL             string              `json:"url"`
	Headers         map[string][]string `json:"headers"`
	Body            interface{}         `json:"body,omitempty"`
	StatusCode      int                 `json:"status_code,omitempty"`
	ResponseBody    interface{}         `json:"response_body,omitempty"`
	ResponseHeaders map[string][]string `json:"response_headers,omitempty"`
	StartTime       time.Time           `json:"start_time"`
	EndTime         *time.Time          `json:"end_time,omitempty"`
	DurationMs      int64               `json:"duration_ms"`
	Error           string              `json:"error,omitempty"`
	ParentToolCall  string              `json:"parent_tool_call,omitempty"`
}

HTTPLog represents an HTTP request/response

type LLMCallLog

type LLMCallLog struct {
	ID             string                 `json:"id"`
	SessionID      string                 `json:"session_id"`
	Provider       string                 `json:"provider"`
	Model          string                 `json:"model"`
	StartTime      time.Time              `json:"start_time"`
	EndTime        *time.Time             `json:"end_time,omitempty"`
	Request        map[string]interface{} `json:"request"`
	Response       map[string]interface{} `json:"response,omitempty"`
	StreamEvents   []StreamEvent          `json:"stream_events,omitempty"`
	Error          string                 `json:"error,omitempty"`
	TokensUsed     *TokenUsage            `json:"tokens_used,omitempty"`
	Cost           *float64               `json:"cost,omitempty"`
	DurationMs     int64                  `json:"duration_ms"`
	ParentToolCall string                 `json:"parent_tool_call,omitempty"`
}

LLMCallLog represents a single LLM API call

type LoggingProvider

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

LoggingProvider wraps an LLM provider to add logging

func (*LoggingProvider) Model

func (lp *LoggingProvider) Model() models.Model

Model returns the underlying model

func (*LoggingProvider) SendMessages

func (lp *LoggingProvider) SendMessages(ctx context.Context, messages []message.Message, tools []tools.BaseTool) (*provider.ProviderResponse, error)

SendMessages implements the Provider interface

func (*LoggingProvider) StreamResponse

func (lp *LoggingProvider) StreamResponse(ctx context.Context, messages []message.Message, tools []tools.BaseTool) <-chan provider.ProviderEvent

StreamResponse implements the Provider interface

type SessionFilters

type SessionFilters struct {
	StartTime *time.Time
	EndTime   *time.Time
	HasError  *bool
	Limit     int
}

SessionFilters defines filters for listing sessions

type SessionLog

type SessionLog struct {
	ID          string            `json:"id"`
	StartTime   time.Time         `json:"start_time"`
	EndTime     *time.Time        `json:"end_time,omitempty"`
	Metadata    map[string]string `json:"metadata"`
	LLMCalls    []LLMCallLog      `json:"llm_calls"`
	ToolCalls   []ToolCallLog     `json:"tool_calls"`
	HTTPCalls   []HTTPLog         `json:"http_calls"`
	CommandArgs []string          `json:"command_args"`
	UserID      string            `json:"user_id,omitempty"`
}

SessionLog represents a complete session with all its data

type Storage

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

Storage handles persisting session logs

func NewStorage

func NewStorage(dataDir string) (*Storage, error)

NewStorage creates a new storage instance

func (*Storage) Close

func (s *Storage) Close() error

Close closes the storage

func (*Storage) DeleteOldSessions

func (s *Storage) DeleteOldSessions(retentionDays int) error

DeleteOldSessions removes sessions older than the retention period

func (*Storage) ListSessions

func (s *Storage) ListSessions(filters SessionFilters) ([]StorageMetadata, error)

ListSessions returns session metadata based on filters

func (*Storage) LoadSession

func (s *Storage) LoadSession(sessionID string) (*SessionLog, error)

LoadSession retrieves a session by ID

func (*Storage) SaveSession

func (s *Storage) SaveSession(session *SessionLog) error

SaveSession persists a complete session log

type StorageMetadata

type StorageMetadata struct {
	ID            string     `db:"id"`
	SessionID     string     `db:"session_id"`
	StartTime     time.Time  `db:"start_time"`
	EndTime       *time.Time `db:"end_time"`
	LLMCallCount  int        `db:"llm_call_count"`
	ToolCallCount int        `db:"tool_call_count"`
	HTTPCallCount int        `db:"http_call_count"`
	TotalTokens   int        `db:"total_tokens"`
	TotalCost     float64    `db:"total_cost"`
	HasError      bool       `db:"has_error"`
}

StorageMetadata is stored in SQLite for quick queries

type StreamEvent

type StreamEvent struct {
	Type      string                 `json:"type"`
	Data      map[string]interface{} `json:"data"`
	Timestamp time.Time              `json:"timestamp"`
}

StreamEvent represents a single streaming event

type TokenUsage

type TokenUsage struct {
	Prompt     int `json:"prompt"`
	Completion int `json:"completion"`
	Total      int `json:"total"`
}

TokenUsage tracks token consumption

type ToolCallLog

type ToolCallLog struct {
	ID            string                 `json:"id"`
	SessionID     string                 `json:"session_id"`
	Name          string                 `json:"name"`
	StartTime     time.Time              `json:"start_time"`
	EndTime       *time.Time             `json:"end_time,omitempty"`
	Input         map[string]interface{} `json:"input"`
	Output        interface{}            `json:"output,omitempty"`
	Error         string                 `json:"error,omitempty"`
	DurationMs    int64                  `json:"duration_ms"`
	ParentID      string                 `json:"parent_id,omitempty"`
	ChildIDs      []string               `json:"child_ids,omitempty"`
	ParentLLMCall string                 `json:"parent_llm_call,omitempty"`
}

ToolCallLog represents a tool invocation

type ToolTracker

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

ToolTracker manages hierarchical tool call tracking

func NewToolTracker

func NewToolTracker(sessionID string, logger *DetailedLogger) *ToolTracker

NewToolTracker creates a new tool tracker

func (*ToolTracker) EndToolCall

func (tt *ToolTracker) EndToolCall(id string, output interface{}, err error)

EndToolCall completes tracking of a tool call

func (*ToolTracker) GetActiveCallStack

func (tt *ToolTracker) GetActiveCallStack() []string

GetActiveCallStack returns the current call stack

func (*ToolTracker) GetCurrentToolCall

func (tt *ToolTracker) GetCurrentToolCall() string

GetCurrentToolCall returns the ID of the currently active tool call

func (*ToolTracker) GetToolCall

func (tt *ToolTracker) GetToolCall(id string) *ToolCallLog

GetToolCall retrieves a tool call by ID

func (*ToolTracker) StartToolCall

func (tt *ToolTracker) StartToolCall(name string, input map[string]interface{}) string

StartToolCall begins tracking a new tool call

Jump to

Keyboard shortcuts

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