Documentation
¶
Overview ¶
Package obs provides a unified observability layer for Go applications, integrating structured logging, metrics, and distributed tracing via OpenTelemetry.
It offers simple, high-level APIs to initialize and use telemetry components without exposing underlying complexity. Ideal for microservices and cloud-native apps.
Index ¶
- type ActionType
- type HistoryEntry
- type MemoryLogger
- func (ml *MemoryLogger) ClearHistory() error
- func (ml *MemoryLogger) GetActionStats() map[ActionType]int
- func (ml *MemoryLogger) GetCurrentStatus() *ServerStatus
- func (ml *MemoryLogger) GetHistory(limit int) []HistoryEntry
- func (ml *MemoryLogger) LogAction(action ActionType, details interface{}, success bool, message string) error
- func (ml *MemoryLogger) UpdateServerStatus(running bool, port int, uptime string, requestCount int) error
- type RecordEntry
- type RecordMode
- type RecordRequest
- type RecordResponse
- type ServerStatus
- type Sink
- func (r *Sink) Close()
- func (r *Sink) GetBaseDir() string
- func (r *Sink) IsEnabled() bool
- func (r *Sink) Record(provider, model string, req *RecordRequest, resp *RecordResponse, ...)
- func (r *Sink) RecordWithMetadata(provider, model string, req *RecordRequest, resp *RecordResponse, ...)
- func (r *Sink) RecordWithScenario(provider, model, scenario string, req *RecordRequest, resp *RecordResponse, ...)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActionType ¶
type ActionType string
ActionType represents the type of action performed
const ( ActionAddProvider ActionType = "add_provider" ActionDeleteProvider ActionType = "delete_provider" ActionUpdateProvider ActionType = "update_provider" ActionStartServer ActionType = "start_server" ActionStopServer ActionType = "stop_server" ActionRestartServer ActionType = "restart_server" ActionGenerateToken ActionType = "generate_token" ActionUpdateDefaults ActionType = "update_defaults" ActionFetchModels ActionType = "fetch_models" )
type HistoryEntry ¶ added in v0.260124.900
type HistoryEntry struct {
Timestamp time.Time `json:"timestamp"`
Action ActionType `json:"action"`
Details interface{} `json:"details"`
Success bool `json:"success"`
Message string `json:"message"`
}
HistoryEntry represents a single history entry
type MemoryLogger ¶ added in v0.260124.900
type MemoryLogger struct {
// contains filtered or unexported fields
}
MemoryLogger manages logging and history
func NewMemoryLogger ¶ added in v0.260124.900
func NewMemoryLogger() (*MemoryLogger, error)
NewMemoryLogger creates a new memory logger
func (*MemoryLogger) ClearHistory ¶ added in v0.260124.900
func (ml *MemoryLogger) ClearHistory() error
ClearHistory clears all history entries
func (*MemoryLogger) GetActionStats ¶ added in v0.260124.900
func (ml *MemoryLogger) GetActionStats() map[ActionType]int
GetActionStats returns statistics for different action types
func (*MemoryLogger) GetCurrentStatus ¶ added in v0.260124.900
func (ml *MemoryLogger) GetCurrentStatus() *ServerStatus
GetCurrentStatus returns current server status
func (*MemoryLogger) GetHistory ¶ added in v0.260124.900
func (ml *MemoryLogger) GetHistory(limit int) []HistoryEntry
GetHistory returns recent history entries
func (*MemoryLogger) LogAction ¶ added in v0.260124.900
func (ml *MemoryLogger) LogAction(action ActionType, details interface{}, success bool, message string) error
LogAction logs an action to history
func (*MemoryLogger) UpdateServerStatus ¶ added in v0.260124.900
func (ml *MemoryLogger) UpdateServerStatus(running bool, port int, uptime string, requestCount int) error
UpdateServerStatus updates server status
type RecordEntry ¶
type RecordEntry struct {
Timestamp string `json:"timestamp"`
RequestID string `json:"request_id"`
Provider string `json:"provider"`
Scenario string `json:"scenario,omitempty"` // Scenario: openai, anthropic, claude_code, etc.
Model string `json:"model"`
Request *RecordRequest `json:"request"`
Response *RecordResponse `json:"response"`
DurationMs int64 `json:"duration_ms"`
Error string `json:"error,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
RecordEntry represents a single recorded request/response pair
type RecordMode ¶
type RecordMode string
RecordMode defines the recording mode
const ( RecordModeAll RecordMode = "all" // Record both request and response RecordModeResponse RecordMode = "response" // Record only response RecordModeScenario RecordMode = "scenario" RecordModeSlim RecordMode = "slim" // TODO: Not implemented yet )
type RecordRequest ¶
type RecordRequest struct {
Method string `json:"method"`
URL string `json:"url"`
Headers map[string]string `json:"headers"`
Body map[string]interface{} `json:"body,omitempty"`
}
RecordRequest represents the HTTP request details
type RecordResponse ¶
type RecordResponse struct {
StatusCode int `json:"status_code"`
Headers map[string]string `json:"headers"`
Body map[string]interface{} `json:"body,omitempty"`
// Streaming support
IsStreaming bool `json:"is_streaming,omitempty"`
StreamChunks []string `json:"-"` // Parsed SSE data chunks
}
RecordResponse represents the HTTP response details
type ServerStatus ¶ added in v0.260124.900
type ServerStatus struct {
Timestamp time.Time `json:"timestamp"`
Running bool `json:"running"`
Port int `json:"port"`
Uptime string `json:"uptime"`
RequestCount int `json:"request_count"`
}
ServerStatus represents server status information
type Sink ¶
type Sink struct {
// contains filtered or unexported fields
}
Sink manages recording of HTTP requests/responses to JSONL files
func NewSink ¶
func NewSink(baseDir string, mode RecordMode) *Sink
NewSink creates a new record sink mode: empty string = disabled, "all" = record all, "response" = response only
func (*Sink) GetBaseDir ¶
GetBaseDir returns the base directory for recordings
func (*Sink) Record ¶
func (r *Sink) Record(provider, model string, req *RecordRequest, resp *RecordResponse, duration time.Duration, err error)
Record records a single request/response pair
func (*Sink) RecordWithMetadata ¶
func (r *Sink) RecordWithMetadata(provider, model string, req *RecordRequest, resp *RecordResponse, duration time.Duration, metadata map[string]interface{}, err error)
RecordWithMetadata records a request/response with additional metadata
func (*Sink) RecordWithScenario ¶
func (r *Sink) RecordWithScenario(provider, model, scenario string, req *RecordRequest, resp *RecordResponse, duration time.Duration, err error)
RecordWithScenario records a request/response with scenario information Uses scenario-based file naming (e.g., claude_code-{date}.jsonl)