Commit 8c7efbb0 authored by Felipe Andrade's avatar Felipe Andrade

metric with error details

parent 98ca6d4e
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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment