@@ -34,26 +34,29 @@ var (
3434const rpcCallLatencyBeholder = "rpc_call_latency"
3535
3636// RPCClientMetrics records RPC call latency to Prometheus and Beholder (failures: success="false"; same pattern as multinode metrics).
37- // Construct once per chain (or process) with ChainFamily and ChainID; pass rpcUrl and isSendOnly on each call
38- // when they vary by node or request.
37+ // Construct once per client with the full stable label set and record requests by call name.
3938type RPCClientMetrics interface {
4039 // RecordRequest records latency for an RPC call (observed in nanoseconds for Prometheus and Beholder).
4140 // Failures use success="false"; derive error rate from rpc_call_latency_count{success="false"} (or equivalent).
42- RecordRequest (ctx context.Context , rpcURL string , isSendOnly bool , callName string , latency time.Duration , err error )
41+ RecordRequest (ctx context.Context , callName string , latency time.Duration , err error )
4342}
4443
4544var _ RPCClientMetrics = (* rpcClientMetrics )(nil )
4645
4746type rpcClientMetrics struct {
4847 chainFamily string
4948 chainID string
49+ rpcURL string
50+ isSendOnly bool
5051 latencyHis metric.Float64Histogram
5152}
5253
53- // RPCClientMetricsConfig holds labels that are fixed for the lifetime of the metrics handle (e.g. one per chain ).
54+ // RPCClientMetricsConfig holds labels that are fixed for the lifetime of the metrics handle (e.g. one per client ).
5455type RPCClientMetricsConfig struct {
5556 ChainFamily string
5657 ChainID string
58+ RPCURL string
59+ IsSendOnly bool
5760}
5861
5962// NewRPCClientMetrics creates RPC client metrics that publish to Prometheus and Beholder.
@@ -65,24 +68,26 @@ func NewRPCClientMetrics(cfg RPCClientMetricsConfig) (RPCClientMetrics, error) {
6568 return & rpcClientMetrics {
6669 chainFamily : cfg .ChainFamily ,
6770 chainID : cfg .ChainID ,
71+ rpcURL : cfg .RPCURL ,
72+ isSendOnly : cfg .IsSendOnly ,
6873 latencyHis : latency ,
6974 }, nil
7075}
7176
72- func (m * rpcClientMetrics ) RecordRequest (ctx context.Context , rpcURL string , isSendOnly bool , callName string , latency time.Duration , err error ) {
77+ func (m * rpcClientMetrics ) RecordRequest (ctx context.Context , callName string , latency time.Duration , err error ) {
7378 successStr := "true"
7479 if err != nil {
7580 successStr = "false"
7681 }
77- sendStr := strconv .FormatBool (isSendOnly )
82+ sendStr := strconv .FormatBool (m . isSendOnly )
7883 latencyNs := float64 (latency )
7984
80- RPCCallLatency .WithLabelValues (m .chainFamily , m .chainID , rpcURL , sendStr , successStr , callName ).Observe (latencyNs )
85+ RPCCallLatency .WithLabelValues (m .chainFamily , m .chainID , m . rpcURL , sendStr , successStr , callName ).Observe (latencyNs )
8186
8287 latAttrs := metric .WithAttributes (
8388 attribute .String ("chainFamily" , m .chainFamily ),
8489 attribute .String ("chainID" , m .chainID ),
85- attribute .String ("rpcUrl" , rpcURL ),
90+ attribute .String ("rpcUrl" , m . rpcURL ),
8691 attribute .String ("isSendOnly" , sendStr ),
8792 attribute .String ("success" , successStr ),
8893 attribute .String ("rpcCallName" , callName ),
@@ -93,7 +98,7 @@ func (m *rpcClientMetrics) RecordRequest(ctx context.Context, rpcURL string, isS
9398// NoopRPCClientMetrics is a no-op implementation for when metrics are disabled.
9499type NoopRPCClientMetrics struct {}
95100
96- func (NoopRPCClientMetrics ) RecordRequest (context.Context , string , bool , string , time.Duration , error ) {
101+ func (NoopRPCClientMetrics ) RecordRequest (context.Context , string , time.Duration , error ) {
97102}
98103
99104var _ RPCClientMetrics = NoopRPCClientMetrics {}
0 commit comments