logstore

package
v1.3.7 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: Apache-2.0 Imports: 30 Imported by: 5

Documentation

Overview

Package logstore provides a logs store for Bifrost.

Index

Constants

View Source
const (
	// DefaultAsyncJobResultTTL is the default TTL for async job results in seconds (1 hour).
	DefaultAsyncJobResultTTL = 3600
)

Variables

View Source
var (
	ErrNotFound    = fmt.Errorf("log not found")
	ErrJobInternal = fmt.Errorf("internal job store error")
)

ValidHistogramDimensions is the set of allowed dimension values

Functions

func BuildTags added in v1.3.2

func BuildTags(l *Log) map[string]string

BuildTags creates the S3 object tag map from a Log's index fields. S3 allows max 10 tags per object; chosen for lifecycle rules and S3 Metadata Tables queryability.

func ClearPayload added in v1.3.2

func ClearPayload(l *Log)

ClearPayload zeros out both the TEXT payload columns and the Parsed virtual fields on a Log struct. Clearing the Parsed fields is necessary to prevent GORM's BeforeCreate/SerializeFields from re-populating TEXT columns. After calling this, the struct only contains index-weight data suitable for a lightweight DB INSERT.

func ClearPayloadFiltered added in v1.3.7

func ClearPayloadFiltered(l *Log, excluded map[string]struct{})

ClearPayloadFiltered zeros only the payload fields that are not present in the excluded set (i.e. the fields that will be sent to object storage). Fields in the excluded set stay in the DB and are left untouched. An empty/nil excluded map is equivalent to ClearPayload.

func ExtractPayload added in v1.3.2

func ExtractPayload(l *Log) map[string]string

ExtractPayload reads the serialized TEXT payload fields from a Log into a map. The map keys are the DB column names.

func ExtractPayloadFiltered added in v1.3.7

func ExtractPayloadFiltered(l *Log, excluded map[string]struct{}) map[string]string

ExtractPayloadFiltered is like ExtractPayload but omits fields present in the excluded set. An empty/nil excluded map is equivalent to ExtractPayload.

func MarshalPayload added in v1.3.2

func MarshalPayload(payload map[string]string) ([]byte, error)

func MergePayloadFromJSON added in v1.3.2

func MergePayloadFromJSON(l *Log, data []byte) error

MergePayloadFromJSON takes a JSON payload (as marshaled by MarshalPayload) and merges the fields back into the Log struct's serialized TEXT columns, then calls DeserializeFields to populate the Parsed virtual fields.

func ObjectKey added in v1.3.2

func ObjectKey(prefix string, timestamp time.Time, logID string) string

ObjectKey constructs the S3 object key for a log entry.

func PayloadFieldNames added in v1.3.2

func PayloadFieldNames() []string

PayloadFieldNames returns the list of DB column names that are payload fields.

Types

type AsyncJob added in v1.2.22

type AsyncJob struct {
	ID           string                 `gorm:"primaryKey;type:varchar(255)" json:"id"`
	Status       schemas.AsyncJobStatus `gorm:"type:varchar(50);index:idx_async_jobs_status;not null" json:"status"`
	RequestType  schemas.RequestType    `gorm:"type:varchar(50);index:idx_async_jobs_request_type;not null" json:"request_type"`
	Response     string                 `gorm:"type:text" json:"response"`
	StatusCode   int                    `gorm:"default:0" json:"status_code,omitempty"`
	Error        string                 `gorm:"type:text" json:"error,omitempty"`
	VirtualKeyID *string                `gorm:"type:varchar(255);index:idx_async_jobs_vk_id" json:"virtual_key_id,omitempty"`
	ResultTTL    int                    `gorm:"default:3600" json:"-"` // TTL in seconds, used to calculate ExpiresAt on completion
	ExpiresAt    *time.Time             `gorm:"index:idx_async_jobs_expires_at" json:"expires_at,omitempty"`
	CreatedAt    time.Time              `gorm:"index;not null" json:"created_at"`
	CompletedAt  *time.Time             `json:"completed_at,omitempty"`
}

AsyncJob represents an asynchronous job record in the database. Jobs are created when requests are submitted to async endpoints and updated when the background operation completes or fails.

func (AsyncJob) TableName added in v1.2.22

func (AsyncJob) TableName() string

TableName sets the table name for GORM

func (*AsyncJob) ToResponse added in v1.2.22

func (j *AsyncJob) ToResponse() *schemas.AsyncJobResponse

ToResponse converts an AsyncJob database record to an AsyncJobResponse for JSON output.

type AsyncJobCleaner added in v1.2.22

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

AsyncJobCleaner manages the cleanup of expired async jobs.

func NewAsyncJobCleaner added in v1.2.22

func NewAsyncJobCleaner(store LogStore, logger schemas.Logger) *AsyncJobCleaner

NewAsyncJobCleaner creates a new AsyncJobCleaner instance.

func (*AsyncJobCleaner) StartCleanupRoutine added in v1.2.22

func (c *AsyncJobCleaner) StartCleanupRoutine()

StartCleanupRoutine starts a goroutine that periodically cleans up expired async jobs.

func (*AsyncJobCleaner) StopCleanupRoutine added in v1.2.22

func (c *AsyncJobCleaner) StopCleanupRoutine()

StopCleanupRoutine gracefully stops the cleanup goroutine.

type AsyncJobExecutor added in v1.2.22

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

AsyncJobExecutor manages async job creation and background execution.

func NewAsyncJobExecutor added in v1.2.22

func NewAsyncJobExecutor(logstore LogStore, governanceStore GovernanceStore, logger schemas.Logger) *AsyncJobExecutor

NewAsyncJobExecutor creates a new AsyncJobExecutor.

func (*AsyncJobExecutor) RetrieveJob added in v1.2.22

func (e *AsyncJobExecutor) RetrieveJob(ctx context.Context, jobID string, vkValue *string, operationType schemas.RequestType) (*AsyncJob, error)

RetrieveJob retrieves a job by its ID.

func (*AsyncJobExecutor) SubmitJob added in v1.2.22

func (e *AsyncJobExecutor) SubmitJob(bifrostCtx *schemas.BifrostContext, resultTTL int, operation AsyncOperation, operationType schemas.RequestType) (*AsyncJob, error)

SubmitJob creates a pending job, starts background execution, and returns the job record.

type AsyncOperation added in v1.2.22

type AsyncOperation func(ctx *schemas.BifrostContext) (any, *schemas.BifrostError)

AsyncOperation represents a function that can be executed asynchronously. It returns the response and an optional BifrostError.

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"`
	ObjectStorage *objectstore.Config `json:"object_storage,omitempty"`
	// ObjectStorageExcludeFields lists payload field names (DB column names) that
	// should NOT be offloaded to object storage and instead remain in the database.
	ObjectStorageExcludeFields []string `json:"object_storage_exclude_fields,omitempty"`
}

Config represents the configuration for the logs store.

func (*Config) UnmarshalJSON

func (c *Config) UnmarshalJSON(data []byte) error

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 DimensionCostHistogramBucket added in v1.3.1

