diff --git a/eth/filters/metrics.go b/eth/filters/metrics.go index 969d7b0f1153..c6f493f41138 100644 --- a/eth/filters/metrics.go +++ b/eth/filters/metrics.go @@ -145,6 +145,16 @@ var ( Help: "Number of dropped txs sent", }, ) + + metricsTraceTxTimer = prometheus.NewHistogramVec( + prometheus.HistogramOpts{ + Subsystem: streamSubsystem, + Name: "trace_tx_duration", + Help: "Trace tx duration in seconds", + Buckets: []float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10}, + }, + []string{}, + ) ) func init() { @@ -173,4 +183,6 @@ func init() { register(metricsDroppedTxsEnd) register(metricsDroppedTxsReceived) register(metricsDroppedTxsSent) + + register(metricsTraceTxTimer) } diff --git a/eth/filters/trace_api.go b/eth/filters/trace_api.go index c53464278c74..e37f201d56f5 100644 --- a/eth/filters/trace_api.go +++ b/eth/filters/trace_api.go @@ -7,6 +7,8 @@ import ( "fmt" "math/big" + "github.com/prometheus/client_golang/prometheus" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/consensus/misc/eip1559" @@ -273,7 +275,11 @@ func traceTx(message *core.Message, txCtx *tracers.Context, vmctx vm.BlockContex if _, err = core.ApplyMessage(vmenv, message, new(core.GasPool).AddGas(message.GasLimit)); err != nil { return nil, fmt.Errorf("tracing failed: %w", err) } - return tracer.GetTrace() + + timer := prometheus.NewTimer(metricsTraceTxTimer.With(nil)) + trace, err := tracer.GetTrace() + timer.ObserveDuration() + return trace, err } // traceBlock traces all transactions in a block.