metric with error details
This commit is contained in:
parent
668228c5c3
commit
98025fdb3f
@ -1,6 +1,9 @@
|
||||
package metrics
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
@ -77,6 +80,8 @@ var (
|
||||
})
|
||||
)
|
||||
|
||||
var nonAlphanumericRegex = regexp.MustCompile(`[^a-zA-Z ]+`)
|
||||
|
||||
func RecordError(provider string, errorLabel string) {
|
||||
if Debug {
|
||||
log.Debug("metric inc", "m", "errors_total",
|
||||
@ -85,6 +90,14 @@ func RecordError(provider string, errorLabel string) {
|
||||
errorsTotal.WithLabelValues(provider, errorLabel).Inc()
|
||||
}
|
||||
|
||||
// RecordErrorDetails concats the error message to the label removing non-alpha chars
|
||||
func RecordErrorDetails(provider string, label string, err error) {
|
||||
errClean := nonAlphanumericRegex.ReplaceAllString(err.Error(), "")
|
||||
errClean = strings.ReplaceAll(errClean, " ", "_")
|
||||
label = fmt.Sprintf("%s.%s", label)
|
||||
RecordError(provider, label)
|
||||
}
|
||||
|
||||
func RecordRPCLatency(provider string, client string, method string, latency time.Duration) {
|
||||
if Debug {
|
||||
log.Debug("metric set", "m", "rpc_latency",
|
||||
|
@ -70,6 +70,7 @@ func (p *Provider) RoundTrip(ctx context.Context) {
|
||||
}
|
||||
} else {
|
||||
log.Error("cant send transaction", "provider", p.name, "err", err)
|
||||
metrics.RecordErrorDetails(p.name, "ethclient.SendTransaction", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user