@aztec-labs/telemetry-client 6.0.0-nightly.20260829

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 (105) hide show
  1. package/dest/attributes.d.ts +143 -0
  2. package/dest/attributes.d.ts.map +1 -0
  3. package/dest/attributes.js +91 -0
  4. package/dest/bench.d.ts +34 -0
  5. package/dest/bench.d.ts.map +1 -0
  6. package/dest/bench.js +115 -0
  7. package/dest/config.d.ts +21 -0
  8. package/dest/config.d.ts.map +1 -0
  9. package/dest/config.js +85 -0
  10. package/dest/index.d.ts +12 -0
  11. package/dest/index.d.ts.map +1 -0
  12. package/dest/index.js +11 -0
  13. package/dest/json_rpc_server_metrics.d.ts +27 -0
  14. package/dest/json_rpc_server_metrics.d.ts.map +1 -0
  15. package/dest/json_rpc_server_metrics.js +154 -0
  16. package/dest/l1_metrics.d.ts +17 -0
  17. package/dest/l1_metrics.d.ts.map +1 -0
  18. package/dest/l1_metrics.js +54 -0
  19. package/dest/lmdb_metrics.d.ts +18 -0
  20. package/dest/lmdb_metrics.d.ts.map +1 -0
  21. package/dest/lmdb_metrics.js +34 -0
  22. package/dest/metric-utils.d.ts +24 -0
  23. package/dest/metric-utils.d.ts.map +1 -0
  24. package/dest/metric-utils.js +59 -0
  25. package/dest/metrics.d.ts +338 -0
  26. package/dest/metrics.d.ts.map +1 -0
  27. package/dest/metrics.js +1702 -0
  28. package/dest/monitored_batch_span_processor.d.ts +33 -0
  29. package/dest/monitored_batch_span_processor.d.ts.map +1 -0
  30. package/dest/monitored_batch_span_processor.js +111 -0
  31. package/dest/nodejs_metrics_monitor.d.ts +19 -0
  32. package/dest/nodejs_metrics_monitor.d.ts.map +1 -0
  33. package/dest/nodejs_metrics_monitor.js +115 -0
  34. package/dest/noop.d.ts +19 -0
  35. package/dest/noop.d.ts.map +1 -0
  36. package/dest/noop.js +104 -0
  37. package/dest/otel.d.ts +43 -0
  38. package/dest/otel.d.ts.map +1 -0
  39. package/dest/otel.js +537 -0
  40. package/dest/otel_filter_metric_exporter.d.ts +20 -0
  41. package/dest/otel_filter_metric_exporter.d.ts.map +1 -0
  42. package/dest/otel_filter_metric_exporter.js +67 -0
  43. package/dest/otel_logger_provider.d.ts +4 -0
  44. package/dest/otel_logger_provider.d.ts.map +1 -0
  45. package/dest/otel_logger_provider.js +25 -0
  46. package/dest/otel_propagation.d.ts +6 -0
  47. package/dest/otel_propagation.d.ts.map +1 -0
  48. package/dest/otel_propagation.js +102 -0
  49. package/dest/otel_resource.d.ts +3 -0
  50. package/dest/otel_resource.d.ts.map +1 -0
  51. package/dest/otel_resource.js +53 -0
  52. package/dest/prom_otel_adapter.d.ts +176 -0
  53. package/dest/prom_otel_adapter.d.ts.map +1 -0
  54. package/dest/prom_otel_adapter.js +292 -0
  55. package/dest/start.d.ts +7 -0
  56. package/dest/start.d.ts.map +1 -0
  57. package/dest/start.js +25 -0
  58. package/dest/telemetry.d.ts +149 -0
  59. package/dest/telemetry.d.ts.map +1 -0
  60. package/dest/telemetry.js +139 -0
  61. package/dest/vendor/attributes.d.ts +6 -0
  62. package/dest/vendor/attributes.d.ts.map +1 -0
  63. package/dest/vendor/attributes.js +6 -0
  64. package/dest/vendor/otel-pino-stream.d.ts +40 -0
  65. package/dest/vendor/otel-pino-stream.d.ts.map +1 -0
  66. package/dest/vendor/otel-pino-stream.js +229 -0
  67. package/dest/with_tracer.d.ts +33 -0
  68. package/dest/with_tracer.d.ts.map +1 -0
  69. package/dest/with_tracer.js +32 -0
  70. package/dest/wrappers/fetch.d.ts +16 -0
  71. package/dest/wrappers/fetch.d.ts.map +1 -0
  72. package/dest/wrappers/fetch.js +42 -0
  73. package/dest/wrappers/index.d.ts +3 -0
  74. package/dest/wrappers/index.d.ts.map +1 -0
  75. package/dest/wrappers/index.js +2 -0
  76. package/dest/wrappers/json_rpc_server.d.ts +4 -0
  77. package/dest/wrappers/json_rpc_server.d.ts.map +1 -0
  78. package/dest/wrappers/json_rpc_server.js +16 -0
  79. package/package.json +95 -0
  80. package/src/attributes.ts +174 -0
  81. package/src/bench.ts +168 -0
  82. package/src/config.ts +135 -0
  83. package/src/index.ts +11 -0
  84. package/src/json_rpc_server_metrics.ts +150 -0
  85. package/src/l1_metrics.ts +64 -0
  86. package/src/lmdb_metrics.ts +45 -0
  87. package/src/metric-utils.ts +75 -0
  88. package/src/metrics.ts +1802 -0
  89. package/src/monitored_batch_span_processor.ts +147 -0
  90. package/src/nodejs_metrics_monitor.ts +135 -0
  91. package/src/noop.ts +152 -0
  92. package/src/otel.ts +482 -0
  93. package/src/otel_filter_metric_exporter.ts +80 -0
  94. package/src/otel_logger_provider.ts +31 -0
  95. package/src/otel_propagation.ts +107 -0
  96. package/src/otel_resource.ts +71 -0
  97. package/src/prom_otel_adapter.ts +450 -0
  98. package/src/start.ts +42 -0
  99. package/src/telemetry.ts +348 -0
  100. package/src/vendor/attributes.ts +6 -0
  101. package/src/vendor/otel-pino-stream.ts +279 -0
  102. package/src/with_tracer.ts +35 -0
  103. package/src/wrappers/fetch.ts +50 -0
  104. package/src/wrappers/index.ts +2 -0
  105. package/src/wrappers/json_rpc_server.ts +26 -0
