@libp2p/kad-dht 13.0.4-fa83ee1c7 → 13.1.0

Sign up to get free protection for your applications and to get access to all the features.
package/src/rpc/index.ts CHANGED
@@ -35,11 +35,17 @@ export class RPC {
35
35
  private readonly handlers: Record<string, DHTMessageHandler>
36
36
  private readonly routingTable: RoutingTable
37
37
  private readonly log: Logger
38
- private readonly metrics?: CounterGroup
38
+ private readonly metrics: {
39
+ operations?: CounterGroup
40
+ errors?: CounterGroup
41
+ }
39
42
 
40
43
  constructor (components: RPCComponents, init: RPCInit) {
41
44
  const { providers, peerRouting, validators, logPrefix, peerInfoMapper } = init
42
- this.metrics = components.metrics?.registerCounterGroup(`${logPrefix.replaceAll(':', '_')}_inbound_rpc_requests`)
45
+ this.metrics = {
46
+ operations: components.metrics?.registerCounterGroup(`${logPrefix.replaceAll(':', '_')}_inbound_rpc_requests_total`),
47
+ errors: components.metrics?.registerCounterGroup(`${logPrefix.replaceAll(':', '_')}_inbound_rpc_errors_total`)
48
+ }
43
49
 
44
50
  this.log = components.logger.forComponent(`${logPrefix}:rpc`)
45
51
  this.routingTable = init.routingTable
@@ -72,16 +78,14 @@ export class RPC {
72
78
  }
73
79
 
74
80
  try {
75
- const value = await handler.handle(peerId, msg)
76
-
77
- this.metrics?.increment({
78
- [`${msg.type}_SUCCESS`]: true
81
+ this.metrics.operations?.increment({
82
+ [msg.type]: true
79
83
  })
80
84
 
81
- return value
85
+ return await handler.handle(peerId, msg)
82
86
  } catch {
83
- this.metrics?.increment({
84
- [`${msg.type}_ERROR`]: true
87
+ this.metrics.errors?.increment({
88
+ [msg.type]: true
85
89
  })
86
90
  }
87
91
  }