Skip to content

Add pluggable metrics interface (no Prometheus dependency) #66

@satmihir

Description

@satmihir

Currently, the library does not expose a way to emit metrics without directly depending on a specific metrics backend (e.g., Prometheus). This limits flexibility for downstream consumers who may want to integrate with different systems such as OpenTelemetry, StatsD, or CloudWatch.

Introduce a lightweight metrics abstraction layer that allows the library to emit metrics via user-provided implementations, without importing Prometheus or any other concrete backend.

Define a minimal set of interfaces:

type Counter interface {
    Inc(delta float64)
}

type Gauge interface {
    Set(value float64)
    Add(delta float64)
}

type Histogram interface {
    Observe(value float64)
}

type MetricsFactory interface {
    NewCounter(name, help string, labels ...string) Counter
    NewGauge(name, help string, labels ...string) Gauge
    NewHistogram(name, help string, buckets []float64, labels ...string) Histogram
}

Libraries will depend only on these interfaces.

A no-op implementation will be provided as default so that metrics can be safely ignored if no factory is supplied:

var NoopFactory MetricsFactory = noopFactory{}

Downstream users can plug in their preferred backend via adapters, e.g.:

  • Prometheus (prometheus.NewCounterVec, etc.)
  • OpenTelemetry
  • StatsD / Datadog
  • CloudWatch

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions