@aztec/telemetry-client 0.0.0-test.1 → 0.0.1-commit.1142ef1

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 (90) hide show
  1. package/dest/attributes.d.ts +33 -9
  2. package/dest/attributes.d.ts.map +1 -1
  3. package/dest/attributes.js +22 -8
  4. package/dest/bench.d.ts +6 -1
  5. package/dest/bench.d.ts.map +1 -1
  6. package/dest/bench.js +31 -14
  7. package/dest/config.d.ts +7 -2
  8. package/dest/config.d.ts.map +1 -1
  9. package/dest/config.js +29 -1
  10. package/dest/index.d.ts +2 -1
  11. package/dest/index.d.ts.map +1 -1
  12. package/dest/index.js +1 -0
  13. package/dest/l1_metrics.d.ts +17 -0
  14. package/dest/l1_metrics.d.ts.map +1 -0
  15. package/dest/l1_metrics.js +54 -0
  16. package/dest/lmdb_metrics.d.ts +5 -3
  17. package/dest/lmdb_metrics.d.ts.map +1 -1
  18. package/dest/lmdb_metrics.js +7 -15
  19. package/dest/metric-utils.d.ts +5 -0
  20. package/dest/metric-utils.d.ts.map +1 -0
  21. package/dest/metric-utils.js +7 -0
  22. package/dest/metrics.d.ts +247 -122
  23. package/dest/metrics.d.ts.map +1 -1
  24. package/dest/metrics.js +1239 -120
  25. package/dest/nodejs_metrics_monitor.d.ts +19 -0
  26. package/dest/nodejs_metrics_monitor.d.ts.map +1 -0
  27. package/dest/nodejs_metrics_monitor.js +109 -0
  28. package/dest/noop.d.ts +9 -4
  29. package/dest/noop.d.ts.map +1 -1
  30. package/dest/noop.js +34 -1
  31. package/dest/otel.d.ts +13 -7
  32. package/dest/otel.d.ts.map +1 -1
  33. package/dest/otel.js +142 -21
  34. package/dest/otel_filter_metric_exporter.d.ts +12 -4
  35. package/dest/otel_filter_metric_exporter.d.ts.map +1 -1
  36. package/dest/otel_filter_metric_exporter.js +38 -4
  37. package/dest/otel_logger_provider.d.ts +1 -1
  38. package/dest/otel_propagation.d.ts +1 -1
  39. package/dest/otel_resource.d.ts +1 -1
  40. package/dest/otel_resource.d.ts.map +1 -1
  41. package/dest/otel_resource.js +31 -2
  42. package/dest/prom_otel_adapter.d.ts +58 -9
  43. package/dest/prom_otel_adapter.d.ts.map +1 -1
  44. package/dest/prom_otel_adapter.js +153 -45
  45. package/dest/start.d.ts +2 -2
  46. package/dest/start.d.ts.map +1 -1
  47. package/dest/start.js +7 -6
  48. package/dest/telemetry.d.ts +62 -34
  49. package/dest/telemetry.d.ts.map +1 -1
  50. package/dest/telemetry.js +47 -24
  51. package/dest/vendor/attributes.d.ts +1 -1
  52. package/dest/vendor/otel-pino-stream.d.ts +1 -2
  53. package/dest/vendor/otel-pino-stream.d.ts.map +1 -1
  54. package/dest/vendor/otel-pino-stream.js +2 -2
  55. package/dest/with_tracer.d.ts +1 -1
  56. package/dest/with_tracer.d.ts.map +1 -1
  57. package/dest/wrappers/fetch.d.ts +2 -2
  58. package/dest/wrappers/fetch.d.ts.map +1 -1
  59. package/dest/wrappers/fetch.js +7 -5
  60. package/dest/wrappers/index.d.ts +1 -1
  61. package/dest/wrappers/json_rpc_server.d.ts +2 -2
  62. package/dest/wrappers/json_rpc_server.d.ts.map +1 -1
  63. package/dest/wrappers/l2_block_stream.d.ts +4 -3
  64. package/dest/wrappers/l2_block_stream.d.ts.map +1 -1
  65. package/dest/wrappers/l2_block_stream.js +385 -11
  66. package/package.json +21 -15
  67. package/src/attributes.ts +42 -11
  68. package/src/bench.ts +37 -15
  69. package/src/config.ts +54 -2
  70. package/src/index.ts +1 -0
  71. package/src/l1_metrics.ts +65 -0
  72. package/src/lmdb_metrics.ts +24 -24
  73. package/src/metric-utils.ts +12 -0
  74. package/src/metrics.ts +1313 -145
  75. package/src/nodejs_metrics_monitor.ts +132 -0
  76. package/src/noop.ts +65 -4
  77. package/src/otel.ts +155 -26
  78. package/src/otel_filter_metric_exporter.ts +47 -5
  79. package/src/otel_resource.ts +40 -2
  80. package/src/prom_otel_adapter.ts +191 -65
  81. package/src/start.ts +7 -6
  82. package/src/telemetry.ts +151 -76
  83. package/src/vendor/otel-pino-stream.ts +1 -4
  84. package/src/wrappers/fetch.ts +24 -31
  85. package/src/wrappers/json_rpc_server.ts +1 -1
  86. package/src/wrappers/l2_block_stream.ts +6 -2
  87. package/dest/event_loop_monitor.d.ts +0 -18
  88. package/dest/event_loop_monitor.d.ts.map +0 -1
  89. package/dest/event_loop_monitor.js +0 -93
  90. package/src/event_loop_monitor.ts +0 -119
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,31 +15,60 @@ 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 } 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
 
