diff --git a/op-ufm/op-ufm/pkg/metrics/metrics.go b/op-ufm/op-ufm/pkg/metrics/metrics.go index c0725b5..ea0e973 100644 --- a/op-ufm/op-ufm/pkg/metrics/metrics.go +++ b/op-ufm/op-ufm/pkg/metrics/metrics.go @@ -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", diff --git a/op-ufm/op-ufm/pkg/provider/roundtrip.go b/op-ufm/op-ufm/pkg/provider/roundtrip.go index 0f4ffca..610b61c 100644 --- a/op-ufm/op-ufm/pkg/provider/roundtrip.go +++ b/op-ufm/op-ufm/pkg/provider/roundtrip.go @@ -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 {