@aztec/telemetry-client 0.0.1-commit.b655e406 → 0.0.1-commit.b8a057fa

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.
Files changed (87) hide show
  1. package/dest/attributes.d.ts +28 -2
  2. package/dest/attributes.d.ts.map +1 -1
  3. package/dest/attributes.js +14 -1
  4. package/dest/bench.d.ts +3 -1
  5. package/dest/bench.d.ts.map +1 -1
  6. package/dest/bench.js +24 -14
  7. package/dest/config.d.ts +4 -1
  8. package/dest/config.d.ts.map +1 -1
  9. package/dest/config.js +24 -10
  10. package/dest/index.d.ts +1 -1
  11. package/dest/l1_metrics.d.ts +2 -2
  12. package/dest/l1_metrics.d.ts.map +1 -1
  13. package/dest/l1_metrics.js +4 -20
  14. package/dest/lmdb_metrics.d.ts +3 -3
  15. package/dest/lmdb_metrics.d.ts.map +1 -1
  16. package/dest/lmdb_metrics.js +4 -20
  17. package/dest/metric-utils.d.ts +24 -0
  18. package/dest/metric-utils.d.ts.map +1 -0
  19. package/dest/metric-utils.js +59 -0
  20. package/dest/metrics.d.ts +314 -196
  21. package/dest/metrics.d.ts.map +1 -1
  22. package/dest/metrics.js +1607 -194
  23. package/dest/monitored_batch_span_processor.d.ts +29 -0
  24. package/dest/monitored_batch_span_processor.d.ts.map +1 -0
  25. package/dest/monitored_batch_span_processor.js +75 -0
  26. package/dest/nodejs_metrics_monitor.d.ts +3 -5
  27. package/dest/nodejs_metrics_monitor.d.ts.map +1 -1
  28. package/dest/nodejs_metrics_monitor.js +19 -40
  29. package/dest/noop.d.ts +6 -3
  30. package/dest/noop.d.ts.map +1 -1
  31. package/dest/noop.js +32 -1
  32. package/dest/otel.d.ts +10 -3
  33. package/dest/otel.d.ts.map +1 -1
  34. package/dest/otel.js +165 -9
  35. package/dest/otel_filter_metric_exporter.d.ts +1 -1
  36. package/dest/otel_filter_metric_exporter.d.ts.map +1 -1
  37. package/dest/otel_logger_provider.d.ts +1 -1
  38. package/dest/otel_propagation.d.ts +3 -1
  39. package/dest/otel_propagation.d.ts.map +1 -1
  40. package/dest/otel_propagation.js +49 -1
  41. package/dest/otel_resource.d.ts +1 -1
  42. package/dest/otel_resource.d.ts.map +1 -1
  43. package/dest/otel_resource.js +14 -2
  44. package/dest/prom_otel_adapter.d.ts +4 -4
  45. package/dest/prom_otel_adapter.d.ts.map +1 -1
  46. package/dest/prom_otel_adapter.js +19 -10
  47. package/dest/start.d.ts +3 -2
  48. package/dest/start.d.ts.map +1 -1
  49. package/dest/start.js +5 -4
  50. package/dest/telemetry.d.ts +38 -26
  51. package/dest/telemetry.d.ts.map +1 -1
  52. package/dest/telemetry.js +46 -23
  53. package/dest/vendor/attributes.d.ts +1 -1
  54. package/dest/vendor/otel-pino-stream.d.ts +1 -1
  55. package/dest/vendor/otel-pino-stream.d.ts.map +1 -1
  56. package/dest/with_tracer.d.ts +1 -1
  57. package/dest/with_tracer.d.ts.map +1 -1
  58. package/dest/wrappers/fetch.d.ts +3 -3
  59. package/dest/wrappers/fetch.d.ts.map +1 -1
  60. package/dest/wrappers/fetch.js +3 -2
  61. package/dest/wrappers/index.d.ts +1 -2
  62. package/dest/wrappers/index.d.ts.map +1 -1
  63. package/dest/wrappers/index.js +0 -1
  64. package/dest/wrappers/json_rpc_server.d.ts +1 -1
  65. package/package.json +9 -6
  66. package/src/attributes.ts +36 -1
  67. package/src/bench.ts +27 -15
  68. package/src/config.ts +38 -10
  69. package/src/l1_metrics.ts +5 -20
  70. package/src/lmdb_metrics.ts +5 -26
  71. package/src/metric-utils.ts +75 -0
  72. package/src/metrics.ts +1692 -237
  73. package/src/monitored_batch_span_processor.ts +100 -0
  74. package/src/nodejs_metrics_monitor.ts +18 -51
  75. package/src/noop.ts +61 -3
  76. package/src/otel.ts +161 -11
  77. package/src/otel_propagation.ts +42 -1
  78. package/src/otel_resource.ts +19 -2
  79. package/src/prom_otel_adapter.ts +16 -23
  80. package/src/start.ts +14 -5
  81. package/src/telemetry.ts +105 -67
  82. package/src/wrappers/fetch.ts +9 -3
  83. package/src/wrappers/index.ts +0 -1
  84. package/dest/wrappers/l2_block_stream.d.ts +0 -15
  85. package/dest/wrappers/l2_block_stream.d.ts.map +0 -1
  86. package/dest/wrappers/l2_block_stream.js +0 -26
  87. package/src/wrappers/l2_block_stream.ts +0 -37
