@dxos/tracing 0.8.4-main.a4bbb77 → 0.8.4-main.ae835ea

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.
@@ -4,11 +4,10 @@ import { Context as Context2 } from "@dxos/context";
4
4
  // src/symbols.ts
5
5
  var symbolTracingContext = Symbol("dxos.tracing.context");
6
6
  var getTracingContext = (target) => {
7
- var _target, _symbolTracingContext;
8
- return (_target = target)[_symbolTracingContext = symbolTracingContext] ?? (_target[_symbolTracingContext] = {
7
+ return target[symbolTracingContext] ??= {
9
8
  infoProperties: {},
10
9
  metricsProperties: {}
11
- });
10
+ };
12
11
  };
13
12
  var TRACE_SPAN_ATTRIBUTE = "dxos.trace-span";
14
13
 
@@ -25,37 +24,27 @@ import { invariant } from "@dxos/invariant";
25
24
  var createId = () => Math.random().toString(36).slice(2);
26
25
 
27
26
  // src/diagnostic.ts
28
- function _define_property(obj, key, value) {
29
- if (key in obj) {
30
- Object.defineProperty(obj, key, {
31
- value,
32
- enumerable: true,
33
- configurable: true,
34
- writable: true
35
- });
36
- } else {
37
- obj[key] = value;
38
- }
39
- return obj;
40
- }
41
27
  var __dxlog_file = "/__w/dxos/dxos/packages/common/tracing/src/diagnostic.ts";
42
28
  var DIAGNOSTICS_TIMEOUT = 1e4;
43
29
  var TraceDiagnosticImpl = class {
44
- unregister() {
45
- this._onUnregister();
46
- }
30
+ id;
31
+ fetch;
32
+ name;
33
+ _onUnregister;
47
34
  constructor(id, fetch, name, _onUnregister) {
48
- _define_property(this, "id", void 0);
49
- _define_property(this, "fetch", void 0);
50
- _define_property(this, "name", void 0);
51
- _define_property(this, "_onUnregister", void 0);
52
35
  this.id = id;
53
36
  this.fetch = fetch;
54
37
  this.name = name;
55
38
  this._onUnregister = _onUnregister;
56
39
  }
40
+ unregister() {
41
+ this._onUnregister();
42
+ }
57
43
  };
58
44
  var DiagnosticsManager = class {
45
+ instanceId = createId();
46
+ registry = /* @__PURE__ */ new Map();
47
+ _instanceTag = null;
59
48
  get instanceTag() {
60
49
  return this._instanceTag;
61
50
  }
@@ -118,37 +107,34 @@ var DiagnosticsManager = class {
118
107
  };
119
108
  }
120
109
  }
121
- constructor() {
122
- _define_property(this, "instanceId", createId());
123
- _define_property(this, "registry", /* @__PURE__ */ new Map());
124
- _define_property(this, "_instanceTag", null);
125
- }
126
110
  };
127
111
 
128
112
  // src/diagnostics-channel.ts
129
113
  import { Trigger, sleep } from "@dxos/async";
130
114
  import { Context } from "@dxos/context";
131
115
  import { invariant as invariant2 } from "@dxos/invariant";
132
- function _define_property2(obj, key, value) {
133
- if (key in obj) {
134
- Object.defineProperty(obj, key, {
135
- value,
136
- enumerable: true,
137
- configurable: true,
138
- writable: true
139
- });
140
- } else {
141
- obj[key] = value;
142
- }
143
- return obj;
144
- }
145
116
  var __dxlog_file2 = "/__w/dxos/dxos/packages/common/tracing/src/diagnostics-channel.ts";
146
117
  var DEFAULT_CHANNEL_NAME = "dxos-diagnostics";
147
118
  var DISCOVER_TIME = 500;