@@ -0,0 +1,33 @@
1
+ import type { TelemetryClient, Tracer } from './telemetry.js';
2
+ /**
3
+ * A minimal class that enables recording metrics with a telemetry client.
4
+ * This base class enables tracing
5
+ *
6
+ * In other words:
7
+ * Enables the ability to call `@trackSpan` on methods.
8
+ *
9
+ * Example:
10
+ *
11
+ * ```
12
+ * import {Attributes, type TelemetryClient, WithTracer, trackSpan } from '@aztec-labs/telemetry-client';
13
+ *
14
+ * class MyClass extends WithTracer {
15
+ * // Constructor is required to be passed the TelemetryClient implementation.
16
+ * constructor(client: TelemetryClient) {
17
+ * super(client, 'MyClass');
18
+ * }
19
+ *
20
+ * @trackSpan('MyClass.myMethod', (arg: string) => ({
21
+ * [Attributes.ARG]: arg,
22
+ * }))
23
+ * public myMethod(arg: string) {
24
+ * // ...
25
+ * }
26
+ * }
27
+ * ```
28
+ */
29
+ export declare class WithTracer {
30
+ readonly tracer: Tracer;
31
+ constructor(client: TelemetryClient, name: string);
32
+ }
33
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2l0aF90cmFjZXIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy93aXRoX3RyYWNlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxlQUFlLEVBQUUsTUFBTSxFQUFFLE1BQU0sZ0JBQWdCLENBQUM7QUFFOUQ7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBMEJHO0FBQ0gscUJBQWEsVUFBVTtJQUNyQixTQUFnQixNQUFNLEVBQUUsTUFBTSxDQUFDO0lBQy9CLFlBQVksTUFBTSxFQUFFLGVBQWUsRUFBRSxJQUFJLEVBQUUsTUFBTSxFQUVoRDtDQUNGIn0=
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with_tracer.d.ts","sourceRoot":"","sources":["../src/with_tracer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,UAAU;IACrB,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,YAAY,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,EAEhD;CACF"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * A minimal class that enables recording metrics with a telemetry client.
3
+ * This base class enables tracing
4
+ *
5
+ * In other words:
6
+ * Enables the ability to call `@trackSpan` on methods.
7
+ *
8
+ * Example:
9
+ *
10
+ * ```
11
+ * import {Attributes, type TelemetryClient, WithTracer, trackSpan } from '@aztec-labs/telemetry-client';
12
+ *
13
+ * class MyClass extends WithTracer {
14
+ * // Constructor is required to be passed the TelemetryClient implementation.
15
+ * constructor(client: TelemetryClient) {
16
+ * super(client, 'MyClass');
17
+ * }
18
+ *
19
+ * @trackSpan('MyClass.myMethod', (arg: string) => ({
20
+ * [Attributes.ARG]: arg,
21
+ * }))
22
+ * public myMethod(arg: string) {
23
+ * // ...
24
+ * }
25
+ * }
26
+ * ```
27
+ */ export class WithTracer {
28
+ tracer;
29
+ constructor(client, name){
30
+ this.tracer = client.getTracer(name);
31
+ }
32
+ }
@@ -0,0 +1,16 @@
1
+ import { defaultFetch } from '@aztec-labs/foundation/json-rpc/client';
2
+ import type { Logger } from '@aztec-labs/foundation/log';
3
+ /**
4
+ * Makes a fetch function that retries based on the given attempts and propagates trace information.
5
+ * @param retries - Sequence of intervals (in seconds) to retry, or a factory function returning an iterator for custom/indefinite backoff.
6
+ * @param noRetry - Whether to stop retries on server errors.
7
+ * @param log - Optional logger for logging attempts.
8
+ * @returns A fetch function.
9
+ */
10
+ export declare function makeTracedFetch(retries: number[] | (() => Generator<number>), defaultNoRetry: boolean, fetch?: typeof defaultFetch, log?: Logger): (host: string, body: unknown, extraHeaders?: Record<string, string>, noRetry?: boolean | undefined) => Promise<{
11
+ response: any;
12
+ headers: {
13
+ get: (header: string) => string | null | undefined;
14
+ };
15
+ }>;
16
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmV0Y2guZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy93cmFwcGVycy9mZXRjaC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sd0NBQXdDLENBQUM7QUFDdEUsT0FBTyxLQUFLLEVBQUUsTUFBTSxFQUFFLE1BQU0sNEJBQTRCLENBQUM7QUFPekQ7Ozs7OztHQU1HO0FBQ0gsd0JBQWdCLGVBQWUsQ0FDN0IsT0FBTyxFQUFFLE1BQU0sRUFBRSxHQUFHLENBQUMsTUFBTSxTQUFTLENBQUMsTUFBTSxDQUFDLENBQUMsRUFDN0MsY0FBYyxFQUFFLE9BQU8sRUFDdkIsS0FBSyxzQkFBZSxFQUNwQixHQUFHLENBQUMsRUFBRSxNQUFNOzs7OztHQThCYiJ9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/wrappers/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAOzD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,SAAS,CAAC,MAAM,CAAC,CAAC,EAC7C,cAAc,EAAE,OAAO,EACvB,KAAK,sBAAe,EACpB,GAAG,CAAC,EAAE,MAAM;;;;;GA8Bb"}
@@ -0,0 +1,42 @@
1
+ import { defaultFetch } from '@aztec-labs/foundation/json-rpc/client';
2
+ import { makeBackoff, retry } from '@aztec-labs/foundation/retry';
3
+ import { SpanKind, SpanStatusCode, context, propagation } from '@opentelemetry/api';
4
+ import { getTelemetryClient } from '../start.js';
5
+ import { ATTR_JSONRPC_METHOD, ATTR_JSONRPC_REQUEST_ID } from '../vendor/attributes.js';
6
+ /**
7
+ * Makes a fetch function that retries based on the given attempts and propagates trace information.
8
+ * @param retries - Sequence of intervals (in seconds) to retry, or a factory function returning an iterator for custom/indefinite backoff.
9
+ * @param noRetry - Whether to stop retries on server errors.
10
+ * @param log - Optional logger for logging attempts.
11
+ * @returns A fetch function.
12
+ */ export function makeTracedFetch(retries, defaultNoRetry, fetch = defaultFetch, log) {
13
+ return (host, body, extraHeaders = {}, noRetry)=>{
14
+ const telemetry = getTelemetryClient();
15
+ return telemetry.getTracer('fetch').startActiveSpan(`JsonRpcClient`, {
16
+ kind: SpanKind.CLIENT
17
+ }, async (span)=>{
18
+ try {
19
+ if (body && typeof body === 'object' && 'id' in body && typeof body.id === 'number') {
20
+ span.setAttribute(ATTR_JSONRPC_REQUEST_ID, body.id);
21
+ }
22
+ if (body && typeof body === 'object' && 'method' in body && typeof body.method === 'string') {
23
+ span.setAttribute(ATTR_JSONRPC_METHOD, body.method);
24
+ }
25
+ const headers = {
26
+ ...extraHeaders
27
+ };
28
+ propagation.inject(context.active(), headers);
29
+ const backoff = typeof retries === 'function' ? retries() : makeBackoff(retries);
30
+ return await retry(()=>fetch(host, body, headers, noRetry ?? defaultNoRetry), `JsonRpcClient request to ${host}`, backoff, log, false);
31
+ } catch (err) {
32
+ span.setStatus({
33
+ code: SpanStatusCode.ERROR,
34
+ message: err?.message ?? String(err)
35
+ });
36
+ throw err;
37
+ } finally{
38
+ span.end();
39
+ }
40
+ });
41
+ };
42
+ }
@@ -0,0 +1,3 @@
1
+ export * from './fetch.js';
2
+ export * from './json_rpc_server.js';
3
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy93cmFwcGVycy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLFlBQVksQ0FBQztBQUMzQixjQUFjLHNCQUFzQixDQUFDIn0=
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/wrappers/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './fetch.js';
2
+ export * from './json_rpc_server.js';
@@ -0,0 +1,4 @@
1
+ import { type SafeJsonRpcServerOptions } from '@aztec-labs/foundation/json-rpc/server';
2
+ import type { ApiSchemaFor } from '@aztec-labs/stdlib/schemas';
3
+ export declare function createTracedJsonRpcServer<T extends object = any>(handler: T, schema: ApiSchemaFor<T>, options?: SafeJsonRpcServerOptions): import("@aztec-labs/foundation/json-rpc/server").SafeJsonRpcServer;
4
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoianNvbl9ycGNfc2VydmVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvd3JhcHBlcnMvanNvbl9ycGNfc2VydmVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxLQUFLLHdCQUF3QixFQUEyQixNQUFNLHdDQUF3QyxDQUFDO0FBQ2hILE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDRCQUE0QixDQUFDO0FBSy9ELHdCQUFnQix5QkFBeUIsQ0FBQyxDQUFDLFNBQVMsTUFBTSxHQUFHLEdBQUcsRUFDOUQsT0FBTyxFQUFFLENBQUMsRUFDVixNQUFNLEVBQUUsWUFBWSxDQUFDLENBQUMsQ0FBQyxFQUN2QixPQUFPLEdBQUUsd0JBQTZCLHNFQWdCdkMifQ==
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json_rpc_server.d.ts","sourceRoot":"","sources":["../../src/wrappers/json_rpc_server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,wBAAwB,EAA2B,MAAM,wCAAwC,CAAC;AAChH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAK/D,wBAAgB,yBAAyB,CAAC,CAAC,SAAS,MAAM,GAAG,GAAG,EAC9D,OAAO,EAAE,CAAC,EACV,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,EACvB,OAAO,GAAE,wBAA6B,sEAgBvC"}
@@ -0,0 +1,16 @@
1
+ import { createSafeJsonRpcServer } from '@aztec-labs/foundation/json-rpc/server';
2
+ import { getOtelJsonRpcServerMetricsMiddleware } from '../json_rpc_server_metrics.js';
3
+ import { getOtelJsonRpcDiagnosticsMiddleware, getOtelJsonRpcPropagationMiddleware } from '../otel_propagation.js';
4
+ export function createTracedJsonRpcServer(handler, schema, options = {}) {
5
+ const otelDiagnostics = getOtelJsonRpcDiagnosticsMiddleware();
6
+ const diagnostic = options.diagnostic ? (ctx, next)=>options.diagnostic(ctx, ()=>otelDiagnostics(ctx, next)) : otelDiagnostics;
7
+ return createSafeJsonRpcServer(handler, schema, {
8
+ ...options,
9
+ diagnostic,
10
+ middlewares: [
11
+ getOtelJsonRpcServerMetricsMiddleware(),
12
+ ...options.middlewares ?? [],
13
+ getOtelJsonRpcPropagationMiddleware()
14
+ ]
15
+ });
16
+ }
package/package.json ADDED
@@ -0,0 +1,95 @@
1
+ {
2
+ "name": "@aztec-labs/telemetry-client",
3
+ "version": "6.0.0-nightly.20260829",
4
+ "inherits": [
5
+ "../package.common.json"
6
+ ],
7
+ "type": "module",
8
+ "exports": {
9
+ ".": "./dest/index.js",
10
+ "./bench": "./dest/bench.js",
11
+ "./config": "./dest/config.js",
12
+ "./start": "./dest/start.js",
13
+ "./otel-pino-stream": "./dest/vendor/otel-pino-stream.js"
14
+ },
15
+ "scripts": {
16
+ "build": "yarn clean && ../scripts/tsc.sh",
17
+ "build:dev": "../scripts/tsc.sh --watch",
18
+ "clean": "rm -rf ./dest .tsbuildinfo",
19
+ "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
20
+ },
21
+ "engines": {
22
+ "node": ">=20.10"
23
+ },
24
+ "files": [
25
+ "dest",
26
+ "src",
27
+ "!*.test.*"
28
+ ],
29
+ "dependencies": {
30
+ "@aztec-labs/foundation": "6.0.0-nightly.20260829",
31
+ "@aztec-labs/stdlib": "6.0.0-nightly.20260829",
32
+ "@opentelemetry/api": "^1.9.0",
33
+ "@opentelemetry/api-logs": "^0.55.0",
34
+ "@opentelemetry/core": "^1.28.0",
35
+ "@opentelemetry/exporter-logs-otlp-http": "^0.55.0",
36
+ "@opentelemetry/exporter-metrics-otlp-http": "^0.55.0",
37
+ "@opentelemetry/exporter-trace-otlp-http": "^0.55.0",
38
+ "@opentelemetry/host-metrics": "^0.36.2",
39
+ "@opentelemetry/otlp-exporter-base": "^0.55.0",
40
+ "@opentelemetry/resource-detector-gcp": "^0.32.0",
41
+ "@opentelemetry/resources": "^1.28.0",
42
+ "@opentelemetry/sdk-logs": "^0.55.0",
43
+ "@opentelemetry/sdk-metrics": "^1.28.0",
44
+ "@opentelemetry/sdk-trace-node": "^1.28.0",
45
+ "@opentelemetry/semantic-conventions": "^1.28.0",
46
+ "prom-client": "^15.1.3",
47
+ "viem": "npm:@aztec/viem@2.38.2"
48
+ },
49
+ "devDependencies": {
50
+ "@jest/globals": "^30.0.0",
51
+ "@types/jest": "^30.0.0",
52
+ "@types/koa": "^2.15.0",
53
+ "@typescript/native-preview": "7.0.0-dev.20260113.1",
54
+ "jest": "^30.0.0",
55
+ "ts-node": "^10.9.1",
56
+ "typescript": "^5.3.3"
57
+ },
58
+ "jest": {
59
+ "extensionsToTreatAsEsm": [
60
+ ".ts"
61
+ ],
62
+ "transform": {
63
+ "^.+\\.tsx?$": [
64
+ "@swc/jest",
65
+ {
66
+ "jsc": {
67
+ "parser": {
68
+ "syntax": "typescript",
69
+ "decorators": true
70
+ },
71
+ "transform": {
72
+ "decoratorVersion": "2022-03"
73
+ }
74
+ }
75
+ }
76
+ ]
77
+ },
78
+ "moduleNameMapper": {
79
+ "^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
80
+ },
81
+ "reporters": [
82
+ "default"
83
+ ],
84
+ "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
85
+ "rootDir": "./src",
86
+ "testTimeout": 120000,
87
+ "setupFiles": [
88
+ "../../foundation/src/jest/setup.mjs"
89
+ ],
90
+ "testEnvironment": "../../foundation/src/jest/env.mjs",
91
+ "setupFilesAfterEnv": [
92
+ "../../foundation/src/jest/setupAfterEnv.mjs"
93
+ ]
94
+ }
95
+ }
@@ -0,0 +1,174 @@
1
+ /**
2
+ * @overview This file contains the custom attributes used in telemetry events.
3
+ * Attribute names exist in a global namespace, alongside metric names. Use this file to ensure that attribute names are unique.
4
+ *
5
+ * To define a new attribute follow these steps:
6
+ * 1. Make sure it's not a semantic attribute that's already been defined by {@link @opentelemetry/semantic-conventions | OpenTelemetry} (e.g. `service.name`)
7
+ * 2. Come up with a unique name for it so that it doesn't clash with other attributes or metrics.
8
+ * 3. Prefix the attribute name with `aztec` to make it clear that it's a custom attribute.
9
+ * 4. Add a description of what the attribute represents and examples of what it might contain.
10
+ * 5. Start using it.
11
+ *
12
+ * @note Attributes and metric names exist in a hierarchy of namespaces. If a name has been used as a namespace, then it can not be used as a name for an attribute or metric.
13
+ * @example If `aztec.circuit.name` has been defined as an attribute then `aztec.circuit` alone can not be re-used for a metric or attribute because it is already a namespace.
14
+ * @see {@link https://opentelemetry.io/docs/specs/semconv/general/attribute-naming/}
15
+ */
16
+
17
+ /** The host of an HTTP request */
18
+ export const HTTP_REQUEST_HOST = 'http.header.request.host';
19
+ export const HTTP_RESPONSE_STATUS_CODE = 'http.response.status_code';
20
+
21
+ export const JSON_RPC_REJECTION_REASON = 'aztec.json_rpc.rejection_reason';
22
+
23
+ /** The Aztec network identifier */
24
+ export const NETWORK_NAME = 'aztec.network_name';
25
+
26
+ export const AZTEC_NODE_ROLE = 'aztec.node_role';
27
+ export const AZTEC_ROLLUP_VERSION = 'aztec.rollup_version';
28
+ export const AZTEC_ROLLUP_ADDRESS = 'aztec.rollup_address';
29
+ export const AZTEC_REGISTRY_ADDRESS = 'aztec.registry_address';
30
+
31
+ /**
32
+ * The name of the protocol circuit being run (e.g. public-kernel-setup or base-rollup)
33
+ * @see {@link @aztec-labs/stdlib/stats:CircuitName}
34
+ */
35
+ export const PROTOCOL_CIRCUIT_NAME = 'aztec.circuit.protocol_circuit_name';
36
+
37
+ /**
38
+ * For an app circuit, the contract:function being run (e.g. Token:transfer)
39
+ */
40
+ export const APP_CIRCUIT_NAME = 'aztec.circuit.app_circuit_name';
41
+
42
+ /** The block archive */
43
+ export const BLOCK_ARCHIVE = 'aztec.block.archive';
44
+ /** The block number */
45
+ export const BLOCK_NUMBER = 'aztec.block.number';
46
+ /** The L2 block hash */
47
+ export const BLOCK_HASH = 'aztec.block.hash';
48
+ /** The slot number */
49
+ export const SLOT_NUMBER = 'aztec.slot.number';
50
+ /** Whether an event happened before or after a slot boundary. */
51
+ export const SLOT_BOUNDARY_SIDE = 'aztec.slot_boundary_side';
52
+ /** The checkpoint number */
53
+ export const CHECKPOINT_NUMBER = 'aztec.checkpoint.number';
54
+ /** The parent's block number */
55
+ export const BLOCK_PARENT = 'aztec.block.parent';
56
+ /** How many txs are being processed to build this block */
57
+ export const BLOCK_CANDIDATE_TXS_COUNT = 'aztec.block.candidate_txs_count';
58
+ /** How many actual txs were included in this block */
59
+ export const BLOCK_TXS_COUNT = 'aztec.block.txs_count';
60
+ /** The block size */
61
+ export const BLOCK_SIZE = 'aztec.block.size';
62
+ /** How many blocks are included in this epoch */
63
+ export const EPOCH_SIZE = 'aztec.epoch.size';
64
+ /** The proposer of a block */
65
+ export const BLOCK_PROPOSER = 'aztec.block.proposer';
66
+ /** The epoch number */
67
+ export const EPOCH_NUMBER = 'aztec.epoch.number';
68
+ /** Kind of an EpochSession: 'full' or 'partial'. */
69
+ export const EPOCH_SESSION_KIND = 'aztec.epoch_session.kind';
70
+ /** The tx hash */
71
+ export const TX_HASH = 'aztec.tx.hash';
72
+ /** Generic attribute representing whether the action was successful or not */
73
+ export const OK = 'aztec.ok';
74
+ /** Generic status attribute */
75
+ export const STATUS = 'aztec.status';
76
+ /** Generic error type attribute */
77
+ export const ERROR_TYPE = 'aztec.error_type';
78
+ /** The cause of an archiver prune (unproven / uncheckpointed / l1_conflict / orphan / l1_mismatch) */
79
+ export const PRUNE_TYPE = 'aztec.archiver.prune_type';
80
+ /** The type of the transaction */
81
+ export const L1_TX_TYPE = 'aztec.l1.tx_type';
82
+ /** The L1 address of the entity that sent a transaction to L1 */
83
+ export const L1_SENDER = 'aztec.l1.sender';
84
+ /** The L1 address receiving rewards */
85
+ export const COINBASE = 'aztec.coinbase';
86
+ /** The phase of the transaction */
87
+ export const TX_PHASE_NAME = 'aztec.tx.phase_name';
88
+ /** The reason for disconnecting a peer */
89
+ export const P2P_GOODBYE_REASON = 'aztec.p2p.goodbye.reason';
90
+ /** The proving job type */
91
+ export const PROVING_JOB_TYPE = 'aztec.proving.job_type';
92
+ /** The proving job id */
93
+ export const PROVING_JOB_ID = 'aztec.proving.job_id';
94
+ /** Merkle tree name */
95
+ export const MERKLE_TREE_NAME = 'aztec.merkle_tree.name';
96
+ /** The prover-id in a root rollup proof. */
97
+ export const ROLLUP_PROVER_ID = 'aztec.rollup.prover_id';
98
+ /** Whether the proof submission was timed out (delayed more than 20 min) */
99
+ export const PROOF_TIMED_OUT = 'aztec.proof.timed_out';
100
+ /** Status of the validator (eg proposer, in-committee, none) */
101
+ export const VALIDATOR_STATUS = 'aztec.validator_status';
102
+
103
+ export const P2P_ID = 'aztec.p2p.id';
104
+ export const P2P_REQ_RESP_PROTOCOL = 'aztec.p2p.req_resp.protocol';
105
+ /** The state of a peer (Healthy, Disconnect, Banned) */
106
+ export const P2P_PEER_SCORE_STATE = 'aztec.p2p.peer_score_state';
107
+ export const POOL_NAME = 'aztec.pool.name';
108
+
109
+ export const PEER_ID = 'aztec.p2p.peer_id';
110
+
111
+ export const SEQUENCER_STATE = 'aztec.sequencer.state';
112
+
113
+ export const SIMULATOR_PHASE = 'aztec.simulator.phase';
114
+ export const TARGET_ADDRESS = 'aztec.address.target';
115
+ export const SENDER_ADDRESS = 'aztec.address.sender';
116
+ export const MANA_USED = 'aztec.mana.used';
117
+ export const TOTAL_INSTRUCTIONS = 'aztec.total_instructions';
118
+
119
+ /** Whether a sync process is the initial run, which is usually slower than iterative ones. */
120
+ export const INITIAL_SYNC = 'aztec.initial_sync';
121
+
122
+ /** Identifier for the tables in a world state DB */
123
+ export const WS_DB_DATA_TYPE = 'aztec.world_state.db_type';
124
+
125
+ /** Identifier for component database (e.g. archiver, tx pool) */
126
+ export const DB_DATA_TYPE = 'aztec.db_type';
127
+
128
+ export const REVERTIBILITY = 'aztec.revertibility';
129
+
130
+ export const GAS_DIMENSION = 'aztec.gas_dimension';
131
+
132
+ export const WORLD_STATE_REQUEST_TYPE = 'aztec.world_state_request';
133
+
134
+ export const NODEJS_EVENT_LOOP_STATE = 'nodejs.eventloop.state';
135
+
136
+ export const TOPIC_NAME = 'aztec.gossip.topic_name';
137
+
138
+ /** Stage of gossiped tx validation (deserialize, fast_validation_setup, fast_validation, pool_precheck, proof_verify, pool_add) */
139
+ export const TX_VALIDATION_STAGE = 'aztec.p2p.tx_validation_stage';
140
+
141
+ /** Operation type enqueued on the mempool serial queue */
142
+ export const MEMPOOL_OPERATION = 'aztec.mempool.operation';
143
+
144
+ /** The reason a transaction was evicted from the tx pool */
145
+ export const TX_POOL_EVICTION_REASON = 'aztec.mempool.eviction_reason';
146
+
147
+ export const TX_COLLECTION_METHOD = 'aztec.tx_collection.method';
148
+
149
+ /** Scope of L1 transaction (sequencer, prover, or other) */
150
+ export const L1_TX_SCOPE = 'aztec.l1_tx.scope';
151
+
152
+ /** Generic error type attribute */
153
+ export const IS_COMMITTEE_MEMBER = 'aztec.is_committee_member';
154
+
155
+ /** Fisherman fee analysis strategy identifier */
156
+ export const FISHERMAN_FEE_STRATEGY_ID = 'aztec.fisherman.strategy_id';
157
+
158
+ /** Whether the analyzed block reached 100% blob capacity */
159
+ export const BLOCK_FULL = 'aztec.block_full';
160
+
161
+ /** The L1 transaction target for block proposal */
162
+ export const L1_BLOCK_PROPOSAL_TX_TARGET = 'aztec.l1.block_proposal_tx_target';
163
+
164
+ /** Whether tracing methods were used to extract block proposal data */
165
+ export const L1_BLOCK_PROPOSAL_USED_TRACE = 'aztec.l1.block_proposal_used_trace';
166
+
167
+ /** HA signer duty type (e.g., BLOCK_PROPOSAL, CHECKPOINT_ATTESTATION) */
168
+ export const HA_DUTY_TYPE = 'aztec.ha_signer.duty_type';
169
+
170
+ /** HA signer node identifier */
171
+ export const HA_NODE_ID = 'aztec.ha_signer.node_id';
172
+
173
+ /** The address of an attester (validator) participating in consensus */
174
+ export const ATTESTER_ADDRESS = 'aztec.attester.address';
package/src/bench.ts ADDED
@@ -0,0 +1,168 @@
1
+ import { createLogger } from '@aztec-labs/foundation/log';
2
+ import type { BatchObservableCallback, Context, MetricOptions, Observable, ValueType } from '@opentelemetry/api';
3
+
4
+ import type { MetricDefinition } from './metrics.js';
5
+ import { NoopTracer } from './noop.js';
6
+ import type {
7
+ AttributesType,
8
+ Gauge,
9
+ Histogram,
10
+ Meter,
11
+ ObservableGauge,
12
+ ObservableUpDownCounter,
13
+ TelemetryClient,
14
+ Tracer,
15
+ UpDownCounter,
16
+ } from './telemetry.js';
17
+
18
+ export type BenchmarkMetricsType = {
19
+ name: string;
20
+ metrics: {
21
+ name: string;
22
+ type: 'gauge' | 'counter' | 'histogram';
23
+ description?: string;
24
+ unit?: string;
25
+ valueType?: ValueType;
26
+ points: BenchmarkDataPoint[];
27
+ }[];
28
+ }[];
29
+
30
+ export class BenchmarkTelemetryClient implements TelemetryClient {
31
+ private meters: InMemoryPlainMeter[] = [];
32
+
33
+ constructor() {
34
+ const log = createLogger('telemetry:client');
35
+ log.info(`Using benchmark telemetry client`);
36
+ }
37
+
38
+ setExportedPublicTelemetry(_prefixes: string[]): void {}
39
+ setPublicTelemetryCollectFrom(_roles: string[]): void {}
40
+
41
+ getMeter(name: string): Meter {
42
+ const meter = new InMemoryPlainMeter(name);
43
+ this.meters.push(meter);
44
+ return meter;
45
+ }
46
+
47
+ getTracer(): Tracer {
48
+ return new NoopTracer();
49
+ }
50
+
51
+ stop(): Promise<void> {
52
+ return Promise.resolve();
53
+ }
54
+
55
+ flush(): Promise<void> {
56
+ return Promise.resolve();
57
+ }
58
+
59
+ isEnabled() {
60
+ return true;
61
+ }
62
+
63
+ getTraceContext(): string | undefined {
64
+ return undefined;
65
+ }
66
+
67
+ extractPropagatedContext() {
68
+ return undefined;
69
+ }
70
+
71
+ getMeters(): BenchmarkMetricsType {
72
+ return this.meters;
73
+ }
74
+
75
+ clear() {
76
+ this.meters.forEach(meter => meter.clear());
77
+ }
78
+ }
79
+
80
+ class InMemoryPlainMeter implements Meter {
81
+ public readonly metrics: InMemoryPlainMetric[] = [];
82
+
83
+ constructor(public readonly name: string) {}
84
+
85
+ clear() {
86
+ this.metrics.forEach(metric => metric.clear());
87
+ }
88
+
89
+ createGauge(metric: MetricDefinition): Gauge {
90
+ return this.createMetric('gauge', metric);
91
+ }
92
+
93
+ createObservableGauge(metric: MetricDefinition): ObservableGauge {
94
+ return this.createMetric('gauge', metric);
95
+ }
96
+
97
+ createHistogram(metric: MetricDefinition, _extraOptions?: Partial<MetricOptions>): Histogram {
98
+ return this.createMetric('histogram', metric);
99
+ }
100
+
101
+ createUpDownCounter(metric: MetricDefinition): UpDownCounter {
102
+ return this.createMetric('counter', metric);
103
+ }
104
+
105
+ createObservableUpDownCounter(metric: MetricDefinition): ObservableUpDownCounter {
106
+ return this.createMetric('counter', metric);
107
+ }
108
+
109
+ private createMetric(type: 'gauge' | 'counter' | 'histogram', metric: MetricDefinition) {
110
+ const m = new InMemoryPlainMetric(type, metric.name, {
111
+ description: metric.description,
112
+ unit: metric.unit,
113
+ valueType: metric.valueType,
114
+ });
115
+ this.metrics.push(m);
116
+ return m;
117
+ }
118
+
119
+ addBatchObservableCallback(
120
+ _callback: BatchObservableCallback<AttributesType>,
121
+ _observables: Observable<AttributesType>[],
122
+ ): void {}
123
+
124
+ removeBatchObservableCallback(
125
+ _callback: BatchObservableCallback<AttributesType>,
126
+ _observables: Observable<AttributesType>[],
127
+ ): void {}
128
+ }
129
+
130
+ export type BenchmarkDataPoint = { value: number; attributes?: AttributesType; context?: Context };
131
+
132
+ class InMemoryPlainMetric {
133
+ public readonly points: BenchmarkDataPoint[] = [];
134
+
135
+ public readonly description?: string;
136
+ public readonly unit?: string;
137
+ public readonly valueType?: ValueType;
138
+
139
+ constructor(
140
+ public readonly type: 'gauge' | 'counter' | 'histogram',
141
+ public readonly name: string,
142
+ options?: MetricOptions,
143
+ ) {
144
+ this.description = options?.description;
145
+ this.unit = options?.unit;
146
+ this.valueType = options?.valueType;
147
+ }
148
+
149
+ add(value: number, attributes?: AttributesType, context?: Context): void {
150
+ this.points.push({ value, attributes, context });
151
+ }
152
+
153
+ record(value: number, attributes?: AttributesType, context?: Context): void {
154
+ this.points.push({ value, attributes, context });
155
+ }
156
+
157
+ addCallback() {}
158
+
159
+ removeCallback() {}
160
+
161
+ getPoints(): BenchmarkDataPoint[] {
162
+ return this.points;
163
+ }
164
+
165
+ clear() {
166
+ this.points.splice(0, this.points.length);
167
+ }
168
+ }