Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions promrus.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ func NewPrometheusHook() (*PrometheusHook, error) {
for _, level := range supportedLevels {
counterVec.WithLabelValues(level.String())
}
// Try to unregister the counter vector, in case already registered for some reason,
// e.g. double initialisation/configuration done by mistake by the end-user.
prometheus.Unregister(counterVec)
// Try to register the counter vector:
err := prometheus.Register(counterVec)
// If another library already registered the same metric, use it
if err != nil {
return nil, err
ar, ok := err.(prometheus.AlreadyRegisteredError)
if !ok {
return nil, err
}
counterVec, ok = ar.ExistingCollector.(*prometheus.CounterVec)
if !ok {
return nil, err
}
}
return &PrometheusHook{
counterVec: counterVec,
Expand Down