@aztec/telemetry-client 0.0.1-commit.fce3e4f → 0.0.1-commit.ff7989d6c

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 (57) hide show
  1. package/dest/attributes.d.ts +18 -1
  2. package/dest/attributes.d.ts.map +1 -1
  3. package/dest/attributes.js +9 -0
  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/l1_metrics.d.ts +2 -2
  8. package/dest/l1_metrics.d.ts.map +1 -1
  9. package/dest/l1_metrics.js +4 -20
  10. package/dest/lmdb_metrics.d.ts +3 -3
  11. package/dest/lmdb_metrics.d.ts.map +1 -1
  12. package/dest/lmdb_metrics.js +4 -20
  13. package/dest/metric-utils.d.ts +24 -0
  14. package/dest/metric-utils.d.ts.map +1 -0
  15. package/dest/metric-utils.js +59 -0
  16. package/dest/metrics.d.ts +283 -206
  17. package/dest/metrics.d.ts.map +1 -1
  18. package/dest/metrics.js +1435 -204
  19. package/dest/nodejs_metrics_monitor.d.ts +3 -5
  20. package/dest/nodejs_metrics_monitor.d.ts.map +1 -1
  21. package/dest/nodejs_metrics_monitor.js +19 -40
  22. package/dest/noop.d.ts +6 -3
  23. package/dest/noop.d.ts.map +1 -1
  24. package/dest/noop.js +32 -1
  25. package/dest/otel.d.ts +5 -3
  26. package/dest/otel.d.ts.map +1 -1
  27. package/dest/otel.js +51 -4
  28. package/dest/otel_resource.d.ts +1 -1
  29. package/dest/otel_resource.d.ts.map +1 -1
  30. package/dest/otel_resource.js +14 -2
  31. package/dest/prom_otel_adapter.d.ts +4 -4
  32. package/dest/prom_otel_adapter.d.ts.map +1 -1
  33. package/dest/prom_otel_adapter.js +19 -10
  34. package/dest/start.d.ts +3 -2
  35. package/dest/start.d.ts.map +1 -1
  36. package/dest/start.js +4 -3
  37. package/dest/telemetry.d.ts +37 -25
  38. package/dest/telemetry.d.ts.map +1 -1
  39. package/dest/telemetry.js +46 -23
  40. package/dest/wrappers/l2_block_stream.d.ts +4 -3
  41. package/dest/wrappers/l2_block_stream.d.ts.map +1 -1
  42. package/dest/wrappers/l2_block_stream.js +385 -11
  43. package/package.json +8 -6
  44. package/src/attributes.ts +25 -0
  45. package/src/bench.ts +27 -15
  46. package/src/l1_metrics.ts +5 -20
  47. package/src/lmdb_metrics.ts +5 -26
  48. package/src/metric-utils.ts +75 -0
  49. package/src/metrics.ts +1513 -249
  50. package/src/nodejs_metrics_monitor.ts +18 -51
  51. package/src/noop.ts +61 -3
  52. package/src/otel.ts +76 -6
  53. package/src/otel_resource.ts +19 -2
  54. package/src/prom_otel_adapter.ts +16 -23
  55. package/src/start.ts +8 -4
  56. package/src/telemetry.ts +105 -66
  57. package/src/wrappers/l2_block_stream.ts +6 -2
@@ -0,0 +1,75 @@
1
+ import type { AttributeValue, MetricOptions } from '@opentelemetry/api';
2
+
3
+ import type { MetricDefinition } from './metrics.js';
4
+ import type { AllowedAttributeNames, Meter, MetricAttributesType, UpDownCounter } from './telemetry.js';
5
+
6
+ /** Extracts OpenTelemetry MetricOptions from a MetricDefinition */
7
+ export function toMetricOptions(def: MetricDefinition): MetricOptions {
8
+ return {
9
+ description: def.description,
10
+ unit: def.unit,
11
+ valueType: def.valueType,
12
+ };
13
+ }
14
+
15
+ /** A mapping of attribute keys to their possible values */
16
+ export type AttributeValuesMap = Partial<Record<AllowedAttributeNames, AttributeValue[]>>;
17
+
18
+ /**
19
+ * Expands an attribute values map into all combinations of attribute objects.
20
+ * Example: { status: ['ok', 'fail'], type: ['a', 'b'] } =>
21
+ * [{ status: 'ok', type: 'a' }, { status: 'ok', type: 'b' }, { status: 'fail', type: 'a' }, { status: 'fail', type: 'b' }]
22
+ */
23
+ export function expandAttributeCombinations(attrMap: AttributeValuesMap): MetricAttributesType[] {
24
+ const keys = Object.keys(attrMap) as AllowedAttributeNames[];
25
+ if (keys.length === 0) {
26
+ return [{}];
27
+ }
28
+
29
+ const result: MetricAttributesType[] = [];
30
+
31
+ function generate(index: number, current: MetricAttributesType) {
32
+ if (index === keys.length) {
33
+ result.push({ ...current });
34
+ return;
35
+ }
36
+ const key = keys[index];
37
+ for (const value of attrMap[key]!) {
38
+ current[key] = value;
39
+ generate(index + 1, current);
40
+ }
41
+ }
42
+
43
+ generate(0, {});
44
+ return result;
45
+ }
46
+
47
+ /**
48
+ * Creates an UpDownCounter and initializes it to 0.
49
+ * @param meter - The meter to create the counter on
50
+ * @param metric - The metric definition
51
+ * @param attributes - Optional attributes for initialization. Can be:
52
+ * - AttributeValuesMap: mapping of attribute keys to arrays of possible values (generates cartesian product)
53
+ * - MetricAttributesType[]: explicit array of attribute objects
54
+ * - undefined: initializes without attributes
55
+ */
56
+ export function createUpDownCounterWithDefault(
57
+ meter: Meter,
58
+ metric: MetricDefinition,
59
+ attributes: AttributeValuesMap | MetricAttributesType[] | undefined = undefined,
60
+ ): UpDownCounter {
61
+ const counter = meter.createUpDownCounter(metric);
62
+ if (attributes === undefined) {
63
+ counter.add(0);
64
+ } else if (Array.isArray(attributes)) {
65
+ for (const attrs of attributes) {
66
+ counter.add(0, attrs);
67
+ }
68
+ } else {
69
+ const combinations = expandAttributeCombinations(attributes);
70
+ for (const attrs of combinations) {
71
+ counter.add(0, attrs);
72
+ }
73
+ }
74
+ return counter;
75
+ }