@@ -1,9 +1,10 @@
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';
5
5
 
6
- import type { Histogram, Meter, MetricsType, ObservableGauge, TelemetryClient } from './telemetry.js';
6
+ import type { MetricDefinition } from './metrics.js';
7
+ import type { Histogram, Meter, ObservableGauge, TelemetryClient } from './telemetry.js';
7
8
 
8
9
  /**
9
10
  * Types matching the gossipsub and libp2p services
@@ -94,9 +95,8 @@ export class OtelGauge<Labels extends LabelsGeneric = NoLabels> implements IGaug
94
95
  help: string,
95
96
  private labelNames: Array<keyof Labels> = [],
96
97
  ) {
97
- this.gauge = meter.createObservableGauge(name as MetricsType, {
98
- description: help,
99
- });
98
+ const metricDef: MetricDefinition = { name, description: help };
99
+ this.gauge = meter.createObservableGauge(metricDef);
100
100
 
101
101
  // Only observe in the callback when collect() is called
102
102
  this.gauge.addCallback(this.handleObservation.bind(this));
@@ -214,8 +214,8 @@ export class OtelHistogram<Labels extends LabelsGeneric = NoLabels> implements I
214
214
  buckets: number[] = [],
215
215
  private labelNames: Array<keyof Labels> = [],
216
216
  ) {
217
- this.histogram = meter.createHistogram(name as MetricsType, {
218
- description: help,
217
+ const metricDef: MetricDefinition = { name, description: help };
218
+ this.histogram = meter.createHistogram(metricDef, {
219
219
  advice: buckets.length ? { explicitBucketBoundaries: buckets } : undefined,
220
220
  });
221
221
  }
@@ -289,15 +289,9 @@ export class OtelAvgMinMax<Labels extends LabelsGeneric = NoLabels> implements I
289
289
  ) {
290
290
  // Create three separate gauges for avg, min, and max
291
291
  this.gauges = {
292
- avg: meter.createObservableGauge(`${name}_avg` as MetricsType, {
293
- description: `${help} (average)`,
294
- }),
295
- min: meter.createObservableGauge(`${name}_min` as MetricsType, {
296
- description: `${help} (minimum)`,
297
- }),
298
- max: meter.createObservableGauge(`${name}_max` as MetricsType, {
299
- description: `${help} (maximum)`,
300
- }),
292
+ avg: meter.createObservableGauge({ name: `${name}_avg`, description: `${help} (average)` }),
293
+ min: meter.createObservableGauge({ name: `${name}_min`, description: `${help} (minimum)` }),
294
+ max: meter.createObservableGauge({ name: `${name}_max`, description: `${help} (maximum)` }),
301
295
  };
302
296
 
303
297
  // Register callbacks for each gauge
@@ -416,12 +410,11 @@ function parseLabelsSafely<Labels extends LabelsGeneric>(labelStr: string, logge
416
410
  */
