Documentation
¶
Overview ¶
Package logging provides a GORM-based logging plugin for Bifrost. This plugin stores comprehensive logs of all requests and responses with search, filter, and pagination capabilities.
Package logging provides database operations for the GORM-based logging plugin ¶
Package logging provides streaming-related functionality for the GORM-based logging plugin ¶
Package logging provides utility functions and interfaces for the GORM-based logging plugin
Index ¶
- Constants
- type ContextKey
- type InitialLogData
- type LogCallback
- type LogManager
- type LogMessage
- type LogOperation
- type LoggerPlugin
- func (p *LoggerPlugin) Cleanup() error
- func (p *LoggerPlugin) GetAvailableModels() []string
- func (p *LoggerPlugin) GetName() string
- func (p *LoggerPlugin) GetPluginLogManager() *PluginLogManager
- func (p *LoggerPlugin) PostHook(ctx *context.Context, result *schemas.BifrostResponse, ...) (*schemas.BifrostResponse, *schemas.BifrostError, error)
- func (p *LoggerPlugin) PreHook(ctx *context.Context, req *schemas.BifrostRequest) (*schemas.BifrostRequest, *schemas.PluginShortCircuit, error)
- func (p *LoggerPlugin) SearchLogs(filters logstore.SearchFilters, pagination logstore.PaginationOptions) (*logstore.SearchResult, error)
- func (p *LoggerPlugin) SetLogCallback(callback LogCallback)
- type PluginLogManager
- type StreamAccumulator
- type StreamChunk
- type StreamUpdateData
- type UpdateLogData
Constants ¶
const (
PluginName = "bifrost-http-logging"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContextKey ¶
type ContextKey string
ContextKey is a custom type for context keys to prevent collisions
const ( DroppedCreateContextKey ContextKey = "bifrost-logging-dropped" CreatedTimestampKey ContextKey = "bifrost-logging-created-timestamp" )
Context keys for logging optimization
type InitialLogData ¶
type InitialLogData struct { Provider string Model string Object string InputHistory []schemas.BifrostMessage Params *schemas.ModelParameters SpeechInput *schemas.SpeechInput TranscriptionInput *schemas.TranscriptionInput Tools *[]schemas.Tool }
InitialLogData contains data for initial log entry creation
type LogCallback ¶
LogCallback is a function that gets called when a new log entry is created
type LogManager ¶
type LogManager interface { // Search searches for log entries based on filters and pagination Search(filters *logstore.SearchFilters, pagination *logstore.PaginationOptions) (*logstore.SearchResult, error) // Get the number of dropped requests GetDroppedRequests() int64 // GetAvailableModels returns all unique models from logs GetAvailableModels() []string }
LogManager defines the main interface that combines all logging functionality
type LogMessage ¶
type LogMessage struct { Operation LogOperation RequestID string Timestamp time.Time // Of the preHook/postHook call InitialData *InitialLogData // For create operations SemanticCacheDebug *schemas.BifrostCacheDebug // For semantic cache operations UpdateData *UpdateLogData // For update operations StreamUpdateData *StreamUpdateData // For stream update operations }
LogMessage represents a message in the logging queue
type LogOperation ¶
type LogOperation string
LogOperation represents the type of logging operation
const ( LogOperationCreate LogOperation = "create" LogOperationUpdate LogOperation = "update" LogOperationStreamUpdate LogOperation = "stream_update" )
type LoggerPlugin ¶
type LoggerPlugin struct {
// contains filtered or unexported fields
}
LoggerPlugin implements the schemas.Plugin interface
func Init ¶
func Init(logger schemas.Logger, logsStore logstore.LogStore, pricingManager *pricing.PricingManager) (*LoggerPlugin, error)
Init creates new logger plugin with given log store
func (*LoggerPlugin) Cleanup ¶
func (p *LoggerPlugin) Cleanup() error
Cleanup is called when the plugin is being shut down
func (*LoggerPlugin) GetAvailableModels ¶
func (p *LoggerPlugin) GetAvailableModels() []string
GetAvailableModels returns all unique models from logs
func (*LoggerPlugin) GetName ¶
func (p *LoggerPlugin) GetName() string
GetName returns the name of the plugin
func (*LoggerPlugin) GetPluginLogManager ¶
func (p *LoggerPlugin) GetPluginLogManager() *PluginLogManager
GetPluginLogManager returns a LogManager interface for this plugin
func (*LoggerPlugin) PostHook ¶
func (p *LoggerPlugin) PostHook(ctx *context.Context, result *schemas.BifrostResponse, err *schemas.BifrostError) (*schemas.BifrostResponse, *schemas.BifrostError, error)
PostHook is called after a response is received - FULLY ASYNC, NO DATABASE I/O
func (*LoggerPlugin) PreHook ¶
func (p *LoggerPlugin) PreHook(ctx *context.Context, req *schemas.BifrostRequest) (*schemas.BifrostRequest, *schemas.PluginShortCircuit, error)
PreHook is called before a request is processed - FULLY ASYNC, NO DATABASE I/O
func (*LoggerPlugin) SearchLogs ¶
func (p *LoggerPlugin) SearchLogs(filters logstore.SearchFilters, pagination logstore.PaginationOptions) (*logstore.SearchResult, error)
SearchLogs searches logs with filters and pagination using GORM
func (*LoggerPlugin) SetLogCallback ¶
func (p *LoggerPlugin) SetLogCallback(callback LogCallback)
SetLogCallback sets a callback function that will be called for each log entry
type PluginLogManager ¶
type PluginLogManager struct {
// contains filtered or unexported fields
}
PluginLogManager implements LogManager interface wrapping the plugin
func (*PluginLogManager) GetAvailableModels ¶
func (p *PluginLogManager) GetAvailableModels() []string
GetAvailableModels returns all unique models from logs
func (*PluginLogManager) GetDroppedRequests ¶
func (p *PluginLogManager) GetDroppedRequests() int64
func (*PluginLogManager) Search ¶
func (p *PluginLogManager) Search(filters *logstore.SearchFilters, pagination *logstore.PaginationOptions) (*logstore.SearchResult, error)
type StreamAccumulator ¶
type StreamAccumulator struct { RequestID string Chunks []*StreamChunk IsComplete bool FinalTimestamp time.Time Object string // Store object type once for the entire stream // contains filtered or unexported fields }
StreamAccumulator manages accumulation of streaming chunks
type StreamChunk ¶
type StreamChunk struct { Timestamp time.Time // When chunk was received Delta *schemas.BifrostStreamDelta // The actual delta content FinishReason *string // If this is the final chunk TokenUsage *schemas.LLMUsage // Token usage if available SemanticCacheDebug *schemas.BifrostCacheDebug // Semantic cache debug if available Cost *float64 // Cost in dollars from pricing plugin ErrorDetails *schemas.BifrostError // Error if any }
StreamChunk represents a single streaming chunk
type StreamUpdateData ¶
type StreamUpdateData struct { ErrorDetails *schemas.BifrostError Model string // May be different from request Object string // May be different from request TokenUsage *schemas.LLMUsage Cost *float64 // Cost in dollars from pricing plugin Delta *schemas.BifrostStreamDelta // The actual streaming delta FinishReason *string // If the stream is finished TranscriptionOutput *schemas.BifrostTranscribe // For transcription stream responses }
StreamUpdateData contains lightweight data for streaming delta updates
type UpdateLogData ¶
type UpdateLogData struct { Status string TokenUsage *schemas.LLMUsage Cost *float64 // Cost in dollars from pricing plugin OutputMessage *schemas.BifrostMessage EmbeddingOutput *[]schemas.BifrostEmbedding ToolCalls *[]schemas.ToolCall ErrorDetails *schemas.BifrostError Model string // May be different from request Object string // May be different from request SpeechOutput *schemas.BifrostSpeech // For non-streaming speech responses TranscriptionOutput *schemas.BifrostTranscribe // For non-streaming transcription responses }
UpdateLogData contains data for log entry updates