runtime

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package runtime provides a backend-agnostic metrics collection abstraction for runtime observability. It includes an in-memory implementation for testing and a no-op implementation for zero-overhead production use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

type Collector interface {
	// Counter returns a named counter (creates if needed).
	Counter(name string) CounterMetric
	// Gauge returns a named gauge (creates if needed).
	Gauge(name string) GaugeMetric
	// Histogram returns a named histogram with the given bucket boundaries.
	Histogram(name string, buckets []float64) HistogramMetric
}

Collector is the interface for recording runtime metrics.

func Nop

func Nop() Collector

Nop returns a Collector that discards all metrics with zero allocation.

type CounterMetric

type CounterMetric interface {
	Inc()
}

CounterMetric is a monotonically increasing counter.

type GaugeMetric

type GaugeMetric interface {
	Set(value float64)
}

GaugeMetric is a metric that can be set to any value.

type HistogramMetric

type HistogramMetric interface {
	Observe(value float64)
}

HistogramMetric records observations into pre-defined buckets.

type HistogramSnapshot

type HistogramSnapshot struct {
	Count   int64
	Sum     float64
	Buckets map[float64]int64 // upper bound -> cumulative count
}

HistogramSnapshot is a point-in-time copy of a histogram.

type InMemoryCollector

type InMemoryCollector struct {
	// contains filtered or unexported fields
}

InMemoryCollector stores metrics in memory for testing and local use.

func NewInMemory

func NewInMemory() *InMemoryCollector

NewInMemory creates a new InMemoryCollector.

func (*InMemoryCollector) Counter

func (c *InMemoryCollector) Counter(name string) CounterMetric

Counter returns or creates a named counter.

func (*InMemoryCollector) Gauge

func (c *InMemoryCollector) Gauge(name string) GaugeMetric

Gauge returns or creates a named gauge.

func (*InMemoryCollector) Histogram

func (c *InMemoryCollector) Histogram(name string, buckets []float64) HistogramMetric

Histogram returns or creates a named histogram with bucket boundaries.

func (*InMemoryCollector) Snapshot

func (c *InMemoryCollector) Snapshot() Snapshot

Snapshot returns a point-in-time copy of all metrics.

type Snapshot

type Snapshot struct {
	Counters   map[string]int64
	Gauges     map[string]float64
	Histograms map[string]HistogramSnapshot
}

Snapshot is a point-in-time copy of all metric values.

Jump to

Keyboard shortcuts

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