cmetrics package provides Prometheus metrics with a declare-then-use model: register your counters and histograms up front, then emit them from anywhere. The cprometheus package (from gocopper/pkg) exposes them over HTTP.
Declaring Metrics
To declare your application’s metrics, provide a*cmetrics.Registry and add cmetrics.WireModule to your wire set:
pkg/app/metrics.go
copper create already include this file and the wiring, so you only need to add your metrics to the registry.
Emitting Metrics
To emit a metric, injectcmetrics.Metrics and reference the metric by name:
Emitting an unregistered metric name (or a mismatched label set) logs a warning and does nothing; it will never panic or return an error.
Built-in HTTP Metrics
Every registry automatically includes two built-in metrics, which are emitted bychttp.RequestLoggerMiddleware (wired in by default):
http_requests_total{status_code, path}http_request_duration_seconds{status_code, path}
path label is the route template (/api/rockets/{id}) rather than the raw URL, so cardinality stays manageable.
Exposing the Metrics Endpoint
To expose your metrics over HTTP, addcprometheus.WireModule, register *cprometheus.Router in your handler, and enable the endpoint in your config: