ceremonyclient/go-libp2p/p2p/metricshelper/registerer.go
2023-08-20 23:07:43 -05:00

21 lines
480 B
Go

package metricshelper
import (
"errors"
"github.com/prometheus/client_golang/prometheus"
)
// RegisterCollectors registers the collectors with reg ignoring
// reregistration error and panics on any other error
func RegisterCollectors(reg prometheus.Registerer, collectors ...prometheus.Collector) {
for _, c := range collectors {
err := reg.Register(c)
if err != nil {
if ok := errors.As(err, &prometheus.AlreadyRegisteredError{}); !ok {
panic(err)
}
}
}
}