Documentation
¶
Index ¶
- Constants
- Variables
- func DecActiveSessions()
- func GetMemoryStatsJSON() ([]byte, error)
- func IncActiveSessions()
- func RecordMemoryStats()
- func RecordModelLatency(duration time.Duration)
- func RecordModelRequest(model string)
- func RecordStorageError(operation string)
- func RecordStorageOperation(operation string)
- func RecordToolCall(toolName string)
- func RecordToolDuration(toolName string, duration time.Duration)
- func SetActiveSessions(count int64)
- func StartCPUProfile(w io.Writer) error
- func StopCPUProfile()
- func WriteHeapProfile(w io.Writer) error
- type Config
- type Counter
- type Event
- type EventType
- type Gauge
- func (g *Gauge) Add(delta int64)
- func (g *Gauge) Dec()
- func (g *Gauge) Get() int64
- func (g *Gauge) GetFloat64() float64
- func (g *Gauge) Inc()
- func (g *Gauge) Labels() Labels
- func (g *Gauge) MarshalJSON() ([]byte, error)
- func (g *Gauge) Name() string
- func (g *Gauge) Set(value int64)
- func (g *Gauge) SetFloat64(value float64)
- func (g *Gauge) String() string
- func (g *Gauge) Type() MetricType
- type Histogram
- func (h *Histogram) GetBuckets() []int64
- func (h *Histogram) GetCount() int64
- func (h *Histogram) GetSum() float64
- func (h *Histogram) Labels() Labels
- func (h *Histogram) MarshalJSON() ([]byte, error)
- func (h *Histogram) Name() string
- func (h *Histogram) Observe(value float64)
- func (h *Histogram) ObserveDuration(duration time.Duration)
- func (h *Histogram) P50() float64
- func (h *Histogram) P90() float64
- func (h *Histogram) P99() float64
- func (h *Histogram) Percentile(p float64) float64
- func (h *Histogram) String() string
- func (h *Histogram) Type() MetricType
- type Hub
- func (h *Hub) Close()
- func (h *Hub) DroppedEvents() int64
- func (h *Hub) Flush()
- func (h *Hub) GetStats() Stats
- func (h *Hub) Publish(event Event)
- func (h *Hub) Stop()
- func (h *Hub) Subscribe() (<-chan Event, func())
- func (h *Hub) SubscribeWithID() (<-chan Event, string)
- func (h *Hub) Unsubscribe(id string)
- func (h *Hub) Wait()
- type Labels
- type MemoryStats
- type Metric
- type MetricType
- type Persister
- type ProfileConfig
- type ProfileRecorder
- type Registry
- func (r *Registry) Export() map[string]any
- func (r *Registry) ExportJSON() ([]byte, error)
- func (r *Registry) GetAllCounters() []*Counter
- func (r *Registry) GetAllGauges() []*Gauge
- func (r *Registry) GetAllHistograms() []*Histogram
- func (r *Registry) GetCounter(name string, labels Labels) (*Counter, bool)
- func (r *Registry) GetGauge(name string, labels Labels) (*Gauge, bool)
- func (r *Registry) GetHistogram(name string, labels Labels) (*Histogram, bool)
- func (r *Registry) RegisterCounter(name string, labels Labels) *Counter
- func (r *Registry) RegisterGauge(name string, labels Labels) *Gauge
- func (r *Registry) RegisterHistogram(name string, labels Labels, buckets []float64) *Histogram
- func (r *Registry) WriteTo(w io.Writer) (int64, error)
- type SQLiteStore
- func (s *SQLiteStore) Append(ctx context.Context, streamID string, events []Event) error
- func (s *SQLiteStore) Close() error
- func (s *SQLiteStore) Read(ctx context.Context, streamID string, fromVersion int64) ([]Event, error)
- func (s *SQLiteStore) ReadByType(ctx context.Context, streamID string, eventType EventType) ([]Event, error)
- type Stats
- type Timer
Constants ¶
const ( MetricToolCallsTotal = "tool_calls_total" MetricToolDurationSeconds = "tool_duration_seconds" MetricModelRequestsTotal = "model_requests_total" MetricModelLatencySeconds = "model_latency_seconds" MetricStorageOperationsTotal = "storage_operations_total" MetricStorageErrorsTotal = "storage_errors_total" MetricActiveSessions = "active_sessions" MetricMemoryUsageBytes = "memory_usage_bytes" )
Predefined metric names for Buckley.
const ( // DefaultPersistBatchSize is the max events to buffer before writing. DefaultPersistBatchSize = 100 // DefaultPersistFlushInterval is how often to flush buffered events. DefaultPersistFlushInterval = 500 * time.Millisecond )
const ( // DefaultEventQueueSize is the default buffer size for the event queue. DefaultEventQueueSize = 1000 // DefaultBatchSize is the default number of events to batch before flushing. DefaultBatchSize = 100 // DefaultFlushInterval is the default interval to flush batched events. DefaultFlushInterval = 100 * time.Millisecond // DefaultRateLimit is the default rate limit for events per second. DefaultRateLimit = 1000 // DefaultSubscriberChannelSize is the default buffer size for subscriber channels. DefaultSubscriberChannelSize = 64 )
Variables ¶
var DefaultHistogramBuckets = []float64{
0.001,
0.005,
0.01,
0.025,
0.05,
0.1,
0.25,
0.5,
1.0,
2.5,
5.0,
10.0,
}
DefaultHistogramBuckets are the default latency buckets in milliseconds. Buckets: 1ms, 5ms, 10ms, 25ms, 50ms, 100ms, 250ms, 500ms, 1s, 2.5s, 5s, 10s
var DefaultRegistry = NewRegistry()
DefaultRegistry is the default global registry.
Functions ¶
func DecActiveSessions ¶
func DecActiveSessions()
DecActiveSessions decrements the active sessions count.
func GetMemoryStatsJSON ¶
GetMemoryStatsJSON returns memory statistics as JSON.
func IncActiveSessions ¶
func IncActiveSessions()
IncActiveSessions increments the active sessions count.
func RecordMemoryStats ¶
func RecordMemoryStats()
RecordMemoryStats records current memory statistics.
func RecordModelLatency ¶
RecordModelLatency records the latency of a model request.
func RecordModelRequest ¶
func RecordModelRequest(model string)
RecordModelRequest records a model request.
func RecordStorageError ¶
func RecordStorageError(operation string)
RecordStorageError records a storage error.
func RecordStorageOperation ¶
func RecordStorageOperation(operation string)
RecordStorageOperation records a storage operation.
func RecordToolDuration ¶
RecordToolDuration records the duration of a tool execution.
func SetActiveSessions ¶
func SetActiveSessions(count int64)
SetActiveSessions sets the number of active sessions.
func StartCPUProfile ¶
StartCPUProfile starts CPU profiling and writes to the given writer. Returns an error if profiling is already started.
func WriteHeapProfile ¶
WriteHeapProfile writes the current heap profile to the given writer.
Types ¶
type Config ¶
type Config struct {
// EventQueueSize is the buffer size for the internal event queue.
// Events are dropped if the queue is full.
EventQueueSize int
// BatchSize is the number of events to accumulate before flushing to subscribers.
BatchSize int
// FlushInterval is the maximum time to wait before flushing batched events.
FlushInterval time.Duration
// RateLimit is the maximum number of events per second.
// Events exceeding this rate are dropped.
RateLimit int
// SubscriberChannelSize is the buffer size for individual subscriber channels.
SubscriberChannelSize int
}
Config holds configuration options for the Hub.
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter is a monotonically increasing metric.
func NewCounter ¶
NewCounter creates a new counter with the given name and labels.
func RegisterCounter ¶
RegisterCounter registers a counter in the default registry.
func (*Counter) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
type Event ¶
type Event struct {
Type EventType `json:"type"`
Timestamp time.Time `json:"timestamp"`
SessionID string `json:"sessionId,omitempty"`
PlanID string `json:"planId,omitempty"`
TaskID string `json:"taskId,omitempty"`
Data map[string]any `json:"data,omitempty"`
}
Event describes workflow telemetry that UIs and IPC clients can consume.
type EventType ¶
type EventType string
EventType identifies the kind of telemetry event.
const ( EventPlanCreated EventType = "plan.created" EventPlanUpdated EventType = "plan.updated" EventTaskStarted EventType = "task.started" EventTaskCompleted EventType = "task.completed" EventTaskFailed EventType = "task.failed" EventResearchStarted EventType = "research.started" EventResearchCompleted EventType = "research.completed" EventResearchFailed EventType = "research.failed" EventBuilderStarted EventType = "builder.started" EventBuilderCompleted EventType = "builder.completed" EventBuilderFailed EventType = "builder.failed" EventCostUpdated EventType = "cost.updated" EventTokenUsageUpdated EventType = "tokens.updated" EventShellCommandStarted EventType = "shell.started" EventShellCommandCompleted EventType = "shell.completed" EventShellCommandFailed EventType = "shell.failed" EventToolStarted EventType = "tool.started" EventToolCompleted EventType = "tool.completed" EventToolFailed EventType = "tool.failed" EventModelStreamStarted EventType = "model.stream_start" EventModelStreamEnded EventType = "model.stream_end" EventIndexStarted EventType = "index.started" EventIndexCompleted EventType = "index.completed" EventIndexFailed EventType = "index.failed" EventEditorInline EventType = "editor.inline" EventEditorPropose EventType = "editor.propose" EventEditorApply EventType = "editor.apply" EventUICommand EventType = "ui.command" EventExperimentStarted EventType = "experiment.started" EventExperimentCompleted EventType = "experiment.completed" EventExperimentFailed EventType = "experiment.failed" EventExperimentVariantStarted EventType = "experiment.variant.started" EventExperimentVariantCompleted EventType = "experiment.variant.completed" EventExperimentVariantFailed EventType = "experiment.variant.failed" EventRLMIteration EventType = "rlm.iteration" EventCircuitFailure EventType = "circuit.failure" EventCircuitStateChange EventType = "circuit.state_change" // RLM transparency events EventRLMEscalation EventType = "rlm.escalation" // Weight tier escalation EventRLMToolCall EventType = "rlm.tool_call" // Sub-agent tool execution EventRLMReasoning EventType = "rlm.reasoning" // Coordinator reasoning trace EventRLMBudgetWarning EventType = "rlm.budget_warning" // Token/time budget alerts // Browser runtime events EventBrowserSessionCreated EventType = "browser.session_created" EventBrowserSessionClosed EventType = "browser.session_closed" EventBrowserObserve EventType = "browser.observe" EventBrowserAction EventType = "browser.action" EventBrowserActionFailed EventType = "browser.action_failed" EventBrowserFrameDelivered EventType = "browser.frame_delivered" EventBrowserStreamEvent EventType = "browser.stream_event" // Machine state events EventMachineSpawned EventType = "machine.spawned" EventMachineState EventType = "machine.state" EventMachineCompleted EventType = "machine.completed" EventMachineFailed EventType = "machine.failed" EventMachineSteering EventType = "machine.steering" // Machine lock events EventMachineLockAcquired EventType = "machine.lock.acquired" EventMachineLockWaiting EventType = "machine.lock.waiting" EventMachineLockReleased EventType = "machine.lock.released" EventMachineLockStale EventType = "machine.lock.stale" // Machine tool events EventMachineToolStart EventType = "machine.tool.start" EventMachineToolComplete EventType = "machine.tool.complete" // Machine review events EventMachineReview EventType = "machine.review" EventMachineIteration EventType = "machine.iteration" )
type Gauge ¶
type Gauge struct {
// contains filtered or unexported fields
}
Gauge is a metric that can go up and down.
func RegisterGauge ¶
RegisterGauge registers a gauge in the default registry.
func (*Gauge) GetFloat64 ¶
GetFloat64 returns the current value as float64.
func (*Gauge) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Gauge) SetFloat64 ¶
SetFloat64 sets the gauge to the given float64 value (stored as nanoseconds for time values).
type Histogram ¶
type Histogram struct {
// contains filtered or unexported fields
}
Histogram is a metric that samples observations and counts them in buckets.
func NewHistogram ¶
NewHistogram creates a new histogram with the given name, labels, and buckets. If buckets is nil, DefaultHistogramBuckets is used.
func RegisterHistogram ¶
RegisterHistogram registers a histogram in the default registry.
func (*Histogram) GetBuckets ¶
GetBuckets returns the bucket counts.
func (*Histogram) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Histogram) Observe ¶
Observe records a value in the histogram. Value should be in seconds (float64).
func (*Histogram) ObserveDuration ¶
ObserveDuration records a duration observation.
func (*Histogram) Percentile ¶
Percentile returns the estimated value at the given percentile (0-1). Returns 0 if no observations have been recorded.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub is an optimized telemetry event hub that supports: - Non-blocking event publishing with buffered queue - Event batching for high-frequency scenarios - Rate limiting using token bucket algorithm - Thread-safe subscriber management - Graceful shutdown with event flushing
func NewHubWithConfig ¶
NewHubWithConfig creates a new telemetry hub with custom configuration.
func (*Hub) Close ¶
func (h *Hub) Close()
Close unsubscribes all listeners and prevents future publications. This is an alias for Stop() + Wait() for backward compatibility.
func (*Hub) DroppedEvents ¶
DroppedEvents returns the total number of events dropped due to rate limiting or full subscriber channels.
func (*Hub) Flush ¶
func (h *Hub) Flush()
Flush forces an immediate flush of batched events. This is useful for tests or when immediate delivery is required.
func (*Hub) Publish ¶
Publish notifies all subscribers of an event. This method is non-blocking; events are dropped if the queue is full. Maintains backward compatibility with the original Hub.Publish signature.
func (*Hub) Stop ¶
func (h *Hub) Stop()
Stop initiates graceful shutdown and flushes remaining events. This method returns immediately; use Wait() to block until complete.
func (*Hub) Subscribe ¶
Subscribe returns a channel that will receive future events and a cleanup func. Maintains backward compatibility with the original Hub.Subscribe signature.
func (*Hub) SubscribeWithID ¶
SubscribeWithID returns a channel that will receive future events and a subscriber ID. The returned ID can be used with Unsubscribe(id) for explicit unsubscription.
func (*Hub) Unsubscribe ¶
Unsubscribe removes a subscriber by ID and closes its channel. This is thread-safe and can be called concurrently.
type MemoryStats ¶
type MemoryStats struct {
Alloc uint64 `json:"alloc"`
TotalAlloc uint64 `json:"total_alloc"`
Sys uint64 `json:"sys"`
NumGC uint32 `json:"num_gc"`
HeapAlloc uint64 `json:"heap_alloc"`
HeapSys uint64 `json:"heap_sys"`
HeapIdle uint64 `json:"heap_idle"`
HeapInuse uint64 `json:"heap_inuse"`
HeapReleased uint64 `json:"heap_released"`
HeapObjects uint64 `json:"heap_objects"`
StackInuse uint64 `json:"stack_inuse"`
StackSys uint64 `json:"stack_sys"`
Goroutines int `json:"goroutines"`
Timestamp int64 `json:"timestamp"`
}
MemoryStats holds key memory statistics.
func GetMemoryStats ¶
func GetMemoryStats() MemoryStats
GetMemoryStats returns current memory statistics.
type Metric ¶
type Metric interface {
Name() string
Type() MetricType
String() string
}
Metric is the common interface for all metric types.
type MetricType ¶
type MetricType string
MetricType identifies the kind of metric.
const ( MetricTypeCounter MetricType = "counter" MetricTypeGauge MetricType = "gauge" MetricTypeHistogram MetricType = "histogram" )
type Persister ¶
type Persister struct {
// contains filtered or unexported fields
}
Persister subscribes to a Hub and durably writes events to a SQLiteStore. Events are batched for write efficiency.
func NewPersister ¶
func NewPersister(hub *Hub, store *SQLiteStore, streamID string) *Persister
NewPersister creates a Persister that subscribes to the Hub and writes events to the store under the given streamID (typically a session ID).
type ProfileConfig ¶
ProfileConfig holds configuration for continuous profiling.
func DefaultProfileConfig ¶
func DefaultProfileConfig() *ProfileConfig
DefaultProfileConfig returns default profiling configuration.
type ProfileRecorder ¶
type ProfileRecorder struct {
// contains filtered or unexported fields
}
ProfileRecorder handles continuous profiling.
func NewProfileRecorder ¶
func NewProfileRecorder(config *ProfileConfig) *ProfileRecorder
NewProfileRecorder creates a new profile recorder.
func (*ProfileRecorder) Start ¶
func (pr *ProfileRecorder) Start()
Start begins continuous profiling.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages all metrics.
func (*Registry) ExportJSON ¶
ExportJSON exports all metrics as JSON.
func (*Registry) GetAllCounters ¶
GetAllCounters returns all registered counters.
func (*Registry) GetAllGauges ¶
GetAllGauges returns all registered gauges.
func (*Registry) GetAllHistograms ¶
GetAllHistograms returns all registered histograms.
func (*Registry) GetCounter ¶
GetCounter retrieves a counter by name and labels.
func (*Registry) GetHistogram ¶
GetHistogram retrieves a histogram by name and labels.
func (*Registry) RegisterCounter ¶
RegisterCounter registers a counter metric.
func (*Registry) RegisterGauge ¶
RegisterGauge registers a gauge metric.
func (*Registry) RegisterHistogram ¶
RegisterHistogram registers a histogram metric.
type SQLiteStore ¶
type SQLiteStore struct {
// contains filtered or unexported fields
}
SQLiteStore persists telemetry events to SQLite for replay and analysis.
func NewSQLiteStore ¶
func NewSQLiteStore(dbPath string) (*SQLiteStore, error)
NewSQLiteStore creates a new SQLite-backed event store. Accepts a file path or ":memory:" for in-memory storage.
func (*SQLiteStore) Append ¶
Append writes events to the store. Each event gets an auto-incremented version within the stream for ordering and replay.
func (*SQLiteStore) Close ¶
func (s *SQLiteStore) Close() error
Close closes the database connection.
func (*SQLiteStore) Read ¶
func (s *SQLiteStore) Read(ctx context.Context, streamID string, fromVersion int64) ([]Event, error)
Read returns events for a stream starting from the given version (inclusive). Pass version=0 to read all events.
func (*SQLiteStore) ReadByType ¶
func (s *SQLiteStore) ReadByType(ctx context.Context, streamID string, eventType EventType) ([]Event, error)
ReadByType returns events for a stream filtered by event type.