type DimensionCostHistogramBucket struct {
	Timestamp   time.Time          `json:"timestamp"`
	TotalCost   float64            `json:"total_cost"`
	ByDimension map[string]float64 `json:"by_dimension"`
}

DimensionCostHistogramBucket represents a single time bucket for dimension-grouped cost data

type DimensionCostHistogramResult added in v1.3.1

type DimensionCostHistogramResult struct {
	Buckets           []DimensionCostHistogramBucket `json:"buckets"`
	BucketSizeSeconds int64                          `json:"bucket_size_seconds"`
	Dimension         HistogramDimension             `json:"dimension"`
	DimensionValues   []string                       `json:"dimension_values"`
}

DimensionCostHistogramResult represents the dimension cost histogram query result

type DimensionLatencyHistogramBucket added in v1.3.1

type DimensionLatencyHistogramBucket struct {
	Timestamp   time.Time                        `json:"timestamp"`
	ByDimension map[string]DimensionLatencyStats `json:"by_dimension"`
}

DimensionLatencyHistogramBucket represents a single time bucket for dimension-grouped latency data

type DimensionLatencyHistogramResult added in v1.3.1

type DimensionLatencyHistogramResult struct {
	Buckets           []DimensionLatencyHistogramBucket `json:"buckets"`
	BucketSizeSeconds int64                             `json:"bucket_size_seconds"`
	Dimension         HistogramDimension                `json:"dimension"`
	DimensionValues   []string                          `json:"dimension_values"`
}

DimensionLatencyHistogramResult represents the dimension latency histogram query result

type DimensionLatencyStats added in v1.3.1

type DimensionLatencyStats struct {
	AvgLatency    float64 `json:"avg_latency"`
	P90Latency    float64 `json:"p90_latency"`
	P95Latency    float64 `json:"p95_latency"`
	P99Latency    float64 `json:"p99_latency"`
	TotalRequests int64   `json:"total_requests"`
}

DimensionLatencyStats represents latency statistics for a single dimension value

type DimensionTokenHistogramBucket added in v1.3.1

type DimensionTokenHistogramBucket struct {
	Timestamp   time.Time                      `json:"timestamp"`
	ByDimension map[string]DimensionTokenStats `json:"by_dimension"`
}

DimensionTokenHistogramBucket represents a single time bucket for dimension-grouped token data

type DimensionTokenHistogramResult added in v1.3.1

type DimensionTokenHistogramResult struct {
	Buckets           []DimensionTokenHistogramBucket `json:"buckets"`
	BucketSizeSeconds int64                           `json:"bucket_size_seconds"`
	Dimension         HistogramDimension              `json:"dimension"`
	DimensionValues   []string                        `json:"dimension_values"`
}

DimensionTokenHistogramResult represents the dimension token histogram query result

type DimensionTokenStats added in v1.3.1

type DimensionTokenStats struct {
	PromptTokens     int64 `json:"prompt_tokens"`
	CompletionTokens int64 `json:"completion_tokens"`
	TotalTokens      int64 `json:"total_tokens"`
}

DimensionTokenStats represents token statistics for a single dimension value

type GovernanceStore added in v1.2.22

type GovernanceStore interface {
	GetVirtualKey(ctx context.Context, vkValue string) (*configstoreTables.TableVirtualKey, bool)
}

GovernanceStore is an interface that provides access to the governance store.

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 HistogramDimension added in v1.3.1

type HistogramDimension string

HistogramDimension represents a column that can be used as a grouping dimension in histograms

const (
	DimensionProvider     HistogramDimension = "provider"
	DimensionTeam         HistogramDimension = "team_id"
	DimensionCustomer     HistogramDimension = "customer_id"
	DimensionUser         HistogramDimension = "user_id"
	DimensionBusinessUnit HistogramDimension = "business_unit_id"
)

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 HybridLogStore added in v1.3.2

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

HybridLogStore wraps an existing LogStore and offloads large payload fields to object storage while keeping a lightweight index in the DB.

Method routing:

  • Delegated directly (40+ methods): all analytics, search, histogram, ranking, distinct, MCP, async job methods
  • Intercepted: Create, CreateIfNotExists, BatchCreateIfNotExists, FindByID, Update, DeleteLog, DeleteLogs, DeleteLogsBatch, Close

func (*HybridLogStore) BatchCreateIfNotExists added in v1.3.2

func (h *HybridLogStore) BatchCreateIfNotExists(ctx context.Context, entries []*Log) error

func (*HybridLogStore) BulkUpdateCost added in v1.3.2

func (h *HybridLogStore) BulkUpdateCost(ctx context.Context, updates map[string]float64) error

func (*HybridLogStore) Close added in v1.3.2

func (h *HybridLogStore) Close(ctx context.Context) error

func (*HybridLogStore) Create added in v1.3.2

func (h *HybridLogStore) Create(ctx context.Context, entry *Log) error

func (*HybridLogStore) CreateAsyncJob added in v1.3.2

func (h *HybridLogStore) CreateAsyncJob(ctx context.Context, job *AsyncJob) error

func (*HybridLogStore) CreateIfNotExists added in v1.3.2

func (h *HybridLogStore) CreateIfNotExists(ctx context.Context, entry *Log) error

func (*HybridLogStore) CreateMCPToolLog added in v1.3.2

func (h *HybridLogStore) CreateMCPToolLog(ctx context.Context, entry *MCPToolLog) error

func (*HybridLogStore) DeleteExpiredAsyncJobs added in v1.3.2

func (h *HybridLogStore) DeleteExpiredAsyncJobs(ctx context.Context) (int64, error)

func (*HybridLogStore) DeleteLog added in v1.3.2

func (h *HybridLogStore) DeleteLog(ctx context.Context, id string) error

func (*HybridLogStore) DeleteLogs added in v1.3.2

func (h *HybridLogStore) DeleteLogs(ctx context.Context, ids []string) error

func (*HybridLogStore) DeleteLogsBatch added in v1.3.2

func (h *HybridLogStore) DeleteLogsBatch(ctx context.Context, cutoff time.Time, batchSize int) (int64, error)

func (*HybridLogStore) DeleteMCPToolLogs added in v1.3.2

func (h *HybridLogStore) DeleteMCPToolLogs(ctx context.Context, ids []string) error

func (*HybridLogStore) DeleteStaleAsyncJobs added in v1.3.2

func (h *HybridLogStore) DeleteStaleAsyncJobs(ctx context.Context, staleSince time.Time) (int64, error)

func (*HybridLogStore) DroppedUploads added in v1.3.2

func (h *HybridLogStore) DroppedUploads() int64

DroppedUploads returns the number of S3 uploads that were dropped.

func (*HybridLogStore) FindAll added in v1.3.2

func (h *HybridLogStore) FindAll(ctx context.Context, query any, fields ...string) ([]*Log, error)

func (*HybridLogStore) FindAllDistinct added in v1.3.2

func (h *HybridLogStore) FindAllDistinct(ctx context.Context, query any, fields ...string) ([]*Log, error)

func (*HybridLogStore) FindAsyncJobByID added in v1.3.2

