@aztec/telemetry-client 0.0.1-commit.b655e406 → 0.0.1-commit.b8a057fa

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.
Files changed (87) hide show
  1. package/dest/attributes.d.ts +28 -2
  2. package/dest/attributes.d.ts.map +1 -1
  3. package/dest/attributes.js +14 -1
  4. package/dest/bench.d.ts +3 -1
  5. package/dest/bench.d.ts.map +1 -1
  6. package/dest/bench.js +24 -14
  7. package/dest/config.d.ts +4 -1
  8. package/dest/config.d.ts.map +1 -1
  9. package/dest/config.js +24 -10
  10. package/dest/index.d.ts +1 -1
  11. package/dest/l1_metrics.d.ts +2 -2
  12. package/dest/l1_metrics.d.ts.map +1 -1
  13. package/dest/l1_metrics.js +4 -20
  14. package/dest/lmdb_metrics.d.ts +3 -3
  15. package/dest/lmdb_metrics.d.ts.map +1 -1
  16. package/dest/lmdb_metrics.js +4 -20
  17. package/dest/metric-utils.d.ts +24 -0
  18. package/dest/metric-utils.d.ts.map +1 -0
  19. package/dest/metric-utils.js +59 -0
  20. package/dest/metrics.d.ts +314 -196
  21. package/dest/metrics.d.ts.map +1 -1
  22. package/dest/metrics.js +1607 -194
  23. package/dest/monitored_batch_span_processor.d.ts +29 -0
  24. package/dest/monitored_batch_span_processor.d.ts.map +1 -0
  25. package/dest/monitored_batch_span_processor.js +75 -0
  26. package/dest/nodejs_metrics_monitor.d.ts +3 -5
  27. package/dest/nodejs_metrics_monitor.d.ts.map +1 -1
  28. package/dest/nodejs_metrics_monitor.js +19 -40
  29. package/dest/noop.d.ts +6 -3
  30. package/dest/noop.d.ts.map +1 -1
  31. package/dest/noop.js +32 -1
  32. package/dest/otel.d.ts +10 -3
  33. package/dest/otel.d.ts.map +1 -1
  34. package/dest/otel.js +165 -9
  35. package/dest/otel_filter_metric_exporter.d.ts +1 -1
  36. package/dest/otel_filter_metric_exporter.d.ts.map +1 -1
  37. package/dest/otel_logger_provider.d.ts +1 -1
  38. package/dest/otel_propagation.d.ts +3 -1
  39. package/dest/otel_propagation.d.ts.map +1 -1
  40. package/dest/otel_propagation.js +49 -1
  41. package/dest/otel_resource.d.ts +1 -1
  42. package/dest/otel_resource.d.ts.map +1 -1
  43. package/dest/otel_resource.js +14 -2
  44. package/dest/prom_otel_adapter.d.ts +4 -4
  45. package/dest/prom_otel_adapter.d.ts.map +1 -1
  46. package/dest/prom_otel_adapter.js +19 -10
  47. package/dest/start.d.ts +3 -2
  48. package/dest/start.d.ts.map +1 -1
  49. package/dest/start.js +5 -4
  50. package/dest/telemetry.d.ts +38 -26
  51. package/dest/telemetry.d.ts.map +1 -1
  52. package/dest/telemetry.js +46 -23
  53. package/dest/vendor/attributes.d.ts +1 -1
  54. package/dest/vendor/otel-pino-stream.d.ts +1 -1
  55. package/dest/vendor/otel-pino-stream.d.ts.map +1 -1
  56. package/dest/with_tracer.d.ts +1 -1
  57. package/dest/with_tracer.d.ts.map +1 -1
  58. package/dest/wrappers/fetch.d.ts +3 -3
  59. package/dest/wrappers/fetch.d.ts.map +1 -1
  60. package/dest/wrappers/fetch.js +3 -2
  61. package/dest/wrappers/index.d.ts +1 -2
  62. package/dest/wrappers/index.d.ts.map +1 -1
  63. package/dest/wrappers/index.js +0 -1
  64. package/dest/wrappers/json_rpc_server.d.ts +1 -1
  65. package/package.json +9 -6
  66. package/src/attributes.ts +36 -1
  67. package/src/bench.ts +27 -15
  68. package/src/config.ts +38 -10
  69. package/src/l1_metrics.ts +5 -20
  70. package/src/lmdb_metrics.ts +5 -26
  71. package/src/metric-utils.ts +75 -0
  72. package/src/metrics.ts +1692 -237
  73. package/src/monitored_batch_span_processor.ts +100 -0
  74. package/src/nodejs_metrics_monitor.ts +18 -51
  75. package/src/noop.ts +61 -3
  76. package/src/otel.ts +161 -11
  77. package/src/otel_propagation.ts +42 -1
  78. package/src/otel_resource.ts +19 -2
  79. package/src/prom_otel_adapter.ts +16 -23
  80. package/src/start.ts +14 -5
  81. package/src/telemetry.ts +105 -67
  82. package/src/wrappers/fetch.ts +9 -3
  83. package/src/wrappers/index.ts +0 -1
  84. package/dest/wrappers/l2_block_stream.d.ts +0 -15
  85. package/dest/wrappers/l2_block_stream.d.ts.map +0 -1
  86. package/dest/wrappers/l2_block_stream.js +0 -26
  87. package/src/wrappers/l2_block_stream.ts +0 -37
