@aztec/telemetry-client 0.0.1-commit.2ed92850 → 0.0.1-commit.2f68f620
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 +13 -2
- package/dest/attributes.d.ts.map +1 -1
- package/dest/attributes.js +6 -1
- package/dest/config.d.ts +3 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +17 -9
- package/dest/lmdb_metrics.d.ts +2 -2
- package/dest/lmdb_metrics.d.ts.map +1 -1
- package/dest/metric-utils.d.ts +21 -2
- package/dest/metric-utils.d.ts.map +1 -1
- package/dest/metric-utils.js +52 -0
- package/dest/metrics.d.ts +70 -4
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +372 -11
- 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 +1 -1
- package/dest/nodejs_metrics_monitor.d.ts.map +1 -1
- package/dest/nodejs_metrics_monitor.js +7 -1
- package/dest/otel.d.ts +6 -1
- package/dest/otel.d.ts.map +1 -1
- package/dest/otel.js +73 -4
- 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 +4 -3
- package/dest/start.d.ts +3 -2
- package/dest/start.d.ts.map +1 -1
- package/dest/start.js +3 -3
- package/dest/telemetry.d.ts +5 -4
- package/dest/telemetry.d.ts.map +1 -1
- package/dest/telemetry.js +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/l2_block_stream.d.ts +2 -2
- package/dest/wrappers/l2_block_stream.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/attributes.ts +17 -1
- package/src/config.ts +24 -9
- package/src/metric-utils.ts +64 -1
- package/src/metrics.ts +382 -11
- package/src/monitored_batch_span_processor.ts +100 -0
- package/src/nodejs_metrics_monitor.ts +4 -1
- package/src/otel.ts +52 -3
- package/src/otel_propagation.ts +42 -1
- package/src/otel_resource.ts +19 -2
- package/src/prom_otel_adapter.ts +4 -5
- package/src/start.ts +12 -4
- package/src/telemetry.ts +4 -3
- package/src/wrappers/fetch.ts +9 -3
- package/src/wrappers/l2_block_stream.ts +1 -4
package/src/otel.ts
CHANGED
|
@@ -28,12 +28,13 @@ import {
|
|
|
28
28
|
type PeriodicExportingMetricReaderOptions,
|
|
29
29
|
View,
|
|
30
30
|
} from '@opentelemetry/sdk-metrics';
|
|
31
|
-
import {
|
|
31
|
+
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
|
|
32
32
|
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from '@opentelemetry/semantic-conventions';
|
|
33
33
|
|
|
34
34
|
import type { TelemetryClientConfig } from './config.js';
|
|
35
35
|
import { toMetricOptions } from './metric-utils.js';
|
|
36
36
|
import type { MetricDefinition } from './metrics.js';
|
|
37
|
+
import { MonitoredBatchSpanProcessor } from './monitored_batch_span_processor.js';
|
|
37
38
|
import { NodejsMetricsMonitor } from './nodejs_metrics_monitor.js';
|
|
38
39
|
import { OtelFilterMetricExporter, PublicOtelFilterMetricExporter } from './otel_filter_metric_exporter.js';
|
|
39
40
|
import { registerOtelLoggerProvider } from './otel_logger_provider.js';
|
|
@@ -95,6 +96,11 @@ export class OpenTelemetryClient implements TelemetryClient {
|
|
|
95
96
|
private meters: Map<string, WrappedMeter> = new Map<string, WrappedMeter>();
|
|
96
97
|
private tracers: Map<string, Tracer> = new Map<string, Tracer>();
|
|
97
98
|
|
|
99
|
+
/** Memoized shutdown promise. The telemetry client is shared between the aztec-node and an embedded prover-node,
|
|
100
|
+
* so stop() can be invoked more than once; the providers throw "shutdown may only be called once" and
|
|
101
|
+
* "invalid attempt to force flush after shutdown" if that happens. Guarding here makes stop()/flush() idempotent. */
|
|
102
|
+
private stopPromise: Promise<void> | undefined;
|
|
103
|
+
|
|
98
104
|
protected constructor(
|
|
99
105
|
private resource: IResource,
|
|
100
106
|
private meterProvider: MeterProvider,
|
|
@@ -168,6 +174,10 @@ export class OpenTelemetryClient implements TelemetryClient {
|
|
|
168
174
|
}
|
|
169
175
|
|
|
170
176
|
public async flush() {
|
|
177
|
+
// Flushing after the providers have been shut down throws "invalid attempt to force flush after shutdown".
|
|
178
|
+
if (this.stopPromise) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
171
181
|
await Promise.all([
|
|
172
182
|
this.meterProvider.forceFlush(),
|
|
173
183
|
this.loggerProvider?.forceFlush(),
|
|
@@ -175,7 +185,11 @@ export class OpenTelemetryClient implements TelemetryClient {
|
|
|
175
185
|
]);
|
|
176
186
|
}
|
|
177
187
|
|
|
178
|
-
public
|
|
188
|
+
public stop() {
|
|
189
|
+
return (this.stopPromise ??= this.doStop());
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
private async doStop() {
|
|
179
193
|
this.nodejsMetricsMonitor?.stop();
|
|
180
194
|
|
|
181
195
|
const flushAndShutdown = async (provider?: { forceFlush: () => Promise<void>; shutdown: () => Promise<void> }) => {
|
|
@@ -334,6 +348,36 @@ export class OpenTelemetryClient implements TelemetryClient {
|
|
|
334
348
|
true,
|
|
335
349
|
),
|
|
336
350
|
}),
|
|
351
|
+
// L1 gas prices in gwei: priority fees ~0.01-10, base fees ~1-500, spikes to 1000+
|
|
352
|
+
new View({
|
|
353
|
+
instrumentType: InstrumentType.HISTOGRAM,
|
|
354
|
+
instrumentUnit: 'gwei',
|
|
355
|
+
aggregation: new ExplicitBucketHistogramAggregation(
|
|
356
|
+
[0.1, 0.5, 1, 2, 5, 10, 20, 50, 100, 200, 500, 1_000],
|
|
357
|
+
true,
|
|
358
|
+
),
|
|
359
|
+
}),
|
|
360
|
+
// L1 gas consumption: tx gas 100k-30M, calldata/blob gas varies
|
|
361
|
+
new View({
|
|
362
|
+
instrumentType: InstrumentType.HISTOGRAM,
|
|
363
|
+
instrumentUnit: 'gas',
|
|
364
|
+
aggregation: new ExplicitBucketHistogramAggregation(
|
|
365
|
+
[
|
|
366
|
+
10_000, 50_000, 100_000, 250_000, 500_000, 1_000_000, 2_000_000, 5_000_000, 10_000_000, 15_000_000,
|
|
367
|
+
30_000_000,
|
|
368
|
+
],
|
|
369
|
+
true,
|
|
370
|
+
),
|
|
371
|
+
}),
|
|
372
|
+
// L1 tx total fee in ETH: typically 0.001 - 1 ETH
|
|
373
|
+
new View({
|
|
374
|
+
instrumentType: InstrumentType.HISTOGRAM,
|
|
375
|
+
instrumentUnit: 'eth',
|
|
376
|
+
aggregation: new ExplicitBucketHistogramAggregation(
|
|
377
|
+
[0.0001, 0.0005, 0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5, 10],
|
|
378
|
+
true,
|
|
379
|
+
),
|
|
380
|
+
}),
|
|
337
381
|
],
|
|
338
382
|
});
|
|
339
383
|
}
|
|
@@ -343,7 +387,12 @@ export class OpenTelemetryClient implements TelemetryClient {
|
|
|
343
387
|
const tracerProvider = new NodeTracerProvider({
|
|
344
388
|
resource,
|
|
345
389
|
spanProcessors: config.tracesCollectorUrl
|
|
346
|
-
? [
|
|
390
|
+
? [
|
|
391
|
+
new MonitoredBatchSpanProcessor(new OTLPTraceExporter({ url: config.tracesCollectorUrl.href }), log, {
|
|
392
|
+
maxQueueSize: config.otelBspMaxQueueSize,
|
|
393
|
+
minTraceDurationMs: config.otelMinTraceDurationMs,
|
|
394
|
+
}),
|
|
395
|
+
]
|
|
347
396
|
: [],
|
|
348
397
|
});
|
|
349
398
|
|
package/src/otel_propagation.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { DiagnosticsMiddleware } from '@aztec/foundation/json-rpc/server';
|
|
2
|
+
|
|
1
3
|
import { ROOT_CONTEXT, type Span, SpanKind, SpanStatusCode, propagation } from '@opentelemetry/api';
|
|
2
4
|
import type Koa from 'koa';
|
|
3
5
|
|
|
@@ -17,7 +19,7 @@ export function getOtelJsonRpcPropagationMiddleware(
|
|
|
17
19
|
const context = propagation.extract(ROOT_CONTEXT, ctx.request.headers);
|
|
18
20
|
const method = (ctx.request.body as any)?.method;
|
|
19
21
|
return tracer.startActiveSpan(
|
|
20
|
-
`JsonRpcServer.${method ?? '
|
|
22
|
+
`JsonRpcServer.${method ?? 'batch'}`,
|
|
21
23
|
{ kind: SpanKind.SERVER },
|
|
22
24
|
context,
|
|
23
25
|
async (span: Span): Promise<void> => {
|
|
@@ -48,3 +50,42 @@ export function getOtelJsonRpcPropagationMiddleware(
|
|
|
48
50
|
);
|
|
49
51
|
};
|
|
50
52
|
}
|
|
53
|
+
|
|
54
|
+
export function getOtelJsonRpcDiagnosticsMiddleware(): DiagnosticsMiddleware {
|
|
55
|
+
return function otelJsonRpcDiagnostics(ctx, next) {
|
|
56
|
+
const [namespace, method] = splitNamespace(ctx.method);
|
|
57
|
+
const scope = namespace ?? 'UnknownHandler';
|
|
58
|
+
const tracer = getTelemetryClient().getTracer(scope);
|
|
59
|
+
return tracer.startActiveSpan(
|
|
60
|
+
`${scope}.${method}`,
|
|
61
|
+
{ kind: SpanKind.INTERNAL, attributes: { [ATTR_JSONRPC_METHOD]: ctx.method } },
|
|
62
|
+
async span => {
|
|
63
|
+
if (ctx.id !== null) {
|
|
64
|
+
span.setAttribute(ATTR_JSONRPC_REQUEST_ID, ctx.id);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
await next();
|
|
69
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
70
|
+
} catch (err) {
|
|
71
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: err instanceof Error ? err.message : String(err) });
|
|
72
|
+
if (typeof err === 'string' || err instanceof Error) {
|
|
73
|
+
span.recordException(err);
|
|
74
|
+
}
|
|
75
|
+
throw err;
|
|
76
|
+
} finally {
|
|
77
|
+
span.end();
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function splitNamespace(fullMethod: string): [namespace: string | undefined, method: string] {
|
|
85
|
+
const idx = fullMethod.indexOf('_');
|
|
86
|
+
if (idx > -1) {
|
|
87
|
+
return [fullMethod.slice(0, idx), fullMethod.slice(idx + 1)];
|
|
88
|
+
} else {
|
|
89
|
+
return [undefined, fullMethod];
|
|
90
|
+
}
|
|
91
|
+
}
|
package/src/otel_resource.ts
CHANGED
|
@@ -7,10 +7,26 @@ import {
|
|
|
7
7
|
osDetectorSync,
|
|
8
8
|
serviceInstanceIdDetectorSync,
|
|
9
9
|
} from '@opentelemetry/resources';
|
|
10
|
-
import {
|
|
10
|
+
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from '@opentelemetry/semantic-conventions';
|
|
11
|
+
import { readFileSync } from 'fs';
|
|
12
|
+
import { dirname, resolve } from 'path';
|
|
13
|
+
import { fileURLToPath } from 'url';
|
|
11
14
|
|
|
12
15
|
import { AZTEC_NODE_ROLE, AZTEC_REGISTRY_ADDRESS, AZTEC_ROLLUP_ADDRESS, AZTEC_ROLLUP_VERSION } from './attributes.js';
|
|
13
16
|
|
|
17
|
+
/** Reads the Aztec client version from the release manifest. */
|
|
18
|
+
function getAztecVersion(): string | undefined {
|
|
19
|
+
try {
|
|
20
|
+
const releasePleasePath = resolve(
|
|
21
|
+
dirname(fileURLToPath(import.meta.url)),
|
|
22
|
+
'../../../.release-please-manifest.json',
|
|
23
|
+
);
|
|
24
|
+
return JSON.parse(readFileSync(releasePleasePath, 'utf-8'))['.'];
|
|
25
|
+
} catch {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
14
30
|
export function getOtelResource(): IResource {
|
|
15
31
|
const resource = detectResourcesSync({
|
|
16
32
|
detectors: [
|
|
@@ -42,7 +58,8 @@ const aztecNetworkDetectorSync: DetectorSync = {
|
|
|
42
58
|
}
|
|
43
59
|
const aztecAttributes = {
|
|
44
60
|
// this gets overwritten by OTEL_RESOURCE_ATTRIBUTES (if set)
|
|
45
|
-
[
|
|
61
|
+
[ATTR_SERVICE_NAME]: role ? `aztec-${role}` : undefined,
|
|
62
|
+
[ATTR_SERVICE_VERSION]: getAztecVersion(),
|
|
46
63
|
[AZTEC_NODE_ROLE]: role,
|
|
47
64
|
[AZTEC_ROLLUP_VERSION]: process.env.ROLLUP_VERSION ?? 'canonical',
|
|
48
65
|
[AZTEC_ROLLUP_ADDRESS]: process.env.ROLLUP_CONTRACT_ADDRESS,
|
package/src/prom_otel_adapter.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
1
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import { Timer } from '@aztec/foundation/timer';
|
|
3
3
|
|
|
4
4
|
import { Registry } from 'prom-client';
|
|
@@ -410,12 +410,11 @@ function parseLabelsSafely<Labels extends LabelsGeneric>(labelStr: string, logge
|
|
|
410
410
|
*/
|
|
411
411
|
export class OtelMetricsAdapter extends Registry implements MetricsRegister {
|
|
412
412
|
private readonly meter: Meter;
|
|
413
|
+
private logger: Logger;
|
|
413
414
|
|
|
414
|
-
constructor(
|
|
415
|
-
telemetryClient: TelemetryClient,
|
|
416
|
-
private logger: Logger = createLogger('telemetry:otel-metrics-adapter'),
|
|
417
|
-
) {
|
|
415
|
+
constructor(telemetryClient: TelemetryClient, bindings?: LoggerBindings) {
|
|
418
416
|
super();
|
|
417
|
+
this.logger = createLogger('telemetry:otel-metrics-adapter', bindings);
|
|
419
418
|
this.meter = telemetryClient.getMeter('metrics-adapter');
|
|
420
419
|
}
|
|
421
420
|
|
package/src/start.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
1
|
+
import { type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
2
2
|
|
|
3
3
|
import type { TelemetryClientConfig } from './config.js';
|
|
4
4
|
import { NoopTelemetryClient } from './noop.js';
|
|
@@ -9,14 +9,22 @@ export * from './config.js';
|
|
|
9
9
|
let initialized = false;
|
|
10
10
|
let telemetry: TelemetryClient = new NoopTelemetryClient();
|
|
11
11
|
|
|
12
|
-
export async function initTelemetryClient(
|
|
13
|
-
|
|
12
|
+
export async function initTelemetryClient(
|
|
13
|
+
config: TelemetryClientConfig,
|
|
14
|
+
bindings?: LoggerBindings,
|
|
15
|
+
): Promise<TelemetryClient> {
|
|
16
|
+
const log = createLogger('telemetry:client', bindings);
|
|
14
17
|
if (initialized) {
|
|
15
18
|
log.warn('Telemetry client has already been initialized once');
|
|
16
19
|
return telemetry;
|
|
17
20
|
}
|
|
18
21
|
|
|
19
|
-
if (
|
|
22
|
+
if (
|
|
23
|
+
config.metricsCollectorUrl ||
|
|
24
|
+
config.publicMetricsCollectorUrl ||
|
|
25
|
+
config.tracesCollectorUrl ||
|
|
26
|
+
config.logsCollectorUrl
|
|
27
|
+
) {
|
|
20
28
|
log.info(`Using OpenTelemetry client with custom collector`);
|
|
21
29
|
// Lazy load OpenTelemetry to avoid loading heavy deps at startup
|
|
22
30
|
const { OpenTelemetryClient } = await import('./otel.js');
|
package/src/telemetry.ts
CHANGED
|
@@ -20,7 +20,7 @@ import type * as Attributes from './attributes.js';
|
|
|
20
20
|
import type { MetricDefinition } from './metrics.js';
|
|
21
21
|
import { getTelemetryClient } from './start.js';
|
|
22
22
|
|
|
23
|
-
export { toMetricOptions } from './metric-utils.js';
|
|
23
|
+
export { toMetricOptions, createUpDownCounterWithDefault } from './metric-utils.js';
|
|
24
24
|
|
|
25
25
|
export { type Span, SpanStatusCode, ValueType, type Context } from '@opentelemetry/api';
|
|
26
26
|
|
|
@@ -48,7 +48,6 @@ type BannedMetricAttributeNames = (typeof Attributes)[
|
|
|
48
48
|
| 'TX_HASH'
|
|
49
49
|
| 'PROVING_JOB_ID'
|
|
50
50
|
| 'P2P_ID'
|
|
51
|
-
| 'P2P_REQ_RESP_BATCH_REQUESTS_COUNT'
|
|
52
51
|
| 'TARGET_ADDRESS'
|
|
53
52
|
| 'MANA_USED'
|
|
54
53
|
| 'TOTAL_INSTRUCTIONS'];
|
|
@@ -56,8 +55,10 @@ type BannedMetricAttributeNames = (typeof Attributes)[
|
|
|
56
55
|
/** Global registry of attributes */
|
|
57
56
|
export type AttributesType = Partial<Record<AttributeNames, AttributeValue>>;
|
|
58
57
|
|
|
58
|
+
export type AllowedAttributeNames = Exclude<AttributeNames, BannedMetricAttributeNames>;
|
|
59
|
+
|
|
59
60
|
/** Subset of attributes allowed to be added to metrics */
|
|
60
|
-
export type MetricAttributesType = Partial<Record<
|
|
61
|
+
export type MetricAttributesType = Partial<Record<AllowedAttributeNames, AttributeValue>>;
|
|
61
62
|
|
|
62
63
|
/** Re-export MetricDefinition for convenience */
|
|
63
64
|
export type { MetricDefinition } from './metrics.js';
|
package/src/wrappers/fetch.ts
CHANGED
|
@@ -9,12 +9,17 @@ import { ATTR_JSONRPC_METHOD, ATTR_JSONRPC_REQUEST_ID } from '../vendor/attribut
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Makes a fetch function that retries based on the given attempts and propagates trace information.
|
|
12
|
-
* @param retries - Sequence of intervals (in seconds) to retry.
|
|
12
|
+
* @param retries - Sequence of intervals (in seconds) to retry, or a factory function returning an iterator for custom/indefinite backoff.
|
|
13
13
|
* @param noRetry - Whether to stop retries on server errors.
|
|
14
14
|
* @param log - Optional logger for logging attempts.
|
|
15
15
|
* @returns A fetch function.
|
|
16
16
|
*/
|
|
17
|
-
export function makeTracedFetch(
|
|
17
|
+
export function makeTracedFetch(
|
|
18
|
+
retries: number[] | (() => Generator<number>),
|
|
19
|
+
defaultNoRetry: boolean,
|
|
20
|
+
fetch = defaultFetch,
|
|
21
|
+
log?: Logger,
|
|
22
|
+
) {
|
|
18
23
|
return (host: string, body: unknown, extraHeaders: Record<string, string> = {}, noRetry?: boolean) => {
|
|
19
24
|
const telemetry = getTelemetryClient();
|
|
20
25
|
return telemetry.getTracer('fetch').startActiveSpan(`JsonRpcClient`, { kind: SpanKind.CLIENT }, async span => {
|
|
@@ -27,10 +32,11 @@ export function makeTracedFetch(retries: number[], defaultNoRetry: boolean, fetc
|
|
|
27
32
|
}
|
|
28
33
|
const headers = { ...extraHeaders };
|
|
29
34
|
propagation.inject(context.active(), headers);
|
|
35
|
+
const backoff = typeof retries === 'function' ? retries() : makeBackoff(retries);
|
|
30
36
|
return await retry(
|
|
31
37
|
() => fetch(host, body, headers, noRetry ?? defaultNoRetry),
|
|
32
38
|
`JsonRpcClient request to ${host}`,
|
|
33
|
-
|
|
39
|
+
backoff,
|
|
34
40
|
log,
|
|
35
41
|
false,
|
|
36
42
|
);
|
|
@@ -11,10 +11,7 @@ import { type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client'
|
|
|
11
11
|
/** Extends an L2BlockStream with a tracer to create a new trace per iteration. */
|
|
12
12
|
export class TraceableL2BlockStream extends L2BlockStream implements Traceable {
|
|
13
13
|
constructor(
|
|
14
|
-
l2BlockSource: Pick<
|
|
15
|
-
L2BlockSource,
|
|
16
|
-
'getBlocks' | 'getBlockHeader' | 'getL2Tips' | 'getCheckpoints' | 'getCheckpointedBlocks'
|
|
17
|
-
>,
|
|
14
|
+
l2BlockSource: Pick<L2BlockSource, 'getBlocks' | 'getBlockData' | 'getL2Tips' | 'getCheckpoints'>,
|
|
18
15
|
localData: L2BlockStreamLocalDataProvider,
|
|
19
16
|
handler: L2BlockStreamEventHandler,
|
|
20
17
|
public readonly tracer: Tracer,
|