func (h *HybridLogStore) FindAsyncJobByID(ctx context.Context, id string) (*AsyncJob, error)

func (*HybridLogStore) FindByID added in v1.3.2

func (h *HybridLogStore) FindByID(ctx context.Context, id string) (*Log, error)

func (*HybridLogStore) FindFirst added in v1.3.2

func (h *HybridLogStore) FindFirst(ctx context.Context, query any, fields ...string) (*Log, error)

func (*HybridLogStore) FindMCPToolLog added in v1.3.2

func (h *HybridLogStore) FindMCPToolLog(ctx context.Context, id string) (*MCPToolLog, error)

func (*HybridLogStore) Flush added in v1.3.2

func (h *HybridLogStore) Flush(ctx context.Context, since time.Time) error

func (*HybridLogStore) FlushMCPToolLogs added in v1.3.2

func (h *HybridLogStore) FlushMCPToolLogs(ctx context.Context, since time.Time) error

func (*HybridLogStore) GetAvailableMCPVirtualKeys added in v1.3.2

func (h *HybridLogStore) GetAvailableMCPVirtualKeys(ctx context.Context) ([]MCPToolLog, error)

func (*HybridLogStore) GetAvailableServerLabels added in v1.3.2

func (h *HybridLogStore) GetAvailableServerLabels(ctx context.Context) ([]string, error)

func (*HybridLogStore) GetAvailableToolNames added in v1.3.2

func (h *HybridLogStore) GetAvailableToolNames(ctx context.Context) ([]string, error)

func (*HybridLogStore) GetCostHistogram added in v1.3.2

func (h *HybridLogStore) GetCostHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*CostHistogramResult, error)

func (*HybridLogStore) GetDimensionCostHistogram added in v1.3.2

func (h *HybridLogStore) GetDimensionCostHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64, dimension HistogramDimension) (*DimensionCostHistogramResult, error)

func (*HybridLogStore) GetDimensionLatencyHistogram added in v1.3.2

func (h *HybridLogStore) GetDimensionLatencyHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64, dimension HistogramDimension) (*DimensionLatencyHistogramResult, error)

func (*HybridLogStore) GetDimensionTokenHistogram added in v1.3.2

func (h *HybridLogStore) GetDimensionTokenHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64, dimension HistogramDimension) (*DimensionTokenHistogramResult, error)

func (*HybridLogStore) GetDistinctAliases added in v1.3.2

func (h *HybridLogStore) GetDistinctAliases(ctx context.Context) ([]string, error)

func (*HybridLogStore) GetDistinctKeyPairs added in v1.3.2

func (h *HybridLogStore) GetDistinctKeyPairs(ctx context.Context, idCol, nameCol string) ([]KeyPairResult, error)

func (*HybridLogStore) GetDistinctMetadataKeys added in v1.3.2

func (h *HybridLogStore) GetDistinctMetadataKeys(ctx context.Context) (map[string][]string, error)

func (*HybridLogStore) GetDistinctModels added in v1.3.2

func (h *HybridLogStore) GetDistinctModels(ctx context.Context) ([]string, error)

func (*HybridLogStore) GetDistinctRoutingEngines added in v1.3.2

func (h *HybridLogStore) GetDistinctRoutingEngines(ctx context.Context) ([]string, error)

func (*HybridLogStore) GetDistinctStopReasons added in v1.3.6

func (h *HybridLogStore) GetDistinctStopReasons(ctx context.Context) ([]string, error)

func (*HybridLogStore) GetHistogram added in v1.3.2

func (h *HybridLogStore) GetHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*HistogramResult, error)

func (*HybridLogStore) GetLatencyHistogram added in v1.3.2

func (h *HybridLogStore) GetLatencyHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*LatencyHistogramResult, error)

func (*HybridLogStore) GetMCPCostHistogram added in v1.3.2

func (h *HybridLogStore) GetMCPCostHistogram(ctx context.Context, filters MCPToolLogSearchFilters, bucketSizeSeconds int64) (*MCPCostHistogramResult, error)

func (*HybridLogStore) GetMCPHistogram added in v1.3.2

func (h *HybridLogStore) GetMCPHistogram(ctx context.Context, filters MCPToolLogSearchFilters, bucketSizeSeconds int64) (*MCPHistogramResult, error)

func (*HybridLogStore) GetMCPToolLogStats added in v1.3.2

func (h *HybridLogStore) GetMCPToolLogStats(ctx context.Context, filters MCPToolLogSearchFilters) (*MCPToolLogStats, error)

func (*HybridLogStore) GetMCPTopTools added in v1.3.2

func (h *HybridLogStore) GetMCPTopTools(ctx context.Context, filters MCPToolLogSearchFilters, limit int) (*MCPTopToolsResult, error)

func (*HybridLogStore) GetModelHistogram added in v1.3.2

func (h *HybridLogStore) GetModelHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ModelHistogramResult, error)

func (*HybridLogStore) GetModelRankings added in v1.3.2

func (h *HybridLogStore) GetModelRankings(ctx context.Context, filters SearchFilters) (*ModelRankingResult, error)

func (*HybridLogStore) GetProviderCostHistogram added in v1.3.2

func (h *HybridLogStore) GetProviderCostHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ProviderCostHistogramResult, error)

func (*HybridLogStore) GetProviderLatencyHistogram added in v1.3.2

func (h *HybridLogStore) GetProviderLatencyHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ProviderLatencyHistogramResult, error)

func (*HybridLogStore) GetProviderTokenHistogram added in v1.3.2

func (h *HybridLogStore) GetProviderTokenHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ProviderTokenHistogramResult, error)

func (*HybridLogStore) GetSessionLogs added in v1.3.2

func (h *HybridLogStore) GetSessionLogs(ctx context.Context, sessionID string, pagination PaginationOptions) (*SessionDetailResult, error)

func (*HybridLogStore) GetSessionSummary added in v1.3.2

func (h *HybridLogStore) GetSessionSummary(ctx context.Context, sessionID string) (*SessionSummaryResult, error)

func (*HybridLogStore) GetStats added in v1.3.2

func (h *HybridLogStore) GetStats(ctx context.Context, filters SearchFilters) (*SearchStats, error)

func (*HybridLogStore) GetTokenHistogram added in v1.3.2

func (h *HybridLogStore) GetTokenHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*TokenHistogramResult, error)

func (*HybridLogStore) GetUserRankings added in v1.3.2

func (h *HybridLogStore) GetUserRankings(ctx context.Context, filters SearchFilters) (*UserRankingResult, error)

func (*HybridLogStore) HasLogs added in v1.3.2

func (h *HybridLogStore) HasLogs(ctx context.Context) (bool, error)

func (*HybridLogStore) HasMCPToolLogs added in v1.3.2

func (h *HybridLogStore) HasMCPToolLogs(ctx context.Context) (bool, error)

func (*HybridLogStore) IsLogEntryPresent added in v1.3.2

func (h *HybridLogStore) IsLogEntryPresent(ctx context.Context, id string) (bool, error)

func (*HybridLogStore) Ping added in v1.3.2

func (h *HybridLogStore) Ping(ctx context.Context) error

