obs

package
v0.260430.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: MPL-2.0 Imports: 8 Imported by: 0

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

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 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 RecordEntryV2

type RecordEntryV2 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"`

	// Dual-stage request recording
	OriginalRequest    *RecordRequest `json:"original_request,omitempty"`    // Before any transforms
	TransformedRequest *RecordRequest `json:"transformed_request,omitempty"` // After base transform

	// Dual-stage response recording
	ProviderResponse *RecordResponse `json:"provider_response,omitempty"` // Raw response from provider
	FinalResponse    *RecordResponse `json:"final_response,omitempty"`    // Final response to client

	DurationMs     int64                  `json:"duration_ms"`
	Error          string                 `json:"error,omitempty"`
	Metadata       map[string]interface{} `json:"metadata,omitempty"`
	TransformSteps []string               `json:"transform_steps,omitempty"` // Applied transforms
}

RecordEntryV2 represents a V2 recorded entry with dual-stage request/response recording This is used for protocol conversion scenarios where we need to capture: - Original request (before transforms) - Transformed request (after protocol conversion) - Provider response (raw response from provider) - Final response (after reverse transformation, if applicable)

type RecordMode

type RecordMode string

RecordMode defines the recording mode

const (
	RecordModeAll      RecordMode = "all" // Record both request and response
	RecordModeScenario RecordMode = "scenario"
	RecordModeSlim     RecordMode = "slim" // TODO: Not implemented yet

	RecordModeRequest           RecordMode = "request"          // Record only requests (original + transformed)
	RecordModeResponse          RecordMode = "response"         // Record only response
	RecordModeV2RequestResponse RecordMode = "request_response" // Record both requests and responses
)

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 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 V2 modes: "request", "response_only", "request_response"

func (*Sink) Close

func (r *Sink) Close()

Close closes all open record files

func (*Sink) GetBaseDir

func (r *Sink) GetBaseDir() string

GetBaseDir returns the base directory for recordings

func (*Sink) IsEnabled

func (r *Sink) IsEnabled() bool

IsEnabled returns whether recording is enabled

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) RecordEntryV2

func (r *Sink) RecordEntryV2(entry *RecordEntryV2)

RecordEntryV2 records a V2 entry with dual-stage request/response recording This is used for protocol conversion scenarios where we need to capture requests at multiple stages

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)

Jump to

Keyboard shortcuts

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