Documentation
¶
Overview ¶
Package debug provides request/response capture functionality for debugging.
Package debug provides request/response capture functionality for debugging.
Package debug provides request/response capture functionality for debugging.
Index ¶
- Constants
- func RedactSensitive(data []byte) []byte
- type CaptureEntry
- type CaptureLogger
- func (c *CaptureLogger) CaptureNormalized(requestID string, provider string, data []byte)
- func (c *CaptureLogger) CaptureOriginal(requestID string, data []byte)
- func (c *CaptureLogger) CaptureTransformed(requestID string, provider string, data []byte)
- func (c *CaptureLogger) CaptureUpstreamRequest(requestID string, provider string, data []byte)
- func (c *CaptureLogger) CaptureUpstreamResponse(requestID string, provider string, data []byte)
- func (c *CaptureLogger) Close() error
- type DebugCapture
- type Storage
Constants ¶
const ( PhaseOriginal = "original" PhaseNormalized = "normalized" PhaseUpstreamRequest = "upstream-request" PhaseUpstreamResponse = "upstream-response" PhaseTransformed = "transformed" )
Capture phase constants.
Variables ¶
This section is empty.
Functions ¶
func RedactSensitive ¶
RedactSensitive redacts sensitive fields (api_key, api-key, authorization) from JSON data. It replaces values with "[REDACTED]".
Types ¶
type CaptureEntry ¶
type CaptureEntry struct {
Timestamp time.Time `json:"timestamp"`
Phase string `json:"phase"`
Provider string `json:"provider"`
RequestID string `json:"request_id"`
Data json.RawMessage `json:"data"`
}
CaptureEntry represents a single captured request/response phase.
type CaptureLogger ¶
type CaptureLogger struct {
// contains filtered or unexported fields
}
CaptureLogger handles async capture of request/response data for debugging. It uses a buffered channel and background worker to avoid blocking the main request flow.
func NewCaptureLogger ¶
func NewCaptureLogger(storage *Storage, enabled bool) *CaptureLogger
NewCaptureLogger creates a new async capture logger. Returns nil if capture is not enabled or storage is nil. The logger starts a background worker goroutine that processes capture entries.
func (*CaptureLogger) CaptureNormalized ¶
func (c *CaptureLogger) CaptureNormalized(requestID string, provider string, data []byte)
CaptureNormalized captures the request after normalization to the internal format. The provider parameter indicates which provider this request is being routed to. The capture is performed asynchronously via the background worker.
func (*CaptureLogger) CaptureOriginal ¶
func (c *CaptureLogger) CaptureOriginal(requestID string, data []byte)
CaptureOriginal captures the original incoming request data. This is called before any transformation occurs. The capture is performed asynchronously via the background worker.
func (*CaptureLogger) CaptureTransformed ¶
func (c *CaptureLogger) CaptureTransformed(requestID string, provider string, data []byte)
CaptureTransformed captures the final response after transformation to Anthropic format. This is the response that will be sent back to the client. The capture is performed asynchronously via the background worker.
func (*CaptureLogger) CaptureUpstreamRequest ¶
func (c *CaptureLogger) CaptureUpstreamRequest(requestID string, provider string, data []byte)
CaptureUpstreamRequest captures the request as sent to the upstream provider. This is after all transformations have been applied. The capture is performed asynchronously via the background worker.
func (*CaptureLogger) CaptureUpstreamResponse ¶
func (c *CaptureLogger) CaptureUpstreamResponse(requestID string, provider string, data []byte)
CaptureUpstreamResponse captures the raw response from the upstream provider. This is before any transformation back to the Anthropic format. The capture is performed asynchronously via the background worker.
func (*CaptureLogger) Close ¶
func (c *CaptureLogger) Close() error
Close shuts down the capture logger. It closes the entry channel and waits for the background worker to finish. Any entries still in the channel will be processed before Close returns. Safe to call multiple times - only the first call will have effect.
type DebugCapture ¶
type DebugCapture struct {
Enabled bool `json:"enabled"`
Directory string `json:"directory"`
MaxFiles int `json:"max_files"`
MaxFileSize int64 `json:"max_file_size"`
CapturePhases []string `json:"capture_phases"`
RedactAPIKeys bool `json:"redact_api_keys"`
}
DebugCapture holds configuration for request/response capture.
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage manages debug capture file storage with rotation.
func NewStorage ¶
func NewStorage(cfg config.DebugCapture) (*Storage, error)
NewStorage creates a new debug storage manager. It ensures the debug directory exists and scans existing files to set initial fileCount.
func (*Storage) WriteEntry ¶
func (s *Storage) WriteEntry(entry CaptureEntry) error
WriteEntry marshals the entry to JSON and writes it to the current file. It handles file rotation when MaxFileSize is exceeded and deletes oldest files when MaxFiles is exceeded. Thread-safe via mutex.