148
119
  var DiagnosticsChannel = class _DiagnosticsChannel {
120
+ _channelName;
149
121
  static get supported() {
150
122
  return globalThis.BroadcastChannel != null;
151
123
  }
124
+ _ctx = new Context(void 0, {
125
+ F: __dxlog_file2,
126
+ L: 46
127
+ });
128
+ // Separate channels becauase the client and server may be in the same process.
129
+ _serveChannel = void 0;
130
+ _clientChannel = void 0;
131
+ constructor(_channelName = DEFAULT_CHANNEL_NAME) {
132
+ this._channelName = _channelName;
133
+ if (_DiagnosticsChannel.supported) {
134
+ this._serveChannel = new BroadcastChannel(_channelName);
135
+ this._clientChannel = new BroadcastChannel(_channelName);
136
+ }
137
+ }
152
138
  destroy() {
153
139
  void this._ctx.dispose();
154
140
  this._serveChannel?.close();
@@ -274,40 +260,11 @@ var DiagnosticsChannel = class _DiagnosticsChannel {
274
260
  this._clientChannel.removeEventListener("message", listener);
275
261
  }
276
262
  }
277
- constructor(_channelName = DEFAULT_CHANNEL_NAME) {
278
- _define_property2(this, "_channelName", void 0);
279
- _define_property2(this, "_ctx", void 0);
280
- _define_property2(this, "_serveChannel", void 0);
281
- _define_property2(this, "_clientChannel", void 0);
282
- this._channelName = _channelName;
283
- this._ctx = new Context(void 0, {
284
- F: __dxlog_file2,
285
- L: 46
286
- });
287
- this._serveChannel = void 0;
288
- this._clientChannel = void 0;
289
- if (_DiagnosticsChannel.supported) {
290
- this._serveChannel = new BroadcastChannel(_channelName);
291
- this._clientChannel = new BroadcastChannel(_channelName);
292
- }
293
- }
294
263
  };
295
264
 
296
265
  // src/remote/metrics.ts
297
- function _define_property3(obj, key, value) {
298
- if (key in obj) {
299
- Object.defineProperty(obj, key, {
300
- value,
301
- enumerable: true,
302
- configurable: true,
303
- writable: true
304
- });
305
- } else {
306
- obj[key] = value;
307
- }
308
- return obj;
309
- }
310
266
  var RemoteMetrics = class {
267
+ _metrics = /* @__PURE__ */ new Set();
311
268
  registerProcessor(processor) {
312
269
  this._metrics.add(processor);
313
270
  }
@@ -323,26 +280,12 @@ var RemoteMetrics = class {
323
280
  gauge(name, value, data) {
324
281
  return Array.from(this._metrics.values()).map((processor) => processor.gauge(name, value, data));
325
282
  }
326
- constructor() {
327
- _define_property3(this, "_metrics", /* @__PURE__ */ new Set());
328
- }
329
283
  };
330
284
 
331
285
  // src/remote/tracing.ts
332
- function _define_property4(obj, key, value) {
333
- if (key in obj) {
334
- Object.defineProperty(obj, key, {
335
- value,
336
- enumerable: true,
337
- configurable: true,
338
- writable: true
339
- });
340
- } else {
341
- obj[key] = value;
342
- }
343
- return obj;
344
- }
345
286
  var RemoteTracing = class {
287
+ _tracing;
288
+ _spanMap = /* @__PURE__ */ new Map();
346
289
  registerProcessor(processor) {
347
290
  this._tracing = processor;
348
291
  }
@@ -365,28 +308,15 @@ var RemoteTracing = class {
365
308
  }
366
309
  }
367
310
  }
368
- constructor() {
369
- _define_property4(this, "_tracing", void 0);
370
- _define_property4(this, "_spanMap", /* @__PURE__ */ new Map());
371
- }
372
311
  };
373
312
 
374
313
  // src/trace-sender.ts
375
314
  import { Stream } from "@dxos/codec-protobuf/stream";
