@aztec/telemetry-client 0.0.1-commit.b655e406 → 0.0.1-commit.c31f2472
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 +12 -1
- package/dest/attributes.d.ts.map +1 -1
- package/dest/attributes.js +6 -0
- 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 +2 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +7 -1
- 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 +246 -196
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +1238 -194
- 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 +5 -3
- package/dest/otel.d.ts.map +1 -1
- package/dest/otel.js +66 -5
- 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 +1 -1
- package/dest/otel_resource.d.ts +1 -1
- 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 +4 -3
- package/dest/telemetry.d.ts +37 -25
- 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 +2 -2
- package/dest/wrappers/fetch.d.ts.map +1 -1
- 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 +15 -0
- package/src/bench.ts +27 -15
- package/src/config.ts +14 -1
- 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 +1311 -237
- package/src/nodejs_metrics_monitor.ts +18 -51
- package/src/noop.ts +61 -3
- package/src/otel.ts +92 -8
- package/src/prom_otel_adapter.ts +16 -23
- package/src/start.ts +8 -4
- package/src/telemetry.ts +105 -66
- package/src/wrappers/l2_block_stream.ts +6 -2
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
|
+
}
|