func (*HybridLogStore) SearchLogs added in v1.3.2

func (h *HybridLogStore) SearchLogs(ctx context.Context, filters SearchFilters, pagination PaginationOptions) (*SearchResult, error)

func (*HybridLogStore) SearchMCPToolLogs added in v1.3.2

func (h *HybridLogStore) SearchMCPToolLogs(ctx context.Context, filters MCPToolLogSearchFilters, pagination PaginationOptions) (*MCPToolLogSearchResult, error)

func (*HybridLogStore) Update added in v1.3.2

func (h *HybridLogStore) Update(ctx context.Context, id string, entry any) error

func (*HybridLogStore) UpdateAsyncJob added in v1.3.2

func (h *HybridLogStore) UpdateAsyncJob(ctx context.Context, id string, updates map[string]interface{}) error

func (*HybridLogStore) UpdateMCPToolLog added in v1.3.2

func (h *HybridLogStore) UpdateMCPToolLog(ctx context.Context, id string, entry any) error

type KeyPairResult added in v1.2.22

type KeyPairResult struct {
	ID   string `gorm:"column:id"`
	Name string `gorm:"column:name"`
}

KeyPairResult represents an ID-Name pair returned from DISTINCT queries

type LatencyHistogramBucket added in v1.2.24

type LatencyHistogramBucket struct {
	Timestamp     time.Time `json:"timestamp"`
	AvgLatency    float64   `json:"avg_latency"`
	P90Latency    float64   `json:"p90_latency"`
	P95Latency    float64   `json:"p95_latency"`
	P99Latency    float64   `json:"p99_latency"`
	TotalRequests int64     `json:"total_requests"`
}

LatencyHistogramBucket represents a single time bucket for latency data

type LatencyHistogramResult added in v1.2.24

type LatencyHistogramResult struct {
	Buckets           []LatencyHistogramBucket `json:"buckets"`
	BucketSizeSeconds int64                    `json:"bucket_size_seconds"`
}

LatencyHistogramResult represents the latency histogram query result

type Log