376
- function _define_property5(obj, key, value) {
377
- if (key in obj) {
378
- Object.defineProperty(obj, key, {
379
- value,
380
- enumerable: true,
381
- configurable: true,
382
- writable: true
383
- });
384
- } else {
385
- obj[key] = value;
386
- }
387
- return obj;
388
- }
389
315
  var TraceSender = class {
316
+ _traceProcessor;
317
+ constructor(_traceProcessor) {
318
+ this._traceProcessor = _traceProcessor;
319
+ }
390
320
  streamTrace(request) {
391
321
  return new Stream(({ ctx, next }) => {
392
322
  const flushEvents = (resources, spans2, logs) => {
@@ -468,53 +398,40 @@ var TraceSender = class {
468
398
  flushEvents(null, null, null);
469
399
  });
470
400
  }
471
- constructor(_traceProcessor) {
472
- _define_property5(this, "_traceProcessor", void 0);
473
- this._traceProcessor = _traceProcessor;
474
- }
475
401
  };
476
402
 
477
403
  // src/weak-ref.ts
478
404
  var WeakRefMock = class {
479
- deref() {
480
- return void 0;
481
- }
482
405
  // eslint-disable-next-line @typescript-eslint/no-useless-constructor
483
406
  constructor(target) {
484
407
  }
408
+ deref() {
409
+ return void 0;
410
+ }
485
411
  };
486
412
  var WeakRef = globalThis.WeakRef ?? WeakRefMock;
487
413
 
488
414
  // src/trace-processor.ts
489
- function _define_property6(obj, key, value) {
490
- if (key in obj) {
491
- Object.defineProperty(obj, key, {
492
- value,
493
- enumerable: true,
494
- configurable: true,
495
- writable: true
496
- });
497
- } else {
498
- obj[key] = value;
499
- }
500
- return obj;
501
- }
502
- var _globalThis;
503
415
  var __dxlog_file3 = "/__w/dxos/dxos/packages/common/tracing/src/trace-processor.ts";
504
416
  var ResourceEntry = class {
505
- getMetric(name) {
506
- return this.data.metrics?.find((metric) => metric.name === name);
507
- }
417
+ data;
418
+ instance;
419
+ annotation;
420
+ /**
421
+ * Sometimes bundlers mangle class names: WebFile -> WebFile2.
422
+ *
423
+ * We use a heuristic to remove the suffix.
424
+ */
425
+ sanitizedClassName;
508
426
  constructor(data, instance, annotation) {
509
- _define_property6(this, "data", void 0);
510
- _define_property6(this, "instance", void 0);
511
- _define_property6(this, "annotation", void 0);
512
- _define_property6(this, "sanitizedClassName", void 0);
513
427
  this.data = data;
514
428
  this.instance = instance;
515
429
  this.annotation = annotation;
516
430
  this.sanitizedClassName = sanitizeClassName(data.className);
517
431
  }
432
+ getMetric(name) {
433
+ return this.data.metrics?.find((metric) => metric.name === name);
434
+ }
518
435
  };
519
436
  var MAX_RESOURCE_RECORDS = 2e3;
520
437
  var MAX_SPAN_RECORDS = 1e3;
@@ -523,6 +440,34 @@ var REFRESH_INTERVAL = 1e3;
523
440
  var MAX_INFO_OBJECT_DEPTH = 8;
524
441
  var IS_CLOUDFLARE_WORKERS = !!globalThis?.navigator?.userAgent?.includes("Cloudflare-Workers");
525
442
  var TraceProcessor = class {
443
+ diagnostics = new DiagnosticsManager();
444
+ diagnosticsChannel = new DiagnosticsChannel();
445
+ remoteMetrics = new RemoteMetrics();
446
+ remoteTracing = new RemoteTracing();
447
+ subscriptions = /* @__PURE__ */ new Set();
448
+ resources = /* @__PURE__ */ new Map();
449
+ resourceInstanceIndex = /* @__PURE__ */ new WeakMap();
450
+ resourceIdList = [];
451
+ spans = /* @__PURE__ */ new Map();
452
+ spanIdList = [];
453
+ logs = [];
454
+ _instanceTag = null;
455
+ constructor() {
456
+ log.addProcessor(this._logProcessor.bind(this), void 0, {
457
+ F: __dxlog_file3,
458
+ L: 103,
459
+ S: this,
460
+ C: (f, a) => f(...a)
461
+ });
462
+ if (!IS_CLOUDFLARE_WORKERS) {
463
+ const refreshInterval = setInterval(this.refresh.bind(this), REFRESH_INTERVAL);
464
+ unrefTimeout(refreshInterval);
465
+ }
466
+ if (DiagnosticsChannel.supported) {
467
+ this.diagnosticsChannel.serve(this.diagnostics);
468
+ }
469
+ this.diagnosticsChannel.unref();
470
+ }
526
471
  setInstanceTag(tag) {
527
472
  this._instanceTag = tag;
528
473
  this.diagnostics.setInstanceTag(tag);
@@ -634,10 +579,10 @@ var TraceProcessor = class {
634
579
  let _changed = false;
635
580
  const oldInfo = resource2.data.info;
636
581
  resource2.data.info = this.getResourceInfo(instance);
637
- _changed || (_changed = !areEqualShallow(oldInfo, resource2.data.info));
582
+ _changed ||= !areEqualShallow(oldInfo, resource2.data.info);
638
583
  const oldMetrics = resource2.data.metrics;
639
584
  resource2.data.metrics = this.getResourceMetrics(instance);
640
- _changed || (_changed = !areEqualShallow(oldMetrics, resource2.data.metrics));
585
+ _changed ||= !areEqualShallow(oldMetrics, resource2.data.metrics);
641
586
  this._markResourceDirty(resource2.data.id);
642
587
  }
643
588
  for (const subscription of this.subscriptions) {
@@ -691,67 +636,73 @@ var TraceProcessor = class {
691
636
  subscription.newLogs.push(log2);
692
637
  }
693
638
  }
694
- constructor() {
695
- _define_property6(this, "diagnostics", new DiagnosticsManager());
696
- _define_property6(this, "diagnosticsChannel", new DiagnosticsChannel());
697
- _define_property6(this, "remoteMetrics", new RemoteMetrics());
698
- _define_property6(this, "remoteTracing", new RemoteTracing());
699
- _define_property6(this, "subscriptions", /* @__PURE__ */ new Set());
700
- _define_property6(this, "resources", /* @__PURE__ */ new Map());
701
- _define_property6(this, "resourceInstanceIndex", /* @__PURE__ */ new WeakMap());
702
- _define_property6(this, "resourceIdList", []);
703
- _define_property6(this, "spans", /* @__PURE__ */ new Map());
704
- _define_property6(this, "spanIdList", []);
705
- _define_property6(this, "logs", []);
706
- _define_property6(this, "_instanceTag", null);
707
- _define_property6(this, "_logProcessor", (config, entry) => {
708
- switch (entry.level) {
709
- case LogLevel.ERROR:
710
- case LogLevel.WARN:
711
- case LogLevel.TRACE: {
712
- const scope = entry.meta?.S;
713
- const resource2 = this.resourceInstanceIndex.get(scope);
714
- if (!resource2) {
715
- return;
716
- }
717
- const context = getContextFromEntry(entry) ?? {};
718
- for (const key of Object.keys(context)) {
719
- context[key] = sanitizeValue(context[key], 0, this);
720
- }
721
- const entryToPush = {
722
- level: entry.level,
723
- message: entry.message ?? (entry.error ? entry.error.message ?? String(entry.error) : ""),
724
- context,
725
- timestamp: /* @__PURE__ */ new Date(),
726
- meta: {
727
- file: entry.meta?.F ?? "",
728
- line: entry.meta?.L ?? 0,
729
- resourceId: resource2.data.id
730
- }
731
- };
732
- this._pushLog(entryToPush);
733
- break;
639
+ _logProcessor = (config, entry) => {
640
+ switch (entry.level) {
641
+ case LogLevel.ERROR:
642
+ case LogLevel.WARN:
643
+ case LogLevel.TRACE: {
644
+ const scope = entry.meta?.S;
645
+ const resource2 = this.resourceInstanceIndex.get(scope);
646
+ if (!resource2) {
647
+ return;
648
+ }
649
+ const context = getContextFromEntry(entry) ?? {};
650
+ for (const key of Object.keys(context)) {
651
+ context[key] = sanitizeValue(context[key], 0, this);
734
652
  }
735
- default:
653
+ const entryToPush = {
654
+ level: entry.level,
655
+ message: entry.message ?? (entry.error ? entry.error.message ?? String(entry.error) : ""),
656
+ context,
657
+ timestamp: /* @__PURE__ */ new Date(),
658
+ meta: {
659
+ file: entry.meta?.F ?? "",
660
+ line: entry.meta?.L ?? 0,
661
+ resourceId: resource2.data.id
662
+ }
663
+ };
664
+ this._pushLog(entryToPush);
665
+ break;
736
666
  }
737
- });
738
- log.addProcessor(this._logProcessor.bind(this), void 0, {
739
- F: __dxlog_file3,
740
- L: 103,
741
- S: this,
742
- C: (f, a) => f(...a)
743
- });
744
- if (!IS_CLOUDFLARE_WORKERS) {
745
- const refreshInterval = setInterval(this.refresh.bind(this), REFRESH_INTERVAL);
746
- unrefTimeout(refreshInterval);
667
+ default:
747
668
  }
748
- if (DiagnosticsChannel.supported) {
749
- this.diagnosticsChannel.serve(this.diagnostics);
750
- }
751
- this.diagnosticsChannel.unref();
752
- }
669
+ };
753
670
  };
754
671
  var TracingSpan = class _TracingSpan {
672
+ _traceProcessor;
673
+ static nextId = 0;
674
+ id;
675
+ parentId = null;
676
+ methodName;
677
+ resourceId = null;
678
+ op;
679
+ attributes;
680
+ startTs;
681
+ endTs = null;
682
+ error = null;
683
+ _showInBrowserTimeline;
684
+ _ctx = null;
685
+ constructor(_traceProcessor, params) {
686
+ this._traceProcessor = _traceProcessor;
687
+ this.id = _TracingSpan.nextId++;
688
+ this.methodName = params.methodName;
689
+ this.resourceId = _traceProcessor.getResourceId(params.instance);
690
+ this.startTs = performance.now();
691
+ this._showInBrowserTimeline = params.showInBrowserTimeline;
692
+ this.op = params.op;
693
+ this.attributes = params.attributes ?? {};
694
+ if (params.parentCtx) {
695
+ this._ctx = params.parentCtx.derive({
696
+ attributes: {
697
+ [TRACE_SPAN_ATTRIBUTE]: this.id
698
+ }
699
+ });
700
+ const parentId = params.parentCtx.getAttribute(TRACE_SPAN_ATTRIBUTE);
701
+ if (typeof parentId === "number") {
702
+ this.parentId = parentId;
703
+ }
704
+ }
705
+ }
755
706
  get name() {
756
707
  const resource2 = this._traceProcessor.resources.get(this.resourceId);
757
708
  return resource2 ? `${resource2.sanitizedClassName}#${resource2.data.instanceId}.${this.methodName}` : this.methodName;
@@ -793,46 +744,7 @@ var TracingSpan = class _TracingSpan {
793
744
  });
794
745
  }
795
746
  }
796
- constructor(_traceProcessor, params) {
797
- _define_property6(this, "_traceProcessor", void 0);
798
- _define_property6(this, "id", void 0);
799
- _define_property6(this, "parentId", void 0);
800
- _define_property6(this, "methodName", void 0);
801
- _define_property6(this, "resourceId", void 0);
802
- _define_property6(this, "op", void 0);
803
- _define_property6(this, "attributes", void 0);
804
- _define_property6(this, "startTs", void 0);
805
- _define_property6(this, "endTs", void 0);
806
- _define_property6(this, "error", void 0);
807
- _define_property6(this, "_showInBrowserTimeline", void 0);
808
- _define_property6(this, "_ctx", void 0);
809
- this._traceProcessor = _traceProcessor;
810
- this.parentId = null;
811
- this.resourceId = null;
812
- this.endTs = null;
813
- this.error = null;
814
- this._ctx = null;
815
- this.id = _TracingSpan.nextId++;
816
- this.methodName = params.methodName;
817
- this.resourceId = _traceProcessor.getResourceId(params.instance);
818
- this.startTs = performance.now();
819
- this._showInBrowserTimeline = params.showInBrowserTimeline;
820
- this.op = params.op;
821
- this.attributes = params.attributes ?? {};
822
- if (params.parentCtx) {
823
- this._ctx = params.parentCtx.derive({
824
- attributes: {
825
- [TRACE_SPAN_ATTRIBUTE]: this.id
826
- }
827
- });
828
- const parentId = params.parentCtx.getAttribute(TRACE_SPAN_ATTRIBUTE);
829
- if (typeof parentId === "number") {
830
- this.parentId = parentId;
831
- }
832
- }
833
- }
834
747
  };
835
- _define_property6(TracingSpan, "nextId", 0);
836
748
  var serializeError = (err) => {
837
749
  if (err instanceof Error) {
838
750
  return {
@@ -844,7 +756,7 @@ var serializeError = (err) => {
844
756
  message: String(err)
845
757
  };
846
758
  };
847
- var TRACE_PROCESSOR = (_globalThis = globalThis).TRACE_PROCESSOR ?? (_globalThis.TRACE_PROCESSOR = new TraceProcessor());
759
+ var TRACE_PROCESSOR = globalThis.TRACE_PROCESSOR ??= new TraceProcessor();
848
760
  var sanitizeValue = (value, depth, traceProcessor) => {
849
761
  switch (typeof value) {
850
762
  case "string":
@@ -917,18 +829,15 @@ var isMapLike = (value) => value instanceof Map || typeof value === "object" &&
917
829
 
918
830
  // src/api.ts
919
831
  var resource = (options) => (constructor) => {
920
- const klass = /* @__PURE__ */ (() => {
921
- class _class extends constructor {
922
- constructor(...rest) {
923
- super(...rest);
924
- TRACE_PROCESSOR.createTraceResource({
925
- constructor,
926
- annotation: options?.annotation,
927
- instance: this
928
- });
929
- }
832
+ const klass = /* @__PURE__ */ (() => class extends constructor {
833
+ constructor(...rest) {
834
+ super(...rest);
835
+ TRACE_PROCESSOR.createTraceResource({
836
+ constructor,
837
+ annotation: options?.annotation,
838
+ instance: this
839
+ });
930
840
  }
931
- return _class;
932
841
  })();
933
842
  Object.defineProperty(klass, "name", {
934
843
  value: constructor.name
@@ -1007,20 +916,12 @@ var trace = {
1007
916
  };
1008
917
 
1009
918
  // src/metrics/base.ts
1010
- function _define_property7(obj, key, value) {
1011
- if (key in obj) {
1012
- Object.defineProperty(obj, key, {
1013
- value,
1014
- enumerable: true,
1015
- configurable: true,
1016
- writable: true
1017
- });
1018
- } else {
1019
- obj[key] = value;
1020
- }
1021
- return obj;
1022
- }
1023
919
  var BaseCounter = class {
920
+ /**
921
+ * @internal
922
+ */
923
+ _instance;
924
+ name;
1024
925
  /**
1025
926
  * @internal
1026
927
  */
@@ -1030,27 +931,16 @@ var BaseCounter = class {
1030
931
  }
1031
932
  _tick(time) {
1032
933
  }
1033
- constructor() {
1034
- _define_property7(this, "_instance", void 0);
1035
- _define_property7(this, "name", void 0);
1036
- }
1037
934
  };
1038
935
 
1039
936
  // src/metrics/unary-counter.ts
1040
- function _define_property8(obj, key, value) {
1041
- if (key in obj) {
1042
- Object.defineProperty(obj, key, {
1043
- value,
1044
- enumerable: true,
1045
- configurable: true,
1046
- writable: true
1047
- });
1048
- } else {
1049
- obj[key] = value;
1050
- }
1051
- return obj;
1052
- }
1053
937
  var UnaryCounter = class extends BaseCounter {
938
+ value = 0;
939
+ units;
940
+ constructor({ units } = {}) {
941
+ super();
942
+ this.units = units;
943
+ }
1054
944
  inc(by = 1) {
1055
945
  this.value += by;
1056
946
  }
@@ -1063,28 +953,19 @@ var UnaryCounter = class extends BaseCounter {
1063
953
  }
1064
954
  };
1065
955
  }
1066
- constructor({ units } = {}) {
1067
- super(), _define_property8(this, "value", 0), _define_property8(this, "units", void 0);
1068
- this.units = units;
1069
- }
1070
956
  };
1071
957
 
1072
958
  // src/metrics/time-series-counter.ts
1073
- function _define_property9(obj, key, value) {
1074
- if (key in obj) {
1075
- Object.defineProperty(obj, key, {
1076
- value,
1077
- enumerable: true,
1078
- configurable: true,
1079
- writable: true
1080
- });
1081
- } else {
1082
- obj[key] = value;
1083
- }
1084
- return obj;
1085
- }
1086
959
  var MAX_BUCKETS = 60;
1087
960
  var TimeSeriesCounter = class extends BaseCounter {
961
+ _currentValue = 0;
962
+ _totalValue = 0;
963
+ _buckets = [];
964
+ units;
965
+ constructor({ units } = {}) {
966
+ super();
967
+ this.units = units;
968
+ }
1088
969
  inc(by = 1) {
1089
970
  this._currentValue += by;
1090
971
  this._totalValue += by;
@@ -1113,28 +994,15 @@ var TimeSeriesCounter = class extends BaseCounter {
1113
994
  }
1114
995
  };
1115
996
  }
1116
- constructor({ units } = {}) {
1117
- super(), _define_property9(this, "_currentValue", 0), _define_property9(this, "_totalValue", 0), _define_property9(this, "_buckets", []), _define_property9(this, "units", void 0);
1118
- this.units = units;
1119
- }
1120
997
  };
1121
998
 
1122
999
  // src/metrics/time-usage-counter.ts
1123
- function _define_property10(obj, key, value) {
1124
- if (key in obj) {
1125
- Object.defineProperty(obj, key, {
1126
- value,
1127
- enumerable: true,
1128
- configurable: true,
1129
- writable: true
1130
- });
1131
- } else {
1132
- obj[key] = value;
1133
- }
1134
- return obj;
1135
- }
1136
1000
  var MAX_BUCKETS2 = 60;
1137
1001
  var TimeUsageCounter = class extends BaseCounter {
1002
+ _currentValue = 0;
1003
+ _totalValue = 0;
1004
+ _buckets = [];
1005
+ _lastTickTime = performance.now();
1138
1006
  record(time) {
1139
1007
  this._currentValue += time;
1140
1008
  this._totalValue += time;
@@ -1175,26 +1043,16 @@ var TimeUsageCounter = class extends BaseCounter {
1175
1043
  }
1176
1044
  };
1177
1045
  }
1178
- constructor(...args) {
1179
- super(...args), _define_property10(this, "_currentValue", 0), _define_property10(this, "_totalValue", 0), _define_property10(this, "_buckets", []), _define_property10(this, "_lastTickTime", performance.now());
1180
- }
1181
1046
  };
1182
1047
 
1183
1048
  // src/metrics/map-counter.ts
1184
- function _define_property11(obj, key, value) {
1185
- if (key in obj) {
1186
- Object.defineProperty(obj, key, {
1187
- value,
1188
- enumerable: true,
1189
- configurable: true,
1190
- writable: true
1191
- });
1192
- } else {
1193
- obj[key] = value;
1194
- }
1195
- return obj;
1196
- }
1197
1049
  var MapCounter = class extends BaseCounter {
1050
+ values = /* @__PURE__ */ new Map();
1051
+ units;
1052
+ constructor({ units } = {}) {
1053
+ super();
1054
+ this.units = units;
1055
+ }
1198
1056
  inc(key, by = 1) {
1199
1057
  const prev = this.values.get(key) ?? 0;
1200
1058
  this.values.set(key, prev + by);
@@ -1211,27 +1069,14 @@ var MapCounter = class extends BaseCounter {
1211
1069
  }
1212
1070
  };
1213
1071
  }
1214
- constructor({ units } = {}) {
1215
- super(), _define_property11(this, "values", /* @__PURE__ */ new Map()), _define_property11(this, "units", void 0);
1216
- this.units = units;
1217
- }
1218
1072
  };
1219
1073
 
1220
1074
  // src/metrics/custom-counter.ts
1221
- function _define_property12(obj, key, value) {
1222
- if (key in obj) {
1223
- Object.defineProperty(obj, key, {
1224
- value,
1225
- enumerable: true,
1226
- configurable: true,
1227
- writable: true
1228
- });
1229
- } else {
1230
- obj[key] = value;
1231
- }
1232
- return obj;
1233
- }
1234
1075
  var CustomCounter = class extends BaseCounter {
1076
+ _getData;
1077
+ constructor(_getData) {
1078
+ super(), this._getData = _getData;
1079
+ }
1235
1080
  getData() {
1236
1081
  return {
1237
1082
  name: this.name,
@@ -1240,9 +1085,6 @@ var CustomCounter = class extends BaseCounter {
1240
1085
  }
1241
1086
  };
1242
1087
  }
1243
- constructor(_getData) {
1244
- super(), _define_property12(this, "_getData", void 0), this._getData = _getData;
1245
- }
1246
1088
  };
1247
1089
 
1248
1090
  // src/index.ts