@@ -1,4 +1,3 @@
1
- export * from './l2_block_stream.js';
2
1
  export * from './fetch.js';
3
2
  export * from './json_rpc_server.js';
4
- //# sourceMappingURL=index.d.ts.map
3
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy93cmFwcGVycy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLFlBQVksQ0FBQztBQUMzQixjQUFjLHNCQUFzQixDQUFDIn0=
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/wrappers/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/wrappers/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC"}
@@ -1,3 +1,2 @@
1
- export * from './l2_block_stream.js';
2
1
  export * from './fetch.js';
3
2
  export * from './json_rpc_server.js';
@@ -1,4 +1,4 @@
1
1
  import { type SafeJsonRpcServerOptions } from '@aztec/foundation/json-rpc/server';
2
2
  import type { ApiSchemaFor } from '@aztec/stdlib/schemas';
3
3
  export declare function createTracedJsonRpcServer<T extends object = any>(handler: T, schema: ApiSchemaFor<T>, options?: SafeJsonRpcServerOptions): import("@aztec/foundation/json-rpc/server").SafeJsonRpcServer;
4
- //# sourceMappingURL=json_rpc_server.d.ts.map
4
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoianNvbl9ycGNfc2VydmVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvd3JhcHBlcnMvanNvbl9ycGNfc2VydmVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxLQUFLLHdCQUF3QixFQUEyQixNQUFNLG1DQUFtQyxDQUFDO0FBQzNHLE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBSTFELHdCQUFnQix5QkFBeUIsQ0FBQyxDQUFDLFNBQVMsTUFBTSxHQUFHLEdBQUcsRUFDOUQsT0FBTyxFQUFFLENBQUMsRUFDVixNQUFNLEVBQUUsWUFBWSxDQUFDLENBQUMsQ0FBQyxFQUN2QixPQUFPLEdBQUUsd0JBQTZCLGlFQU12QyJ9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/telemetry-client",
3
- "version": "0.0.1-commit.b655e406",
3
+ "version": "0.0.1-commit.b8a057fa",
4
4
  "inherits": [
5
5
  "../package.common.json"
6
6
  ],
@@ -8,11 +8,13 @@
8
8
  "exports": {
9
9
  ".": "./dest/index.js",
10
10
  "./bench": "./dest/bench.js",
11
+ "./config": "./dest/config.js",
12
+ "./start": "./dest/start.js",
11
13
  "./otel-pino-stream": "./dest/vendor/otel-pino-stream.js"
12
14
  },
