@aztec/telemetry-client 0.0.1-commit.f2ce05ee → 0.0.1-commit.f5a9928
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 +22 -2
- package/dest/attributes.d.ts.map +1 -1
- package/dest/attributes.js +11 -1
- package/dest/config.d.ts +3 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +17 -9
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/json_rpc_server_metrics.d.ts +27 -0
- package/dest/json_rpc_server_metrics.d.ts.map +1 -0
- package/dest/json_rpc_server_metrics.js +154 -0
- package/dest/lmdb_metrics.d.ts +2 -2
- package/dest/lmdb_metrics.d.ts.map +1 -1
- package/dest/metrics.d.ts +84 -5
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +450 -19
- 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/otel.d.ts +6 -1
- package/dest/otel.d.ts.map +1 -1
- package/dest/otel.js +99 -4
- package/dest/otel_propagation.d.ts +4 -1
- package/dest/otel_propagation.d.ts.map +1 -1
- package/dest/otel_propagation.js +64 -6
- package/dest/start.d.ts +1 -1
- package/dest/start.d.ts.map +1 -1
- package/dest/start.js +1 -1
- package/dest/telemetry.d.ts +5 -3
- package/dest/telemetry.d.ts.map +1 -1
- package/dest/vendor/attributes.d.ts +2 -1
- package/dest/vendor/attributes.d.ts.map +1 -1
- package/dest/vendor/attributes.js +1 -0
- 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 -2
- package/dest/wrappers/index.d.ts.map +1 -1
- package/dest/wrappers/index.js +0 -1
- package/dest/wrappers/json_rpc_server.d.ts +1 -1
- package/dest/wrappers/json_rpc_server.d.ts.map +1 -1
- package/dest/wrappers/json_rpc_server.js +6 -1
- package/package.json +3 -3
- package/src/attributes.ts +29 -1
- package/src/config.ts +24 -9
- package/src/index.ts +1 -0
- package/src/json_rpc_server_metrics.ts +151 -0
- package/src/metrics.ts +473 -19
- package/src/monitored_batch_span_processor.ts +100 -0
- package/src/otel.ts +69 -3
- package/src/otel_propagation.ts +63 -5
- package/src/start.ts +6 -1
- package/src/telemetry.ts +6 -2
- package/src/vendor/attributes.ts +1 -0
- package/src/wrappers/fetch.ts +9 -3
- package/src/wrappers/index.ts +0 -1
- package/src/wrappers/json_rpc_server.ts +13 -2
- package/dest/wrappers/l2_block_stream.d.ts +0 -16
- package/dest/wrappers/l2_block_stream.d.ts.map +0 -1
- package/dest/wrappers/l2_block_stream.js +0 -400
- package/src/wrappers/l2_block_stream.ts +0 -41
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
2
|
+
|
|
3
|
+
import { type Context, SpanStatusCode } from '@opentelemetry/api';
|
|
4
|
+
import { hrTimeToMilliseconds } from '@opentelemetry/core';
|
|
5
|
+
import type { SpanExporter } from '@opentelemetry/sdk-trace-base';
|
|
6
|
+
import { BatchSpanProcessor, type BufferConfig, type ReadableSpan, type Span } from '@opentelemetry/sdk-trace-node';
|
|
7
|
+
|
|
8
|
+
/** Minimum interval between drop warnings to avoid log spam. */
|
|
9
|
+
const DROP_WARNING_INTERVAL_MS = 30_000;
|
|
10
|
+
|
|
11
|
+
const DEFAULT_MIN_TRACE_DURATION_MS = 10;
|
|
12
|
+
|
|
13
|
+
const DEFAULT_MAX_QUEUE_SIZE = 16384;
|
|
14
|
+
|
|
15
|
+
/** Cap on the per-export batch size, so a large queue can actually be drained instead of dribbling out
|
|
16
|
+
* at the SDK default of 512 spans per scheduled export. Kept <= maxQueueSize per the BatchSpanProcessor contract. */
|
|
17
|
+
const DEFAULT_MAX_EXPORT_BATCH_SIZE = 2048;
|
|
18
|
+
|
|
19
|
+
export type MonitoredBatchSpanProcessorConfig = BufferConfig & {
|
|
20
|
+
minTraceDurationMs?: number;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Wraps BatchSpanProcessor to emit warnings when spans are dropped due to a full queue.
|
|
25
|
+
* The standard BatchSpanProcessor silently discards spans when its internal queue reaches
|
|
26
|
+
* maxQueueSize, making telemetry data loss invisible to operators.
|
|
27
|
+
*/
|
|
28
|
+
export class MonitoredBatchSpanProcessor extends BatchSpanProcessor {
|
|
29
|
+
private readonly maxQueueSize: number;
|
|
30
|
+
private readonly minTraceDurationMs: number;
|
|
31
|
+
private readonly log: Logger;
|
|
32
|
+
|
|
33
|
+
private approxQueueSize = 0;
|
|
34
|
+
private droppedSinceLastWarning = 0;
|
|
35
|
+
private totalDropped = 0;
|
|
36
|
+
private lastWarningTime = 0;
|
|
37
|
+
|
|
38
|
+
constructor(exporter: SpanExporter, log: Logger, config?: MonitoredBatchSpanProcessorConfig) {
|
|
39
|
+
const maxQueueSize = config?.maxQueueSize ?? DEFAULT_MAX_QUEUE_SIZE;
|
|
40
|
+
const maxExportBatchSize = Math.min(config?.maxExportBatchSize ?? DEFAULT_MAX_EXPORT_BATCH_SIZE, maxQueueSize);
|
|
41
|
+
super(exporter, { ...config, maxQueueSize, maxExportBatchSize });
|
|
42
|
+
this.maxQueueSize = maxQueueSize;
|
|
43
|
+
this.minTraceDurationMs = Math.max(0, config?.minTraceDurationMs ?? DEFAULT_MIN_TRACE_DURATION_MS);
|
|
44
|
+
this.log = log;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
override onStart(span: Span, parentContext: Context): void {
|
|
48
|
+
super.onStart(span, parentContext);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
override onEnd(span: ReadableSpan): void {
|
|
52
|
+
if (this.shouldDropShortSpan(span)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (this.approxQueueSize >= this.maxQueueSize) {
|
|
57
|
+
this.droppedSinceLastWarning++;
|
|
58
|
+
this.totalDropped++;
|
|
59
|
+
this.maybeLogDropWarning();
|
|
60
|
+
} else {
|
|
61
|
+
this.approxQueueSize++;
|
|
62
|
+
}
|
|
63
|
+
super.onEnd(span);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
override async forceFlush(): Promise<void> {
|
|
67
|
+
await super.forceFlush();
|
|
68
|
+
this.approxQueueSize = 0;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
override async shutdown(): Promise<void> {
|
|
72
|
+
if (this.totalDropped > 0) {
|
|
73
|
+
this.log.warn(`BatchSpanProcessor shutting down with ${this.totalDropped} total spans dropped`, {
|
|
74
|
+
totalDropped: this.totalDropped,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
await super.shutdown();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private shouldDropShortSpan(span: ReadableSpan): boolean {
|
|
81
|
+
return (
|
|
82
|
+
this.minTraceDurationMs > 0 &&
|
|
83
|
+
span.status.code !== SpanStatusCode.ERROR &&
|
|
84
|
+
hrTimeToMilliseconds(span.duration) < this.minTraceDurationMs
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private maybeLogDropWarning(): void {
|
|
89
|
+
const now = Date.now();
|
|
90
|
+
if (now - this.lastWarningTime >= DROP_WARNING_INTERVAL_MS) {
|
|
91
|
+
this.log.warn(
|
|
92
|
+
`BatchSpanProcessor dropping spans: queue full (maxQueueSize=${this.maxQueueSize}). ` +
|
|
93
|
+
`${this.droppedSinceLastWarning} dropped since last warning, ${this.totalDropped} total.`,
|
|
94
|
+
{ droppedSinceLastWarning: this.droppedSinceLastWarning, totalDropped: this.totalDropped },
|
|
95
|
+
);
|
|
96
|
+
this.droppedSinceLastWarning = 0;
|
|
97
|
+
this.lastWarningTime = now;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
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> }) => {
|
|
@@ -241,6 +255,23 @@ export class OpenTelemetryClient implements TelemetryClient {
|
|
|
241
255
|
true,
|
|
242
256
|
),
|
|
243
257
|
}),
|
|
258
|
+
// Pending-to-mined delay routinely exceeds the 1-minute ceiling of the generic `ms`
|
|
259
|
+
// view below under load, so it would saturate at 60s. Give this one metric wider
|
|
260
|
+
// buckets (1s to 10min). This must precede the generic `ms` view: when multiple views
|
|
261
|
+
// match an instrument, the SDK keeps the first-registered compatible storage, so the
|
|
262
|
+
// first view in this list wins the bucket boundaries.
|
|
263
|
+
new View({
|
|
264
|
+
instrumentType: InstrumentType.HISTOGRAM,
|
|
265
|
+
instrumentName: 'aztec.mempool.tx_mined_delay',
|
|
266
|
+
instrumentUnit: 'ms',
|
|
267
|
+
aggregation: new ExplicitBucketHistogramAggregation(
|
|
268
|
+
[
|
|
269
|
+
1_000, 2_500, 5_000, 7_500, 10_000, 15_000, 30_000, 45_000, 60_000, 90_000, 120_000, 180_000, 300_000,
|
|
270
|
+
600_000,
|
|
271
|
+
],
|
|
272
|
+
true,
|
|
273
|
+
),
|
|
274
|
+
}),
|
|
244
275
|
new View({
|
|
245
276
|
instrumentType: InstrumentType.HISTOGRAM,
|
|
246
277
|
instrumentUnit: 'ms',
|
|
@@ -334,6 +365,36 @@ export class OpenTelemetryClient implements TelemetryClient {
|
|
|
334
365
|
true,
|
|
335
366
|
),
|
|
336
367
|
}),
|
|
368
|
+
// L1 gas prices in gwei: priority fees ~0.01-10, base fees ~1-500, spikes to 1000+
|
|
369
|
+
new View({
|
|
370
|
+
instrumentType: InstrumentType.HISTOGRAM,
|
|
371
|
+
instrumentUnit: 'gwei',
|
|
372
|
+
aggregation: new ExplicitBucketHistogramAggregation(
|
|
373
|
+
[0.1, 0.5, 1, 2, 5, 10, 20, 50, 100, 200, 500, 1_000],
|
|
374
|
+
true,
|
|
375
|
+
),
|
|
376
|
+
}),
|
|
377
|
+
// L1 gas consumption: tx gas 100k-30M, calldata/blob gas varies
|
|
378
|
+
new View({
|
|
379
|
+
instrumentType: InstrumentType.HISTOGRAM,
|
|
380
|
+
instrumentUnit: 'gas',
|
|
381
|
+
aggregation: new ExplicitBucketHistogramAggregation(
|
|
382
|
+
[
|
|
383
|
+
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,
|
|
384
|
+
30_000_000,
|
|
385
|
+
],
|
|
386
|
+
true,
|
|
387
|
+
),
|
|
388
|
+
}),
|
|
389
|
+
// L1 tx total fee in ETH: typically 0.001 - 1 ETH
|
|
390
|
+
new View({
|
|
391
|
+
instrumentType: InstrumentType.HISTOGRAM,
|
|
392
|
+
instrumentUnit: 'eth',
|
|
393
|
+
aggregation: new ExplicitBucketHistogramAggregation(
|
|
394
|
+
[0.0001, 0.0005, 0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5, 10],
|
|
395
|
+
true,
|
|
396
|
+
),
|
|
397
|
+
}),
|
|
337
398
|
],
|
|
338
399
|
});
|
|
339
400
|
}
|
|
@@ -343,7 +404,12 @@ export class OpenTelemetryClient implements TelemetryClient {
|
|
|
343
404
|
const tracerProvider = new NodeTracerProvider({
|
|
344
405
|
resource,
|
|
345
406
|
spanProcessors: config.tracesCollectorUrl
|
|
346
|
-
? [
|
|
407
|
+
? [
|
|
408
|
+
new MonitoredBatchSpanProcessor(new OTLPTraceExporter({ url: config.tracesCollectorUrl.href }), log, {
|
|
409
|
+
maxQueueSize: config.otelBspMaxQueueSize,
|
|
410
|
+
minTraceDurationMs: config.otelMinTraceDurationMs,
|
|
411
|
+
}),
|
|
412
|
+
]
|
|
347
413
|
: [],
|
|
348
414
|
});
|
|
349
415
|
|
package/src/otel_propagation.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
+
import type { DiagnosticsMiddleware } from '@aztec/foundation/json-rpc/server';
|
|
2
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
3
|
+
|
|
1
4
|
import { ROOT_CONTEXT, type Span, SpanKind, SpanStatusCode, propagation } from '@opentelemetry/api';
|
|
2
5
|
import type Koa from 'koa';
|
|
3
6
|
|
|
7
|
+
import { getJsonRpcServerMetrics, splitJsonRpcMethod } from './json_rpc_server_metrics.js';
|
|
4
8
|
import { getTelemetryClient } from './start.js';
|
|
5
9
|
import {
|
|
6
10
|
ATTR_JSONRPC_ERROR_CODE,
|
|
7
11
|
ATTR_JSONRPC_ERROR_MSG,
|
|
8
12
|
ATTR_JSONRPC_METHOD,
|
|
9
13
|
ATTR_JSONRPC_REQUEST_ID,
|
|
14
|
+
ATTR_JSONRPC_SERVICE,
|
|
10
15
|
} from './vendor/attributes.js';
|
|
11
16
|
|
|
12
17
|
export function getOtelJsonRpcPropagationMiddleware(
|
|
@@ -15,21 +20,36 @@ export function getOtelJsonRpcPropagationMiddleware(
|
|
|
15
20
|
return function otelJsonRpcPropagation(ctx: Koa.Context, next: () => Promise<void>) {
|
|
16
21
|
const tracer = getTelemetryClient().getTracer(scope);
|
|
17
22
|
const context = propagation.extract(ROOT_CONTEXT, ctx.request.headers);
|
|
18
|
-
const method = (ctx.request.body as any)?.method;
|
|
19
23
|
return tracer.startActiveSpan(
|
|
20
|
-
`JsonRpcServer
|
|
24
|
+
`JsonRpcServer`,
|
|
21
25
|
{ kind: SpanKind.SERVER },
|
|
22
26
|
context,
|
|
23
27
|
async (span: Span): Promise<void> => {
|
|
24
28
|
if (ctx.id) {
|
|
25
29
|
span.setAttribute(ATTR_JSONRPC_REQUEST_ID, ctx.id);
|
|
26
30
|
}
|
|
27
|
-
if (method) {
|
|
28
|
-
span.setAttribute(ATTR_JSONRPC_METHOD, method);
|
|
29
|
-
}
|
|
30
31
|
|
|
31
32
|
try {
|
|
32
33
|
await next();
|
|
34
|
+
const requestBody = (ctx.request as { body?: unknown }).body;
|
|
35
|
+
if (
|
|
36
|
+
requestBody &&
|
|
37
|
+
typeof requestBody === 'object' &&
|
|
38
|
+
!Array.isArray(requestBody) &&
|
|
39
|
+
'method' in requestBody
|
|
40
|
+
) {
|
|
41
|
+
const fullMethod = requestBody.method;
|
|
42
|
+
if (typeof fullMethod === 'string') {
|
|
43
|
+
const [service, method] = splitJsonRpcMethod(fullMethod);
|
|
44
|
+
span.updateName(`JsonRpcServer.${service ? `${service}.` : ''}${method}`);
|
|
45
|
+
span.setAttribute(ATTR_JSONRPC_METHOD, method);
|
|
46
|
+
if (service) {
|
|
47
|
+
span.setAttribute(ATTR_JSONRPC_SERVICE, service);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
} else if (Array.isArray(requestBody)) {
|
|
51
|
+
span.updateName(`JsonRpcServer.batch`);
|
|
52
|
+
}
|
|
33
53
|
const err = (ctx.body as any).error?.message;
|
|
34
54
|
const code = (ctx.body as any).error?.code;
|
|
35
55
|
if (err) {
|
|
@@ -48,3 +68,41 @@ export function getOtelJsonRpcPropagationMiddleware(
|
|
|
48
68
|
);
|
|
49
69
|
};
|
|
50
70
|
}
|
|
71
|
+
|
|
72
|
+
export function getOtelJsonRpcDiagnosticsMiddleware(metricsProvider = getJsonRpcServerMetrics): DiagnosticsMiddleware {
|
|
73
|
+
return function otelJsonRpcDiagnostics(ctx, next) {
|
|
74
|
+
const [service, method] = splitJsonRpcMethod(ctx.method);
|
|
75
|
+
const scope = service ?? 'UnknownHandler';
|
|
76
|
+
const tracer = getTelemetryClient().getTracer(scope);
|
|
77
|
+
const attributes = {
|
|
78
|
+
...(service === undefined ? {} : { [ATTR_JSONRPC_SERVICE]: service }),
|
|
79
|
+
[ATTR_JSONRPC_METHOD]: method,
|
|
80
|
+
};
|
|
81
|
+
return tracer.startActiveSpan(`${scope}.${method}`, { kind: SpanKind.INTERNAL, attributes }, async span => {
|
|
82
|
+
const timer = new Timer();
|
|
83
|
+
let ok = false;
|
|
84
|
+
if (ctx.id !== null) {
|
|
85
|
+
span.setAttribute(ATTR_JSONRPC_REQUEST_ID, ctx.id);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
await next();
|
|
90
|
+
ok = true;
|
|
91
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
92
|
+
} catch (err) {
|
|
93
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: err instanceof Error ? err.message : String(err) });
|
|
94
|
+
if (typeof err === 'string' || err instanceof Error) {
|
|
95
|
+
span.recordException(err);
|
|
96
|
+
}
|
|
97
|
+
throw err;
|
|
98
|
+
} finally {
|
|
99
|
+
const metrics = metricsProvider();
|
|
100
|
+
metrics.recordRequest(ctx.method, timer.ms(), ok);
|
|
101
|
+
if (ctx.requestValidationDurationMs !== undefined && ctx.requestValidationSucceeded !== undefined) {
|
|
102
|
+
metrics.recordRequestValidation(ctx.method, ctx.requestValidationDurationMs, ctx.requestValidationSucceeded);
|
|
103
|
+
}
|
|
104
|
+
span.end();
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
}
|
package/src/start.ts
CHANGED
|
@@ -19,7 +19,12 @@ export async function initTelemetryClient(
|
|
|
19
19
|
return telemetry;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
if (
|
|
22
|
+
if (
|
|
23
|
+
config.metricsCollectorUrl ||
|
|
24
|
+
config.publicMetricsCollectorUrl ||
|
|
25
|
+
config.tracesCollectorUrl ||
|
|
26
|
+
config.logsCollectorUrl
|
|
27
|
+
) {
|
|
23
28
|
log.info(`Using OpenTelemetry client with custom collector`);
|
|
24
29
|
// Lazy load OpenTelemetry to avoid loading heavy deps at startup
|
|
25
30
|
const { OpenTelemetryClient } = await import('./otel.js');
|
package/src/telemetry.ts
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
import type * as Attributes from './attributes.js';
|
|
20
20
|
import type { MetricDefinition } from './metrics.js';
|
|
21
21
|
import { getTelemetryClient } from './start.js';
|
|
22
|
+
import type * as VendorAttributes from './vendor/attributes.js';
|
|
22
23
|
|
|
23
24
|
export { toMetricOptions, createUpDownCounterWithDefault } from './metric-utils.js';
|
|
24
25
|
|
|
@@ -28,6 +29,8 @@ type ValuesOf<T> = T extends Record<string, infer U> ? U : never;
|
|
|
28
29
|
|
|
29
30
|
type AttributeNames = ValuesOf<typeof Attributes>;
|
|
30
31
|
|
|
32
|
+
type AllowedVendorMetricAttributeNames = (typeof VendorAttributes)['ATTR_JSONRPC_METHOD' | 'ATTR_JSONRPC_SERVICE'];
|
|
33
|
+
|
|
31
34
|
/**
|
|
32
35
|
* This is a set of attributes that could lead to high cardinality in the metrics.
|
|
33
36
|
* If you find yourself wanting to capture this data in a metric consider if it makes sense to capture
|
|
@@ -48,7 +51,6 @@ type BannedMetricAttributeNames = (typeof Attributes)[
|
|
|
48
51
|
| 'TX_HASH'
|
|
49
52
|
| 'PROVING_JOB_ID'
|
|
50
53
|
| 'P2P_ID'
|
|
51
|
-
| 'P2P_REQ_RESP_BATCH_REQUESTS_COUNT'
|
|
52
54
|
| 'TARGET_ADDRESS'
|
|
53
55
|
| 'MANA_USED'
|
|
54
56
|
| 'TOTAL_INSTRUCTIONS'];
|
|
@@ -56,7 +58,9 @@ type BannedMetricAttributeNames = (typeof Attributes)[
|
|
|
56
58
|
/** Global registry of attributes */
|
|
57
59
|
export type AttributesType = Partial<Record<AttributeNames, AttributeValue>>;
|
|
58
60
|
|
|
59
|
-
export type AllowedAttributeNames =
|
|
61
|
+
export type AllowedAttributeNames =
|
|
62
|
+
| Exclude<AttributeNames, BannedMetricAttributeNames>
|
|
63
|
+
| AllowedVendorMetricAttributeNames;
|
|
60
64
|
|
|
61
65
|
/** Subset of attributes allowed to be added to metrics */
|
|
62
66
|
export type MetricAttributesType = Partial<Record<AllowedAttributeNames, AttributeValue>>;
|
package/src/vendor/attributes.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// See https://opentelemetry.io/docs/specs/semconv/rpc/json-rpc/
|
|
2
2
|
export const ATTR_JSONRPC_METHOD = 'rpc.method';
|
|
3
|
+
export const ATTR_JSONRPC_SERVICE = 'rpc.service';
|
|
3
4
|
export const ATTR_JSONRPC_REQUEST_ID = 'rpc.jsonrpc.request_id';
|
|
4
5
|
export const ATTR_JSONRPC_ERROR_CODE = 'rpc.jsonrpc.error_code';
|
|
5
6
|
export const ATTR_JSONRPC_ERROR_MSG = 'rpc.jsonrpc.error_message';
|
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
|
);
|
package/src/wrappers/index.ts
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
import { type SafeJsonRpcServerOptions, createSafeJsonRpcServer } from '@aztec/foundation/json-rpc/server';
|
|
2
2
|
import type { ApiSchemaFor } from '@aztec/stdlib/schemas';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { getOtelJsonRpcServerMetricsMiddleware } from '../json_rpc_server_metrics.js';
|
|
5
|
+
import { getOtelJsonRpcDiagnosticsMiddleware, getOtelJsonRpcPropagationMiddleware } from '../otel_propagation.js';
|
|
5
6
|
|
|
6
7
|
export function createTracedJsonRpcServer<T extends object = any>(
|
|
7
8
|
handler: T,
|
|
8
9
|
schema: ApiSchemaFor<T>,
|
|
9
10
|
options: SafeJsonRpcServerOptions = {},
|
|
10
11
|
) {
|
|
12
|
+
const otelDiagnostics = getOtelJsonRpcDiagnosticsMiddleware();
|
|
13
|
+
const diagnostic = options.diagnostic
|
|
14
|
+
? (ctx: Parameters<typeof otelDiagnostics>[0], next: Parameters<typeof otelDiagnostics>[1]) =>
|
|
15
|
+
options.diagnostic!(ctx, () => otelDiagnostics(ctx, next))
|
|
16
|
+
: otelDiagnostics;
|
|
11
17
|
return createSafeJsonRpcServer(handler, schema, {
|
|
12
18
|
...options,
|
|
13
|
-
|
|
19
|
+
diagnostic,
|
|
20
|
+
middlewares: [
|
|
21
|
+
getOtelJsonRpcServerMetricsMiddleware(),
|
|
22
|
+
...(options.middlewares ?? []),
|
|
23
|
+
getOtelJsonRpcPropagationMiddleware(),
|
|
24
|
+
],
|
|
14
25
|
});
|
|
15
26
|
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import { type L2BlockSource, L2BlockStream, type L2BlockStreamEventHandler, type L2BlockStreamLocalDataProvider } from '@aztec/stdlib/block';
|
|
3
|
-
import { type Traceable, type Tracer } from '@aztec/telemetry-client';
|
|
4
|
-
/** Extends an L2BlockStream with a tracer to create a new trace per iteration. */
|
|
5
|
-
export declare class TraceableL2BlockStream extends L2BlockStream implements Traceable {
|
|
6
|
-
readonly tracer: Tracer;
|
|
7
|
-
private readonly name;
|
|
8
|
-
constructor(l2BlockSource: Pick<L2BlockSource, 'getBlocks' | 'getBlockHeader' | 'getL2Tips' | 'getCheckpoints' | 'getCheckpointedBlocks'>, localData: L2BlockStreamLocalDataProvider, handler: L2BlockStreamEventHandler, tracer: Tracer, name?: string, log?: import("@aztec/foundation/log").Logger, opts?: {
|
|
9
|
-
proven?: boolean;
|
|
10
|
-
pollIntervalMS?: number;
|
|
11
|
-
batchSize?: number;
|
|
12
|
-
startingBlock?: BlockNumber;
|
|
13
|
-
});
|
|
14
|
-
work(): Promise<void>;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibDJfYmxvY2tfc3RyZWFtLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvd3JhcHBlcnMvbDJfYmxvY2tfc3RyZWFtLnRzIl0s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