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