@aztec/telemetry-client 0.0.0-test.0 → 0.0.1-commit.023c3e5
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 +33 -9
- package/dest/attributes.d.ts.map +1 -1
- package/dest/attributes.js +22 -8
- package/dest/bench.d.ts +6 -1
- package/dest/bench.d.ts.map +1 -1
- package/dest/bench.js +31 -14
- package/dest/config.d.ts +7 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +29 -1
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -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 +5 -3
- package/dest/lmdb_metrics.d.ts.map +1 -1
- package/dest/lmdb_metrics.js +7 -15
- 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 +247 -122
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +1239 -120
- 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 +9 -4
- package/dest/noop.d.ts.map +1 -1
- package/dest/noop.js +34 -1
- package/dest/otel.d.ts +13 -7
- package/dest/otel.d.ts.map +1 -1
- package/dest/otel.js +142 -21
- package/dest/otel_filter_metric_exporter.d.ts +12 -4
- package/dest/otel_filter_metric_exporter.d.ts.map +1 -1
- package/dest/otel_filter_metric_exporter.js +38 -4
- 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/otel_resource.d.ts.map +1 -1
- package/dest/otel_resource.js +43 -2
- package/dest/prom_otel_adapter.d.ts +61 -12
- package/dest/prom_otel_adapter.d.ts.map +1 -1
- package/dest/prom_otel_adapter.js +157 -48
- package/dest/start.d.ts +3 -2
- package/dest/start.d.ts.map +1 -1
- package/dest/start.js +8 -7
- package/dest/telemetry.d.ts +63 -34
- package/dest/telemetry.d.ts.map +1 -1
- package/dest/telemetry.js +47 -24
- package/dest/vendor/attributes.d.ts +1 -1
- package/dest/vendor/otel-pino-stream.d.ts +1 -2
- package/dest/vendor/otel-pino-stream.d.ts.map +1 -1
- package/dest/vendor/otel-pino-stream.js +2 -2
- 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/fetch.js +7 -5
- package/dest/wrappers/index.d.ts +1 -1
- package/dest/wrappers/json_rpc_server.d.ts +2 -2
- package/dest/wrappers/json_rpc_server.d.ts.map +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 +21 -15
- package/src/attributes.ts +42 -11
- package/src/bench.ts +37 -15
- package/src/config.ts +54 -2
- package/src/index.ts +1 -0
- package/src/l1_metrics.ts +65 -0
- package/src/lmdb_metrics.ts +24 -24
- package/src/metric-utils.ts +75 -0
- package/src/metrics.ts +1313 -145
- package/src/nodejs_metrics_monitor.ts +135 -0
- package/src/noop.ts +65 -4
- package/src/otel.ts +155 -26
- package/src/otel_filter_metric_exporter.ts +47 -5
- package/src/otel_resource.ts +57 -2
- package/src/prom_otel_adapter.ts +195 -70
- package/src/start.ts +12 -8
- package/src/telemetry.ts +153 -76
- package/src/vendor/otel-pino-stream.ts +1 -4
- package/src/wrappers/fetch.ts +24 -31
- package/src/wrappers/json_rpc_server.ts +1 -1
- package/src/wrappers/l2_block_stream.ts +6 -2
- package/dest/event_loop_monitor.d.ts +0 -18
- package/dest/event_loop_monitor.d.ts.map +0 -1
- package/dest/event_loop_monitor.js +0 -93
- package/src/event_loop_monitor.ts +0 -119
package/src/bench.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
|
|
1
3
|
import type { BatchObservableCallback, Context, MetricOptions, Observable, ValueType } from '@opentelemetry/api';
|
|
2
4
|
|
|
5
|
+
import type { MetricDefinition } from './metrics.js';
|
|
3
6
|
import { NoopTracer } from './noop.js';
|
|
4
7
|
import type {
|
|
5
8
|
AttributesType,
|
|
6
9
|
Gauge,
|
|
7
10
|
Histogram,
|
|
8
11
|
Meter,
|
|
9
|
-
MetricsType,
|
|
10
12
|
ObservableGauge,
|
|
11
13
|
ObservableUpDownCounter,
|
|
12
14
|
TelemetryClient,
|
|
@@ -29,6 +31,14 @@ export type BenchmarkMetricsType = {
|
|
|
29
31
|
export class BenchmarkTelemetryClient implements TelemetryClient {
|
|
30
32
|
private meters: InMemoryPlainMeter[] = [];
|
|
31
33
|
|
|
34
|
+
constructor() {
|
|
35
|
+
const log = createLogger('telemetry:client');
|
|
36
|
+
log.info(`Using benchmark telemetry client`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
setExportedPublicTelemetry(_prefixes: string[]): void {}
|
|
40
|
+
setPublicTelemetryCollectFrom(_roles: string[]): void {}
|
|
41
|
+
|
|
32
42
|
getMeter(name: string): Meter {
|
|
33
43
|
const meter = new InMemoryPlainMeter(name);
|
|
34
44
|
this.meters.push(meter);
|
|
@@ -51,6 +61,14 @@ export class BenchmarkTelemetryClient implements TelemetryClient {
|
|
|
51
61
|
return true;
|
|
52
62
|
}
|
|
53
63
|
|
|
64
|
+
getTraceContext(): string | undefined {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
extractPropagatedContext() {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
54
72
|
getMeters(): BenchmarkMetricsType {
|
|
55
73
|
return this.meters;
|
|
56
74
|
}
|
|
@@ -69,30 +87,34 @@ class InMemoryPlainMeter implements Meter {
|
|
|
69
87
|
this.metrics.forEach(metric => metric.clear());
|
|
70
88
|
}
|
|
71
89
|
|
|
72
|
-
createGauge(
|
|
73
|
-
return this.createMetric('gauge',
|
|
90
|
+
createGauge(metric: MetricDefinition): Gauge {
|
|
91
|
+
return this.createMetric('gauge', metric);
|
|
74
92
|
}
|
|
75
93
|
|
|
76
|
-
createObservableGauge(
|
|
77
|
-
return this.createMetric('gauge',
|
|
94
|
+
createObservableGauge(metric: MetricDefinition): ObservableGauge {
|
|
95
|
+
return this.createMetric('gauge', metric);
|
|
78
96
|
}
|
|
79
97
|
|
|
80
|
-
createHistogram(
|
|
81
|
-
return this.createMetric('histogram',
|
|
98
|
+
createHistogram(metric: MetricDefinition, _extraOptions?: Partial<MetricOptions>): Histogram {
|
|
99
|
+
return this.createMetric('histogram', metric);
|
|
82
100
|
}
|
|
83
101
|
|
|
84
|
-
createUpDownCounter(
|
|
85
|
-
return this.createMetric('counter',
|
|
102
|
+
createUpDownCounter(metric: MetricDefinition): UpDownCounter {
|
|
103
|
+
return this.createMetric('counter', metric);
|
|
86
104
|
}
|
|
87
105
|
|
|
88
|
-
createObservableUpDownCounter(
|
|
89
|
-
return this.createMetric('counter',
|
|
106
|
+
createObservableUpDownCounter(metric: MetricDefinition): ObservableUpDownCounter {
|
|
107
|
+
return this.createMetric('counter', metric);
|
|
90
108
|
}
|
|
91
109
|
|
|
92
|
-
private createMetric(type: 'gauge' | 'counter' | 'histogram',
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
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;
|
|
96
118
|
}
|
|
97
119
|
|
|
98
120
|
addBatchObservableCallback(
|
package/src/config.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import { type ConfigMappingsType, getConfigFromMappings } from '@aztec/foundation/config';
|
|
1
|
+
import { type ConfigMappingsType, booleanConfigHelper, getConfigFromMappings } from '@aztec/foundation/config';
|
|
2
2
|
|
|
3
3
|
export interface TelemetryClientConfig {
|
|
4
4
|
metricsCollectorUrl?: URL;
|
|
5
|
+
publicMetricsCollectorUrl?: URL;
|
|
6
|
+
publicIncludeMetrics: string[];
|
|
7
|
+
publicMetricsOptOut: boolean;
|
|
8
|
+
publicMetricsCollectFrom: string[];
|
|
5
9
|
tracesCollectorUrl?: URL;
|
|
6
10
|
logsCollectorUrl?: URL;
|
|
7
11
|
otelCollectIntervalMs: number;
|
|
8
12
|
otelExportTimeoutMs: number;
|
|
9
|
-
otelExcludeMetrics
|
|
13
|
+
otelExcludeMetrics: string[];
|
|
14
|
+
otelIncludeMetrics: string[];
|
|
10
15
|
}
|
|
11
16
|
|
|
12
17
|
export const telemetryClientConfigMappings: ConfigMappingsType<TelemetryClientConfig> = {
|
|
@@ -49,6 +54,53 @@ export const telemetryClientConfigMappings: ConfigMappingsType<TelemetryClientCo
|
|
|
49
54
|
: [],
|
|
50
55
|
defaultValue: [],
|
|
51
56
|
},
|
|
57
|
+
otelIncludeMetrics: {
|
|
58
|
+
env: 'OTEL_INCLUDE_METRICS',
|
|
59
|
+
description: 'A list of metric prefixes to include in export (ignored if OTEL_EXCLUDE_METRICS is set)',
|
|
60
|
+
parseEnv: (val: string) =>
|
|
61
|
+
val
|
|
62
|
+
? val
|
|
63
|
+
.split(',')
|
|
64
|
+
.map(s => s.trim())
|
|
65
|
+
.filter(s => s.length > 0)
|
|
66
|
+
: [],
|
|
67
|
+
defaultValue: [],
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
publicMetricsCollectorUrl: {
|
|
71
|
+
env: 'PUBLIC_OTEL_EXPORTER_OTLP_METRICS_ENDPOINT',
|
|
72
|
+
description: 'A URL to publish a subset of metrics for public consumption',
|
|
73
|
+
parseEnv: (val: string) => val && new URL(val),
|
|
74
|
+
},
|
|
75
|
+
publicMetricsCollectFrom: {
|
|
76
|
+
env: 'PUBLIC_OTEL_COLLECT_FROM',
|
|
77
|
+
description: 'The role types to collect metrics from',
|
|
78
|
+
parseEnv: (val: string) =>
|
|
79
|
+
val
|
|
80
|
+
? val
|
|
81
|
+
.split(',')
|
|
82
|
+
.map(s => s.trim())
|
|
83
|
+
.filter(s => s.length > 0)
|
|
84
|
+
: [],
|
|
85
|
+
defaultValue: [],
|
|
86
|
+
},
|
|
87
|
+
publicIncludeMetrics: {
|
|
88
|
+
env: 'PUBLIC_OTEL_INCLUDE_METRICS',
|
|
89
|
+
description: 'A list of metric prefixes to publicly export',
|
|
90
|
+
parseEnv: (val: string) =>
|
|
91
|
+
val
|
|
92
|
+
? val
|
|
93
|
+
.split(',')
|
|
94
|
+
.map(s => s.trim())
|
|
95
|
+
.filter(s => s.length > 0)
|
|
96
|
+
: [],
|
|
97
|
+
defaultValue: [],
|
|
98
|
+
},
|
|
99
|
+
publicMetricsOptOut: {
|
|
100
|
+
env: 'PUBLIC_OTEL_OPT_OUT',
|
|
101
|
+
description: 'Whether to opt out of sharing optional telemetry',
|
|
102
|
+
...booleanConfigHelper(true),
|
|
103
|
+
},
|
|
52
104
|
};
|
|
53
105
|
|
|
54
106
|
export function getConfigEnvVars(): TelemetryClientConfig {
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * as Attributes from './attributes.js';
|
|
|
4
4
|
export * from './with_tracer.js';
|
|
5
5
|
export * from './prom_otel_adapter.js';
|
|
6
6
|
export * from './lmdb_metrics.js';
|
|
7
|
+
export * from './l1_metrics.js';
|
|
7
8
|
export * from './wrappers/index.js';
|
|
8
9
|
export * from './start.js';
|
|
9
10
|
export * from './otel_propagation.js';
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
+
|
|
3
|
+
import { type Chain, type FallbackTransport, type Hex, type HttpTransport, type PublicClient, formatEther } from 'viem';
|
|
4
|
+
|
|
5
|
+
import { L1_SENDER } from './attributes.js';
|
|
6
|
+
import { L1_BALANCE_ETH, L1_BLOB_BASE_FEE_WEI, L1_BLOCK_HEIGHT, L1_GAS_PRICE_WEI } from './metrics.js';
|
|
7
|
+
import type { BatchObservableResult, Meter, ObservableGauge } from './telemetry.js';
|
|
8
|
+
|
|
9
|
+
export class L1Metrics {
|
|
10
|
+
private l1BlockHeight: ObservableGauge;
|
|
11
|
+
private l1BalanceEth: ObservableGauge;
|
|
12
|
+
private gasPriceWei: ObservableGauge;
|
|
13
|
+
private blobBaseFeeWei: ObservableGauge;
|
|
14
|
+
private addresses: Hex[];
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
private meter: Meter,
|
|
18
|
+
private client: PublicClient<FallbackTransport<HttpTransport[]>, Chain>,
|
|
19
|
+
addresses: EthAddress[],
|
|
20
|
+
) {
|
|
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);
|
|
25
|
+
|
|
26
|
+
this.addresses = addresses.map(addr => addr.toString());
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
start() {
|
|
30
|
+
this.meter.addBatchObservableCallback(this.observe, [this.l1BalanceEth, this.l1BlockHeight]);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
stop() {
|
|
34
|
+
this.meter.removeBatchObservableCallback(this.observe, [this.l1BalanceEth, this.l1BlockHeight]);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private observe = async (observer: BatchObservableResult) => {
|
|
38
|
+
const blockNumber = await this.client.getBlockNumber();
|
|
39
|
+
const ethBalances = await Promise.all(
|
|
40
|
+
this.addresses.map(address =>
|
|
41
|
+
this.client.getBalance({
|
|
42
|
+
address,
|
|
43
|
+
blockNumber,
|
|
44
|
+
}),
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const gasPrice = await this.client.getGasPrice();
|
|
49
|
+
const blobFee = await this.client.getBlobBaseFee();
|
|
50
|
+
|
|
51
|
+
observer.observe(this.l1BlockHeight, Number(blockNumber));
|
|
52
|
+
observer.observe(this.gasPriceWei, Number(gasPrice));
|
|
53
|
+
observer.observe(this.blobBaseFeeWei, Number(blobFee));
|
|
54
|
+
|
|
55
|
+
for (let i = 0; i < ethBalances.length; i++) {
|
|
56
|
+
const wei = ethBalances[i];
|
|
57
|
+
const address = this.addresses[i];
|
|
58
|
+
const eth = parseFloat(formatEther(wei, 'wei'));
|
|
59
|
+
|
|
60
|
+
observer.observe(this.l1BalanceEth, eth, {
|
|
61
|
+
[L1_SENDER]: address,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
package/src/lmdb_metrics.ts
CHANGED
|
@@ -1,36 +1,35 @@
|
|
|
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
|
-
export type LmdbStatsCallback = () => Promise<{
|
|
4
|
+
export type LmdbStatsCallback = () => Promise<{
|
|
5
|
+
mappingSize: number;
|
|
6
|
+
physicalFileSize: number;
|
|
7
|
+
numItems: number;
|
|
8
|
+
actualSize: number;
|
|
9
|
+
}>;
|
|
11
10
|
|
|
12
11
|
export class LmdbMetrics {
|
|
13
12
|
private dbMapSize: ObservableGauge;
|
|
13
|
+
private dbPhysicalFileSize: ObservableGauge;
|
|
14
14
|
private dbUsedSize: ObservableGauge;
|
|
15
15
|
private dbNumItems: ObservableGauge;
|
|
16
16
|
|
|
17
|
-
constructor(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
this.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
unit: 'By',
|
|
27
|
-
});
|
|
28
|
-
this.dbNumItems = meter.createObservableGauge(Metrics.DB_NUM_ITEMS, {
|
|
29
|
-
description: 'LMDB Num Items',
|
|
30
|
-
valueType: ValueType.INT,
|
|
31
|
-
});
|
|
17
|
+
constructor(
|
|
18
|
+
meter: Meter,
|
|
19
|
+
private attributes?: AttributesType,
|
|
20
|
+
private getStats?: LmdbStatsCallback,
|
|
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);
|
|
32
26
|
|
|
33
|
-
meter.addBatchObservableCallback(this.recordDBMetrics, [
|
|
27
|
+
meter.addBatchObservableCallback(this.recordDBMetrics, [
|
|
28
|
+
this.dbMapSize,
|
|
29
|
+
this.dbPhysicalFileSize,
|
|
30
|
+
this.dbUsedSize,
|
|
31
|
+
this.dbNumItems,
|
|
32
|
+
]);
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
private recordDBMetrics = async (observable: BatchObservableResult) => {
|
|
@@ -39,6 +38,7 @@ export class LmdbMetrics {
|
|
|
39
38
|
}
|
|
40
39
|
const metrics = await this.getStats();
|
|
41
40
|
observable.observe(this.dbMapSize, metrics.mappingSize, this.attributes);
|
|
41
|
+
observable.observe(this.dbPhysicalFileSize, metrics.physicalFileSize, this.attributes);
|
|
42
42
|
observable.observe(this.dbNumItems, metrics.numItems, this.attributes);
|
|
43
43
|
observable.observe(this.dbUsedSize, metrics.actualSize, this.attributes);
|
|
44
44
|
};
|
|
@@ -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
|
+
}
|