logging

package module
v1.2.15 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2025 License: Apache-2.0 Imports: 10 Imported by: 2

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 utility functions and interfaces for the GORM-based logging plugin

Index

Constants

View Source
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

type LogCallback func(*logstore.Log)

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

PostHook is called after a response is received - FULLY ASYNC, NO DATABASE I/O

func (*LoggerPlugin) PreHook

PreHook is called before a request is processed - FULLY ASYNC, NO DATABASE I/O

func (*LoggerPlugin) SearchLogs

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

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

Jump to

Keyboard shortcuts

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