@aztec/telemetry-client 0.0.1-commit.b655e406 → 0.0.1-commit.b9865e97
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 +24 -2
- package/dest/attributes.d.ts.map +1 -1
- package/dest/attributes.js +12 -1
- package/dest/bench.d.ts +3 -1
- package/dest/bench.d.ts.map +1 -1
- package/dest/bench.js +24 -14
- package/dest/config.d.ts +4 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +24 -10
- package/dest/index.d.ts +1 -1
- package/dest/l1_metrics.d.ts +2 -2
- package/dest/l1_metrics.d.ts.map +1 -1
- package/dest/l1_metrics.js +4 -20
- package/dest/lmdb_metrics.d.ts +3 -3
- package/dest/lmdb_metrics.d.ts.map +1 -1
- package/dest/lmdb_metrics.js +4 -20
- 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 +312 -196
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +1599 -194
- package/dest/monitored_batch_span_processor.d.ts +29 -0
- package/dest/monitored_batch_span_processor.d.ts.map +1 -0
- package/dest/monitored_batch_span_processor.js +75 -0
- package/dest/nodejs_metrics_monitor.d.ts +3 -5
- package/dest/nodejs_metrics_monitor.d.ts.map +1 -1
- package/dest/nodejs_metrics_monitor.js +19 -40
- package/dest/noop.d.ts +6 -3
- package/dest/noop.d.ts.map +1 -1
- package/dest/noop.js +32 -1
- package/dest/otel.d.ts +10 -3
- package/dest/otel.d.ts.map +1 -1
- package/dest/otel.js +139 -9
- package/dest/otel_filter_metric_exporter.d.ts +1 -1
- package/dest/otel_filter_metric_exporter.d.ts.map +1 -1
- package/dest/otel_logger_provider.d.ts +1 -1
- package/dest/otel_propagation.d.ts +3 -1
- package/dest/otel_propagation.d.ts.map +1 -1
- package/dest/otel_propagation.js +49 -1
- package/dest/otel_resource.d.ts +1 -1
- package/dest/otel_resource.d.ts.map +1 -1
- package/dest/otel_resource.js +14 -2
- package/dest/prom_otel_adapter.d.ts +4 -4
- package/dest/prom_otel_adapter.d.ts.map +1 -1
- package/dest/prom_otel_adapter.js +19 -10
- package/dest/start.d.ts +3 -2
- package/dest/start.d.ts.map +1 -1
- package/dest/start.js +5 -4
- package/dest/telemetry.d.ts +38 -26
- package/dest/telemetry.d.ts.map +1 -1
- package/dest/telemetry.js +46 -23
- package/dest/vendor/attributes.d.ts +1 -1
- package/dest/vendor/otel-pino-stream.d.ts +1 -1
- package/dest/vendor/otel-pino-stream.d.ts.map +1 -1
- package/dest/with_tracer.d.ts +1 -1
- package/dest/with_tracer.d.ts.map +1 -1
- package/dest/wrappers/fetch.d.ts +3 -3
- package/dest/wrappers/fetch.d.ts.map +1 -1
- package/dest/wrappers/fetch.js +3 -2
- package/dest/wrappers/index.d.ts +1 -1
- package/dest/wrappers/json_rpc_server.d.ts +1 -1
- package/dest/wrappers/l2_block_stream.d.ts +4 -3
- package/dest/wrappers/l2_block_stream.d.ts.map +1 -1
- package/dest/wrappers/l2_block_stream.js +385 -11
- package/package.json +9 -6
- package/src/attributes.ts +32 -1
- package/src/bench.ts +27 -15
- package/src/config.ts +38 -10
- package/src/l1_metrics.ts +5 -20
- package/src/lmdb_metrics.ts +5 -26
- package/src/metric-utils.ts +75 -0
- package/src/metrics.ts +1682 -237
- package/src/monitored_batch_span_processor.ts +100 -0
- package/src/nodejs_metrics_monitor.ts +18 -51
- package/src/noop.ts +61 -3
- package/src/otel.ts +144 -11
- package/src/otel_propagation.ts +42 -1
- package/src/otel_resource.ts +19 -2
- package/src/prom_otel_adapter.ts +16 -23
- package/src/start.ts +14 -5
- package/src/telemetry.ts +105 -67
- package/src/wrappers/fetch.ts +9 -3
- package/src/wrappers/l2_block_stream.ts +3 -2
package/src/config.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
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) =>
|
|
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) =>
|
|
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) =>
|
|
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
|
-
|
|
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
|
-
|
|
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) =>
|
|
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(
|
|
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 {
|
|
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
|
-
|
|
23
|
-
|
|
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
|
}
|
package/src/lmdb_metrics.ts
CHANGED
|
@@ -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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
+
}
|