type Log struct {
	ID                      string    `gorm:"primaryKey;type:varchar(255)" json:"id"`
	ParentRequestID         *string   `gorm:"type:varchar(255);index" json:"parent_request_id"`
	Timestamp               time.Time `gorm:"index;index:idx_logs_ts_provider_status,priority:1;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;index:idx_logs_ts_provider_status,priority:2;not null" json:"provider"`
	Model                   string    `gorm:"type:varchar(255);index;not null" json:"model"`
	Alias                   *string   `gorm:"type:varchar(255);index" json:"alias,omitempty"` // Set when model was resolved via alias mapping; the original name the caller used
	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"`
	AttemptTrail            string    `gorm:"type:text" json:"-"` // JSON serialized []schemas.KeyAttemptRecord
	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"`
	RoutingEnginesUsedStr   *string   `gorm:"type:varchar(255);column:routing_engines_used" json:"-"` // Comma-separated routing engines
	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"`
	SelectedPromptName      *string   `gorm:"type:varchar(255)" json:"selected_prompt_name"`
	SelectedPromptVersion   *string   `gorm:"type:varchar(64)" json:"selected_prompt_version"`
	SelectedPromptID        *string   `gorm:"type:varchar(36)" json:"selected_prompt_id"`
	UserID                  *string   `gorm:"type:varchar(255);index:idx_logs_user_id" json:"user_id"`
	UserName                *string   `gorm:"type:varchar(255)" json:"user_name"`
	TeamID                  *string   `gorm:"type:varchar(255);index:idx_logs_team_id" json:"team_id"`
	TeamName                *string   `gorm:"type:varchar(255)" json:"team_name"`
	CustomerID              *string   `gorm:"type:varchar(255);index:idx_logs_customer_id" json:"customer_id"`
	CustomerName            *string   `gorm:"type:varchar(255)" json:"customer_name"`
	BusinessUnitID          *string   `gorm:"type:varchar(255);index:idx_logs_business_unit_id" json:"business_unit_id"`
	BusinessUnitName        *string   `gorm:"type:varchar(255)" json:"business_unit_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
	RerankOutput            string    `gorm:"type:text" json:"-"` // JSON serialized []schemas.RerankResult
	OCROutput               string    `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostOCRResponse
	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
	OCRInput                string    `gorm:"type:text" json:"-"` // JSON serialized *schemas.OCRDocument
	ImageGenerationInput    string    `gorm:"type:text" json:"-"` // JSON serialized *schemas.ImageGenerationInput
	ImageEditInput          string    `gorm:"type:text" json:"-"` // JSON serialized *schemas.ImageEditInput
	ImageVariationInput     string    `gorm:"type:text" json:"-"` // JSON serialized *schemas.ImageVariationInput
	VideoGenerationInput    string    `gorm:"type:text" json:"-"` // JSON serialized *schemas.VideoGenerationInput
	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
	ListModelsOutput        string    `gorm:"type:text" json:"-"` // JSON serialized []schemas.Model
	VideoGenerationOutput   string    `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostVideoGenerationResponse
	VideoRetrieveOutput     string    `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostVideoRetrieveResponse
	VideoDownloadOutput     string    `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostVideoDownloadResponse
	VideoListOutput         string    `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostVideoListResponse
	VideoDeleteOutput       string    `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostVideoDeleteResponse
	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;index:idx_logs_ts_provider_status,priority:3;not null" json:"status"` // "processing", "success", or "error"
	StopReason              *string   `gorm:"type:varchar(50);index:idx_logs_stop_reason" json:"stop_reason,omitempty"`                   // Why the model stopped: "stop", "length", "content_filter", "tool_calls", etc.
	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
	PassthroughRequestBody  string    `gorm:"type:text" json:"passthrough_request_body,omitempty"`  // Raw body for passthrough requests (UTF-8)
	PassthroughResponseBody string    `gorm:"type:text" json:"passthrough_response_body,omitempty"` // Raw body for passthrough responses (UTF-8)
	RoutingEngineLogs       string    `gorm:"type:text" json:"routing_engine_logs,omitempty"`       // Formatted routing engine decision logs
	PluginLogs              string    `gorm:"type:text" json:"plugin_logs,omitempty"`               // JSON serialized plugin log entries grouped by plugin name
	Metadata                *string   `gorm:"type:text" json:"-"`                                   // JSON serialized map[string]interface{}
	IsLargePayloadRequest   bool      `gorm:"default:false" json:"is_large_payload_request"`
	IsLargePayloadResponse  bool      `gorm:"default:false" json:"is_large_payload_response"`
	HasObject               bool      `gorm:"default:false" json:"-"` // True when payload is stored in object storage

	// 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:"-"`
	CachedReadTokens int `gorm:"default:0" json:"-"`

	CreatedAt time.Time `gorm:"index;not null" json:"created_at"`

	// Virtual fields for JSON output - these will be populated when needed
	RoutingEnginesUsed          []string                                `gorm:"-" json:"routing_engines_used,omitempty"` // Virtual field deserialized from JSON
	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"`
	RerankOutputParsed          []schemas.RerankResult                  `gorm:"-" json:"rerank_output,omitempty"`
	OCROutputParsed             *schemas.BifrostOCRResponse             `gorm:"-" json:"ocr_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"`
	OCRInputParsed              *schemas.OCRDocument                    `gorm:"-" json:"ocr_input,omitempty"`
	ImageGenerationInputParsed  *schemas.ImageGenerationInput           `gorm:"-" json:"image_generation_input,omitempty"`
	ImageEditInputParsed        *schemas.ImageEditInput                 `gorm:"-" json:"image_edit_input,omitempty"`
	ImageVariationInputParsed   *schemas.ImageVariationInput            `gorm:"-" json:"image_variation_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"`
	ListModelsOutputParsed      []schemas.Model                         `gorm:"-" json:"list_models_output,omitempty"`
	MetadataParsed              map[string]interface{}                  `gorm:"-" json:"metadata,omitempty"`
	VideoGenerationInputParsed  *schemas.VideoGenerationInput           `gorm:"-" json:"video_generation_input,omitempty"`
	VideoGenerationOutputParsed *schemas.BifrostVideoGenerationResponse `gorm:"-" json:"video_generation_output,omitempty"`
	VideoRetrieveOutputParsed   *schemas.BifrostVideoGenerationResponse `gorm:"-" json:"video_retrieve_output,omitempty"`
	VideoDownloadOutputParsed   *schemas.BifrostVideoDownloadResponse   `gorm:"-" json:"video_download_output,omitempty"`
	VideoListOutputParsed       *schemas.BifrostVideoListResponse       `gorm:"-" json:"video_list_output,omitempty"`
	VideoDeleteOutputParsed     *schemas.BifrostVideoDeleteResponse     `gorm:"-" json:"video_delete_output,omitempty"`
	AttemptTrailParsed          []schemas.KeyAttemptRecord              `gorm:"-" json:"attempt_trail,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

func NewLogEntryFromMap(entry map[string]interface{}) *Log

NewLogEntryFromMap creates a new Log from a map[string]interface{}

func (*Log) AfterFind

func (l *Log) AfterFind(tx *gorm.DB) error

AfterFind GORM hook to deserialize JSON fields

func (*Log) BeforeCreate

func (l *Log) BeforeCreate(tx *gorm.DB) error

BeforeCreate GORM hook to set created_at and serialize JSON fields

func (*Log) BuildContentSummary

func (l *Log) BuildContentSummary() string

BuildContentSummary creates a searchable text summary

func (*Log) BuildInputContentSummary added in v1.3.2

func (l *Log) BuildInputContentSummary() string

BuildInputContentSummary extracts the last user message text from input fields. This is used in hybrid mode for the content_summary column, which powers full-text search and serves as a display fallback in the log list table. Only the last message is kept — the full conversation history lives in object storage and is merged back on FindByID.

func (*Log) DeserializeFields

func (l *Log) DeserializeFields() error

DeserializeFields converts JSON strings back to Go structs

func (*Log) SerializeFields

func (l *Log) SerializeFields() error

SerializeFields converts Go structs to JSON strings for storage

func (Log) TableName

func (Log) TableName() string

TableName sets the table name for GORM

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
	BatchCreateIfNotExists(ctx context.Context, entries []*Log) error
	FindByID(ctx context.Context, id string) (*Log, error)
	IsLogEntryPresent(ctx context.Context, id string) (bool, error)
	FindFirst(ctx context.Context, query any, fields ...string) (*Log, error)
	FindAll(ctx context.Context, query any, fields ...string) ([]*Log, error)
	FindAllDistinct(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)
	GetSessionLogs(ctx context.Context, sessionID string, pagination PaginationOptions) (*SessionDetailResult, error)
	GetSessionSummary(ctx context.Context, sessionID string) (*SessionSummaryResult, 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)
	GetLatencyHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*LatencyHistogramResult, error)
	GetProviderCostHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ProviderCostHistogramResult, error)
	GetProviderTokenHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ProviderTokenHistogramResult, error)
	GetProviderLatencyHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ProviderLatencyHistogramResult, error)
	GetModelRankings(ctx context.Context, filters SearchFilters) (*ModelRankingResult, error)
	GetUserRankings(ctx context.Context, filters SearchFilters) (*UserRankingResult, error)
	// GetDimensionCostHistogram returns time-bucketed cost data grouped by the specified dimension (e.g., team_id, customer_id).
	GetDimensionCostHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64, dimension HistogramDimension) (*DimensionCostHistogramResult, error)
	// GetDimensionTokenHistogram returns time-bucketed token usage grouped by the specified dimension.
	GetDimensionTokenHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64, dimension HistogramDimension) (*DimensionTokenHistogramResult, error)
	// GetDimensionLatencyHistogram returns time-bucketed latency percentiles grouped by the specified dimension.
	GetDimensionLatencyHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64, dimension HistogramDimension) (*DimensionLatencyHistogramResult, 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)

	// Distinct value methods for filter data
	GetDistinctModels(ctx context.Context) ([]string, error)
	GetDistinctAliases(ctx context.Context) ([]string, error)
	GetDistinctKeyPairs(ctx context.Context, idCol, nameCol string) ([]KeyPairResult, error)
	GetDistinctRoutingEngines(ctx context.Context) ([]string, error)
	GetDistinctStopReasons(ctx context.Context) ([]string, error)
	GetDistinctMetadataKeys(ctx context.Context) (map[string][]string, error)

	// MCP Tool Log histogram methods
	GetMCPHistogram(ctx context.Context, filters MCPToolLogSearchFilters, bucketSizeSeconds int64) (*MCPHistogramResult, error)
	GetMCPCostHistogram(ctx context.Context, filters MCPToolLogSearchFilters, bucketSizeSeconds int64) (*MCPCostHistogramResult, error)
	GetMCPTopTools(ctx context.Context, filters MCPToolLogSearchFilters, limit int) (*MCPTopToolsResult, 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)

	// Async Job methods
	CreateAsyncJob(ctx context.Context, job *AsyncJob) error
	FindAsyncJobByID(ctx context.Context, id string) (*AsyncJob, error)
	UpdateAsyncJob(ctx context.Context, id string, updates map[string]interface{}) error
	DeleteExpiredAsyncJobs(ctx context.Context) (int64, error)
	DeleteStaleAsyncJobs(ctx context.Context, staleSince time.Time) (int64, error)
}

LogStore is the interface for the log store.

func NewLogStore

func NewLogStore(ctx context.Context, config *Config, logger schemas.Logger) (LogStore, error)

NewLogStore creates a new log store based on the configuration. When ObjectStorage is configured, the returned store is wrapped with a HybridLogStore that offloads payloads to S3-compatible object storage.

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 MCPCostHistogramBucket added in v1.2.31

type MCPCostHistogramBucket struct {
	Timestamp time.Time `json:"timestamp"`
	TotalCost float64   `json:"total_cost"`
}

MCPCostHistogramBucket represents a single time bucket for MCP cost data

type MCPCostHistogramResult added in v1.2.31

type MCPCostHistogramResult struct {
	Buckets           []MCPCostHistogramBucket `json:"buckets"`
	BucketSizeSeconds int64                    `json:"bucket_size_seconds"`
}

MCPCostHistogramResult represents the MCP cost histogram query result

type MCPHistogramBucket added in v1.2.31

type MCPHistogramBucket struct {
	Timestamp time.Time `json:"timestamp"`
	Count     int64     `json:"count"`
	Success   int64     `json:"success"`
	Error     int64     `json:"error"`
}

MCPHistogramBucket represents a single time bucket for MCP tool call volume

type MCPHistogramResult added in v1.2.31

type MCPHistogramResult struct {
	Buckets           []MCPHistogramBucket `json:"buckets"`
	BucketSizeSeconds int64                `json:"bucket_size_seconds"`
}

MCPHistogramResult represents the MCP tool call volume histogram query result

type MCPToolLog added in v1.2.17

type MCPToolLog struct {
	ID             string    `gorm:"primaryKey;type:varchar(255)" json:"id"`
	RequestID      string    `gorm:"type:varchar(255);column:request_id;index:idx_mcp_logs_request_id" json:"request_id,omitempty"`             // The original request ID from context
	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"
	Metadata       string    `gorm:"type:text" json:"-"`                                                // JSON serialized map[string]interface{}
	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"`
	MetadataParsed     map[string]interface{}  `gorm:"-" json:"metadata,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) 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 MCPTopToolResult added in v1.2.31

type MCPTopToolResult struct {
	ToolName string  `json:"tool_name"`
	Count    int64   `json:"count"`
	Cost     float64 `json:"cost"`
}

MCPTopToolResult represents a single tool's aggregated stats

type MCPTopToolsResult added in v1.2.31

type MCPTopToolsResult struct {
	Tools []MCPTopToolResult `json:"tools"`
}

MCPTopToolsResult represents the top N MCP tools by call count

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 ModelRankingEntry added in v1.2.31

type ModelRankingEntry struct {
	Model         string  `json:"model"`
	Provider      string  `json:"provider"`
	TotalRequests int64   `json:"total_requests"`
	SuccessCount  int64   `json:"success_count"`
	SuccessRate   float64 `json:"success_rate"`
	TotalTokens   int64   `json:"total_tokens"`
	TotalCost     float64 `json:"total_cost"`
	AvgLatency    float64 `json:"avg_latency"`
}

ModelRankingEntry represents aggregated stats for a single model over a time period.

type ModelRankingResult added in v1.2.31

type ModelRankingResult struct {
	Rankings []ModelRankingWithTrend `json:"rankings"`
}

ModelRankingResult is the response for the model rankings endpoint.

type ModelRankingTrend added in v1.2.31

type ModelRankingTrend struct {
	HasPreviousPeriod bool    `json:"has_previous_period"`
	RequestsTrend     float64 `json:"requests_trend"`
	TokensTrend       float64 `json:"tokens_trend"`
	CostTrend         float64 `json:"cost_trend"`
	LatencyTrend      float64 `json:"latency_trend"`
}

ModelRankingTrend represents the percentage change compared to the previous period.

type ModelRankingWithTrend added in v1.2.31

type ModelRankingWithTrend struct {
	ModelRankingEntry
	Trend ModelRankingTrend `json:"trend"`
}

ModelRankingWithTrend combines ranking entry with trend data.

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 ProviderCostHistogramBucket added in v1.2.25

type ProviderCostHistogramBucket struct {
	Timestamp  time.Time          `json:"timestamp"`
	TotalCost  float64            `json:"total_cost"`
	ByProvider map[string]float64 `json:"by_provider"`
}

ProviderCostHistogramBucket represents a single time bucket for provider cost data

type ProviderCostHistogramResult added in v1.2.25

type ProviderCostHistogramResult struct {
	Buckets           []ProviderCostHistogramBucket `json:"buckets"`
	BucketSizeSeconds int64                         `json:"bucket_size_seconds"`
	Providers         []string                      `json:"providers"`
}

ProviderCostHistogramResult represents the provider cost histogram query result

type ProviderLatencyHistogramBucket added in v1.2.25

type ProviderLatencyHistogramBucket struct {
	Timestamp  time.Time                       `json:"timestamp"`
	ByProvider map[string]ProviderLatencyStats `json:"by_provider"`
}

ProviderLatencyHistogramBucket represents a single time bucket for provider latency data

type ProviderLatencyHistogramResult added in v1.2.25

type ProviderLatencyHistogramResult struct {
	Buckets           []ProviderLatencyHistogramBucket `json:"buckets"`
	BucketSizeSeconds int64                            `json:"bucket_size_seconds"`
	Providers         []string                         `json:"providers"`
}

ProviderLatencyHistogramResult represents the provider latency histogram query result

type ProviderLatencyStats added in v1.2.25

type ProviderLatencyStats struct {
	AvgLatency    float64 `json:"avg_latency"`
	P90Latency    float64 `json:"p90_latency"`
	P95Latency    float64 `json:"p95_latency"`
	P99Latency    float64 `json:"p99_latency"`
	TotalRequests int64   `json:"total_requests"`
}

ProviderLatencyStats represents latency statistics for a single provider

type ProviderTokenHistogramBucket added in v1.2.25

type ProviderTokenHistogramBucket struct {
	Timestamp  time.Time                     `json:"timestamp"`
	ByProvider map[string]ProviderTokenStats `json:"by_provider"`
}

ProviderTokenHistogramBucket represents a single time bucket for provider token data

type ProviderTokenHistogramResult added in v1.2.25

type ProviderTokenHistogramResult struct {
	Buckets           []ProviderTokenHistogramBucket `json:"buckets"`
	BucketSizeSeconds int64                          `json:"bucket_size_seconds"`
	Providers         []string                       `json:"providers"`
}

ProviderTokenHistogramResult represents the provider token histogram query result

type ProviderTokenStats added in v1.2.25

type ProviderTokenStats struct {
	PromptTokens     int64 `json:"prompt_tokens"`
	CompletionTokens int64 `json:"completion_tokens"`
	TotalTokens      int64 `json:"total_tokens"`
}

ProviderTokenStats represents token statistics for a single provider

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) BatchCreateIfNotExists added in v1.2.24

func (s *RDBLogStore) BatchCreateIfNotExists(ctx context.Context, entries []*Log) error

BatchCreateIfNotExists inserts multiple log entries in a single transaction. Uses ON CONFLICT DO NOTHING for idempotency.

func (*RDBLogStore) BulkUpdateCost added in v1.1.49

func (s *RDBLogStore) BulkUpdateCost(ctx context.Context, updates map[string]float64) error

BulkUpdateCost updates log costs in bulk, using a PostgreSQL-specific batched VALUES update when available and per-row updates for other dialects.

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) CreateAsyncJob added in v1.2.22

func (s *RDBLogStore) CreateAsyncJob(ctx context.Context, job *AsyncJob) error

CreateAsyncJob creates a new async job record in 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) DeleteExpiredAsyncJobs added in v1.2.22

func (s *RDBLogStore) DeleteExpiredAsyncJobs(ctx context.Context) (int64, error)

DeleteExpiredAsyncJobs deletes async jobs whose expires_at has passed. Only deletes jobs that have a non-null expires_at (i.e., completed or failed jobs). Deletes in batches to avoid long-running transactions that hold row locks.

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) DeleteStaleAsyncJobs added in v1.2.22

func (s *RDBLogStore) DeleteStaleAsyncJobs(ctx context.Context, staleSince time.Time) (int64, error)

DeleteStaleAsyncJobs deletes async jobs stuck in "processing" status since before the given time. This handles edge cases like marshal failures or server crashes that leave jobs permanently stuck.

func (*RDBLogStore) FindAll added in v1.1.0

func (s *RDBLogStore) FindAll(ctx context.Context, query any, fields ...string) ([]*Log, error)

FindAll finds all log entries from the database.

func (*RDBLogStore) FindAllDistinct added in v1.2.24

func (s *RDBLogStore) FindAllDistinct(ctx context.Context, query any, fields ...string) ([]*Log, error)

FindAllDistinct finds all distinct log entries for the given fields. Uses SQL DISTINCT to return only unique combinations, avoiding loading all rows when only unique values are needed (e.g., for filter dropdowns).

func (*RDBLogStore) FindAsyncJobByID added in v1.2.22

func (s *RDBLogStore) FindAsyncJobByID(ctx context.Context, id string) (*AsyncJob, error)

FindAsyncJobByID retrieves an async job by its ID.

func (*RDBLogStore) FindByID added in v1.2.9

func (s *RDBLogStore) FindByID(ctx context.Context, id string) (*Log, error)

FindByID gets a log entry from the database by its ID.

func (*RDBLogStore) FindFirst added in v1.1.0

func (s *RDBLogStore) FindFirst(ctx context.Context, query any, fields ...string) (*Log, error)

FindFirst gets a log entry from the database.

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) Flush added in v1.1.0

func (s *RDBLogStore) Flush(ctx context.Context, since time.Time) error

Flush deletes old log entries from the database.

func (*RDBLogStore) FlushMCPToolLogs added in v1.2.17

func (s *RDBLogStore) FlushMCPToolLogs(ctx context.Context, since time.Time) error

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. Scoped to recent data to avoid full table scans.

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. Scoped to recent data to avoid full table scans.

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. Scoped to recent data to avoid full table scans.

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) GetDimensionCostHistogram added in v1.3.1

func (s *RDBLogStore) GetDimensionCostHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64, dimension HistogramDimension) (*DimensionCostHistogramResult, error)

GetDimensionCostHistogram returns time-bucketed cost data grouped by the specified dimension. Uses the mv_logs_hourly materialized view on PostgreSQL when eligible; falls back to raw queries otherwise.

func (*RDBLogStore) GetDimensionLatencyHistogram added in v1.3.1

func (s *RDBLogStore) GetDimensionLatencyHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64, dimension HistogramDimension) (*DimensionLatencyHistogramResult, error)

GetDimensionLatencyHistogram returns time-bucketed latency percentiles grouped by the specified dimension. Uses the mv_logs_hourly materialized view on PostgreSQL when eligible; falls back to raw queries otherwise. The fallback path computes AVG latency only (no percentiles) since percentile_cont is Postgres-specific.

func (*RDBLogStore) GetDimensionTokenHistogram added in v1.3.1

func (s *RDBLogStore) GetDimensionTokenHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64, dimension HistogramDimension) (*DimensionTokenHistogramResult, error)

GetDimensionTokenHistogram returns time-bucketed token usage grouped by the specified dimension. Uses the mv_logs_hourly materialized view on PostgreSQL when eligible; falls back to raw queries otherwise.

func (*RDBLogStore) GetDistinctAliases added in v1.3.1

func (s *RDBLogStore) GetDistinctAliases(ctx context.Context) ([]string, error)

GetDistinctAliases returns all unique non-empty alias values using SELECT DISTINCT. Scoped to recent data to avoid full table scans.

func (*RDBLogStore) GetDistinctKeyPairs added in v1.2.22

func (s *RDBLogStore) GetDistinctKeyPairs(ctx context.Context, idCol, nameCol string) ([]KeyPairResult, error)

GetDistinctKeyPairs returns unique non-empty ID-Name pairs for the given columns using SELECT DISTINCT. idCol and nameCol must be valid column names (e.g., "selected_key_id", "selected_key_name").

func (*RDBLogStore) GetDistinctMetadataKeys added in v1.2.28

func (s *RDBLogStore) GetDistinctMetadataKeys(ctx context.Context) (map[string][]string, error)

GetDistinctMetadataKeys returns unique metadata keys and their distinct values from recent logs. It scans a bounded number of recent rows to avoid memory bloat on large tables.

func (*RDBLogStore) GetDistinctModels added in v1.2.22

func (s *RDBLogStore) GetDistinctModels(ctx context.Context) ([]string, error)

GetDistinctModels returns all unique non-empty model values using SELECT DISTINCT. Scoped to recent data to avoid full table scans.

func (*RDBLogStore) GetDistinctRoutingEngines added in v1.2.22

func (s *RDBLogStore) GetDistinctRoutingEngines(ctx context.Context) ([]string, error)

GetDistinctRoutingEngines returns all unique routing engine values from the comma-separated column. Scoped to recent data to avoid full table scans.

func (*RDBLogStore) GetDistinctStopReasons added in v1.3.6

func (s *RDBLogStore) GetDistinctStopReasons(ctx context.Context) ([]string, error)

GetDistinctStopReasons returns all unique non-empty stop_reason values using SELECT DISTINCT. Scoped to recent data to avoid full table scans.

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) GetLatencyHistogram added in v1.2.24

func (s *RDBLogStore) GetLatencyHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*LatencyHistogramResult, error)

GetLatencyHistogram returns time-bucketed latency percentiles (avg, p90, p95, p99) for the given filters. PostgreSQL uses database-level percentile_cont aggregation (returns 1 row per bucket). MySQL and SQLite fall back to Go-based percentile computation (loads individual latency values).

func (*RDBLogStore) GetMCPCostHistogram added in v1.2.31

func (s *RDBLogStore) GetMCPCostHistogram(ctx context.Context, filters MCPToolLogSearchFilters, bucketSizeSeconds int64) (*MCPCostHistogramResult, error)

GetMCPCostHistogram returns time-bucketed MCP cost data for the given filters.

func (*RDBLogStore) GetMCPHistogram added in v1.2.31

func (s *RDBLogStore) GetMCPHistogram(ctx context.Context, filters MCPToolLogSearchFilters, bucketSizeSeconds int64) (*MCPHistogramResult, error)

GetMCPHistogram returns time-bucketed MCP tool call volume 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) GetMCPTopTools added in v1.2.31

func (s *RDBLogStore) GetMCPTopTools(ctx context.Context, filters MCPToolLogSearchFilters, limit int) (*MCPTopToolsResult, error)

GetMCPTopTools returns the top N MCP tools by call count for 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) GetModelRankings added in v1.2.31

func (s *RDBLogStore) GetModelRankings(ctx context.Context, filters SearchFilters) (*ModelRankingResult, error)

GetModelRankings returns models ranked by usage with trend comparison to the previous period.

func (*RDBLogStore) GetProviderCostHistogram added in v1.2.25

func (s *RDBLogStore) GetProviderCostHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ProviderCostHistogramResult, error)

GetProviderCostHistogram returns time-bucketed cost data with provider breakdown for the given filters.

func (*RDBLogStore) GetProviderLatencyHistogram added in v1.2.25

func (s *RDBLogStore) GetProviderLatencyHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ProviderLatencyHistogramResult, error)

GetProviderLatencyHistogram returns time-bucketed latency percentiles with provider breakdown for the given filters. PostgreSQL uses database-level percentile_cont aggregation. MySQL and SQLite fall back to Go-based percentile computation.

func (*RDBLogStore) GetProviderTokenHistogram added in v1.2.25

func (s *RDBLogStore) GetProviderTokenHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ProviderTokenHistogramResult, error)

GetProviderTokenHistogram returns time-bucketed token usage with provider breakdown for the given filters.

func (*RDBLogStore) GetSessionLogs added in v1.3.1

func (s *RDBLogStore) GetSessionLogs(ctx context.Context, sessionID string, pagination PaginationOptions) (*SessionDetailResult, error)

GetSessionLogs returns paginated logs for a single parent_request_id session.

func (*RDBLogStore) GetSessionSummary added in v1.3.1

func (s *RDBLogStore) GetSessionSummary(ctx context.Context, sessionID string) (*SessionSummaryResult, error)

GetSessionSummary returns aggregate totals for a single parent_request_id session.

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) GetUserRankings added in v1.3.1

func (s *RDBLogStore) GetUserRankings(ctx context.Context, filters SearchFilters) (*UserRankingResult, error)

GetUserRankings returns users ranked by usage with trend comparison to the previous period.

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) IsLogEntryPresent added in v1.3.0

func (s *RDBLogStore) IsLogEntryPresent(ctx context.Context, id string) (bool, error)

IsLogEntryPresent checks if a log entry is present in the database. Here we dont load entire log entry in memory - just check if it exists.

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) Update added in v1.1.0

func (s *RDBLogStore) Update(ctx context.Context, id string, entry any) error

Update updates a log entry in the database.

func (*RDBLogStore) UpdateAsyncJob added in v1.2.22

func (s *RDBLogStore) UpdateAsyncJob(ctx context.Context, id string, updates map[string]interface{}) error

UpdateAsyncJob updates an async job record with the provided fields.

func (*RDBLogStore) UpdateMCPToolLog added in v1.2.17

func (s *RDBLogStore) UpdateMCPToolLog(ctx context.Context, id string, entry any) error

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"`
	Aliases           []string          `json:"aliases,omitempty"`
	Status            []string          `json:"status,omitempty"`
	StopReasons       []string          `json:"stop_reasons,omitempty"` // For filtering by stop reason (stop, length, content_filter, refusal, tool_calls, etc.)
	Objects           []string          `json:"objects,omitempty"`      // For filtering by request type (chat.completion, text.completion, embedding)
	ParentRequestID   string            `json:"parent_request_id,omitempty"`
	SelectedKeyIDs    []string          `json:"selected_key_ids,omitempty"`
	VirtualKeyIDs     []string          `json:"virtual_key_ids,omitempty"`
	RoutingRuleIDs    []string          `json:"routing_rule_ids,omitempty"`
	TeamIDs           []string          `json:"team_ids,omitempty"`
	CustomerIDs       []string          `json:"customer_ids,omitempty"`
	UserIDs           []string          `json:"user_ids,omitempty"`
	BusinessUnitIDs   []string          `json:"business_unit_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"`
	MetadataFilters   map[string]string `json:"metadata_filters,omitempty"` // key=metadataKey, value=metadataValue for filtering by metadata
}

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 individual attempts that succeeded
	UserFacingSuccessRate     float64 `json:"user_facing_success_rate"`                // Percentage of user requests that ultimately succeeded (fallback chains counted as one request)
	UserFacingTotalRequests   int64   `json:"user_facing_total_requests"`              // Count of root requests (fallback_index = 0) used as denominator for UserFacingSuccessRate
	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
	CacheHitRateTotalRequests *int64  `json:"cache_hit_rate_total_requests,omitempty"` // Completed requests used as local-cache hit-rate denominator
	DirectCacheHits           *int64  `json:"direct_cache_hits,omitempty"`             // Number of direct (exact) semantic cache hits
	SemanticCacheHits         *int64  `json:"semantic_cache_hits,omitempty"`           // Number of semantic (fuzzy) cache hits
}