29
+ type AttributeNames = ValuesOf<typeof Attributes>;
30
+
31
+ /**
32
+ * This is a set of attributes that could lead to high cardinality in the metrics.
33
+ * If you find yourself wanting to capture this data in a metric consider if it makes sense to capture
34
+ * as the metric value instead of an attribute or consider logging instead.
35
+ *
36
+ * Think twice before removing an attribute from this list.
37
+ */
38
+ type BannedMetricAttributeNames = (typeof Attributes)[
39
+ | 'BLOCK_NUMBER'
40
+ | 'BLOCK_ARCHIVE'
41
+ | 'SLOT_NUMBER'
42
+ | 'BLOCK_PARENT'
43
+ | 'BLOCK_CANDIDATE_TXS_COUNT'
44
+ | 'BLOCK_TXS_COUNT'
45
+ | 'BLOCK_SIZE'
46
+ | 'EPOCH_SIZE'
47
+ | 'EPOCH_NUMBER'
48
+ | 'TX_HASH'
49
+ | 'PROVING_JOB_ID'
50
+ | 'P2P_ID'
51
+ | 'P2P_REQ_RESP_BATCH_REQUESTS_COUNT'
52
+ | 'TARGET_ADDRESS'
53
+ | 'MANA_USED'
54
+ | 'TOTAL_INSTRUCTIONS'];
55
+
27
56
  /** Global registry of attributes */
28
- type AttributesType = Partial<Record<ValuesOf<typeof Attributes>, AttributeValue>>;
29
- export type { AttributesType };
57
+ export type AttributesType = Partial<Record<AttributeNames, AttributeValue>>;
30
58
 
31
- /** Global registry of metrics */
32
- type MetricsType = (typeof Metrics)[keyof typeof Metrics];
33
- export type { MetricsType };
59
+ /** Subset of attributes allowed to be added to metrics */
60
+ export type MetricAttributesType = Partial<Record<Exclude<AttributeNames, BannedMetricAttributeNames>, AttributeValue>>;
34
61
 
35
- export type Gauge = OtelGauge<AttributesType>;
36
- export type Histogram = OtelHistogram<AttributesType>;
37
- export type UpDownCounter = OtelUpDownCounter<AttributesType>;
38
- export type ObservableGauge = OtelObservableGauge<AttributesType>;
39
- export type ObservableUpDownCounter = OtelObservableUpDownCounter<AttributesType>;
40
- export type ObservableResult = OtelObservableResult<AttributesType>;
41
- export type BatchObservableResult = OtelBatchObservableResult<AttributesType>;
62
+ /** Re-export MetricDefinition for convenience */
63
+ export type { MetricDefinition } from './metrics.js';
64
+
65
+ export type Gauge = OtelGauge<MetricAttributesType>;
66
+ export type Histogram = OtelHistogram<MetricAttributesType>;
67
+ export type UpDownCounter = OtelUpDownCounter<MetricAttributesType>;
68
+ export type ObservableGauge = OtelObservableGauge<MetricAttributesType>;
69
+ export type ObservableUpDownCounter = OtelObservableUpDownCounter<MetricAttributesType>;
70
+ export type ObservableResult = OtelObservableResult<MetricAttributesType>;
71
+ export type BatchObservableResult = OtelBatchObservableResult<MetricAttributesType>;
42
72
 
43
73
  export type { Tracer };
44
74
 
