@sentio/runtime 2.49.2-rc.3 → 2.49.2-rc.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentio/runtime",
3
- "version": "2.49.2-rc.3",
3
+ "version": "2.49.2-rc.5",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
package/src/metrics.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { Attributes, Counter, metrics, Gauge } from '@opentelemetry/api'
1
+ import { AsyncLocalStorage } from 'node:async_hooks'
2
+ import { Attributes, Counter, metrics, Gauge, Histogram } from '@opentelemetry/api'
2
3
 
3
4
  const getMeter = () => metrics.getMeter('processor')
4
5
 
@@ -48,6 +49,29 @@ class G {
48
49
  }
49
50
  }
50
51
 
52
+ class H {
53
+ private _histogram: Histogram<Attributes>
54
+ private value: number = 0
55
+
56
+ constructor(private name: string) {}
57
+
58
+ get histogram(): Histogram<Attributes> {
59
+ if (!this._histogram) {
60
+ this._histogram = getMeter().createHistogram(this.name)
61
+ }
62
+ return this._histogram
63
+ }
64
+
65
+ record(value: number, attributes?: Attributes) {
66
+ this.histogram.record(value, attributes)
67
+ this.value = value
68
+ }
69
+
70
+ get() {
71
+ return this.value
72
+ }
73
+ }
74
+
51
75
  export const dbMetrics = {
52
76
  send_counts: {
53
77
  get: new C('store_get_send'),
@@ -119,17 +143,11 @@ export const providerMetrics = {
119
143
  hit_count: new C('provider_hit_count'),
120
144
  miss_count: new C('provider_miss_count'),
121
145
  queue_size: new G('provider_queue_size'),
122
- total_duration: new C('provider_total_duration'),
123
- total_queued: new C('provider_total_queued'),
124
146
  stats() {
125
147
  return {
126
148
  hit_count: this.hit_count.get(),
127
149
  miss_count: this.miss_count.get(),
128
- queue_size: this.queue_size.get(),
129
- total_duration: this.total_duration.get(),
130
- total_queued: this.total_queued.get(),
131
- average_queue_time: this.total_queued.get() / (this.hit_count.get() + this.miss_count.get()),
132
- average_duration: this.total_duration.get() / (this.hit_count.get() + this.miss_count.get())
150
+ queue_size: this.queue_size.get()
133
151
  }
134
152
  }
135
153
  }
@@ -138,23 +156,27 @@ export const processMetrics = {
138
156
  process_binding_count: new C('process_binding_count'),
139
157
  process_binding_time: new C('process_binding_time'),
140
158
  process_binding_error: new C('process_binding_error'),
141
- process_ethcall_count: new C('process_ethcall_count'),
142
159
  process_eventemit_count: new C('process_eventemit_count'),
143
160
  process_metricrecord_count: new C('process_metricrecord_count'),
144
161
  process_pricecall_count: new C('process_pricecall_count'),
145
- process_template_count: new C('process_template_count'),
146
- process_handler_duration: new G('process_handler_duration'),
162
+ processor_handler_duration: new H('processor_handler_duration'),
163
+ processor_rpc_duration: new H('processor_rpc_duration'),
164
+ processor_rpc_queue_duration: new H('processor_rpc_queue_duration'),
165
+ processor_template_instance_count: new C('process_template_instance_count'),
147
166
  stats() {
148
167
  return {
149
168
  process_binding_count: this.process_binding_count.get(),
150
169
  process_binding_time: this.process_binding_time.get(),
151
170
  process_binding_error: this.process_binding_error.get(),
152
- process_ethcall_count: this.process_ethcall_count.get(),
153
171
  process_eventemit_count: this.process_eventemit_count.get(),
154
172
  process_metricrecord_count: this.process_metricrecord_count.get(),
155
173
  process_pricecall_count: this.process_pricecall_count.get(),
156
- process_template_count: this.process_template_count.get(),
157
- process_handler_duration: this.process_handler_duration.get()
174
+ processor_handler_duration: this.processor_handler_duration.get(),
175
+ processor_rpc_duration: this.processor_rpc_duration.get(),
176
+ processor_rpc_queue_duration: this.processor_rpc_queue_duration.get(),
177
+ processor_template_instance_count: this.processor_template_instance_count.get()
158
178
  }
159
179
  }
160
180
  }
181
+
182
+ export const metricsStorage = new AsyncLocalStorage<string>()
package/src/otlp.ts CHANGED
@@ -21,7 +21,7 @@ export async function setupOTLP(debug?: boolean) {
21
21
  exporter: new OTLPMetricExporter()
22
22
  }),
23
23
  new PrometheusExporter({
24
- // http://localhost:4041/metrics
24
+ host: '0.0.0.0',
25
25
  port: 4041
26
26
  })
27
27
  ]
package/src/provider.ts CHANGED
@@ -4,9 +4,9 @@ import PQueue from 'p-queue'
4
4
  import { Endpoints } from './endpoints.js'
5
5
  import { EthChainId } from '@sentio/chain'
6
6
  import { LRUCache } from 'lru-cache'
7
- import { providerMetrics } from './metrics.js'
7
+ import { providerMetrics, processMetrics, metricsStorage } from './metrics.js'
8
8
  import { GLOBAL_CONFIG } from './global-config.js'
9
- const { miss_count, hit_count, total_duration, total_queued, queue_size } = providerMetrics
9
+ const { miss_count, hit_count, queue_size } = providerMetrics
10
10
 
11
11
  export const DummyProvider = new JsonRpcProvider('', Network.from(1))
12
12
 
@@ -127,11 +127,25 @@ export class QueuedStaticJsonRpcProvider extends JsonRpcProvider {
127
127
  const queued: number = Date.now()
128
128
  perform = this.executor.add(() => {
129
129
  const started = Date.now()
130
- total_queued.add(started - queued)
131
-
132
- return super.send(method, params).finally(() => {
133
- total_duration.add(Date.now() - started)
130
+ processMetrics.processor_rpc_queue_duration.record(started - queued, {
131
+ chain_id: this._network.chainId.toString(),
132
+ handler: metricsStorage.getStore()
134
133
  })
134
+
135
+ let success = true
136
+ return super
137
+ .send(method, params)
138
+ .catch((e) => {
139
+ success = false
140
+ throw e
141
+ })
142
+ .finally(() => {
143
+ processMetrics.processor_rpc_duration.record(Date.now() - started, {
144
+ chain_id: this._network.chainId.toString(),
145
+ handler: metricsStorage.getStore(),
146
+ success
147
+ })
148
+ })
135
149
  })
136
150
 
137
151
  queue_size.record(this.executor.size)