417
411
  export class OtelMetricsAdapter extends Registry implements MetricsRegister {
418
412
  private readonly meter: Meter;
413
+ private logger: Logger;
419
414
 
420
- constructor(
421
- telemetryClient: TelemetryClient,
422
- private logger: Logger = createLogger('telemetry:otel-metrics-adapter'),
423
- ) {
415
+ constructor(telemetryClient: TelemetryClient, bindings?: LoggerBindings) {
424
416
  super();
417
+ this.logger = createLogger('telemetry:otel-metrics-adapter', bindings);
425
418
  this.meter = telemetryClient.getMeter('metrics-adapter');
426
419
  }
427
420
 
@@ -429,7 +422,7 @@ export class OtelMetricsAdapter extends Registry implements MetricsRegister {
429
422
  return new OtelGauge<Labels>(
430
423
  this.logger,
431
424
  this.meter,
432
- configuration.name as MetricsType,
425
+ configuration.name,
433
426
  configuration.help,
434
427
  configuration.labelNames,
435
428
  );
@@ -439,7 +432,7 @@ export class OtelMetricsAdapter extends Registry implements MetricsRegister {
439
432
  return new OtelHistogram<Labels>(
440
433
  this.logger,
441
434
  this.meter,
442
- configuration.name as MetricsType,
435
+ configuration.name,
443
436
  configuration.help,
444
437
  configuration.buckets,
445
438
  configuration.labelNames,
@@ -450,7 +443,7 @@ export class OtelMetricsAdapter extends Registry implements MetricsRegister {
450
443
  return new OtelAvgMinMax<Labels>(
451
444
  this.logger,
452
445
  this.meter,
453
- configuration.name as MetricsType,
446
+ configuration.name,
454
447
  configuration.help,
455
448
  configuration.labelNames,
456
449
  );
package/src/start.ts CHANGED
@@ -1,8 +1,7 @@
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';
5
- import { OpenTelemetryClient } from './otel.js';
6
5
  import type { TelemetryClient } from './telemetry.js';
7
6
 
8
7
  export * from './config.js';
@@ -10,15 +9,25 @@ export * from './config.js';
10
9
  let initialized = false;
11
10
  let telemetry: TelemetryClient = new NoopTelemetryClient();
12
11
 
13
- export function initTelemetryClient(config: TelemetryClientConfig): TelemetryClient {
14
- const log = createLogger('telemetry:client');
12
+ export async function initTelemetryClient(
13
+ config: TelemetryClientConfig,
14
+ bindings?: LoggerBindings,
15
+ ): Promise<TelemetryClient> {
16
+ const log = createLogger('telemetry:client', bindings);
15
17
  if (initialized) {
16
18
  log.warn('Telemetry client has already been initialized once');
17
19
  return telemetry;
18
20
  }
19
21
 
20
- if (config.metricsCollectorUrl || config.publicMetricsCollectorUrl) {
22
+ if (
23
+ config.metricsCollectorUrl ||
24
+ config.publicMetricsCollectorUrl ||
25
+ config.tracesCollectorUrl ||
26
+ config.logsCollectorUrl
27
+ ) {
21
28
  log.info(`Using OpenTelemetry client with custom collector`);
29
+ // Lazy load OpenTelemetry to avoid loading heavy deps at startup
30
+ const { OpenTelemetryClient } = await import('./otel.js');
22
31
  telemetry = OpenTelemetryClient.createAndStart(config, log);
23
32
  } else {
24
33
  log.info('Using NoopTelemetryClient');
package/src/telemetry.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  type AttributeValue,
3
3
  type BatchObservableCallback,
4
+ type Context,
4
5
  type MetricOptions,
5
6
  type Observable,
6
7
  type BatchObservableResult as OtelBatchObservableResult,
@@ -14,13 +15,14 @@ import {
14
15
  SpanStatusCode,
15
16
  type Tracer,
16
17
  } from '@opentelemetry/api';
17
- import { isPromise } from 'node:util/types';
18
18
 
19
19
  import type * as Attributes from './attributes.js';
20
- import type * as Metrics from './metrics.js';
20
+ import type { MetricDefinition } from './metrics.js';
21
21
  import { getTelemetryClient } from './start.js';
22
22
 
23
- export { type Span, SpanStatusCode, ValueType } from '@opentelemetry/api';
23
+ export { toMetricOptions, createUpDownCounterWithDefault } from './metric-utils.js';
24
+
25
+ export { type Span, SpanStatusCode, ValueType, type Context } from '@opentelemetry/api';
24
26
 
25
27
  type ValuesOf<T> = T extends Record<string, infer U> ? U : never;
26
28
 
@@ -46,7 +48,6 @@ type BannedMetricAttributeNames = (typeof Attributes)[
46
48
  | 'TX_HASH'
47
49
  | 'PROVING_JOB_ID'
48
50
  | 'P2P_ID'
49
- | 'P2P_REQ_RESP_BATCH_REQUESTS_COUNT'
50
51
  | 'TARGET_ADDRESS'
51
52
  | 'MANA_USED'
52
53
  | 'TOTAL_INSTRUCTIONS'];
@@ -54,11 +55,13 @@ type BannedMetricAttributeNames = (typeof Attributes)[
54
55
  /** Global registry of attributes */
55
56
  export type AttributesType = Partial<Record<AttributeNames, AttributeValue>>;
56
57
 
58
+ export type AllowedAttributeNames = Exclude<AttributeNames, BannedMetricAttributeNames>;
59
+
57
60
  /** Subset of attributes allowed to be added to metrics */
58
- export type MetricAttributesType = Partial<Record<Exclude<AttributeNames, BannedMetricAttributeNames>, AttributeValue>>;
61
+ export type MetricAttributesType = Partial<Record<AllowedAttributeNames, AttributeValue>>;
59
62
 
60
- /** Global registry of metrics */
61
- export type MetricsType = (typeof Metrics)[keyof typeof Metrics];
63
+ /** Re-export MetricDefinition for convenience */
64
+ export type { MetricDefinition } from './metrics.js';
62
65
 
63
66
  export type Gauge = OtelGauge<MetricAttributesType>;
64
67
  export type Histogram = OtelHistogram<MetricAttributesType>;
@@ -77,17 +80,15 @@ export type { Tracer };
77
80
  export interface Meter {
78
81
  /**
79
82
  * Creates a new gauge instrument. A gauge is a metric that represents a single numerical value that can arbitrarily go up and down.
80
- * @param name - The name of the gauge
81
- * @param options - The options for the gauge
83
+ * @param metric - The metric definition
82
84
  */
83
- createGauge(name: MetricsType, options?: MetricOptions): Gauge;
85
+ createGauge(metric: MetricDefinition): Gauge;
84
86
 
85
87
  /**
86
- * Creates a new gauge instrument. A gauge is a metric that represents a single numerical value that can arbitrarily go up and down.
87
- * @param name - The name of the gauge
88
- * @param options - The options for the gauge
88
+ * Creates a new observable gauge instrument. A gauge is a metric that represents a single numerical value that can arbitrarily go up and down.
89
+ * @param metric - The metric definition
89
90
  */
90
- createObservableGauge(name: MetricsType, options?: MetricOptions): ObservableGauge;
91
+ createObservableGauge(metric: MetricDefinition): ObservableGauge;
91
92
 
92
93
  addBatchObservableCallback(
93
94
  callback: BatchObservableCallback<AttributesType>,
@@ -101,24 +102,22 @@ export interface Meter {
101
102
 
102
103
  /**
103
104
  * Creates a new histogram instrument. A histogram is a metric that samples observations (usually things like request durations or response sizes) and counts them in configurable buckets.
104
- * @param name - The name of the histogram
105
- * @param options - The options for the histogram
105
+ * @param metric - The metric definition
106
+ * @param extraOptions - Optional extra options (e.g., advice for bucket boundaries)
106
107
  */
107
- createHistogram(name: MetricsType, options?: MetricOptions): Histogram;
108
+ createHistogram(metric: MetricDefinition, extraOptions?: Partial<MetricOptions>): Histogram;
108
109
 
109
110
  /**
110
111
  * Creates a new counter instrument. A counter can go up or down with a delta from the previous value.
111
- * @param name - The name of the counter
112
- * @param options - The options for the counter
112
+ * @param metric - The metric definition
113
113
  */
114
- createUpDownCounter(name: MetricsType, options?: MetricOptions): UpDownCounter;
114
+ createUpDownCounter(metric: MetricDefinition): UpDownCounter;
115
115
 
116
116
  /**
117
- * Creates a new gauge instrument. A gauge is a metric that represents a single numerical value that can arbitrarily go up and down.
118
- * @param name - The name of the gauge
119
- * @param options - The options for the gauge
117
+ * Creates a new observable up/down counter instrument.
118
+ * @param metric - The metric definition
120
119
  */
121
- createObservableUpDownCounter(name: MetricsType, options?: MetricOptions): ObservableUpDownCounter;
120
+ createObservableUpDownCounter(metric: MetricDefinition): ObservableUpDownCounter;
122
121
  }
123
122
 
124
123
  /**
@@ -160,6 +159,17 @@ export interface TelemetryClient {
160
159
  * Updates the roles that would share telemetry (if enabled)
161
160
  */
162
161
  setPublicTelemetryCollectFrom(roles: string[]): void;
162
+
163
+ /**
164
+ * Get current trace context as an opaque string for propagation.
165
+ * Returns the W3C traceparent header value if a trace is active, undefined otherwise.
166
+ */
167
+ getTraceContext(): string | undefined;
168
+
169
+ /**
170
+ * Recreates a context propagated by a remote system
171
+ */
172
+ extractPropagatedContext(traceContext: string): Context | undefined;
163
173
  }
164
174
 
165
175
  /** Objects that adhere to this interface can use @trackSpan */
@@ -204,24 +214,36 @@ export function trackSpan<T extends Traceable, F extends (...args: any[]) => any
204
214
  // "active" means the span will be alive for the duration of the function execution
205
215
  // and if any other spans are started during the execution of originalMethod, they will be children of this span
206
216
  // behind the scenes this uses AsyncLocalStorage https://nodejs.org/dist/latest-v22.x/docs/api/async_context.html
207
- return this.tracer.startActiveSpan(name, async (span: Span) => {
208
- span.setAttributes(currentAttrs ?? {});
209
-
210
- try {
211
- const res = await originalMethod.call(this, ...args);
212
- const extraAttrs = extraAttributes?.call(this, res);
213
- span.setAttributes(extraAttrs ?? {});
214
- return res;
215
- } catch (err) {
216
- span.setStatus({
217
- code: SpanStatusCode.ERROR,
218
- message: String(err),
219
- });
220
- throw err;
221
- } finally {
222
- span.end();
223
- }
224
- });
217
+ return this.tracer.startActiveSpan(
218
+ name,
219
+ {
220
+ attributes: currentAttrs,
221
+ },
222
+ async (span: Span) => {
223
+ try {
224
+ const res = await originalMethod.call(this, ...args);
225
+ const extraAttrs = extraAttributes?.call(this, res);
226
+ span.setAttributes(extraAttrs ?? {});
227
+ span.setStatus({
228
+ code: SpanStatusCode.OK,
229
+ });
230
+ return res;
231
+ } catch (err) {
232
+ span.setStatus({
233
+ code: SpanStatusCode.ERROR,
234
+ message: String(err),
235
+ });
236
+
237
+ if (typeof err === 'string' || (err && err instanceof Error)) {
238
+ span.recordException(err);
239
+ }
240
+
241
+ throw err;
242
+ } finally {
243
+ span.end();
244
+ }
245
+ },
246
+ );
225
247
  } as F;
226
248
  };
227
249
  }
@@ -265,41 +287,57 @@ export function wrapCallbackInSpan<F extends (...args: any[]) => any>(
265
287
  export function runInSpan<A extends any[], R>(
266
288
  tracer: Tracer | string,
267
289
  spanName: string,
268
- callback: (span: Span, ...args: A) => R,
269
- ): (...args: A) => R {
270
- return (...args: A): R => {
290
+ callback: (span: Span, ...args: A) => Promise<R>,
291
+ ): (...args: A) => Promise<R> {
292
+ return (...args: A): Promise<R> => {
271
293
  const actualTracer = typeof tracer === 'string' ? getTelemetryClient().getTracer(tracer) : tracer;
272
- return actualTracer.startActiveSpan(spanName, (span: Span): R => {
273
- let deferSpanEnd = false;
294
+ return actualTracer.startActiveSpan(spanName, async (span: Span): Promise<R> => {
274
295
  try {
275
- const res = callback(span, ...args);
276
- if (isPromise(res)) {
277
- deferSpanEnd = true;
278
- return res
279
- .catch(err => {
280
- span.setStatus({
281
- code: SpanStatusCode.ERROR,
282
- message: String(err),
283
- });
284
- throw err;
285
- })
286
- .finally(() => {
287
- span.end();
288
- }) as R;
289
- } else {
290
- return res;
291
- }
296
+ const res = await callback(span, ...args);
297
+ span.setStatus({
298
+ code: SpanStatusCode.OK,
299
+ });
300
+
301
+ return res;
292
302
  } catch (err) {
293
303
  span.setStatus({
294
304
  code: SpanStatusCode.ERROR,
295
305
  message: String(err),
296
306
  });
307
+ if (typeof err === 'string' || (err && err instanceof Error)) {
308
+ span.recordException(err);
309
+ }
297
310
  throw err;
298
311
  } finally {
299
- if (!deferSpanEnd) {
300
- span.end();
301
- }
312
+ span.end();
302
313
  }
303
314
  });
304
315
  };
305
316
  }
317
+
318
+ /**
319
+ * Execute a callback within a span immediately (for one-off traced calls).
320
+ * Unlike runInSpan which returns a reusable function, this executes right away.
321
+ */
322
+ export function execInSpan<R>(
323
+ tracer: Tracer | string,
324
+ spanName: string,
325
+ callback: (span: Span) => Promise<R>,
326
+ ): Promise<R> {
327
+ const actualTracer = typeof tracer === 'string' ? getTelemetryClient().getTracer(tracer) : tracer;
328
+ return actualTracer.startActiveSpan(spanName, async (span: Span): Promise<R> => {
329
+ try {
330
+ const res = await callback(span);
331
+ span.setStatus({ code: SpanStatusCode.OK });
332
+ return res;
333
+ } catch (err) {
334
+ span.setStatus({ code: SpanStatusCode.ERROR, message: String(err) });
335
+ if (typeof err === 'string' || (err && err instanceof Error)) {
336
+ span.recordException(err);
337
+ }
338
+ throw err;
339
+ } finally {
340
+ span.end();
341
+ }
342
+ });
343
+ }
@@ -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(retries: number[], defaultNoRetry: boolean, fetch = defaultFetch, log?: Logger) {
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
- makeBackoff(retries),
39
+ backoff,
34
40
  log,
35
41
  false,
36
42
  );
@@ -1,3 +1,2 @@
1
- export * from './l2_block_stream.js';
2
1
  export * from './fetch.js';
3
2
  export * from './json_rpc_server.js';
@@ -1,15 +0,0 @@
1
- import { type L2BlockSource, L2BlockStream, type L2BlockStreamEventHandler, type L2BlockStreamLocalDataProvider } from '@aztec/stdlib/block';
2
- import { type Traceable, type Tracer } from '@aztec/telemetry-client';
3
- /** Extends an L2BlockStream with a tracer to create a new trace per iteration. */
4
- export declare class TraceableL2BlockStream extends L2BlockStream implements Traceable {
5
- readonly tracer: Tracer;
6
- private readonly name;
7
- constructor(l2BlockSource: Pick<L2BlockSource, 'getPublishedBlocks' | 'getBlockHeader' | 'getL2Tips'>, localData: L2BlockStreamLocalDataProvider, handler: L2BlockStreamEventHandler, tracer: Tracer, name?: string, log?: import("@aztec/foundation/log").Logger, opts?: {
8
- proven?: boolean;
9
- pollIntervalMS?: number;
10
- batchSize?: number;
11
- startingBlock?: number;
12
- });
13
- work(): Promise<void>;
14
- }
15
- //# sourceMappingURL=l2_block_stream.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"l2_block_stream.d.ts","sourceRoot":"","sources":["../../src/wrappers/l2_block_stream.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,aAAa,EAClB,aAAa,EACb,KAAK,yBAAyB,EAC9B,KAAK,8BAA8B,EACpC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,MAAM,EAAa,MAAM,yBAAyB,CAAC;AAEjF,kFAAkF;AAClF,qBAAa,sBAAuB,SAAQ,aAAc,YAAW,SAAS;aAK1D,MAAM,EAAE,MAAM;IAC9B,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAJrB,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,oBAAoB,GAAG,gBAAgB,GAAG,WAAW,CAAC,EACzF,SAAS,EAAE,8BAA8B,EACzC,OAAO,EAAE,yBAAyB,EAClB,MAAM,EAAE,MAAM,EACb,IAAI,GAAE,MAAwB,EAC/C,GAAG,yCAAqC,EACxC,IAAI,GAAE;QACJ,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,aAAa,CAAC,EAAE,MAAM,CAAC;KACnB;IAUC,IAAI;CAGd"}
@@ -1,26 +0,0 @@
1
- function _ts_decorate(decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- }
7
- import { createLogger } from '@aztec/foundation/log';
8
- import { L2BlockStream } from '@aztec/stdlib/block';
9
- import { trackSpan } from '@aztec/telemetry-client';
10
- /** Extends an L2BlockStream with a tracer to create a new trace per iteration. */ export class TraceableL2BlockStream extends L2BlockStream {
11
- tracer;
12
- name;
13
- constructor(l2BlockSource, localData, handler, tracer, name = 'L2BlockStream', log = createLogger('types:block_stream'), opts = {}){
14
- super(l2BlockSource, localData, handler, log, opts), this.tracer = tracer, this.name = name;
15
- }
16
- // We need to use a non-arrow function to be able to access `this`
17
- // See https://www.typescriptlang.org/docs/handbook/2/functions.html#declaring-this-in-a-function
18
- work() {
19
- return super.work();
20
- }
21
- }
22
- _ts_decorate([
23
- trackSpan(function() {
24
- return `${this.name}.work`;
25
- })
26
- ], TraceableL2BlockStream.prototype, "work", null);
@@ -1,37 +0,0 @@
1
- import { createLogger } from '@aztec/foundation/log';
2
- import {
3
- type L2BlockSource,
4
- L2BlockStream,
5
- type L2BlockStreamEventHandler,
6
- type L2BlockStreamLocalDataProvider,
7
- } from '@aztec/stdlib/block';
8
- import { type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client';
9
-
10
- /** Extends an L2BlockStream with a tracer to create a new trace per iteration. */
11
- export class TraceableL2BlockStream extends L2BlockStream implements Traceable {
12
- constructor(
13
- l2BlockSource: Pick<L2BlockSource, 'getPublishedBlocks' | 'getBlockHeader' | 'getL2Tips'>,
14
- localData: L2BlockStreamLocalDataProvider,
15
- handler: L2BlockStreamEventHandler,
16
- public readonly tracer: Tracer,
17
- private readonly name: string = 'L2BlockStream',
18
- log = createLogger('types:block_stream'),
19
- opts: {
20
- proven?: boolean;
21
- pollIntervalMS?: number;
22
- batchSize?: number;
23
- startingBlock?: number;
24
- } = {},
25
- ) {
26
- super(l2BlockSource, localData, handler, log, opts);
27
- }
28
-
29
- // We need to use a non-arrow function to be able to access `this`
30
- // See https://www.typescriptlang.org/docs/handbook/2/functions.html#declaring-this-in-a-function
31
- @trackSpan(function () {
32
- return `${this!.name}.work`;
33
- })
34
- override work() {
35
- return super.work();
36
- }
37
- }