Hello Prometheans,
At my company, we’ve run into multiple production panics using promauto due to issues with counter.With(prometheus.Labels{})—whether it’s typos, missing/extra labels, or messing up the order when using counter.WithLabelValues().
To solve this, we built a custom wrapper that adds type safety by using a struct for labels instead of a raw map. With Go generics, it’s straightforward: you declare a type (struct with fields = labels) at the metric registration stage, and only that type can be used when calling the metric.
I’ve put together a PR for this:
https://github.com/prometheus/client_golang/pull/1598
It’s an optional sub-package (called promsafe), fully non-breaking, and easy to switch to for those already using promauto. Currently, it covers only Counter, but if the idea gains traction, I’m happy to extend it to other metrics.
I’d really appreciate your support—or even critical feedback if you’re not on board with the idea.