Documentation
¶
Overview ¶
Package telemetry provides a global metrics registry with pluggable backends (expvar, Prometheus, or no-op) for recording anonymous usage statistics.
Index ¶
- func Init(m Metrics)
- func InitFromConfig(cfg config.Config)
- func RecordBytes(stage string, n int64)
- func RecordCapture(sourceKind string)
- func RecordError(category string)
- func RecordUpload(success bool, durationMs int64)
- func Snapshot() map[string]any
- func TimedUpload(ctx context.Context, fn func(context.Context) error) error
- type ExpvarMetrics
- type Metrics
- type NoopMetrics
- type PrometheusMetrics
- func (p *PrometheusMetrics) Handler() http.Handler
- func (p *PrometheusMetrics) RecordBytes(stage string, n int64)
- func (p *PrometheusMetrics) RecordCapture(sourceKind string)
- func (p *PrometheusMetrics) RecordError(category string)
- func (p *PrometheusMetrics) RecordUpload(success bool, durationMs int64)
- func (p *PrometheusMetrics) Snapshot() map[string]any
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init(m Metrics)
Init sets the global metrics implementation. Call this once at startup with your chosen backend.
func InitFromConfig ¶
InitFromConfig initializes the global telemetry based on config settings. Call this early in your main() or application setup.
func RecordBytes ¶
RecordBytes records n bytes processed at the named pipeline stage.
func RecordCapture ¶
func RecordCapture(sourceKind string)
RecordCapture increments the capture event counter for the given source kind.
func RecordError ¶
func RecordError(category string)
RecordError increments the error counter for the given category.
func RecordUpload ¶
RecordUpload records the outcome and duration of an upload attempt.
Types ¶
type ExpvarMetrics ¶
type ExpvarMetrics struct {
// contains filtered or unexported fields
}
ExpvarMetrics implements Metrics using Go's built-in expvar package. Expvar publishes metrics at /debug/vars (HTTP handler can be registered separately).
func NewExpvarMetrics ¶
func NewExpvarMetrics() *ExpvarMetrics
NewExpvarMetrics creates and registers an expvar-based metrics collector.
func (*ExpvarMetrics) RecordBytes ¶
func (e *ExpvarMetrics) RecordBytes(stage string, n int64)
func (*ExpvarMetrics) RecordCapture ¶
func (e *ExpvarMetrics) RecordCapture(sourceKind string)
func (*ExpvarMetrics) RecordError ¶
func (e *ExpvarMetrics) RecordError(category string)
func (*ExpvarMetrics) RecordUpload ¶
func (e *ExpvarMetrics) RecordUpload(success bool, durationMs int64)
func (*ExpvarMetrics) Snapshot ¶
func (e *ExpvarMetrics) Snapshot() map[string]any
type Metrics ¶
type Metrics interface {
// RecordCapture increments capture event count and tracks source type
RecordCapture(sourceKind string)
// RecordBytes tracks bytes processed (ingested, normalized, uploaded)
RecordBytes(stage string, n int64)
// RecordUpload increments upload attempts and tracks success/failure
RecordUpload(success bool, durationMs int64)
// RecordError increments error count by category
RecordError(category string)
// Snapshot returns current metrics as a map for debugging/export
Snapshot() map[string]any
}
Metrics represents the core telemetry interface for collecting anonymized metrics. Implementations include expvar (default) and prometheus (optional).
type NoopMetrics ¶
type NoopMetrics struct{}
NoopMetrics is a silent implementation for when telemetry is disabled.
func (*NoopMetrics) RecordBytes ¶
func (n *NoopMetrics) RecordBytes(stage string, bytes int64)
func (*NoopMetrics) RecordCapture ¶
func (n *NoopMetrics) RecordCapture(sourceKind string)
func (*NoopMetrics) RecordError ¶
func (n *NoopMetrics) RecordError(category string)
func (*NoopMetrics) RecordUpload ¶
func (n *NoopMetrics) RecordUpload(success bool, durationMs int64)
func (*NoopMetrics) Snapshot ¶
func (n *NoopMetrics) Snapshot() map[string]any
type PrometheusMetrics ¶
type PrometheusMetrics struct {
// contains filtered or unexported fields
}
PrometheusMetrics provides Prometheus-compatible metrics collection. Each instance owns its own prometheus.Registry for full isolation. The Prometheus counters are the single source of truth — Snapshot() reads directly from them, eliminating dual bookkeeping.
func NewPrometheusMetrics ¶
func NewPrometheusMetrics() *PrometheusMetrics
NewPrometheusMetrics creates a new Prometheus metrics collector with its own registry.
func (*PrometheusMetrics) Handler ¶
func (p *PrometheusMetrics) Handler() http.Handler
Handler returns an HTTP handler for the /metrics endpoint. The handler only exposes metrics from this instance's registry.
Example usage:
http.Handle("/metrics", metrics.Handler())
http.ListenAndServe(":2112", nil)
func (*PrometheusMetrics) RecordBytes ¶
func (p *PrometheusMetrics) RecordBytes(stage string, n int64)
RecordBytes records the number of bytes processed at a given stage.
func (*PrometheusMetrics) RecordCapture ¶
func (p *PrometheusMetrics) RecordCapture(sourceKind string)
RecordCapture increments the capture counter for a given source kind.
func (*PrometheusMetrics) RecordError ¶
func (p *PrometheusMetrics) RecordError(category string)
RecordError increments the error counter for a given category.
func (*PrometheusMetrics) RecordUpload ¶
func (p *PrometheusMetrics) RecordUpload(success bool, durationMs int64)
RecordUpload records an upload attempt with its success status and duration.
func (*PrometheusMetrics) Snapshot ¶
func (p *PrometheusMetrics) Snapshot() map[string]any
Snapshot returns a point-in-time view of all metrics by reading directly from the Prometheus registry. This is the single source of truth.