@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/lib/chunk-KAWZ7VNL.js +131 -0
- package/lib/chunk-KAWZ7VNL.js.map +1 -0
- package/lib/index.d.ts +20 -14
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/processor-runner.js +2 -2
- package/lib/processor-runner.js.map +1 -1
- package/package.json +1 -1
- package/src/metrics.ts +36 -14
- package/src/otlp.ts +1 -1
- package/src/provider.ts +20 -6
- package/lib/chunk-J24RUMUG.js +0 -131
- package/lib/chunk-J24RUMUG.js.map +0 -1
package/package.json
CHANGED
package/src/metrics.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
import {
|
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
|
-
|
146
|
-
|
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
|
-
|
157
|
-
|
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
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,
|
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
|
-
|
131
|
-
|
132
|
-
|
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)
|