Documentation
¶
Overview ¶
Package observability provides hooks for exposing query timing and error metrics. Currently uses a simple in-memory collector interface that can be wired to Prometheus, OpenTelemetry, or any metrics backend.
Index ¶
- type Collector
- type Hook
- func (h *Hook) AfterMutation(_ context.Context, qc *hook.QueryContext, _, _ any) error
- func (h *Hook) AfterQuery(_ context.Context, qc *hook.QueryContext, _ any) error
- func (h *Hook) BeforeMutation(_ context.Context, qc *hook.QueryContext, _ any) (*hook.HookResult, error)
- func (h *Hook) BeforeQuery(_ context.Context, qc *hook.QueryContext) (*hook.HookResult, error)
- type InMemoryCollector
- type MetricEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Collector ¶
type Collector interface {
// RecordQuery records timing for a query/mutation.
RecordQuery(table, operation string, duration time.Duration, err error)
}
Collector is the interface for recording metrics.
type Hook ¶
type Hook struct {
// contains filtered or unexported fields
}
Hook is a combined PreQueryHook and PostQueryHook that measures query timing.
func (*Hook) AfterMutation ¶
AfterMutation records the duration for mutations.
func (*Hook) AfterQuery ¶
AfterQuery records the duration.
func (*Hook) BeforeMutation ¶
func (h *Hook) BeforeMutation(_ context.Context, qc *hook.QueryContext, _ any) (*hook.HookResult, error)
BeforeMutation records the start time for mutations.
func (*Hook) BeforeQuery ¶
func (h *Hook) BeforeQuery(_ context.Context, qc *hook.QueryContext) (*hook.HookResult, error)
BeforeQuery records the start time.
type InMemoryCollector ¶
type InMemoryCollector struct {
TotalQueries atomic.Int64
TotalErrors atomic.Int64
// contains filtered or unexported fields
}
InMemoryCollector is a simple in-memory metrics collector for testing.
func NewInMemoryCollector ¶
func NewInMemoryCollector() *InMemoryCollector
NewInMemoryCollector creates a new in-memory collector.
func (*InMemoryCollector) Entries ¶
func (c *InMemoryCollector) Entries() []MetricEntry
Entries returns all recorded metric entries.
func (*InMemoryCollector) RecordQuery ¶
func (c *InMemoryCollector) RecordQuery(table, operation string, duration time.Duration, err error)
func (*InMemoryCollector) Reset ¶
func (c *InMemoryCollector) Reset()
Reset clears all recorded entries.