observability

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 5 Imported by: 0

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

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 NewHook

func NewHook(c Collector) *Hook

NewHook creates a new observability hook with the given collector.

func (*Hook) AfterMutation

func (h *Hook) AfterMutation(_ context.Context, qc *hook.QueryContext, _, _ any) error

AfterMutation records the duration for mutations.

func (*Hook) AfterQuery

func (h *Hook) AfterQuery(_ context.Context, qc *hook.QueryContext, _ any) error

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.

type MetricEntry

type MetricEntry struct {
	Table     string
	Operation string
	Duration  time.Duration
	Error     error
	Timestamp time.Time
}

MetricEntry represents a single recorded metric.

Jump to

Keyboard shortcuts

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