type SessionDetailResult added in v1.3.1

type SessionDetailResult struct {
	SessionID     string            `json:"session_id"`
	Logs          []Log             `json:"logs"`
	Pagination    PaginationOptions `json:"pagination"`
	Count         int64             `json:"count"`
	ReturnedCount int               `json:"returned_count"`
	HasMore       bool              `json:"has_more"`
}

type SessionSummaryResult added in v1.3.1

type SessionSummaryResult struct {
	SessionID   string  `json:"session_id"`
	Count       int64   `json:"count"`
	TotalCost   float64 `json:"total_cost"`
	TotalTokens int64   `json:"total_tokens"`
	StartedAt   string  `json:"started_at,omitempty"`
	LatestAt    string  `json:"latest_at,omitempty"`
	DurationMs  int64   `json:"duration_ms"`
}

type SortBy

type SortBy string
const (
	SortByTimestamp SortBy = "timestamp"
	SortByLatency   SortBy = "latency"
	SortByTokens    SortBy = "tokens"
	SortByCost      SortBy = "cost"
)

type SortOrder

type SortOrder string
const (
	SortAsc  SortOrder = "asc"
	SortDesc SortOrder = "desc"
)

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"`
	CachedReadTokens int64     `json:"cached_read_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

type UserRankingEntry added in v1.3.1

type UserRankingEntry struct {
	UserID        string  `json:"user_id"`
	TotalRequests int64   `json:"total_requests"`
	TotalTokens   int64   `json:"total_tokens"`
	TotalCost     float64 `json:"total_cost"`
}

UserRankingEntry represents a single user's usage statistics.

type UserRankingResult added in v1.3.1

type UserRankingResult struct {
	Rankings []UserRankingWithTrend `json:"rankings"`
}

UserRankingResult is the response for the user rankings endpoint.

type UserRankingTrend added in v1.3.1

type UserRankingTrend struct {
	HasPreviousPeriod bool    `json:"has_previous_period"`
	RequestsTrend     float64 `json:"requests_trend"`
	TokensTrend       float64 `json:"tokens_trend"`
	CostTrend         float64 `json:"cost_trend"`
}

UserRankingTrend represents the percentage change compared to the previous period.

type UserRankingWithTrend added in v1.3.1

type UserRankingWithTrend struct {
	UserRankingEntry
	Trend UserRankingTrend `json:"trend"`
}

UserRankingWithTrend combines ranking entry with trend data.

Jump to

Keyboard shortcuts

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