@aztec/telemetry-client 0.0.1-commit.d3ec352c → 0.0.1-commit.d6f2b3f94
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 +10 -1
- package/dest/attributes.d.ts.map +1 -1
- package/dest/attributes.js +5 -0
- package/dest/bench.d.ts +3 -1
- package/dest/bench.d.ts.map +1 -1
- package/dest/bench.js +24 -14
- package/dest/l1_metrics.d.ts +2 -2
- package/dest/l1_metrics.d.ts.map +1 -1
- package/dest/l1_metrics.js +4 -20
- package/dest/lmdb_metrics.d.ts +3 -3
- package/dest/lmdb_metrics.d.ts.map +1 -1
- package/dest/lmdb_metrics.js +4 -20
- package/dest/metric-utils.d.ts +24 -0
- package/dest/metric-utils.d.ts.map +1 -0
- package/dest/metric-utils.js +59 -0
- package/dest/metrics.d.ts +251 -207
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +1264 -205
- package/dest/nodejs_metrics_monitor.d.ts +3 -5
- package/dest/nodejs_metrics_monitor.d.ts.map +1 -1
- package/dest/nodejs_metrics_monitor.js +19 -40
- package/dest/noop.d.ts +6 -3
- package/dest/noop.d.ts.map +1 -1
- package/dest/noop.js +32 -1
- package/dest/otel.d.ts +5 -3
- package/dest/otel.d.ts.map +1 -1
- package/dest/otel.js +51 -4
- package/dest/otel_resource.d.ts +1 -1
- package/dest/otel_resource.d.ts.map +1 -1
- package/dest/otel_resource.js +14 -2
- package/dest/prom_otel_adapter.d.ts +4 -4
- package/dest/prom_otel_adapter.d.ts.map +1 -1
- package/dest/prom_otel_adapter.js +19 -10
- package/dest/start.d.ts +3 -2
- package/dest/start.d.ts.map +1 -1
- package/dest/start.js +4 -3
- package/dest/telemetry.d.ts +37 -25
- package/dest/telemetry.d.ts.map +1 -1
- package/dest/telemetry.js +46 -23
- package/dest/wrappers/l2_block_stream.d.ts +2 -2
- package/dest/wrappers/l2_block_stream.d.ts.map +1 -1
- package/dest/wrappers/l2_block_stream.js +385 -11
- package/package.json +6 -4
- package/src/attributes.ts +13 -0
- package/src/bench.ts +27 -15
- package/src/l1_metrics.ts +5 -20
- package/src/lmdb_metrics.ts +5 -26
- package/src/metric-utils.ts +75 -0
- package/src/metrics.ts +1338 -250
- package/src/nodejs_metrics_monitor.ts +18 -51
- package/src/noop.ts +61 -3
- package/src/otel.ts +76 -6
- package/src/otel_resource.ts +19 -2
- package/src/prom_otel_adapter.ts +16 -23
- package/src/start.ts +8 -4
- package/src/telemetry.ts +105 -66
- package/src/wrappers/l2_block_stream.ts +4 -1
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
|
|
20
|
+
import type { MetricDefinition } from './metrics.js';
|
|
21
21
|
import { getTelemetryClient } from './start.js';
|
|
22
22
|
|
|
23
|
-
export {
|
|
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
|
|
|
@@ -54,11 +56,13 @@ type BannedMetricAttributeNames = (typeof Attributes)[
|
|
|
54
56
|
/** Global registry of attributes */
|
|
55
57
|
export type AttributesType = Partial<Record<AttributeNames, AttributeValue>>;
|
|
56
58
|
|
|
59
|
+
export type AllowedAttributeNames = Exclude<AttributeNames, BannedMetricAttributeNames>;
|
|
60
|
+
|
|
57
61
|
/** Subset of attributes allowed to be added to metrics */
|
|
58
|
-
export type MetricAttributesType = Partial<Record<
|
|
62
|
+
export type MetricAttributesType = Partial<Record<AllowedAttributeNames, AttributeValue>>;
|
|
59
63
|
|
|
60
|
-
/**
|
|
61
|
-
export type
|
|
64
|
+
/** Re-export MetricDefinition for convenience */
|
|
65
|
+
export type { MetricDefinition } from './metrics.js';
|
|
62
66
|
|
|
63
67
|
export type Gauge = OtelGauge<MetricAttributesType>;
|
|
64
68
|
export type Histogram = OtelHistogram<MetricAttributesType>;
|
|
@@ -77,17 +81,15 @@ export type { Tracer };
|
|
|
77
81
|
export interface Meter {
|
|
78
82
|
/**
|
|
79
83
|
* 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
|
|
81
|
-
* @param options - The options for the gauge
|
|
84
|
+
* @param metric - The metric definition
|
|
82
85
|
*/
|
|
83
|
-
createGauge(
|
|
86
|
+
createGauge(metric: MetricDefinition): Gauge;
|
|
84
87
|
|
|
85
88
|
/**
|
|
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
|
|
88
|
-
* @param options - The options for the gauge
|
|
89
|
+
* Creates a new observable gauge instrument. A gauge is a metric that represents a single numerical value that can arbitrarily go up and down.
|
|
90
|
+
* @param metric - The metric definition
|
|
89
91
|
*/
|
|
90
|
-
createObservableGauge(
|
|
92
|
+
createObservableGauge(metric: MetricDefinition): ObservableGauge;
|
|
91
93
|
|
|
92
94
|
addBatchObservableCallback(
|
|
93
95
|
callback: BatchObservableCallback<AttributesType>,
|
|
@@ -101,24 +103,22 @@ export interface Meter {
|
|
|
101
103
|
|
|
102
104
|
/**
|
|
103
105
|
* 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
|
|
105
|
-
* @param
|
|
106
|
+
* @param metric - The metric definition
|
|
107
|
+
* @param extraOptions - Optional extra options (e.g., advice for bucket boundaries)
|
|
106
108
|
*/
|
|
107
|
-
createHistogram(
|
|
109
|
+
createHistogram(metric: MetricDefinition, extraOptions?: Partial<MetricOptions>): Histogram;
|
|
108
110
|
|
|
109
111
|
/**
|
|
110
112
|
* Creates a new counter instrument. A counter can go up or down with a delta from the previous value.
|
|
111
|
-
* @param
|
|
112
|
-
* @param options - The options for the counter
|
|
113
|
+
* @param metric - The metric definition
|
|
113
114
|
*/
|
|
114
|
-
createUpDownCounter(
|
|
115
|
+
createUpDownCounter(metric: MetricDefinition): UpDownCounter;
|
|
115
116
|
|
|
116
117
|
/**
|
|
117
|
-
* Creates a new
|
|
118
|
-
* @param
|
|
119
|
-
* @param options - The options for the gauge
|
|
118
|
+
* Creates a new observable up/down counter instrument.
|
|
119
|
+
* @param metric - The metric definition
|
|
120
120
|
*/
|
|
121
|
-
createObservableUpDownCounter(
|
|
121
|
+
createObservableUpDownCounter(metric: MetricDefinition): ObservableUpDownCounter;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
/**
|
|
@@ -160,6 +160,17 @@ export interface TelemetryClient {
|
|
|
160
160
|
* Updates the roles that would share telemetry (if enabled)
|
|
161
161
|
*/
|
|
162
162
|
setPublicTelemetryCollectFrom(roles: string[]): void;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Get current trace context as an opaque string for propagation.
|
|
166
|
+
* Returns the W3C traceparent header value if a trace is active, undefined otherwise.
|
|
167
|
+
*/
|
|
168
|
+
getTraceContext(): string | undefined;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Recreates a context propagated by a remote system
|
|
172
|
+
*/
|
|
173
|
+
extractPropagatedContext(traceContext: string): Context | undefined;
|
|
163
174
|
}
|
|
164
175
|
|
|
165
176
|
/** Objects that adhere to this interface can use @trackSpan */
|
|
@@ -204,24 +215,36 @@ export function trackSpan<T extends Traceable, F extends (...args: any[]) => any
|
|
|
204
215
|
// "active" means the span will be alive for the duration of the function execution
|
|
205
216
|
// and if any other spans are started during the execution of originalMethod, they will be children of this span
|
|
206
217
|
// behind the scenes this uses AsyncLocalStorage https://nodejs.org/dist/latest-v22.x/docs/api/async_context.html
|
|
207
|
-
return this.tracer.startActiveSpan(
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
218
|
+
return this.tracer.startActiveSpan(
|
|
219
|
+
name,
|
|
220
|
+
{
|
|
221
|
+
attributes: currentAttrs,
|
|
222
|
+
},
|
|
223
|
+
async (span: Span) => {
|
|
224
|
+
try {
|
|
225
|
+
const res = await originalMethod.call(this, ...args);
|
|
226
|
+
const extraAttrs = extraAttributes?.call(this, res);
|
|
227
|
+
span.setAttributes(extraAttrs ?? {});
|
|
228
|
+
span.setStatus({
|
|
229
|
+
code: SpanStatusCode.OK,
|
|
230
|
+
});
|
|
231
|
+
return res;
|
|
232
|
+
} catch (err) {
|
|
233
|
+
span.setStatus({
|
|
234
|
+
code: SpanStatusCode.ERROR,
|
|
235
|
+
message: String(err),
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
if (typeof err === 'string' || (err && err instanceof Error)) {
|
|
239
|
+
span.recordException(err);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
throw err;
|
|
243
|
+
} finally {
|
|
244
|
+
span.end();
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
);
|
|
225
248
|
} as F;
|
|
226
249
|
};
|
|
227
250
|
}
|
|
@@ -265,41 +288,57 @@ export function wrapCallbackInSpan<F extends (...args: any[]) => any>(
|
|
|
265
288
|
export function runInSpan<A extends any[], R>(
|
|
266
289
|
tracer: Tracer | string,
|
|
267
290
|
spanName: string,
|
|
268
|
-
callback: (span: Span, ...args: A) => R
|
|
269
|
-
): (...args: A) => R {
|
|
270
|
-
return (...args: A): R => {
|
|
291
|
+
callback: (span: Span, ...args: A) => Promise<R>,
|
|
292
|
+
): (...args: A) => Promise<R> {
|
|
293
|
+
return (...args: A): Promise<R> => {
|
|
271
294
|
const actualTracer = typeof tracer === 'string' ? getTelemetryClient().getTracer(tracer) : tracer;
|
|
272
|
-
return actualTracer.startActiveSpan(spanName, (span: Span): R => {
|
|
273
|
-
let deferSpanEnd = false;
|
|
295
|
+
return actualTracer.startActiveSpan(spanName, async (span: Span): Promise<R> => {
|
|
274
296
|
try {
|
|
275
|
-
const res = callback(span, ...args);
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
-
}
|
|
297
|
+
const res = await callback(span, ...args);
|
|
298
|
+
span.setStatus({
|
|
299
|
+
code: SpanStatusCode.OK,
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
return res;
|
|
292
303
|
} catch (err) {
|
|
293
304
|
span.setStatus({
|
|
294
305
|
code: SpanStatusCode.ERROR,
|
|
295
306
|
message: String(err),
|
|
296
307
|
});
|
|
308
|
+
if (typeof err === 'string' || (err && err instanceof Error)) {
|
|
309
|
+
span.recordException(err);
|
|
310
|
+
}
|
|
297
311
|
throw err;
|
|
298
312
|
} finally {
|
|
299
|
-
|
|
300
|
-
span.end();
|
|
301
|
-
}
|
|
313
|
+
span.end();
|
|
302
314
|
}
|
|
303
315
|
});
|
|
304
316
|
};
|
|
305
317
|
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Execute a callback within a span immediately (for one-off traced calls).
|
|
321
|
+
* Unlike runInSpan which returns a reusable function, this executes right away.
|
|
322
|
+
*/
|
|
323
|
+
export function execInSpan<R>(
|
|
324
|
+
tracer: Tracer | string,
|
|
325
|
+
spanName: string,
|
|
326
|
+
callback: (span: Span) => Promise<R>,
|
|
327
|
+
): Promise<R> {
|
|
328
|
+
const actualTracer = typeof tracer === 'string' ? getTelemetryClient().getTracer(tracer) : tracer;
|
|
329
|
+
return actualTracer.startActiveSpan(spanName, async (span: Span): Promise<R> => {
|
|
330
|
+
try {
|
|
331
|
+
const res = await callback(span);
|
|
332
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
333
|
+
return res;
|
|
334
|
+
} catch (err) {
|
|
335
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: String(err) });
|
|
336
|
+
if (typeof err === 'string' || (err && err instanceof Error)) {
|
|
337
|
+
span.recordException(err);
|
|
338
|
+
}
|
|
339
|
+
throw err;
|
|
340
|
+
} finally {
|
|
341
|
+
span.end();
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
}
|
|
@@ -11,7 +11,10 @@ import { type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client'
|
|
|
11
11
|
/** Extends an L2BlockStream with a tracer to create a new trace per iteration. */
|
|
12
12
|
export class TraceableL2BlockStream extends L2BlockStream implements Traceable {
|
|
13
13
|
constructor(
|
|
14
|
-
l2BlockSource: Pick<
|
|
14
|
+
l2BlockSource: Pick<
|
|
15
|
+
L2BlockSource,
|
|
16
|
+
'getBlocks' | 'getBlockHeader' | 'getL2Tips' | 'getCheckpoints' | 'getCheckpointedBlocks'
|
|
17
|
+
>,
|
|
15
18
|
localData: L2BlockStreamLocalDataProvider,
|
|
16
19
|
handler: L2BlockStreamEventHandler,
|
|
17
20
|
public readonly tracer: Tracer,
|