Documentation
¶
Overview ¶
Package logstore provides a logs store for Bifrost.
Index ¶
- Variables
- type CleanerConfig
- type Config
- type CostHistogramBucket
- type CostHistogramResult
- type HistogramBucket
- type HistogramResult
- type Log
- type LogRetentionManager
- type LogStore
- type LogStoreType
- type LogsCleaner
- type MCPToolLog
- type MCPToolLogSearchFilters
- type MCPToolLogSearchResult
- type MCPToolLogStats
- type ModelHistogramBucket
- type ModelHistogramResult
- type ModelUsageStats
- type PaginationOptions
- type PostgresConfig
- type RDBLogStore
- func (s *RDBLogStore) BulkUpdateCost(ctx context.Context, updates map[string]float64) error
- func (s *RDBLogStore) Close(ctx context.Context) error
- func (s *RDBLogStore) Create(ctx context.Context, entry *Log) error
- func (s *RDBLogStore) CreateIfNotExists(ctx context.Context, entry *Log) error
- func (s *RDBLogStore) CreateMCPToolLog(ctx context.Context, entry *MCPToolLog) error
- func (s *RDBLogStore) DeleteLog(ctx context.Context, id string) error
- func (s *RDBLogStore) DeleteLogs(ctx context.Context, ids []string) error
- func (s *RDBLogStore) DeleteLogsBatch(ctx context.Context, cutoff time.Time, batchSize int) (deletedCount int64, err error)
- func (s *RDBLogStore) DeleteMCPToolLogs(ctx context.Context, ids []string) error
- func (s *RDBLogStore) FindAll(ctx context.Context, query any, fields ...string) ([]*Log, error)
- func (s *RDBLogStore) FindByID(ctx context.Context, id string) (*Log, error)
- func (s *RDBLogStore) FindFirst(ctx context.Context, query any, fields ...string) (*Log, error)
- func (s *RDBLogStore) FindMCPToolLog(ctx context.Context, id string) (*MCPToolLog, error)
- func (s *RDBLogStore) Flush(ctx context.Context, since time.Time) error
- func (s *RDBLogStore) FlushMCPToolLogs(ctx context.Context, since time.Time) error
- func (s *RDBLogStore) GetAvailableMCPVirtualKeys(ctx context.Context) ([]MCPToolLog, error)
- func (s *RDBLogStore) GetAvailableServerLabels(ctx context.Context) ([]string, error)
- func (s *RDBLogStore) GetAvailableToolNames(ctx context.Context) ([]string, error)
- func (s *RDBLogStore) GetCostHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*CostHistogramResult, error)
- func (s *RDBLogStore) GetHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*HistogramResult, error)
- func (s *RDBLogStore) GetMCPToolLogStats(ctx context.Context, filters MCPToolLogSearchFilters) (*MCPToolLogStats, error)
- func (s *RDBLogStore) GetModelHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ModelHistogramResult, error)
- func (s *RDBLogStore) GetStats(ctx context.Context, filters SearchFilters) (*SearchStats, error)
- func (s *RDBLogStore) GetTokenHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*TokenHistogramResult, error)
- func (s *RDBLogStore) HasLogs(ctx context.Context) (bool, error)
- func (s *RDBLogStore) HasMCPToolLogs(ctx context.Context) (bool, error)
- func (s *RDBLogStore) Ping(ctx context.Context) error
- func (s *RDBLogStore) SearchLogs(ctx context.Context, filters SearchFilters, pagination PaginationOptions) (*SearchResult, error)
- func (s *RDBLogStore) SearchMCPToolLogs(ctx context.Context, filters MCPToolLogSearchFilters, ...) (*MCPToolLogSearchResult, error)
- func (s *RDBLogStore) Update(ctx context.Context, id string, entry any) error
- func (s *RDBLogStore) UpdateMCPToolLog(ctx context.Context, id string, entry any) error
- type SQLiteConfig
- type SearchFilters
- type SearchResult
- type SearchStats
- type SortBy
- type SortOrder
- type TokenHistogramBucket
- type TokenHistogramResult
Constants ¶
This section is empty.
Variables ¶
var (
ErrNotFound = fmt.Errorf("log not found")
)
Functions ¶
This section is empty.
Types ¶
type CleanerConfig ¶ added in v1.1.36
type CleanerConfig struct {
RetentionDays int
}
CleanerConfig holds configuration for the log cleaner
type Config ¶
type Config struct {
Enabled bool `json:"enabled"`
Type LogStoreType `json:"type"`
RetentionDays int `json:"retention_days"`
Config any `json:"config"`
}
Config represents the configuration for the logs store.
func (*Config) UnmarshalJSON ¶
UnmarshalJSON is the custom unmarshal logic for Config
type CostHistogramBucket ¶ added in v1.2.13
type CostHistogramBucket struct {
Timestamp time.Time `json:"timestamp"`
TotalCost float64 `json:"total_cost"`
ByModel map[string]float64 `json:"by_model"`
}
CostHistogramBucket represents a single time bucket for cost data
type CostHistogramResult ¶ added in v1.2.13
type CostHistogramResult struct {
Buckets []CostHistogramBucket `json:"buckets"`
BucketSizeSeconds int64 `json:"bucket_size_seconds"`
Models []string `json:"models"`
}
CostHistogramResult represents the cost histogram query result
type HistogramBucket ¶ added in v1.2.13
type HistogramBucket struct {
Timestamp time.Time `json:"timestamp"`
Count int64 `json:"count"`
Success int64 `json:"success"`
Error int64 `json:"error"`
}
HistogramBucket represents a single time bucket in the histogram
type HistogramResult ¶ added in v1.2.13
type HistogramResult struct {
Buckets []HistogramBucket `json:"buckets"`
BucketSizeSeconds int64 `json:"bucket_size_seconds"`
}
HistogramResult represents the histogram query result
type Log ¶
type Log struct {
ID string `gorm:"primaryKey;type:varchar(255)" json:"id"`
ParentRequestID *string `gorm:"type:varchar(255)" json:"parent_request_id"`
Timestamp time.Time `gorm:"index;not null" json:"timestamp"`
Object string `gorm:"type:varchar(255);index;not null;column:object_type" json:"object"` // text.completion, chat.completion, or embedding
Provider string `gorm:"type:varchar(255);index;not null" json:"provider"`
Model string `gorm:"type:varchar(255);index;not null" json:"model"`
NumberOfRetries int `gorm:"default:0" json:"number_of_retries"`
FallbackIndex int `gorm:"default:0" json:"fallback_index"`
SelectedKeyID string `gorm:"type:varchar(255);index:idx_logs_selected_key_id" json:"selected_key_id"`
SelectedKeyName string `gorm:"type:varchar(255)" json:"selected_key_name"`
VirtualKeyID *string `gorm:"type:varchar(255);index:idx_logs_virtual_key_id" json:"virtual_key_id"`
VirtualKeyName *string `gorm:"type:varchar(255)" json:"virtual_key_name"`
RoutingEngineUsed *string `gorm:"type:varchar(255);index:idx_logs_routing_engine_used" json:"routing_engine_used"`
RoutingRuleID *string `gorm:"type:varchar(255);index:idx_logs_routing_rule_id" json:"routing_rule_id"`
RoutingRuleName *string `gorm:"type:varchar(255)" json:"routing_rule_name"`
InputHistory string `gorm:"type:text" json:"-"` // JSON serialized []schemas.ChatMessage
ResponsesInputHistory string `gorm:"type:text" json:"-"` // JSON serialized []schemas.ResponsesMessage
OutputMessage string `gorm:"type:text" json:"-"` // JSON serialized *schemas.ChatMessage
ResponsesOutput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.ResponsesMessage
EmbeddingOutput string `gorm:"type:text" json:"-"` // JSON serialized [][]float32
Params string `gorm:"type:text" json:"-"` // JSON serialized *schemas.ModelParameters
Tools string `gorm:"type:text" json:"-"` // JSON serialized []schemas.Tool
ToolCalls string `gorm:"type:text" json:"-"` // JSON serialized []schemas.ToolCall (For backward compatibility, tool calls are now in the content)
SpeechInput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.SpeechInput
TranscriptionInput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.TranscriptionInput
ImageGenerationInput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.ImageGenerationInput
SpeechOutput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostSpeech
TranscriptionOutput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostTranscribe
ImageGenerationOutput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostImageGenerationResponse
CacheDebug string `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostCacheDebug
Latency *float64 `gorm:"index:idx_logs_latency" json:"latency,omitempty"`
TokenUsage string `gorm:"type:text" json:"-"` // JSON serialized *schemas.LLMUsage
Cost *float64 `gorm:"index" json:"cost,omitempty"` // Cost in dollars (total cost of the request - includes cache lookup cost)
Status string `gorm:"type:varchar(50);index;not null" json:"status"` // "processing", "success", or "error"
ErrorDetails string `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostError
Stream bool `gorm:"default:false" json:"stream"` // true if this was a streaming response
ContentSummary string `gorm:"type:text" json:"-"`
RawRequest string `gorm:"type:text" json:"raw_request"` // Populated when `send-back-raw-request` is on
RawResponse string `gorm:"type:text" json:"raw_response"` // Populated when `send-back-raw-response` is on
// Denormalized token fields for easier querying
PromptTokens int `gorm:"default:0" json:"-"`
CompletionTokens int `gorm:"default:0" json:"-"`
TotalTokens int `gorm:"index:idx_logs_total_tokens;default:0" json:"-"`
CreatedAt time.Time `gorm:"index;not null" json:"created_at"`
// Virtual fields for JSON output - these will be populated when needed
InputHistoryParsed []schemas.ChatMessage `gorm:"-" json:"input_history,omitempty"`
ResponsesInputHistoryParsed []schemas.ResponsesMessage `gorm:"-" json:"responses_input_history,omitempty"`
OutputMessageParsed *schemas.ChatMessage `gorm:"-" json:"output_message,omitempty"`
ResponsesOutputParsed []schemas.ResponsesMessage `gorm:"-" json:"responses_output,omitempty"`
EmbeddingOutputParsed []schemas.EmbeddingData `gorm:"-" json:"embedding_output,omitempty"`
ParamsParsed interface{} `gorm:"-" json:"params,omitempty"`
ToolsParsed []schemas.ChatTool `gorm:"-" json:"tools,omitempty"`
ToolCallsParsed []schemas.ChatAssistantMessageToolCall `gorm:"-" json:"tool_calls,omitempty"` // For backward compatibility, tool calls are now in the content
TokenUsageParsed *schemas.BifrostLLMUsage `gorm:"-" json:"token_usage,omitempty"`
ErrorDetailsParsed *schemas.BifrostError `gorm:"-" json:"error_details,omitempty"`
SpeechInputParsed *schemas.SpeechInput `gorm:"-" json:"speech_input,omitempty"`
TranscriptionInputParsed *schemas.TranscriptionInput `gorm:"-" json:"transcription_input,omitempty"`
ImageGenerationInputParsed *schemas.ImageGenerationInput `gorm:"-" json:"image_generation_input,omitempty"`
SpeechOutputParsed *schemas.BifrostSpeechResponse `gorm:"-" json:"speech_output,omitempty"`
TranscriptionOutputParsed *schemas.BifrostTranscriptionResponse `gorm:"-" json:"transcription_output,omitempty"`
ImageGenerationOutputParsed *schemas.BifrostImageGenerationResponse `gorm:"-" json:"image_generation_output,omitempty"`
CacheDebugParsed *schemas.BifrostCacheDebug `gorm:"-" json:"cache_debug,omitempty"`
// Populated in handlers after find using the virtual key id and key id
VirtualKey *tables.TableVirtualKey `gorm:"-" json:"virtual_key,omitempty"` // redacted
SelectedKey *schemas.Key `gorm:"-" json:"selected_key,omitempty"` // redacted
RoutingRule *tables.TableRoutingRule `gorm:"-" json:"routing_rule,omitempty"` // redacted
}
Log represents a complete log entry for a request/response cycle This is the GORM model with appropriate tags
func NewLogEntryFromMap ¶ added in v1.2.9
NewLogEntryFromMap creates a new Log from a map[string]interface{}
func (*Log) BeforeCreate ¶
BeforeCreate GORM hook to set created_at and serialize JSON fields
func (*Log) BeforeSave ¶
BeforeSave GORM hook to serialize JSON fields
func (*Log) BuildContentSummary ¶
BuildContentSummary creates a searchable text summary
func (*Log) DeserializeFields ¶
DeserializeFields converts JSON strings back to Go structs
func (*Log) SerializeFields ¶
SerializeFields converts Go structs to JSON strings for storage
type LogRetentionManager ¶ added in v1.1.36
type LogRetentionManager interface {
DeleteLogsBatch(ctx context.Context, cutoff time.Time, batchSize int) (deletedCount int64, err error)
}
LogRetentionManager defines the interface for managing log retention and deletion
type LogStore ¶
type LogStore interface {
Ping(ctx context.Context) error
Create(ctx context.Context, entry *Log) error
CreateIfNotExists(ctx context.Context, entry *Log) error
FindByID(ctx context.Context, id string) (*Log, error)
FindFirst(ctx context.Context, query any, fields ...string) (*Log, error)
FindAll(ctx context.Context, query any, fields ...string) ([]*Log, error)
HasLogs(ctx context.Context) (bool, error)
SearchLogs(ctx context.Context, filters SearchFilters, pagination PaginationOptions) (*SearchResult, error)
GetStats(ctx context.Context, filters SearchFilters) (*SearchStats, error)
GetHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*HistogramResult, error)
GetTokenHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*TokenHistogramResult, error)
GetCostHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*CostHistogramResult, error)
GetModelHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ModelHistogramResult, error)
Update(ctx context.Context, id string, entry any) error
BulkUpdateCost(ctx context.Context, updates map[string]float64) error
Flush(ctx context.Context, since time.Time) error
Close(ctx context.Context) error
DeleteLog(ctx context.Context, id string) error
DeleteLogs(ctx context.Context, ids []string) error
DeleteLogsBatch(ctx context.Context, cutoff time.Time, batchSize int) (deletedCount int64, err error)
// MCP Tool Log methods
CreateMCPToolLog(ctx context.Context, entry *MCPToolLog) error
FindMCPToolLog(ctx context.Context, id string) (*MCPToolLog, error)
UpdateMCPToolLog(ctx context.Context, id string, entry any) error
SearchMCPToolLogs(ctx context.Context, filters MCPToolLogSearchFilters, pagination PaginationOptions) (*MCPToolLogSearchResult, error)
GetMCPToolLogStats(ctx context.Context, filters MCPToolLogSearchFilters) (*MCPToolLogStats, error)
HasMCPToolLogs(ctx context.Context) (bool, error)
DeleteMCPToolLogs(ctx context.Context, ids []string) error
FlushMCPToolLogs(ctx context.Context, since time.Time) error
GetAvailableToolNames(ctx context.Context) ([]string, error)
GetAvailableServerLabels(ctx context.Context) ([]string, error)
GetAvailableMCPVirtualKeys(ctx context.Context) ([]MCPToolLog, error)
}
LogStore is the interface for the log store.
type LogStoreType ¶
type LogStoreType string
LogStoreType represents the type of log store.
const ( LogStoreTypeSQLite LogStoreType = "sqlite" LogStoreTypePostgres LogStoreType = "postgres" )
LogStoreTypeSQLite is the type of log store for SQLite.
type LogsCleaner ¶ added in v1.1.36
type LogsCleaner struct {
// contains filtered or unexported fields
}
LogsCleaner manages the cleanup of old logs
func NewLogsCleaner ¶ added in v1.1.36
func NewLogsCleaner(manager LogRetentionManager, config CleanerConfig, logger schemas.Logger) *LogsCleaner
NewLogsCleaner creates a new LogsCleaner instance
func (*LogsCleaner) StartCleanupRoutine ¶ added in v1.1.36
func (c *LogsCleaner) StartCleanupRoutine()
StartCleanupRoutine starts a goroutine that periodically cleans up old logs
func (*LogsCleaner) StopCleanupRoutine ¶ added in v1.1.36
func (c *LogsCleaner) StopCleanupRoutine()
StopCleanupRoutine gracefully stops the cleanup goroutine
type MCPToolLog ¶ added in v1.2.17
type MCPToolLog struct {
ID string `gorm:"primaryKey;type:varchar(255)" json:"id"`
LLMRequestID *string `gorm:"type:varchar(255);column:llm_request_id;index:idx_mcp_logs_llm_request_id" json:"llm_request_id,omitempty"` // Links to the LLM request that triggered this tool call
Timestamp time.Time `gorm:"index;not null" json:"timestamp"`
ToolName string `gorm:"type:varchar(255);index:idx_mcp_logs_tool_name;not null" json:"tool_name"`
ServerLabel string `gorm:"type:varchar(255);index:idx_mcp_logs_server_label" json:"server_label,omitempty"` // MCP server that provided the tool
VirtualKeyID *string `gorm:"type:varchar(255);index:idx_mcp_logs_virtual_key_id" json:"virtual_key_id"`
VirtualKeyName *string `gorm:"type:varchar(255)" json:"virtual_key_name"`
Arguments string `gorm:"type:text" json:"-"` // JSON serialized tool arguments
Result string `gorm:"type:text" json:"-"` // JSON serialized tool result
ErrorDetails string `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostError
Latency *float64 `gorm:"index:idx_mcp_logs_latency" json:"latency,omitempty"` // Execution time in milliseconds
Cost *float64 `gorm:"index:idx_mcp_logs_cost" json:"cost,omitempty"` // Cost in dollars (per execution cost)
Status string `gorm:"type:varchar(50);index:idx_mcp_logs_status;not null" json:"status"` // "processing", "success", or "error"
CreatedAt time.Time `gorm:"index;not null" json:"created_at"`
// Virtual fields for JSON output - populated when needed
ArgumentsParsed interface{} `gorm:"-" json:"arguments,omitempty"`
ResultParsed interface{} `gorm:"-" json:"result,omitempty"`
ErrorDetailsParsed *schemas.BifrostError `gorm:"-" json:"error_details,omitempty"`
VirtualKey *tables.TableVirtualKey `gorm:"-" json:"virtual_key,omitempty"`
}
MCPToolLog represents a log entry for MCP tool executions This is separate from the main Log table since MCP tool calls have different fields
func (*MCPToolLog) AfterFind ¶ added in v1.2.17
func (l *MCPToolLog) AfterFind(tx *gorm.DB) error
AfterFind GORM hook to deserialize JSON fields
func (*MCPToolLog) BeforeCreate ¶ added in v1.2.17
func (l *MCPToolLog) BeforeCreate(tx *gorm.DB) error
BeforeCreate GORM hook to set created_at and serialize JSON fields
func (*MCPToolLog) BeforeSave ¶ added in v1.2.17
func (l *MCPToolLog) BeforeSave(tx *gorm.DB) error
BeforeSave GORM hook to serialize JSON fields
func (*MCPToolLog) DeserializeFields ¶ added in v1.2.17
func (l *MCPToolLog) DeserializeFields() error
DeserializeFields converts JSON strings back to Go structs
func (*MCPToolLog) SerializeFields ¶ added in v1.2.17
func (l *MCPToolLog) SerializeFields() error
SerializeFields converts Go structs to JSON strings for storage
func (MCPToolLog) TableName ¶ added in v1.2.17
func (MCPToolLog) TableName() string
TableName sets the table name for GORM
type MCPToolLogSearchFilters ¶ added in v1.2.17
type MCPToolLogSearchFilters struct {
ToolNames []string `json:"tool_names,omitempty"`
ServerLabels []string `json:"server_labels,omitempty"`
Status []string `json:"status,omitempty"`
VirtualKeyIDs []string `json:"virtual_key_ids,omitempty"`
LLMRequestIDs []string `json:"llm_request_ids,omitempty"`
StartTime *time.Time `json:"start_time,omitempty"`
EndTime *time.Time `json:"end_time,omitempty"`
MinLatency *float64 `json:"min_latency,omitempty"`
MaxLatency *float64 `json:"max_latency,omitempty"`
ContentSearch string `json:"content_search,omitempty"`
}
MCPToolLogSearchFilters represents the available filters for MCP tool log searches
type MCPToolLogSearchResult ¶ added in v1.2.17
type MCPToolLogSearchResult struct {
Logs []MCPToolLog `json:"logs"`
Pagination PaginationOptions `json:"pagination"`
Stats MCPToolLogStats `json:"stats"`
HasLogs bool `json:"has_logs"`
}
MCPToolLogSearchResult represents the result of an MCP tool log search
type MCPToolLogStats ¶ added in v1.2.17
type MCPToolLogStats struct {
TotalExecutions int64 `json:"total_executions"`
SuccessRate float64 `json:"success_rate"`
AverageLatency float64 `json:"average_latency"`
TotalCost float64 `json:"total_cost"` // Total cost in dollars
}
MCPToolLogStats represents statistics for MCP tool log searches
type ModelHistogramBucket ¶ added in v1.2.13
type ModelHistogramBucket struct {
Timestamp time.Time `json:"timestamp"`
ByModel map[string]ModelUsageStats `json:"by_model"`
}
ModelHistogramBucket represents a single time bucket for model usage
type ModelHistogramResult ¶ added in v1.2.13
type ModelHistogramResult struct {
Buckets []ModelHistogramBucket `json:"buckets"`
BucketSizeSeconds int64 `json:"bucket_size_seconds"`
Models []string `json:"models"`
}
ModelHistogramResult represents the model histogram query result
type ModelUsageStats ¶ added in v1.2.13
type ModelUsageStats struct {
Total int64 `json:"total"`
Success int64 `json:"success"`
Error int64 `json:"error"`
}
ModelUsageStats represents usage statistics for a single model
type PaginationOptions ¶
type PaginationOptions struct {
Limit int `json:"limit"`
Offset int `json:"offset"`
SortBy string `json:"sort_by"` // "timestamp", "latency", "tokens", "cost"
Order string `json:"order"` // "asc", "desc"
TotalCount int64 `json:"total_count"` // Total number of items matching the query
}
PaginationOptions represents pagination parameters
type PostgresConfig ¶ added in v1.1.0
type PostgresConfig struct {
Host *schemas.EnvVar `json:"host"`
Port *schemas.EnvVar `json:"port"`
User *schemas.EnvVar `json:"user"`
Password *schemas.EnvVar `json:"password"`
DBName *schemas.EnvVar `json:"db_name"`
SSLMode *schemas.EnvVar `json:"ssl_mode"`
MaxIdleConns int `json:"max_idle_conns"`
MaxOpenConns int `json:"max_open_conns"`
}
PostgresConfig represents the configuration for a Postgres database.
type RDBLogStore ¶ added in v1.1.0
type RDBLogStore struct {
// contains filtered or unexported fields
}
RDBLogStore represents a log store that uses a SQLite database.
func (*RDBLogStore) BulkUpdateCost ¶ added in v1.1.49
func (*RDBLogStore) Close ¶ added in v1.1.0
func (s *RDBLogStore) Close(ctx context.Context) error
Close closes the log store.
func (*RDBLogStore) Create ¶ added in v1.1.0
func (s *RDBLogStore) Create(ctx context.Context, entry *Log) error
Create inserts a new log entry into the database.
func (*RDBLogStore) CreateIfNotExists ¶ added in v1.1.40
func (s *RDBLogStore) CreateIfNotExists(ctx context.Context, entry *Log) error
CreateIfNotExists inserts a new log entry only if it doesn't already exist. Uses ON CONFLICT DO NOTHING to handle duplicate key errors gracefully.
func (*RDBLogStore) CreateMCPToolLog ¶ added in v1.2.17
func (s *RDBLogStore) CreateMCPToolLog(ctx context.Context, entry *MCPToolLog) error
CreateMCPToolLog inserts a new MCP tool log entry into the database.
func (*RDBLogStore) DeleteLog ¶ added in v1.1.36
func (s *RDBLogStore) DeleteLog(ctx context.Context, id string) error
DeleteLog deletes a log entry from the database by its ID.
func (*RDBLogStore) DeleteLogs ¶ added in v1.1.36
func (s *RDBLogStore) DeleteLogs(ctx context.Context, ids []string) error
DeleteLogs deletes multiple log entries from the database by their IDs.
func (*RDBLogStore) DeleteLogsBatch ¶ added in v1.1.36
func (s *RDBLogStore) DeleteLogsBatch(ctx context.Context, cutoff time.Time, batchSize int) (deletedCount int64, err error)
DeleteLogsBatch deletes logs older than the cutoff time in batches.
func (*RDBLogStore) DeleteMCPToolLogs ¶ added in v1.2.17
func (s *RDBLogStore) DeleteMCPToolLogs(ctx context.Context, ids []string) error
DeleteMCPToolLogs deletes multiple MCP tool log entries from the database by their IDs.
func (*RDBLogStore) FindByID ¶ added in v1.2.9
FindByID gets a log entry from the database by its ID.
func (*RDBLogStore) FindMCPToolLog ¶ added in v1.2.17
func (s *RDBLogStore) FindMCPToolLog(ctx context.Context, id string) (*MCPToolLog, error)
FindMCPToolLog retrieves a single MCP tool log entry by its ID.
func (*RDBLogStore) FlushMCPToolLogs ¶ added in v1.2.17
FlushMCPToolLogs deletes old processing MCP tool log entries from the database.
func (*RDBLogStore) GetAvailableMCPVirtualKeys ¶ added in v1.2.17
func (s *RDBLogStore) GetAvailableMCPVirtualKeys(ctx context.Context) ([]MCPToolLog, error)
GetAvailableMCPVirtualKeys returns all unique virtual key ID-Name pairs from MCP tool logs.
func (*RDBLogStore) GetAvailableServerLabels ¶ added in v1.2.17
func (s *RDBLogStore) GetAvailableServerLabels(ctx context.Context) ([]string, error)
GetAvailableServerLabels returns all unique server labels from the MCP tool logs.
func (*RDBLogStore) GetAvailableToolNames ¶ added in v1.2.17
func (s *RDBLogStore) GetAvailableToolNames(ctx context.Context) ([]string, error)
GetAvailableToolNames returns all unique tool names from the MCP tool logs.
func (*RDBLogStore) GetCostHistogram ¶ added in v1.2.13
func (s *RDBLogStore) GetCostHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*CostHistogramResult, error)
GetCostHistogram returns time-bucketed cost data with model breakdown for the given filters.
func (*RDBLogStore) GetHistogram ¶ added in v1.2.13
func (s *RDBLogStore) GetHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*HistogramResult, error)
GetHistogram returns time-bucketed request counts for the given filters.
func (*RDBLogStore) GetMCPToolLogStats ¶ added in v1.2.17
func (s *RDBLogStore) GetMCPToolLogStats(ctx context.Context, filters MCPToolLogSearchFilters) (*MCPToolLogStats, error)
GetMCPToolLogStats calculates statistics for MCP tool logs matching the given filters.
func (*RDBLogStore) GetModelHistogram ¶ added in v1.2.13
func (s *RDBLogStore) GetModelHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ModelHistogramResult, error)
GetModelHistogram returns time-bucketed model usage with success/error breakdown for the given filters.
func (*RDBLogStore) GetStats ¶ added in v1.1.31
func (s *RDBLogStore) GetStats(ctx context.Context, filters SearchFilters) (*SearchStats, error)
GetStats calculates statistics for logs matching the given filters.
func (*RDBLogStore) GetTokenHistogram ¶ added in v1.2.13
func (s *RDBLogStore) GetTokenHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*TokenHistogramResult, error)
GetTokenHistogram returns time-bucketed token usage for the given filters.
func (*RDBLogStore) HasLogs ¶ added in v1.1.36
func (s *RDBLogStore) HasLogs(ctx context.Context) (bool, error)
HasLogs checks if there are any logs in the database.
func (*RDBLogStore) HasMCPToolLogs ¶ added in v1.2.17
func (s *RDBLogStore) HasMCPToolLogs(ctx context.Context) (bool, error)
HasMCPToolLogs checks if there are any MCP tool logs in the database.
func (*RDBLogStore) Ping ¶ added in v1.1.8
func (s *RDBLogStore) Ping(ctx context.Context) error
Ping checks if the database is reachable.
func (*RDBLogStore) SearchLogs ¶ added in v1.1.0
func (s *RDBLogStore) SearchLogs(ctx context.Context, filters SearchFilters, pagination PaginationOptions) (*SearchResult, error)
SearchLogs searches for logs in the database without calculating statistics.
func (*RDBLogStore) SearchMCPToolLogs ¶ added in v1.2.17
func (s *RDBLogStore) SearchMCPToolLogs(ctx context.Context, filters MCPToolLogSearchFilters, pagination PaginationOptions) (*MCPToolLogSearchResult, error)
SearchMCPToolLogs searches for MCP tool logs in the database.
func (*RDBLogStore) UpdateMCPToolLog ¶ added in v1.2.17
UpdateMCPToolLog updates an MCP tool log entry in the database.
type SQLiteConfig ¶
type SQLiteConfig struct {
Path string `json:"path"`
}
SQLiteConfig represents the configuration for a SQLite database.
type SearchFilters ¶
type SearchFilters struct {
Providers []string `json:"providers,omitempty"`
Models []string `json:"models,omitempty"`
Status []string `json:"status,omitempty"`
Objects []string `json:"objects,omitempty"` // For filtering by request type (chat.completion, text.completion, embedding)
SelectedKeyIDs []string `json:"selected_key_ids,omitempty"`
VirtualKeyIDs []string `json:"virtual_key_ids,omitempty"`
RoutingRuleIDs []string `json:"routing_rule_ids,omitempty"`
RoutingEngineUsed []string `json:"routing_engine_used,omitempty"` // For filtering by routing engine (routing-rule, governance, loadbalancing)
StartTime *time.Time `json:"start_time,omitempty"`
EndTime *time.Time `json:"end_time,omitempty"`
MinLatency *float64 `json:"min_latency,omitempty"`
MaxLatency *float64 `json:"max_latency,omitempty"`
MinTokens *int `json:"min_tokens,omitempty"`
MaxTokens *int `json:"max_tokens,omitempty"`
MinCost *float64 `json:"min_cost,omitempty"`
MaxCost *float64 `json:"max_cost,omitempty"`
MissingCostOnly bool `json:"missing_cost_only,omitempty"`
ContentSearch string `json:"content_search,omitempty"`
}
SearchFilters represents the available filters for log searches
type SearchResult ¶
type SearchResult struct {
Logs []Log `json:"logs"`
Pagination PaginationOptions `json:"pagination"`
Stats SearchStats `json:"stats"`
HasLogs bool `json:"has_logs"`
}
SearchResult represents the result of a log search
type SearchStats ¶
type SearchStats struct {
TotalRequests int64 `json:"total_requests"`
SuccessRate float64 `json:"success_rate"` // Percentage of successful requests
AverageLatency float64 `json:"average_latency"` // Average latency in milliseconds
TotalTokens int64 `json:"total_tokens"` // Total tokens used
TotalCost float64 `json:"total_cost"` // Total cost in dollars
}
type TokenHistogramBucket ¶ added in v1.2.13
type TokenHistogramBucket struct {
Timestamp time.Time `json:"timestamp"`
PromptTokens int64 `json:"prompt_tokens"`
CompletionTokens int64 `json:"completion_tokens"`
TotalTokens int64 `json:"total_tokens"`
}
TokenHistogramBucket represents a single time bucket for token usage
type TokenHistogramResult ¶ added in v1.2.13
type TokenHistogramResult struct {
Buckets []TokenHistogramBucket `json:"buckets"`
BucketSizeSeconds int64 `json:"bucket_size_seconds"`
}
TokenHistogramResult represents the token histogram query result