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.
--
You received this message because you are subscribed to the Google Groups
"Prometheus Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/prometheus-developers/d20a4f59-6447-4c75-95b2-9fb7525f3478n%40googlegroups.com.