@@ -49,17 +79,15 @@ export type { Tracer };
49
79
  export interface Meter {
50
80
  /**
51
81
  * Creates a new gauge instrument. A gauge is a metric that represents a single numerical value that can arbitrarily go up and down.
52
- * @param name - The name of the gauge
53
- * @param options - The options for the gauge
82
+ * @param metric - The metric definition
54
83
  */
55
- createGauge(name: MetricsType, options?: MetricOptions): Gauge;
84
+ createGauge(metric: MetricDefinition): Gauge;
56
85
 
57
86
  /**
58
- * Creates a new gauge instrument. A gauge is a metric that represents a single numerical value that can arbitrarily go up and down.
59
- * @param name - The name of the gauge
60
- * @param options - The options for the gauge
87
+ * Creates a new observable gauge instrument. A gauge is a metric that represents a single numerical value that can arbitrarily go up and down.
88
+ * @param metric - The metric definition
61
89
  */
62
- createObservableGauge(name: MetricsType, options?: MetricOptions): ObservableGauge;
90
+ createObservableGauge(metric: MetricDefinition): ObservableGauge;
63
91
 
64
92
  addBatchObservableCallback(
65
93
  callback: BatchObservableCallback<AttributesType>,
@@ -73,24 +101,22 @@ export interface Meter {
73
101
 
74
102
  /**
75
103
  * 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.
76
- * @param name - The name of the histogram
77
- * @param options - The options for the histogram
104
+ * @param metric - The metric definition
105
+ * @param extraOptions - Optional extra options (e.g., advice for bucket boundaries)
78
106
  */
79
- createHistogram(name: MetricsType, options?: MetricOptions): Histogram;
107
+ createHistogram(metric: MetricDefinition, extraOptions?: Partial<MetricOptions>): Histogram;
80
108
 
81
109
  /**
82
110
  * Creates a new counter instrument. A counter can go up or down with a delta from the previous value.
83
- * @param name - The name of the counter
84
- * @param options - The options for the counter
111
+ * @param metric - The metric definition
85
112
  */
86
- createUpDownCounter(name: MetricsType, options?: MetricOptions): UpDownCounter;
113
+ createUpDownCounter(metric: MetricDefinition): UpDownCounter;
87
114
 
88
115
  /**
89
- * Creates a new gauge instrument. A gauge is a metric that represents a single numerical value that can arbitrarily go up and down.
90
- * @param name - The name of the gauge
91
- * @param options - The options for the gauge
116
+ * Creates a new observable up/down counter instrument.
117
+ * @param metric - The metric definition
92
118
  */
93
- createObservableUpDownCounter(name: MetricsType, options?: MetricOptions): ObservableUpDownCounter;
119
+ createObservableUpDownCounter(metric: MetricDefinition): ObservableUpDownCounter;
94
120
  }
95
121
 
96
122
  /**
@@ -122,6 +148,27 @@ export interface TelemetryClient {
122
148
  * Flushes the telemetry client.
123
149
  */
124
150
  flush(): Promise<void>;
151
+
152
+ /**
153
+ * Updates what telemetry is exported to the public collector
154
+ */
155
+ setExportedPublicTelemetry(prefixes: string[]): void;
156
+
157
+ /**
158
+ * Updates the roles that would share telemetry (if enabled)
159
+ */
160
+ setPublicTelemetryCollectFrom(roles: string[]): void;
161
+
162
+ /**
163
+ * Get current trace context as an opaque string for propagation.
164
+ * Returns the W3C traceparent header value if a trace is active, undefined otherwise.
165
+ */
166
+ getTraceContext(): string | undefined;
167
+
168
+ /**
169
+ * Recreates a context propagated by a remote system
170
+ */
171
+ extractPropagatedContext(traceContext: string): Context | undefined;
125
172
  }
126
173
 
127
174
  /** Objects that adhere to this interface can use @trackSpan */
@@ -165,25 +212,37 @@ export function trackSpan<T extends Traceable, F extends (...args: any[]) => any
165
212
  // run originalMethod wrapped in an active span
166
213
  // "active" means the span will be alive for the duration of the function execution
167
214
  // and if any other spans are started during the execution of originalMethod, they will be children of this span
168
- // behind the scenes this uses AsyncLocalStorage https://nodejs.org/dist/latest-v18.x/docs/api/async_context.html
169
- return this.tracer.startActiveSpan(name, async (span: Span) => {
170
- span.setAttributes(currentAttrs ?? {});
171
-
172
- try {
173
- const res = await originalMethod.call(this, ...args);
174
- const extraAttrs = extraAttributes?.call(this, res);
175
- span.setAttributes(extraAttrs ?? {});
176
- return res;
177
- } catch (err) {
178
- span.setStatus({
179
- code: SpanStatusCode.ERROR,
180
- message: String(err),
181
- });
182
- throw err;
183
- } finally {
184
- span.end();
185
- }
186
- });
215
+ // behind the scenes this uses AsyncLocalStorage https://nodejs.org/dist/latest-v22.x/docs/api/async_context.html
216
+ return this.tracer.startActiveSpan(
217
+ name,
218
+ {
219
+ attributes: currentAttrs,
220
+ },
221
+ async (span: Span) => {
222
+ try {
223
+ const res = await originalMethod.call(this, ...args);
224
+ const extraAttrs = extraAttributes?.call(this, res);
225
+ span.setAttributes(extraAttrs ?? {});
226
+ span.setStatus({
227
+ code: SpanStatusCode.OK,
228
+ });
229
+ return res;
230
+ } catch (err) {
231
+ span.setStatus({
232
+ code: SpanStatusCode.ERROR,
233
+ message: String(err),
234
+ });
235
+
236
+ if (typeof err === 'string' || (err && err instanceof Error)) {
237
+ span.recordException(err);
238
+ }
239
+
240
+ throw err;
241
+ } finally {
242
+ span.end();
243
+ }
244
+ },
245
+ );
187
246
  } as F;