13
15
  "scripts": {
14
- "build": "yarn clean && tsc -b",
15
- "build:dev": "tsc -b --watch",
16
+ "build": "yarn clean && ../scripts/tsc.sh",
17
+ "build:dev": "../scripts/tsc.sh --watch",
16
18
  "clean": "rm -rf ./dest .tsbuildinfo",
17
19
  "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
18
20
  },
@@ -25,8 +27,8 @@
25
27
  "!*.test.*"
26
28
  ],
27
29
  "dependencies": {
28
- "@aztec/foundation": "0.0.1-commit.b655e406",
29
- "@aztec/stdlib": "0.0.1-commit.b655e406",
30
+ "@aztec/foundation": "0.0.1-commit.b8a057fa",
31
+ "@aztec/stdlib": "0.0.1-commit.b8a057fa",
30
32
  "@opentelemetry/api": "^1.9.0",
31
33
  "@opentelemetry/api-logs": "^0.55.0",
32
34
  "@opentelemetry/core": "^1.28.0",
@@ -42,12 +44,13 @@
42
44
  "@opentelemetry/sdk-trace-node": "^1.28.0",
43
45
  "@opentelemetry/semantic-conventions": "^1.28.0",
44
46
  "prom-client": "^15.1.3",
45
- "viem": "npm:@spalladino/viem@2.38.2-eip7594.0"
47
+ "viem": "npm:@aztec/viem@2.38.2"
46
48
  },
