@aztec-labs/telemetry-client 6.0.0-nightly.20260829
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/dest/attributes.d.ts +143 -0
- package/dest/attributes.d.ts.map +1 -0
- package/dest/attributes.js +91 -0
- package/dest/bench.d.ts +34 -0
- package/dest/bench.d.ts.map +1 -0
- package/dest/bench.js +115 -0
- package/dest/config.d.ts +21 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/config.js +85 -0
- package/dest/index.d.ts +12 -0
- package/dest/index.d.ts.map +1 -0
- package/dest/index.js +11 -0
- package/dest/json_rpc_server_metrics.d.ts +27 -0
- package/dest/json_rpc_server_metrics.d.ts.map +1 -0
- package/dest/json_rpc_server_metrics.js +154 -0
- package/dest/l1_metrics.d.ts +17 -0
- package/dest/l1_metrics.d.ts.map +1 -0
- package/dest/l1_metrics.js +54 -0
- package/dest/lmdb_metrics.d.ts +18 -0
- package/dest/lmdb_metrics.d.ts.map +1 -0
- package/dest/lmdb_metrics.js +34 -0
- package/dest/metric-utils.d.ts +24 -0
- package/dest/metric-utils.d.ts.map +1 -0
- package/dest/metric-utils.js +59 -0
- package/dest/metrics.d.ts +338 -0
- package/dest/metrics.d.ts.map +1 -0
- package/dest/metrics.js +1702 -0
- package/dest/monitored_batch_span_processor.d.ts +33 -0
- package/dest/monitored_batch_span_processor.d.ts.map +1 -0
- package/dest/monitored_batch_span_processor.js +111 -0
- package/dest/nodejs_metrics_monitor.d.ts +19 -0
- package/dest/nodejs_metrics_monitor.d.ts.map +1 -0
- package/dest/nodejs_metrics_monitor.js +115 -0
- package/dest/noop.d.ts +19 -0
- package/dest/noop.d.ts.map +1 -0
- package/dest/noop.js +104 -0
- package/dest/otel.d.ts +43 -0
- package/dest/otel.d.ts.map +1 -0
- package/dest/otel.js +537 -0
- package/dest/otel_filter_metric_exporter.d.ts +20 -0
- package/dest/otel_filter_metric_exporter.d.ts.map +1 -0
- package/dest/otel_filter_metric_exporter.js +67 -0
- package/dest/otel_logger_provider.d.ts +4 -0
- package/dest/otel_logger_provider.d.ts.map +1 -0
- package/dest/otel_logger_provider.js +25 -0
- package/dest/otel_propagation.d.ts +6 -0
- package/dest/otel_propagation.d.ts.map +1 -0
- package/dest/otel_propagation.js +102 -0
- package/dest/otel_resource.d.ts +3 -0
- package/dest/otel_resource.d.ts.map +1 -0
- package/dest/otel_resource.js +53 -0
- package/dest/prom_otel_adapter.d.ts +176 -0
- package/dest/prom_otel_adapter.d.ts.map +1 -0
- package/dest/prom_otel_adapter.js +292 -0
- package/dest/start.d.ts +7 -0
- package/dest/start.d.ts.map +1 -0
- package/dest/start.js +25 -0
- package/dest/telemetry.d.ts +149 -0
- package/dest/telemetry.d.ts.map +1 -0
- package/dest/telemetry.js +139 -0
- package/dest/vendor/attributes.d.ts +6 -0
- package/dest/vendor/attributes.d.ts.map +1 -0
- package/dest/vendor/attributes.js +6 -0
- package/dest/vendor/otel-pino-stream.d.ts +40 -0
- package/dest/vendor/otel-pino-stream.d.ts.map +1 -0
- package/dest/vendor/otel-pino-stream.js +229 -0
- package/dest/with_tracer.d.ts +33 -0
- package/dest/with_tracer.d.ts.map +1 -0
- package/dest/with_tracer.js +32 -0
- package/dest/wrappers/fetch.d.ts +16 -0
- package/dest/wrappers/fetch.d.ts.map +1 -0
- package/dest/wrappers/fetch.js +42 -0
- package/dest/wrappers/index.d.ts +3 -0
- package/dest/wrappers/index.d.ts.map +1 -0
- package/dest/wrappers/index.js +2 -0
- package/dest/wrappers/json_rpc_server.d.ts +4 -0
- package/dest/wrappers/json_rpc_server.d.ts.map +1 -0
- package/dest/wrappers/json_rpc_server.js +16 -0
- package/package.json +95 -0
- package/src/attributes.ts +174 -0
- package/src/bench.ts +168 -0
- package/src/config.ts +135 -0
- package/src/index.ts +11 -0
- package/src/json_rpc_server_metrics.ts +150 -0
- package/src/l1_metrics.ts +64 -0
- package/src/lmdb_metrics.ts +45 -0
- package/src/metric-utils.ts +75 -0
- package/src/metrics.ts +1802 -0
- package/src/monitored_batch_span_processor.ts +147 -0
- package/src/nodejs_metrics_monitor.ts +135 -0
- package/src/noop.ts +152 -0
- package/src/otel.ts +482 -0
- package/src/otel_filter_metric_exporter.ts +80 -0
- package/src/otel_logger_provider.ts +31 -0
- package/src/otel_propagation.ts +107 -0
- package/src/otel_resource.ts +71 -0
- package/src/prom_otel_adapter.ts +450 -0
- package/src/start.ts +42 -0
- package/src/telemetry.ts +348 -0
- package/src/vendor/attributes.ts +6 -0
- package/src/vendor/otel-pino-stream.ts +279 -0
- package/src/with_tracer.ts +35 -0
- package/src/wrappers/fetch.ts +50 -0
- package/src/wrappers/index.ts +2 -0
- package/src/wrappers/json_rpc_server.ts +26 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { Timer } from '@aztec-labs/foundation/timer';
|
|
2
|
+
import * as Attributes from './attributes.js';
|
|
3
|
+
import * as Metrics from './metrics.js';
|
|
4
|
+
import { getTelemetryClient } from './start.js';
|
|
5
|
+
import { ATTR_JSONRPC_METHOD, ATTR_JSONRPC_SERVICE } from './vendor/attributes.js';
|
|
6
|
+
const BATCH_SIZE_BUCKETS = [
|
|
7
|
+
1,
|
|
8
|
+
2,
|
|
9
|
+
5,
|
|
10
|
+
10,
|
|
11
|
+
20,
|
|
12
|
+
50,
|
|
13
|
+
100,
|
|
14
|
+
200,
|
|
15
|
+
500,
|
|
16
|
+
1000
|
|
17
|
+
];
|
|
18
|
+
/** Records bounded-cardinality metrics for registered JSON-RPC calls, rejected requests, and batches. */ export class JsonRpcServerMetrics {
|
|
19
|
+
requestCount;
|
|
20
|
+
requestDuration;
|
|
21
|
+
requestValidationDuration;
|
|
22
|
+
rejectedRequestCount;
|
|
23
|
+
batchCount;
|
|
24
|
+
batchDuration;
|
|
25
|
+
batchSize;
|
|
26
|
+
constructor(telemetry){
|
|
27
|
+
const meter = telemetry.getMeter('JsonRpcServer');
|
|
28
|
+
this.requestCount = meter.createUpDownCounter(Metrics.JSON_RPC_SERVER_REQUEST_COUNT);
|
|
29
|
+
this.requestDuration = meter.createHistogram(Metrics.JSON_RPC_SERVER_REQUEST_DURATION);
|
|
30
|
+
this.requestValidationDuration = meter.createHistogram(Metrics.JSON_RPC_SERVER_REQUEST_VALIDATION_DURATION);
|
|
31
|
+
this.rejectedRequestCount = meter.createUpDownCounter(Metrics.JSON_RPC_SERVER_REJECTED_REQUEST_COUNT);
|
|
32
|
+
this.batchCount = meter.createUpDownCounter(Metrics.JSON_RPC_SERVER_BATCH_COUNT);
|
|
33
|
+
this.batchDuration = meter.createHistogram(Metrics.JSON_RPC_SERVER_BATCH_DURATION);
|
|
34
|
+
this.batchSize = meter.createHistogram(Metrics.JSON_RPC_SERVER_BATCH_SIZE, {
|
|
35
|
+
advice: {
|
|
36
|
+
explicitBucketBoundaries: BATCH_SIZE_BUCKETS
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/** Records the outcome and handler duration of a registered RPC method. */ recordRequest(fullMethod, durationMs, ok) {
|
|
41
|
+
const [service, method] = splitJsonRpcMethod(fullMethod);
|
|
42
|
+
const attributes = {
|
|
43
|
+
...service === undefined ? {} : {
|
|
44
|
+
[ATTR_JSONRPC_SERVICE]: service
|
|
45
|
+
},
|
|
46
|
+
[ATTR_JSONRPC_METHOD]: method,
|
|
47
|
+
[Attributes.OK]: ok
|
|
48
|
+
};
|
|
49
|
+
this.requestCount.add(1, attributes);
|
|
50
|
+
this.requestDuration.record(durationMs, attributes);
|
|
51
|
+
}
|
|
52
|
+
/** Records a pre-dispatch rejection using a fixed reason. */ recordRejectedRequest(reason) {
|
|
53
|
+
this.rejectedRequestCount.add(1, {
|
|
54
|
+
[Attributes.JSON_RPC_REJECTION_REASON]: reason
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/** Records the duration and outcome of validating a registered RPC method's parameters. */ recordRequestValidation(fullMethod, durationMs, ok) {
|
|
58
|
+
const [service, method] = splitJsonRpcMethod(fullMethod);
|
|
59
|
+
this.requestValidationDuration.record(durationMs, {
|
|
60
|
+
...service === undefined ? {} : {
|
|
61
|
+
[ATTR_JSONRPC_SERVICE]: service
|
|
62
|
+
},
|
|
63
|
+
[ATTR_JSONRPC_METHOD]: method,
|
|
64
|
+
[Attributes.OK]: ok
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/** Records the outcome, processing duration, and number of calls in a batch envelope. */ recordBatch(size, durationMs, ok) {
|
|
68
|
+
const attributes = {
|
|
69
|
+
[Attributes.OK]: ok
|
|
70
|
+
};
|
|
71
|
+
this.batchCount.add(1, attributes);
|
|
72
|
+
this.batchDuration.record(durationMs, attributes);
|
|
73
|
+
this.batchSize.record(size, attributes);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
let metricsOwner;
|
|
77
|
+
let metrics;
|
|
78
|
+
export function getJsonRpcServerMetrics() {
|
|
79
|
+
const telemetry = getTelemetryClient();
|
|
80
|
+
if (metricsOwner !== telemetry) {
|
|
81
|
+
metricsOwner = telemetry;
|
|
82
|
+
metrics = new JsonRpcServerMetrics(telemetry);
|
|
83
|
+
}
|
|
84
|
+
return metrics;
|
|
85
|
+
}
|
|
86
|
+
export function getOtelJsonRpcServerMetricsMiddleware(metricsProvider = getJsonRpcServerMetrics) {
|
|
87
|
+
return async function otelJsonRpcServerMetrics(ctx, next) {
|
|
88
|
+
const timer = new Timer();
|
|
89
|
+
await next();
|
|
90
|
+
const requestBody = ctx.request.body;
|
|
91
|
+
if (Array.isArray(requestBody)) {
|
|
92
|
+
metricsProvider().recordBatch(requestBody.length, timer.ms(), Array.isArray(ctx.body));
|
|
93
|
+
}
|
|
94
|
+
for (const reason of getRejectionReasons(ctx.status, ctx.body)){
|
|
95
|
+
metricsProvider().recordRejectedRequest(reason);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export function splitJsonRpcMethod(fullMethod) {
|
|
100
|
+
const separator = fullMethod.indexOf('_');
|
|
101
|
+
return separator === -1 ? [
|
|
102
|
+
undefined,
|
|
103
|
+
fullMethod
|
|
104
|
+
] : [
|
|
105
|
+
fullMethod.slice(0, separator),
|
|
106
|
+
fullMethod.slice(separator + 1)
|
|
107
|
+
];
|
|
108
|
+
}
|
|
109
|
+
function getRejectionReasons(status, response) {
|
|
110
|
+
if (status === 401) {
|
|
111
|
+
return [
|
|
112
|
+
'unauthorized'
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
const responses = Array.isArray(response) ? response : [
|
|
116
|
+
response
|
|
117
|
+
];
|
|
118
|
+
return responses.flatMap((item)=>{
|
|
119
|
+
const code = getErrorCode(item);
|
|
120
|
+
if (code === -32700) {
|
|
121
|
+
return [
|
|
122
|
+
'parse_error'
|
|
123
|
+
];
|
|
124
|
+
}
|
|
125
|
+
if (code === -32601) {
|
|
126
|
+
return [
|
|
127
|
+
'method_not_found'
|
|
128
|
+
];
|
|
129
|
+
}
|
|
130
|
+
if (code === -32600) {
|
|
131
|
+
return [
|
|
132
|
+
'invalid_request'
|
|
133
|
+
];
|
|
134
|
+
}
|
|
135
|
+
if (code === -32603) {
|
|
136
|
+
return [
|
|
137
|
+
'internal_error'
|
|
138
|
+
];
|
|
139
|
+
}
|
|
140
|
+
if (code === -32000) {
|
|
141
|
+
return [
|
|
142
|
+
'bad_request'
|
|
143
|
+
];
|
|
144
|
+
}
|
|
145
|
+
return [];
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
function getErrorCode(response) {
|
|
149
|
+
if (!response || typeof response !== 'object' || !('error' in response)) {
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
const error = response.error;
|
|
153
|
+
return error && typeof error === 'object' && 'code' in error && typeof error.code === 'number' ? error.code : undefined;
|
|
154
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { EthAddress } from '@aztec-labs/foundation/eth-address';
|
|
2
|
+
import { type Chain, type FallbackTransport, type HttpTransport, type PublicClient } from 'viem';
|
|
3
|
+
import type { Meter } from './telemetry.js';
|
|
4
|
+
export declare class L1Metrics {
|
|
5
|
+
private meter;
|
|
6
|
+
private client;
|
|
7
|
+
private l1BlockHeight;
|
|
8
|
+
private l1BalanceEth;
|
|
9
|
+
private gasPriceWei;
|
|
10
|
+
private blobBaseFeeWei;
|
|
11
|
+
private addresses;
|
|
12
|
+
constructor(meter: Meter, client: PublicClient<FallbackTransport<HttpTransport[]>, Chain>, addresses: EthAddress[]);
|
|
13
|
+
start(): void;
|
|
14
|
+
stop(): void;
|
|
15
|
+
private observe;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibDFfbWV0cmljcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2wxX21ldHJpY3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0sb0NBQW9DLENBQUM7QUFDckUsT0FBTyxFQUFFLEtBQUssS0FBSyxFQUFFLEtBQUssaUJBQWlCLEVBQVksS0FBSyxhQUFhLEVBQUUsS0FBSyxZQUFZLEVBQWUsTUFBTSxNQUFNLENBQUM7QUFJeEgsT0FBTyxLQUFLLEVBQXlCLEtBQUssRUFBbUIsTUFBTSxnQkFBZ0IsQ0FBQztBQUVwRixxQkFBYSxTQUFTO0lBUWxCLE9BQU8sQ0FBQyxLQUFLO0lBQ2IsT0FBTyxDQUFDLE1BQU07SUFSaEIsT0FBTyxDQUFDLGFBQWEsQ0FBa0I7SUFDdkMsT0FBTyxDQUFDLFlBQVksQ0FBa0I7SUFDdEMsT0FBTyxDQUFDLFdBQVcsQ0FBa0I7SUFDckMsT0FBTyxDQUFDLGNBQWMsQ0FBa0I7SUFDeEMsT0FBTyxDQUFDLFNBQVMsQ0FBUTtJQUV6QixZQUNVLEtBQUssRUFBRSxLQUFLLEVBQ1osTUFBTSxFQUFFLFlBQVksQ0FBQyxpQkFBaUIsQ0FBQyxhQUFhLEVBQUUsQ0FBQyxFQUFFLEtBQUssQ0FBQyxFQUN2RSxTQUFTLEVBQUUsVUFBVSxFQUFFLEVBUXhCO0lBRUQsS0FBSyxTQUVKO0lBRUQsSUFBSSxTQUVIO0lBRUQsT0FBTyxDQUFDLE9BQU8sQ0EyQmI7Q0FDSCJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"l1_metrics.d.ts","sourceRoot":"","sources":["../src/l1_metrics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,iBAAiB,EAAY,KAAK,aAAa,EAAE,KAAK,YAAY,EAAe,MAAM,MAAM,CAAC;AAIxH,OAAO,KAAK,EAAyB,KAAK,EAAmB,MAAM,gBAAgB,CAAC;AAEpF,qBAAa,SAAS;IAQlB,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,MAAM;IARhB,OAAO,CAAC,aAAa,CAAkB;IACvC,OAAO,CAAC,YAAY,CAAkB;IACtC,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,cAAc,CAAkB;IACxC,OAAO,CAAC,SAAS,CAAQ;IAEzB,YACU,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,YAAY,CAAC,iBAAiB,CAAC,aAAa,EAAE,CAAC,EAAE,KAAK,CAAC,EACvE,SAAS,EAAE,UAAU,EAAE,EAQxB;IAED,KAAK,SAEJ;IAED,IAAI,SAEH;IAED,OAAO,CAAC,OAAO,CA2Bb;CACH"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { formatEther } from 'viem';
|
|
2
|
+
import { L1_SENDER } from './attributes.js';
|
|
3
|
+
import { L1_BALANCE_ETH, L1_BLOB_BASE_FEE_WEI, L1_BLOCK_HEIGHT, L1_GAS_PRICE_WEI } from './metrics.js';
|
|
4
|
+
export class L1Metrics {
|
|
5
|
+
meter;
|
|
6
|
+
client;
|
|
7
|
+
l1BlockHeight;
|
|
8
|
+
l1BalanceEth;
|
|
9
|
+
gasPriceWei;
|
|
10
|
+
blobBaseFeeWei;
|
|
11
|
+
addresses;
|
|
12
|
+
constructor(meter, client, addresses){
|
|
13
|
+
this.meter = meter;
|
|
14
|
+
this.client = client;
|
|
15
|
+
this.observe = async (observer)=>{
|
|
16
|
+
const blockNumber = await this.client.getBlockNumber();
|
|
17
|
+
const ethBalances = await Promise.all(this.addresses.map((address)=>this.client.getBalance({
|
|
18
|
+
address,
|
|
19
|
+
blockNumber
|
|
20
|
+
})));
|
|
21
|
+
const gasPrice = await this.client.getGasPrice();
|
|
22
|
+
const blobFee = await this.client.getBlobBaseFee();
|
|
23
|
+
observer.observe(this.l1BlockHeight, Number(blockNumber));
|
|
24
|
+
observer.observe(this.gasPriceWei, Number(gasPrice));
|
|
25
|
+
observer.observe(this.blobBaseFeeWei, Number(blobFee));
|
|
26
|
+
for(let i = 0; i < ethBalances.length; i++){
|
|
27
|
+
const wei = ethBalances[i];
|
|
28
|
+
const address = this.addresses[i];
|
|
29
|
+
const eth = parseFloat(formatEther(wei, 'wei'));
|
|
30
|
+
observer.observe(this.l1BalanceEth, eth, {
|
|
31
|
+
[L1_SENDER]: address
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
this.l1BlockHeight = meter.createObservableGauge(L1_BLOCK_HEIGHT);
|
|
36
|
+
this.l1BalanceEth = meter.createObservableGauge(L1_BALANCE_ETH);
|
|
37
|
+
this.gasPriceWei = meter.createObservableGauge(L1_GAS_PRICE_WEI);
|
|
38
|
+
this.blobBaseFeeWei = meter.createObservableGauge(L1_BLOB_BASE_FEE_WEI);
|
|
39
|
+
this.addresses = addresses.map((addr)=>addr.toString());
|
|
40
|
+
}
|
|
41
|
+
start() {
|
|
42
|
+
this.meter.addBatchObservableCallback(this.observe, [
|
|
43
|
+
this.l1BalanceEth,
|
|
44
|
+
this.l1BlockHeight
|
|
45
|
+
]);
|
|
46
|
+
}
|
|
47
|
+
stop() {
|
|
48
|
+
this.meter.removeBatchObservableCallback(this.observe, [
|
|
49
|
+
this.l1BalanceEth,
|
|
50
|
+
this.l1BlockHeight
|
|
51
|
+
]);
|
|
52
|
+
}
|
|
53
|
+
observe;
|
|
54
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Meter } from './telemetry.js';
|
|
2
|
+
export type LmdbStatsCallback = () => Promise<{
|
|
3
|
+
mappingSize: number;
|
|
4
|
+
physicalFileSize: number;
|
|
5
|
+
numItems: number;
|
|
6
|
+
actualSize: number;
|
|
7
|
+
}>;
|
|
8
|
+
export declare class LmdbMetrics {
|
|
9
|
+
private attributes?;
|
|
10
|
+
private getStats?;
|
|
11
|
+
private dbMapSize;
|
|
12
|
+
private dbPhysicalFileSize;
|
|
13
|
+
private dbUsedSize;
|
|
14
|
+
private dbNumItems;
|
|
15
|
+
constructor(meter: Meter, attributes?: Partial<Record<"aztec.address.sender" | "aztec.address.target" | "aztec.archiver.prune_type" | "aztec.attester.address" | "aztec.block.archive" | "aztec.block.candidate_txs_count" | "aztec.block.hash" | "aztec.block.number" | "aztec.block.parent" | "aztec.block.proposer" | "aztec.block.size" | "aztec.block.txs_count" | "aztec.block_full" | "aztec.checkpoint.number" | "aztec.circuit.app_circuit_name" | "aztec.circuit.protocol_circuit_name" | "aztec.coinbase" | "aztec.db_type" | "aztec.epoch.number" | "aztec.epoch.size" | "aztec.epoch_session.kind" | "aztec.error_type" | "aztec.fisherman.strategy_id" | "aztec.gas_dimension" | "aztec.gossip.topic_name" | "aztec.ha_signer.duty_type" | "aztec.ha_signer.node_id" | "aztec.initial_sync" | "aztec.is_committee_member" | "aztec.json_rpc.rejection_reason" | "aztec.l1.block_proposal_tx_target" | "aztec.l1.block_proposal_used_trace" | "aztec.l1.sender" | "aztec.l1.tx_type" | "aztec.l1_tx.scope" | "aztec.mana.used" | "aztec.mempool.eviction_reason" | "aztec.mempool.operation" | "aztec.merkle_tree.name" | "aztec.network_name" | "aztec.node_role" | "aztec.ok" | "aztec.p2p.goodbye.reason" | "aztec.p2p.id" | "aztec.p2p.peer_id" | "aztec.p2p.peer_score_state" | "aztec.p2p.req_resp.protocol" | "aztec.p2p.tx_validation_stage" | "aztec.pool.name" | "aztec.proof.timed_out" | "aztec.proving.job_id" | "aztec.proving.job_type" | "aztec.registry_address" | "aztec.revertibility" | "aztec.rollup.prover_id" | "aztec.rollup_address" | "aztec.rollup_version" | "aztec.sequencer.state" | "aztec.simulator.phase" | "aztec.slot.number" | "aztec.slot_boundary_side" | "aztec.status" | "aztec.total_instructions" | "aztec.tx.hash" | "aztec.tx.phase_name" | "aztec.tx_collection.method" | "aztec.validator_status" | "aztec.world_state.db_type" | "aztec.world_state_request" | "http.header.request.host" | "http.response.status_code" | "nodejs.eventloop.state", import("@opentelemetry/api").AttributeValue>> | undefined, getStats?: LmdbStatsCallback | undefined);
|
|
16
|
+
private recordDBMetrics;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG1kYl9tZXRyaWNzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvbG1kYl9tZXRyaWNzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sS0FBSyxFQUF5QyxLQUFLLEVBQW1CLE1BQU0sZ0JBQWdCLENBQUM7QUFFcEcsTUFBTSxNQUFNLGlCQUFpQixHQUFHLE1BQU0sT0FBTyxDQUFDO0lBQzVDLFdBQVcsRUFBRSxNQUFNLENBQUM7SUFDcEIsZ0JBQWdCLEVBQUUsTUFBTSxDQUFDO0lBQ3pCLFFBQVEsRUFBRSxNQUFNLENBQUM7SUFDakIsVUFBVSxFQUFFLE1BQU0sQ0FBQztDQUNwQixDQUFDLENBQUM7QUFFSCxxQkFBYSxXQUFXO0lBUXBCLE9BQU8sQ0FBQyxVQUFVLENBQUM7SUFDbkIsT0FBTyxDQUFDLFFBQVEsQ0FBQztJQVJuQixPQUFPLENBQUMsU0FBUyxDQUFrQjtJQUNuQyxPQUFPLENBQUMsa0JBQWtCLENBQWtCO0lBQzVDLE9BQU8sQ0FBQyxVQUFVLENBQWtCO0lBQ3BDLE9BQU8sQ0FBQyxVQUFVLENBQWtCO0lBRXBDLFlBQ0UsS0FBSyxFQUFFLEtBQUssRUFDSixVQUFVLENBQUMsbzZEQUFnQixFQUMzQixRQUFRLENBQUMsK0JBQW1CLEVBYXJDO0lBRUQsT0FBTyxDQUFDLGVBQWUsQ0FTckI7Q0FDSCJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lmdb_metrics.d.ts","sourceRoot":"","sources":["../src/lmdb_metrics.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAyC,KAAK,EAAmB,MAAM,gBAAgB,CAAC;AAEpG,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,CAAC;IAC5C,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC,CAAC;AAEH,qBAAa,WAAW;IAQpB,OAAO,CAAC,UAAU,CAAC;IACnB,OAAO,CAAC,QAAQ,CAAC;IARnB,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,kBAAkB,CAAkB;IAC5C,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,UAAU,CAAkB;IAEpC,YACE,KAAK,EAAE,KAAK,EACJ,UAAU,CAAC,o6DAAgB,EAC3B,QAAQ,CAAC,+BAAmB,EAarC;IAED,OAAO,CAAC,eAAe,CASrB;CACH"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as Metrics from './metrics.js';
|
|
2
|
+
export class LmdbMetrics {
|
|
3
|
+
attributes;
|
|
4
|
+
getStats;
|
|
5
|
+
dbMapSize;
|
|
6
|
+
dbPhysicalFileSize;
|
|
7
|
+
dbUsedSize;
|
|
8
|
+
dbNumItems;
|
|
9
|
+
constructor(meter, attributes, getStats){
|
|
10
|
+
this.attributes = attributes;
|
|
11
|
+
this.getStats = getStats;
|
|
12
|
+
this.recordDBMetrics = async (observable)=>{
|
|
13
|
+
if (!this.getStats) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const metrics = await this.getStats();
|
|
17
|
+
observable.observe(this.dbMapSize, metrics.mappingSize, this.attributes);
|
|
18
|
+
observable.observe(this.dbPhysicalFileSize, metrics.physicalFileSize, this.attributes);
|
|
19
|
+
observable.observe(this.dbNumItems, metrics.numItems, this.attributes);
|
|
20
|
+
observable.observe(this.dbUsedSize, metrics.actualSize, this.attributes);
|
|
21
|
+
};
|
|
22
|
+
this.dbMapSize = meter.createObservableGauge(Metrics.DB_MAP_SIZE);
|
|
23
|
+
this.dbPhysicalFileSize = meter.createObservableGauge(Metrics.DB_PHYSICAL_FILE_SIZE);
|
|
24
|
+
this.dbUsedSize = meter.createObservableGauge(Metrics.DB_USED_SIZE);
|
|
25
|
+
this.dbNumItems = meter.createObservableGauge(Metrics.DB_NUM_ITEMS);
|
|
26
|
+
meter.addBatchObservableCallback(this.recordDBMetrics, [
|
|
27
|
+
this.dbMapSize,
|
|
28
|
+
this.dbPhysicalFileSize,
|
|
29
|
+
this.dbUsedSize,
|
|
30
|
+
this.dbNumItems
|
|
31
|
+
]);
|
|
32
|
+
}
|
|
33
|
+
recordDBMetrics;
|
|
34
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AttributeValue, MetricOptions } from '@opentelemetry/api';
|
|
2
|
+
import type { MetricDefinition } from './metrics.js';
|
|
3
|
+
import type { AllowedAttributeNames, Meter, MetricAttributesType, UpDownCounter } from './telemetry.js';
|
|
4
|
+
/** Extracts OpenTelemetry MetricOptions from a MetricDefinition */
|
|
5
|
+
export declare function toMetricOptions(def: MetricDefinition): MetricOptions;
|
|
6
|
+
/** A mapping of attribute keys to their possible values */
|
|
7
|
+
export type AttributeValuesMap = Partial<Record<AllowedAttributeNames, AttributeValue[]>>;
|
|
8
|
+
/**
|
|
9
|
+
* Expands an attribute values map into all combinations of attribute objects.
|
|
10
|
+
* Example: { status: ['ok', 'fail'], type: ['a', 'b'] } =>
|
|
11
|
+
* [{ status: 'ok', type: 'a' }, { status: 'ok', type: 'b' }, { status: 'fail', type: 'a' }, { status: 'fail', type: 'b' }]
|
|
12
|
+
*/
|
|
13
|
+
export declare function expandAttributeCombinations(attrMap: AttributeValuesMap): MetricAttributesType[];
|
|
14
|
+
/**
|
|
15
|
+
* Creates an UpDownCounter and initializes it to 0.
|
|
16
|
+
* @param meter - The meter to create the counter on
|
|
17
|
+
* @param metric - The metric definition
|
|
18
|
+
* @param attributes - Optional attributes for initialization. Can be:
|
|
19
|
+
* - AttributeValuesMap: mapping of attribute keys to arrays of possible values (generates cartesian product)
|
|
20
|
+
* - MetricAttributesType[]: explicit array of attribute objects
|
|
21
|
+
* - undefined: initializes without attributes
|
|
22
|
+
*/
|
|
23
|
+
export declare function createUpDownCounterWithDefault(meter: Meter, metric: MetricDefinition, attributes?: AttributeValuesMap | MetricAttributesType[] | undefined): UpDownCounter;
|
|
24
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWV0cmljLXV0aWxzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvbWV0cmljLXV0aWxzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLGNBQWMsRUFBRSxhQUFhLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUV4RSxPQUFPLEtBQUssRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLGNBQWMsQ0FBQztBQUNyRCxPQUFPLEtBQUssRUFBRSxxQkFBcUIsRUFBRSxLQUFLLEVBQUUsb0JBQW9CLEVBQUUsYUFBYSxFQUFFLE1BQU0sZ0JBQWdCLENBQUM7QUFFeEcsbUVBQW1FO0FBQ25FLHdCQUFnQixlQUFlLENBQUMsR0FBRyxFQUFFLGdCQUFnQixHQUFHLGFBQWEsQ0FNcEU7QUFFRCwyREFBMkQ7QUFDM0QsTUFBTSxNQUFNLGtCQUFrQixHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMscUJBQXFCLEVBQUUsY0FBYyxFQUFFLENBQUMsQ0FBQyxDQUFDO0FBRTFGOzs7O0dBSUc7QUFDSCx3QkFBZ0IsMkJBQTJCLENBQUMsT0FBTyxFQUFFLGtCQUFrQixHQUFHLG9CQUFvQixFQUFFLENBc0IvRjtBQUVEOzs7Ozs7OztHQVFHO0FBQ0gsd0JBQWdCLDhCQUE4QixDQUM1QyxLQUFLLEVBQUUsS0FBSyxFQUNaLE1BQU0sRUFBRSxnQkFBZ0IsRUFDeEIsVUFBVSxHQUFFLGtCQUFrQixHQUFHLG9CQUFvQixFQUFFLEdBQUcsU0FBcUIsR0FDOUUsYUFBYSxDQWVmIn0=
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metric-utils.d.ts","sourceRoot":"","sources":["../src/metric-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,qBAAqB,EAAE,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAExG,mEAAmE;AACnE,wBAAgB,eAAe,CAAC,GAAG,EAAE,gBAAgB,GAAG,aAAa,CAMpE;AAED,2DAA2D;AAC3D,MAAM,MAAM,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,qBAAqB,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC;AAE1F;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,kBAAkB,GAAG,oBAAoB,EAAE,CAsB/F;AAED;;;;;;;;GAQG;AACH,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,gBAAgB,EACxB,UAAU,GAAE,kBAAkB,GAAG,oBAAoB,EAAE,GAAG,SAAqB,GAC9E,aAAa,CAef"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** Extracts OpenTelemetry MetricOptions from a MetricDefinition */ export function toMetricOptions(def) {
|
|
2
|
+
return {
|
|
3
|
+
description: def.description,
|
|
4
|
+
unit: def.unit,
|
|
5
|
+
valueType: def.valueType
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Expands an attribute values map into all combinations of attribute objects.
|
|
10
|
+
* Example: { status: ['ok', 'fail'], type: ['a', 'b'] } =>
|
|
11
|
+
* [{ status: 'ok', type: 'a' }, { status: 'ok', type: 'b' }, { status: 'fail', type: 'a' }, { status: 'fail', type: 'b' }]
|
|
12
|
+
*/ export function expandAttributeCombinations(attrMap) {
|
|
13
|
+
const keys = Object.keys(attrMap);
|
|
14
|
+
if (keys.length === 0) {
|
|
15
|
+
return [
|
|
16
|
+
{}
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
const result = [];
|
|
20
|
+
function generate(index, current) {
|
|
21
|
+
if (index === keys.length) {
|
|
22
|
+
result.push({
|
|
23
|
+
...current
|
|
24
|
+
});
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const key = keys[index];
|
|
28
|
+
for (const value of attrMap[key]){
|
|
29
|
+
current[key] = value;
|
|
30
|
+
generate(index + 1, current);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
generate(0, {});
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Creates an UpDownCounter and initializes it to 0.
|
|
38
|
+
* @param meter - The meter to create the counter on
|
|
39
|
+
* @param metric - The metric definition
|
|
40
|
+
* @param attributes - Optional attributes for initialization. Can be:
|
|
41
|
+
* - AttributeValuesMap: mapping of attribute keys to arrays of possible values (generates cartesian product)
|
|
42
|
+
* - MetricAttributesType[]: explicit array of attribute objects
|
|
43
|
+
* - undefined: initializes without attributes
|
|
44
|
+
*/ export function createUpDownCounterWithDefault(meter, metric, attributes = undefined) {
|
|
45
|
+
const counter = meter.createUpDownCounter(metric);
|
|
46
|
+
if (attributes === undefined) {
|
|
47
|
+
counter.add(0);
|
|
48
|
+
} else if (Array.isArray(attributes)) {
|
|
49
|
+
for (const attrs of attributes){
|
|
50
|
+
counter.add(0, attrs);
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
const combinations = expandAttributeCombinations(attributes);
|
|
54
|
+
for (const attrs of combinations){
|
|
55
|
+
counter.add(0, attrs);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return counter;
|
|
59
|
+
}
|