188
247
  };
189
248
  }
@@ -227,41 +286,57 @@ export function wrapCallbackInSpan<F extends (...args: any[]) => any>(
227
286
  export function runInSpan<A extends any[], R>(
228
287
  tracer: Tracer | string,
229
288
  spanName: string,
230
- callback: (span: Span, ...args: A) => R,
231
- ): (...args: A) => R {
232
- return (...args: A): R => {
289
+ callback: (span: Span, ...args: A) => Promise<R>,
290
+ ): (...args: A) => Promise<R> {
291
+ return (...args: A): Promise<R> => {
233
292
  const actualTracer = typeof tracer === 'string' ? getTelemetryClient().getTracer(tracer) : tracer;
234
- return actualTracer.startActiveSpan(spanName, (span: Span): R => {
235
- let deferSpanEnd = false;
293
+ return actualTracer.startActiveSpan(spanName, async (span: Span): Promise<R> => {
236
294
  try {
237
- const res = callback(span, ...args);
238
- if (isPromise(res)) {
239
- deferSpanEnd = true;
240
- return res
241
- .catch(err => {
242
- span.setStatus({
243
- code: SpanStatusCode.ERROR,
244
- message: String(err),
245
- });
246
- throw err;
247
- })
248
- .finally(() => {
249
- span.end();
250
- }) as R;
251
- } else {
252
- return res;
253
- }
295
+ const res = await callback(span, ...args);
296
+ span.setStatus({
297
+ code: SpanStatusCode.OK,
298
+ });
299
+
300
+ return res;
254
301
  } catch (err) {
255
302
  span.setStatus({
256
303
  code: SpanStatusCode.ERROR,
257
304
  message: String(err),
258
305
  });
306
+ if (typeof err === 'string' || (err && err instanceof Error)) {
307
+ span.recordException(err);
308
+ }
259
309
  throw err;
260
310
  } finally {
261
- if (!deferSpanEnd) {
262
- span.end();
263
- }
311
+ span.end();
264
312
  }
265
313
  });
266
314
  };
267
315
  }
316
+
317
+ /**
318
+ * Execute a callback within a span immediately (for one-off traced calls).
319
+ * Unlike runInSpan which returns a reusable function, this executes right away.
320
+ */
321
+ export function execInSpan<R>(
322
+ tracer: Tracer | string,
323
+ spanName: string,
324
+ callback: (span: Span) => Promise<R>,
325
+ ): Promise<R> {
326
+ const actualTracer = typeof tracer === 'string' ? getTelemetryClient().getTracer(tracer) : tracer;
327
+ return actualTracer.startActiveSpan(spanName, async (span: Span): Promise<R> => {
328
+ try {
329
+ const res = await callback(span);
330
+ span.setStatus({ code: SpanStatusCode.OK });
331
+ return res;
332
+ } catch (err) {
333
+ span.setStatus({ code: SpanStatusCode.ERROR, message: String(err) });
334
+ if (typeof err === 'string' || (err && err instanceof Error)) {
335
+ span.recordException(err);
336
+ }
337
+ throw err;
338
+ } finally {
339
+ span.end();
340
+ }
341
+ });
342
+ }
@@ -23,9 +23,6 @@ import { Writable } from 'stream';
23
23
  import { registerOtelLoggerProvider } from '../otel_logger_provider.js';
24
24
  import { getOtelResource } from '../otel_resource.js';
25
25
 
26
- /* eslint-disable @typescript-eslint/ban-types */
27
- /* eslint-disable camelcase */
28
-
29
26
  // This block is a copy (modulo code style and TypeScript types) of the Pino
30
27
  // code that defines log level value and names. This file is part of
31
28
  // *instrumenting* Pino, so we want to avoid a dependency on the library.
@@ -173,7 +170,7 @@ export class OTelPinoStream extends Writable {
173
170
  return;
174
171
  }
175
172
 
176
- // Parse, and handle edge cases similar to how `pino-abtract-transport` does:
173
+ // Parse, and handle edge cases similar to how `pino-abstract-transport` does:
177
174
  // https://github.com/pinojs/pino-abstract-transport/blob/v1.2.0/index.js#L28-L45
178
175
  // - Emitting an 'unknown' event on parse error mimicks pino-abstract-transport.
179
176
  let recObj;
@@ -15,38 +15,31 @@ import { ATTR_JSONRPC_METHOD, ATTR_JSONRPC_REQUEST_ID } from '../vendor/attribut
15
15
  * @returns A fetch function.
16
16
  */
17
17
  export function makeTracedFetch(retries: number[], defaultNoRetry: boolean, fetch = defaultFetch, log?: Logger) {
18
- return (
19
- host: string,
20
- rpcMethod: string,
21
- body: any,
22
- useApiEndpoints: boolean,
23
- extraHeaders: Record<string, string> = {},
24
- noRetry?: boolean,
25
- ) => {
18
+ return (host: string, body: unknown, extraHeaders: Record<string, string> = {}, noRetry?: boolean) => {
26
19
  const telemetry = getTelemetryClient();
27
- return telemetry
28
- .getTracer('fetch')
29
- .startActiveSpan(`JsonRpcClient.${rpcMethod}`, { kind: SpanKind.CLIENT }, async span => {
30
- try {
31
- if (body && typeof body.id === 'number') {
32
- span.setAttribute(ATTR_JSONRPC_REQUEST_ID, body.id);
33
- }
34
- span.setAttribute(ATTR_JSONRPC_METHOD, rpcMethod);
35
- const headers = { ...extraHeaders };
36
- propagation.inject(context.active(), headers);
37
- return await retry(
38
- () => fetch(host, rpcMethod, body, useApiEndpoints, headers, noRetry ?? defaultNoRetry),
39
- `JsonRpcClient request ${rpcMethod} to ${host}`,
40
- makeBackoff(retries),
41
- log,
42
- false,
43
- );
44
- } catch (err: any) {
45
- span.setStatus({ code: SpanStatusCode.ERROR, message: err?.message ?? String(err) });
46
- throw err;
47
- } finally {
48
- span.end();
20
+ return telemetry.getTracer('fetch').startActiveSpan(`JsonRpcClient`, { kind: SpanKind.CLIENT }, async span => {
21
+ try {
22
+ if (body && typeof body === 'object' && 'id' in body && typeof body.id === 'number') {
23
+ span.setAttribute(ATTR_JSONRPC_REQUEST_ID, body.id);
49
24
  }
50
- });
25
+ if (body && typeof body === 'object' && 'method' in body && typeof body.method === 'string') {
26
+ span.setAttribute(ATTR_JSONRPC_METHOD, body.method);
27
+ }
28
+ const headers = { ...extraHeaders };
29
+ propagation.inject(context.active(), headers);
30
+ return await retry(
31
+ () => fetch(host, body, headers, noRetry ?? defaultNoRetry),
32
+ `JsonRpcClient request to ${host}`,
33
+ makeBackoff(retries),
34
+ log,
35
+ false,
36
+ );
37
+ } catch (err: any) {
38
+ span.setStatus({ code: SpanStatusCode.ERROR, message: err?.message ?? String(err) });
39
+ throw err;
40
+ } finally {
41
+ span.end();
42
+ }
43
+ });
51
44
  };
52
45
  }
@@ -6,7 +6,7 @@ import { getOtelJsonRpcPropagationMiddleware } from '../otel_propagation.js';
6
6
  export function createTracedJsonRpcServer<T extends object = any>(
7
7
  handler: T,
8
8
  schema: ApiSchemaFor<T>,
9
- options: Partial<SafeJsonRpcServerOptions> = {},
9
+ options: SafeJsonRpcServerOptions = {},
10
10
  ) {
11
11
  return createSafeJsonRpcServer(handler, schema, {
12
12
  ...options,
@@ -1,3 +1,4 @@
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
1
2
  import { createLogger } from '@aztec/foundation/log';
2
3
  import {
3
4
  type L2BlockSource,
@@ -10,7 +11,10 @@ import { type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client'
10
11
  /** Extends an L2BlockStream with a tracer to create a new trace per iteration. */
11
12
  export class TraceableL2BlockStream extends L2BlockStream implements Traceable {
12
13
  constructor(
13
- l2BlockSource: Pick<L2BlockSource, 'getBlocks' | 'getBlockHeader' | 'getL2Tips'>,
14
+ l2BlockSource: Pick<
15
+ L2BlockSource,
16
+ 'getL2BlocksNew' | 'getBlockHeader' | 'getL2Tips' | 'getPublishedCheckpoints' | 'getCheckpointedBlocks'
17
+ >,
14
18
  localData: L2BlockStreamLocalDataProvider,
15
19
  handler: L2BlockStreamEventHandler,
16
20
  public readonly tracer: Tracer,
@@ -20,7 +24,7 @@ export class TraceableL2BlockStream extends L2BlockStream implements Traceable {
20
24
  proven?: boolean;
21
25
  pollIntervalMS?: number;
22
26
  batchSize?: number;
23
- startingBlock?: number;
27
+ startingBlock?: BlockNumber;
24
28
  } = {},
25
29
  ) {
26
30
  super(l2BlockSource, localData, handler, log, opts);
@@ -1,18 +0,0 @@
1
- import { type Meter } from './telemetry.js';
2
- /**
3
- * Detector for custom Aztec attributes
4
- */
5
- export declare class EventLoopMonitor {
6
- private meter;
7
- private eventLoopDelayGauges;
8
- private eventLoopUilization;
9
- private eventLoopTime;
10
- private started;
11
- private lastELU;
12
- private eventLoopDelay;
13
- constructor(meter: Meter);
14
- start(): void;
15
- stop(): void;
16
- private measure;
17
- }
18
- //# sourceMappingURL=event_loop_monitor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"event_loop_monitor.d.ts","sourceRoot":"","sources":["../src/event_loop_monitor.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,KAAK,EAIX,MAAM,gBAAgB,CAAC;AAExB;;GAEG;AACH,qBAAa,gBAAgB;IAmBf,OAAO,CAAC,KAAK;IAlBzB,OAAO,CAAC,oBAAoB,CAQ1B;IAEF,OAAO,CAAC,mBAAmB,CAAkB;IAC7C,OAAO,CAAC,aAAa,CAAgB;IAErC,OAAO,CAAC,OAAO,CAAS;IAExB,OAAO,CAAC,OAAO,CAAmC;IAClD,OAAO,CAAC,cAAc,CAAoB;gBAEtB,KAAK,EAAE,KAAK;IAgChC,KAAK,IAAI,IAAI;IAab,IAAI,IAAI,IAAI;IAaZ,OAAO,CAAC,OAAO,CAyBb;CACH"}
@@ -1,93 +0,0 @@
1
- import { monitorEventLoopDelay, performance } from 'node:perf_hooks';
2
- import * as Attributes from './attributes.js';
3
- import * as Metrics from './metrics.js';
4
- import { ValueType } from './telemetry.js';
5
- /**
6
- * Detector for custom Aztec attributes
7
- */ export class EventLoopMonitor {
8
- meter;
9
- eventLoopDelayGauges;
10
- eventLoopUilization;
11
- eventLoopTime;
12
- started;
13
- lastELU;
14
- eventLoopDelay;
15
- constructor(meter){
16
- this.meter = meter;
17
- this.started = false;
18
- this.measure = (obs)=>{
19
- const newELU = performance.eventLoopUtilization();
20
- const delta = performance.eventLoopUtilization(newELU, this.lastELU);
21
- this.lastELU = newELU;
22
- // `utilization` [0,1] represents how much the event loop is busy vs waiting for new events to come in
23
- // This should be corelated with CPU usage to gauge the performance characteristics of services
24
- // 100% utilization leads to high latency because the event loop is _always_ busy, there's no breathing room for events to be processed quickly.
25
- // Docs and examples:
26
- // - https://nodesource.com/blog/event-loop-utilization-nodejs
27
- // - https://youtu.be/WetXnEPraYM
28
- obs.observe(this.eventLoopUilization, delta.utilization);
29
- this.eventLoopTime.add(Math.floor(delta.idle), {
30
- [Attributes.NODEJS_EVENT_LOOP_STATE]: 'idle'
31
- });
32
- this.eventLoopTime.add(Math.floor(delta.active), {
33
- [Attributes.NODEJS_EVENT_LOOP_STATE]: 'active'
34
- });
35
- obs.observe(this.eventLoopDelayGauges.min, Math.floor(this.eventLoopDelay.min));
36
- obs.observe(this.eventLoopDelayGauges.mean, Math.floor(this.eventLoopDelay.mean));
37
- obs.observe(this.eventLoopDelayGauges.max, Math.floor(this.eventLoopDelay.max));
38
- obs.observe(this.eventLoopDelayGauges.stddev, Math.floor(this.eventLoopDelay.stddev));
39
- obs.observe(this.eventLoopDelayGauges.p50, Math.floor(this.eventLoopDelay.percentile(50)));
40
- obs.observe(this.eventLoopDelayGauges.p90, Math.floor(this.eventLoopDelay.percentile(90)));
41
- obs.observe(this.eventLoopDelayGauges.p99, Math.floor(this.eventLoopDelay.percentile(99)));
42
- this.eventLoopDelay.reset();
43
- };
44
- const nsObsGauge = (name, description)=>meter.createObservableGauge(name, {
45
- unit: 'ns',
46
- valueType: ValueType.INT,
47
- description
48
- });
49
- this.eventLoopDelayGauges = {
50
- min: nsObsGauge(Metrics.NODEJS_EVENT_LOOP_DELAY_MIN, 'Minimum delay of the event loop'),
51
- mean: nsObsGauge(Metrics.NODEJS_EVENT_LOOP_DELAY_MEAN, 'Mean delay of the event loop'),
52
- max: nsObsGauge(Metrics.NODEJS_EVENT_LOOP_DELAY_MAX, 'Max delay of the event loop'),
53
- stddev: nsObsGauge(Metrics.NODEJS_EVENT_LOOP_DELAY_STDDEV, 'Stddev delay of the event loop'),
54
- p50: nsObsGauge(Metrics.NODEJS_EVENT_LOOP_DELAY_P50, 'P50 delay of the event loop'),
55
- p90: nsObsGauge(Metrics.NODEJS_EVENT_LOOP_DELAY_P90, 'P90 delay of the event loop'),
56
- p99: nsObsGauge(Metrics.NODEJS_EVENT_LOOP_DELAY_P99, 'P99 delay of the event loop')
57
- };
58
- this.eventLoopUilization = meter.createObservableGauge(Metrics.NODEJS_EVENT_LOOP_UTILIZATION, {
59
- valueType: ValueType.DOUBLE,
60
- description: 'How busy is the event loop'
61
- });
62
- this.eventLoopTime = meter.createUpDownCounter(Metrics.NODEJS_EVENT_LOOP_TIME, {
63
- unit: 'ms',
64
- valueType: ValueType.INT,
65
- description: 'How much time the event loop has spent in a given state'
66
- });
67
- this.eventLoopDelay = monitorEventLoopDelay();
68
- }
69
- start() {
70
- if (this.started) {
71
- return;
72
- }
73
- this.lastELU = performance.eventLoopUtilization();
74
- this.eventLoopDelay.enable();
75
- this.meter.addBatchObservableCallback(this.measure, [
76
- this.eventLoopUilization,
77
- ...Object.values(this.eventLoopDelayGauges)
78
- ]);
79
- }
80
- stop() {
81
- if (!this.started) {
82
- return;
83
- }
84
- this.meter.removeBatchObservableCallback(this.measure, [
85
- this.eventLoopUilization,
86
- ...Object.values(this.eventLoopDelayGauges)
87
- ]);
88
- this.eventLoopDelay.disable();
89
- this.eventLoopDelay.reset();
90
- this.lastELU = undefined;
91
- }
92
- measure;
93
- }
@@ -1,119 +0,0 @@
1
- import { type EventLoopUtilization, type IntervalHistogram, monitorEventLoopDelay, performance } from 'node:perf_hooks';
2
-
3
- import * as Attributes from './attributes.js';
4
- import * as Metrics from './metrics.js';
5
- import {
6
- type BatchObservableResult,
7
- type Meter,
8
- type ObservableGauge,
9
- type UpDownCounter,
10
- ValueType,
11
- } from './telemetry.js';
12
-
13
- /**
14
- * Detector for custom Aztec attributes
15
- */
16
- export class EventLoopMonitor {
17
- private eventLoopDelayGauges: {
18
- min: ObservableGauge;
19
- max: ObservableGauge;
20
- mean: ObservableGauge;
21
- stddev: ObservableGauge;
22
- p50: ObservableGauge;
23
- p90: ObservableGauge;
24
- p99: ObservableGauge;
25
- };
26
-
27
- private eventLoopUilization: ObservableGauge;
28
- private eventLoopTime: UpDownCounter;
29
-
30
- private started = false;
31
-
32
- private lastELU: EventLoopUtilization | undefined;
33
- private eventLoopDelay: IntervalHistogram;
34
-
35
- constructor(private meter: Meter) {
36
- const nsObsGauge = (name: (typeof Metrics)[keyof typeof Metrics], description: string) =>
37
- meter.createObservableGauge(name, {
38
- unit: 'ns',
39
- valueType: ValueType.INT,
40
- description,
41
- });
42
-
43
- this.eventLoopDelayGauges = {
44
- min: nsObsGauge(Metrics.NODEJS_EVENT_LOOP_DELAY_MIN, 'Minimum delay of the event loop'),
45
- mean: nsObsGauge(Metrics.NODEJS_EVENT_LOOP_DELAY_MEAN, 'Mean delay of the event loop'),
46
- max: nsObsGauge(Metrics.NODEJS_EVENT_LOOP_DELAY_MAX, 'Max delay of the event loop'),
47
- stddev: nsObsGauge(Metrics.NODEJS_EVENT_LOOP_DELAY_STDDEV, 'Stddev delay of the event loop'),
48
- p50: nsObsGauge(Metrics.NODEJS_EVENT_LOOP_DELAY_P50, 'P50 delay of the event loop'),
49
- p90: nsObsGauge(Metrics.NODEJS_EVENT_LOOP_DELAY_P90, 'P90 delay of the event loop'),
50
- p99: nsObsGauge(Metrics.NODEJS_EVENT_LOOP_DELAY_P99, 'P99 delay of the event loop'),
51
- };
52
-
53
- this.eventLoopUilization = meter.createObservableGauge(Metrics.NODEJS_EVENT_LOOP_UTILIZATION, {
54
- valueType: ValueType.DOUBLE,
55
- description: 'How busy is the event loop',
56
- });
57
-
58
- this.eventLoopTime = meter.createUpDownCounter(Metrics.NODEJS_EVENT_LOOP_TIME, {
59
- unit: 'ms',
60
- valueType: ValueType.INT,
61
- description: 'How much time the event loop has spent in a given state',
62
- });
63
-
64
- this.eventLoopDelay = monitorEventLoopDelay();
65
- }
66
-
67
- start(): void {
68
- if (this.started) {
69
- return;
70
- }
71
-
72
- this.lastELU = performance.eventLoopUtilization();
73
- this.eventLoopDelay.enable();
74
- this.meter.addBatchObservableCallback(this.measure, [
75
- this.eventLoopUilization,
76
- ...Object.values(this.eventLoopDelayGauges),
77
- ]);
78
- }
79
-
80
- stop(): void {
81
- if (!this.started) {
82
- return;
83
- }
84
- this.meter.removeBatchObservableCallback(this.measure, [
85
- this.eventLoopUilization,
86
- ...Object.values(this.eventLoopDelayGauges),
87
- ]);
88
- this.eventLoopDelay.disable();
89
- this.eventLoopDelay.reset();
90
- this.lastELU = undefined;
91
- }
92
-
93
- private measure = (obs: BatchObservableResult): void => {
94
- const newELU = performance.eventLoopUtilization();
95
- const delta = performance.eventLoopUtilization(newELU, this.lastELU);
96
- this.lastELU = newELU;
97
-
98
- // `utilization` [0,1] represents how much the event loop is busy vs waiting for new events to come in
99
- // This should be corelated with CPU usage to gauge the performance characteristics of services
100
- // 100% utilization leads to high latency because the event loop is _always_ busy, there's no breathing room for events to be processed quickly.
101
- // Docs and examples:
102
- // - https://nodesource.com/blog/event-loop-utilization-nodejs
103
- // - https://youtu.be/WetXnEPraYM
104
- obs.observe(this.eventLoopUilization, delta.utilization);
105
-
106
- this.eventLoopTime.add(Math.floor(delta.idle), { [Attributes.NODEJS_EVENT_LOOP_STATE]: 'idle' });
107
- this.eventLoopTime.add(Math.floor(delta.active), { [Attributes.NODEJS_EVENT_LOOP_STATE]: 'active' });
108
-
109
- obs.observe(this.eventLoopDelayGauges.min, Math.floor(this.eventLoopDelay.min));
110
- obs.observe(this.eventLoopDelayGauges.mean, Math.floor(this.eventLoopDelay.mean));
111
- obs.observe(this.eventLoopDelayGauges.max, Math.floor(this.eventLoopDelay.max));
112
- obs.observe(this.eventLoopDelayGauges.stddev, Math.floor(this.eventLoopDelay.stddev));
113
- obs.observe(this.eventLoopDelayGauges.p50, Math.floor(this.eventLoopDelay.percentile(50)));
114
- obs.observe(this.eventLoopDelayGauges.p90, Math.floor(this.eventLoopDelay.percentile(90)));
115
- obs.observe(this.eventLoopDelayGauges.p99, Math.floor(this.eventLoopDelay.percentile(99)));
116
-
117
- this.eventLoopDelay.reset();
118
- };
119
- }