47
49
  "devDependencies": {
48
50
  "@jest/globals": "^30.0.0",
49
51
  "@types/jest": "^30.0.0",
50
52
  "@types/koa": "^2.15.0",
53
+ "@typescript/native-preview": "7.0.0-dev.20260113.1",
51
54
  "jest": "^30.0.0",
52
55
  "ts-node": "^10.9.1",
53
56
  "typescript": "^5.3.3"
package/src/attributes.ts CHANGED
@@ -45,6 +45,10 @@ export const BLOCK_NUMBER = 'aztec.block.number';
45
45
  export const BLOCK_HASH = 'aztec.block.hash';
46
46
  /** The slot number */
47
47
  export const SLOT_NUMBER = 'aztec.slot.number';
48
+ /** Whether an event happened before or after a slot boundary. */
49
+ export const SLOT_BOUNDARY_SIDE = 'aztec.slot_boundary_side';
50
+ /** The checkpoint number */
51
+ export const CHECKPOINT_NUMBER = 'aztec.checkpoint.number';
48
52
  /** The parent's block number */
49
53
  export const BLOCK_PARENT = 'aztec.block.parent';
50
54
  /** How many txs are being processed to build this block */
@@ -59,6 +63,8 @@ export const EPOCH_SIZE = 'aztec.epoch.size';
59
63
  export const BLOCK_PROPOSER = 'aztec.block.proposer';
60
64
  /** The epoch number */
61
65
  export const EPOCH_NUMBER = 'aztec.epoch.number';
66
+ /** Kind of an EpochSession: 'full' or 'partial'. */
67
+ export const EPOCH_SESSION_KIND = 'aztec.epoch_session.kind';
62
68
  /** The tx hash */
63
69
  export const TX_HASH = 'aztec.tx.hash';
64
70
  /** Generic attribute representing whether the action was successful or not */
@@ -67,6 +73,8 @@ export const OK = 'aztec.ok';
67
73
  export const STATUS = 'aztec.status';
68
74
  /** Generic error type attribute */
69
75
  export const ERROR_TYPE = 'aztec.error_type';
76
+ /** The cause of an archiver prune (unproven / uncheckpointed / l1_conflict / orphan / l1_mismatch) */
77
+ export const PRUNE_TYPE = 'aztec.archiver.prune_type';
70
78
  /** The type of the transaction */
71
79
  export const L1_TX_TYPE = 'aztec.l1.tx_type';
72
80
  /** The L1 address of the entity that sent a transaction to L1 */
@@ -92,9 +100,12 @@ export const VALIDATOR_STATUS = 'aztec.validator_status';
92
100
 
93
101
  export const P2P_ID = 'aztec.p2p.id';
94
102
  export const P2P_REQ_RESP_PROTOCOL = 'aztec.p2p.req_resp.protocol';
95
- export const P2P_REQ_RESP_BATCH_REQUESTS_COUNT = 'aztec.p2p.req_resp.batch_requests_count';
103
+ /** The state of a peer (Healthy, Disconnect, Banned) */
104
+ export const P2P_PEER_SCORE_STATE = 'aztec.p2p.peer_score_state';
96
105
  export const POOL_NAME = 'aztec.pool.name';
97
106
 
107
+ export const PEER_ID = 'aztec.p2p.peer_id';
108
+
98
109
  export const SEQUENCER_STATE = 'aztec.sequencer.state';
99
110
 
100
111
  export const SIMULATOR_PHASE = 'aztec.simulator.phase';
@@ -122,6 +133,9 @@ export const NODEJS_EVENT_LOOP_STATE = 'nodejs.eventloop.state';
122
133
 
123
134
  export const TOPIC_NAME = 'aztec.gossip.topic_name';
124
135
 
136
+ /** The reason a transaction was evicted from the tx pool */
137
+ export const TX_POOL_EVICTION_REASON = 'aztec.mempool.eviction_reason';
138
+
125
139
  export const TX_COLLECTION_METHOD = 'aztec.tx_collection.method';
126
140
 
127
141
  /** Scope of L1 transaction (sequencer, prover, or other) */
@@ -129,3 +143,24 @@ export const L1_TX_SCOPE = 'aztec.l1_tx.scope';
129
143
 
130
144
  /** Generic error type attribute */
131
145
  export const IS_COMMITTEE_MEMBER = 'aztec.is_committee_member';
146
+
147
+ /** Fisherman fee analysis strategy identifier */
148
+ export const FISHERMAN_FEE_STRATEGY_ID = 'aztec.fisherman.strategy_id';
149
+
150
+ /** Whether the analyzed block reached 100% blob capacity */
151
+ export const BLOCK_FULL = 'aztec.block_full';
152
+
153
+ /** The L1 transaction target for block proposal */
154
+ export const L1_BLOCK_PROPOSAL_TX_TARGET = 'aztec.l1.block_proposal_tx_target';
155
+
156
+ /** Whether tracing methods were used to extract block proposal data */
157
+ export const L1_BLOCK_PROPOSAL_USED_TRACE = 'aztec.l1.block_proposal_used_trace';
158
+
159
+ /** HA signer duty type (e.g., BLOCK_PROPOSAL, CHECKPOINT_ATTESTATION) */
160
+ export const HA_DUTY_TYPE = 'aztec.ha_signer.duty_type';
161
+
162
+ /** HA signer node identifier */
163
+ export const HA_NODE_ID = 'aztec.ha_signer.node_id';
164
+
165
+ /** The address of an attester (validator) participating in consensus */
166
+ export const ATTESTER_ADDRESS = 'aztec.attester.address';
package/src/bench.ts CHANGED
@@ -2,13 +2,13 @@ import { createLogger } from '@aztec/foundation/log';
2
2
 
3
3
  import type { BatchObservableCallback, Context, MetricOptions, Observable, ValueType } from '@opentelemetry/api';
4
4
 
5
+ import type { MetricDefinition } from './metrics.js';
5
6
  import { NoopTracer } from './noop.js';
6
7
  import type {
7
8
  AttributesType,
8
9
  Gauge,
9
10
  Histogram,
10
11
  Meter,
11
- MetricsType,
12
12
  ObservableGauge,
13
13
  ObservableUpDownCounter,
14
14
  TelemetryClient,
@@ -61,6 +61,14 @@ export class BenchmarkTelemetryClient implements TelemetryClient {
61
61
  return true;
62
62
  }
63
63
 
64
+ getTraceContext(): string | undefined {
65
+ return undefined;
66
+ }
67
+
68
+ extractPropagatedContext() {
69
+ return undefined;
70
+ }
71
+
64
72
  getMeters(): BenchmarkMetricsType {
65
73
  return this.meters;
66
74
  }
@@ -79,30 +87,34 @@ class InMemoryPlainMeter implements Meter {
79
87
  this.metrics.forEach(metric => metric.clear());
80
88
  }
81
89
 
82
- createGauge(name: MetricsType, options?: MetricOptions): Gauge {
83
- return this.createMetric('gauge', name, options);
90
+ createGauge(metric: MetricDefinition): Gauge {
91
+ return this.createMetric('gauge', metric);
84
92
  }
85
93
 
86
- createObservableGauge(name: MetricsType, options?: MetricOptions): ObservableGauge {
87
- return this.createMetric('gauge', name, options);
94
+ createObservableGauge(metric: MetricDefinition): ObservableGauge {
95
+ return this.createMetric('gauge', metric);
88
96
  }
89
97
 
90
- createHistogram(name: MetricsType, options?: MetricOptions): Histogram {
91
- return this.createMetric('histogram', name, options);
98
+ createHistogram(metric: MetricDefinition, _extraOptions?: Partial<MetricOptions>): Histogram {
99
+ return this.createMetric('histogram', metric);
92
100
  }
93
101
 
94
- createUpDownCounter(name: MetricsType, options?: MetricOptions): UpDownCounter {
95
- return this.createMetric('counter', name, options);
102
+ createUpDownCounter(metric: MetricDefinition): UpDownCounter {
103
+ return this.createMetric('counter', metric);
96
104
  }
97
105
 
98
- createObservableUpDownCounter(name: MetricsType, options?: MetricOptions): ObservableUpDownCounter {
99
- return this.createMetric('counter', name, options);
106
+ createObservableUpDownCounter(metric: MetricDefinition): ObservableUpDownCounter {
107
+ return this.createMetric('counter', metric);
100
108
  }
101
109
 
102
- private createMetric(type: 'gauge' | 'counter' | 'histogram', name: string, options?: MetricOptions) {
103
- const metric = new InMemoryPlainMetric(type, name, options);
104
- this.metrics.push(metric);
105
- return metric;
110
+ private createMetric(type: 'gauge' | 'counter' | 'histogram', metric: MetricDefinition) {
111
+ const m = new InMemoryPlainMetric(type, metric.name, {
112
+ description: metric.description,
113
+ unit: metric.unit,
114
+ valueType: metric.valueType,
115
+ });
116
+ this.metrics.push(m);
117
+ return m;
106
118
  }
107
119
 
108
120
  addBatchObservableCallback(
package/src/config.ts CHANGED
@@ -1,4 +1,9 @@
1
- import { type ConfigMappingsType, booleanConfigHelper, getConfigFromMappings } from '@aztec/foundation/config';
1
+ import {
2
+ type ConfigMappingsType,
3
+ booleanConfigHelper,
4
+ getConfigFromMappings,
5
+ numberConfigHelper,
6
+ } from '@aztec/foundation/config';
2
7
 
3
8
  export interface TelemetryClientConfig {
4
9
  metricsCollectorUrl?: URL;
@@ -11,35 +16,36 @@ export interface TelemetryClientConfig {
11
16
  otelCollectIntervalMs: number;
12
17
  otelExportTimeoutMs: number;
13
18
  otelExcludeMetrics: string[];
19
+ otelIncludeMetrics: string[];
20
+ otelMinTraceDurationMs: number;
21
+ otelBspMaxQueueSize: number;
14
22
  }
15
23
 
16
24
  export const telemetryClientConfigMappings: ConfigMappingsType<TelemetryClientConfig> = {
17
25
  metricsCollectorUrl: {
18
26
  env: 'OTEL_EXPORTER_OTLP_METRICS_ENDPOINT',
19
27
  description: 'The URL of the telemetry collector for metrics',
20
- parseEnv: (val: string) => val && new URL(val),
28
+ parseEnv: (val: string) => new URL(val),
21
29
  },
22
30
  tracesCollectorUrl: {
23
31
  env: 'OTEL_EXPORTER_OTLP_TRACES_ENDPOINT',
24
32
  description: 'The URL of the telemetry collector for traces',
25
- parseEnv: (val: string) => val && new URL(val),
33
+ parseEnv: (val: string) => new URL(val),
26
34
  },
27
35
  logsCollectorUrl: {
28
36
  env: 'OTEL_EXPORTER_OTLP_LOGS_ENDPOINT',
29
37
  description: 'The URL of the telemetry collector for logs',
30
- parseEnv: (val: string) => val && new URL(val),
38
+ parseEnv: (val: string) => new URL(val),
31
39
  },
32
40
  otelCollectIntervalMs: {
33
41
  env: 'OTEL_COLLECT_INTERVAL_MS',
34
42
  description: 'The interval at which to collect metrics',
35
- defaultValue: 60000, // Default extracted from otel client
36
- parseEnv: (val: string) => parseInt(val),
43
+ ...numberConfigHelper(60000),
37
44
  },
38
45
  otelExportTimeoutMs: {
39
46
  env: 'OTEL_EXPORT_TIMEOUT_MS',
40
47
  description: 'The timeout for exporting metrics',
41
- defaultValue: 30000, // Default extracted from otel client
42
- parseEnv: (val: string) => parseInt(val),
48
+ ...numberConfigHelper(30000),
43
49
  },
44
50
  otelExcludeMetrics: {
45
51
  env: 'OTEL_EXCLUDE_METRICS',
@@ -53,11 +59,33 @@ export const telemetryClientConfigMappings: ConfigMappingsType<TelemetryClientCo
53
59
  : [],
54
60
  defaultValue: [],
55
61
  },
62
+ otelMinTraceDurationMs: {
63
+ env: 'OTEL_MIN_TRACE_DURATION_MS',
64
+ description: 'The minimum successful trace duration to export in milliseconds. Set to 0 to export all traces.',
65
+ ...numberConfigHelper(10),
66
+ },
67
+ otelBspMaxQueueSize: {
68
+ env: 'OTEL_BSP_MAX_QUEUE_SIZE',
69
+ description: 'The maximum number of completed spans to queue before export.',
70
+ ...numberConfigHelper(16384),
71
+ },
72
+ otelIncludeMetrics: {
73
+ env: 'OTEL_INCLUDE_METRICS',
74
+ description: 'A list of metric prefixes to include in export (ignored if OTEL_EXCLUDE_METRICS is set)',
75
+ parseEnv: (val: string) =>
76
+ val
77
+ ? val
78
+ .split(',')
79
+ .map(s => s.trim())
80
+ .filter(s => s.length > 0)
81
+ : [],
82
+ defaultValue: [],
83
+ },
56
84
 
57
85
  publicMetricsCollectorUrl: {
58
86
  env: 'PUBLIC_OTEL_EXPORTER_OTLP_METRICS_ENDPOINT',
59
87
  description: 'A URL to publish a subset of metrics for public consumption',
60
- parseEnv: (val: string) => val && new URL(val),
88
+ parseEnv: (val: string) => new URL(val),
61
89
  },
62
90
  publicMetricsCollectFrom: {
63
91
  env: 'PUBLIC_OTEL_COLLECT_FROM',
@@ -86,7 +114,7 @@ export const telemetryClientConfigMappings: ConfigMappingsType<TelemetryClientCo
86
114
  publicMetricsOptOut: {
87
115
  env: 'PUBLIC_OTEL_OPT_OUT',
88
116
  description: 'Whether to opt out of sharing optional telemetry',
89
- ...booleanConfigHelper(false),
117
+ ...booleanConfigHelper(true),
90
118
  },
91
119
  };
92
120
 
package/src/l1_metrics.ts CHANGED
@@ -4,7 +4,7 @@ import { type Chain, type FallbackTransport, type Hex, type HttpTransport, type
4
4
 
5
5
  import { L1_SENDER } from './attributes.js';
6
6
  import { L1_BALANCE_ETH, L1_BLOB_BASE_FEE_WEI, L1_BLOCK_HEIGHT, L1_GAS_PRICE_WEI } from './metrics.js';
7
- import { type BatchObservableResult, type Meter, type ObservableGauge, ValueType } from './telemetry.js';
7
+ import type { BatchObservableResult, Meter, ObservableGauge } from './telemetry.js';
8
8
 
9
9
  export class L1Metrics {
10
10
  private l1BlockHeight: ObservableGauge;
@@ -18,25 +18,10 @@ export class L1Metrics {
18
18
  private client: PublicClient<FallbackTransport<HttpTransport[]>, Chain>,
19
19
  addresses: EthAddress[],
20
20
  ) {
21
- this.l1BlockHeight = meter.createObservableGauge(L1_BLOCK_HEIGHT, {
22
- description: 'The latest L1 block seen',
23
- valueType: ValueType.INT,
24
- });
25
- this.l1BalanceEth = meter.createObservableGauge(L1_BALANCE_ETH, {
26
- description: 'Eth balance of an address',
27
- unit: 'eth',
28
- valueType: ValueType.DOUBLE,
29
- });
30
- this.gasPriceWei = meter.createObservableGauge(L1_GAS_PRICE_WEI, {
31
- description: 'L1 gas price',
32
- unit: 'wei',
33
- valueType: ValueType.DOUBLE,
34
- });
35
- this.blobBaseFeeWei = meter.createObservableGauge(L1_BLOB_BASE_FEE_WEI, {
36
- description: 'L1 blob fee',
37
- unit: 'wei',
38
- valueType: ValueType.DOUBLE,
39
- });
21
+ this.l1BlockHeight = meter.createObservableGauge(L1_BLOCK_HEIGHT);
22
+ this.l1BalanceEth = meter.createObservableGauge(L1_BALANCE_ETH);
23
+ this.gasPriceWei = meter.createObservableGauge(L1_GAS_PRICE_WEI);
24
+ this.blobBaseFeeWei = meter.createObservableGauge(L1_BLOB_BASE_FEE_WEI);
40
25
 
41
26
  this.addresses = addresses.map(addr => addr.toString());
42
27
  }
@@ -1,11 +1,5 @@
1
1
  import * as Metrics from './metrics.js';
2
- import {
3
- type AttributesType,
4
- type BatchObservableResult,
5
- type Meter,
6
- type ObservableGauge,
7
- ValueType,
8
- } from './telemetry.js';
2
+ import type { AttributesType, BatchObservableResult, Meter, ObservableGauge } from './telemetry.js';
9
3
 
10
4
  export type LmdbStatsCallback = () => Promise<{
11
5
  mappingSize: number;
@@ -25,25 +19,10 @@ export class LmdbMetrics {
25
19
  private attributes?: AttributesType,
26
20
  private getStats?: LmdbStatsCallback,
27
21
  ) {
28
- this.dbMapSize = meter.createObservableGauge(Metrics.DB_MAP_SIZE, {
29
- description: 'LMDB Map Size',
30
- valueType: ValueType.INT,
31
- unit: 'By',
32
- });
33
- this.dbPhysicalFileSize = meter.createObservableGauge(Metrics.DB_PHYSICAL_FILE_SIZE, {
34
- description: 'LMDB Physical File Size',
35
- valueType: ValueType.INT,
36
- unit: 'By',
37
- });
38
- this.dbUsedSize = meter.createObservableGauge(Metrics.DB_USED_SIZE, {
39
- description: 'LMDB Used Size',
40
- valueType: ValueType.INT,
41
- unit: 'By',
42
- });
43
- this.dbNumItems = meter.createObservableGauge(Metrics.DB_NUM_ITEMS, {
44
- description: 'LMDB Num Items',
45
- valueType: ValueType.INT,
46
- });
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);
47
26
 
48
27
  meter.addBatchObservableCallback(this.recordDBMetrics, [
49
28
  this.dbMapSize,
@@ -0,0 +1,75 @@
1
+ import type { AttributeValue, MetricOptions } from '@opentelemetry/api';
2
+
3
+ import type { MetricDefinition } from './metrics.js';
4
+ import type { AllowedAttributeNames, Meter, MetricAttributesType, UpDownCounter } from './telemetry.js';
5
+
6
+ /** Extracts OpenTelemetry MetricOptions from a MetricDefinition */
7
+ export function toMetricOptions(def: MetricDefinition): MetricOptions {
8
+ return {
9
+ description: def.description,
10
+ unit: def.unit,
11
+ valueType: def.valueType,
12
+ };
13
+ }
14
+
15
+ /** A mapping of attribute keys to their possible values */
16
+ export type AttributeValuesMap = Partial<Record<AllowedAttributeNames, AttributeValue[]>>;
17
+
18
+ /**
19
+ * Expands an attribute values map into all combinations of attribute objects.
20
+ * Example: { status: ['ok', 'fail'], type: ['a', 'b'] } =>
21
+ * [{ status: 'ok', type: 'a' }, { status: 'ok', type: 'b' }, { status: 'fail', type: 'a' }, { status: 'fail', type: 'b' }]
22
+ */
23
+ export function expandAttributeCombinations(attrMap: AttributeValuesMap): MetricAttributesType[] {
24
+ const keys = Object.keys(attrMap) as AllowedAttributeNames[];
25
+ if (keys.length === 0) {
26
+ return [{}];
27
+ }
28
+
29
+ const result: MetricAttributesType[] = [];
30
+
31
+ function generate(index: number, current: MetricAttributesType) {
32
+ if (index === keys.length) {
33
+ result.push({ ...current });
34
+ return;
35
+ }
36
+ const key = keys[index];
37
+ for (const value of attrMap[key]!) {
38
+ current[key] = value;
39
+ generate(index + 1, current);
40
+ }
41
+ }
42
+
43
+ generate(0, {});
44
+ return result;
45
+ }
46
+
47
+ /**
48
+ * Creates an UpDownCounter and initializes it to 0.
49
+ * @param meter - The meter to create the counter on
50
+ * @param metric - The metric definition
51
+ * @param attributes - Optional attributes for initialization. Can be:
52
+ * - AttributeValuesMap: mapping of attribute keys to arrays of possible values (generates cartesian product)
53
+ * - MetricAttributesType[]: explicit array of attribute objects
54
+ * - undefined: initializes without attributes
55
+ */
56
+ export function createUpDownCounterWithDefault(
57
+ meter: Meter,
58
+ metric: MetricDefinition,
59
+ attributes: AttributeValuesMap | MetricAttributesType[] | undefined = undefined,
60
+ ): UpDownCounter {
61
+ const counter = meter.createUpDownCounter(metric);
62
+ if (attributes === undefined) {
63
+ counter.add(0);
64
+ } else if (Array.isArray(attributes)) {
65
+ for (const attrs of attributes) {
66
+ counter.add(0, attrs);
67
+ }
68
+ } else {
69
+ const combinations = expandAttributeCombinations(attributes);
70
+ for (const attrs of combinations) {
71
+ counter.add(0, attrs);
72
+ }
73
+ }
74
+ return counter;
75
+ }