@dxos/tracing 0.8.4-main.406dc2a → 0.8.4-main.422d1c7879

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 (39) hide show
  1. package/dist/lib/browser/index.mjs +451 -620
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +451 -620
  5. package/dist/lib/node-esm/index.mjs.map +4 -4
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/api.d.ts +36 -17
  8. package/dist/types/src/api.d.ts.map +1 -1
  9. package/dist/types/src/buffering-backend.d.ts +24 -0
  10. package/dist/types/src/buffering-backend.d.ts.map +1 -0
  11. package/dist/types/src/diagnostic.d.ts +2 -2
  12. package/dist/types/src/diagnostic.d.ts.map +1 -1
  13. package/dist/types/src/index.d.ts +1 -2
  14. package/dist/types/src/index.d.ts.map +1 -1
  15. package/dist/types/src/remote/index.d.ts +0 -1
  16. package/dist/types/src/remote/index.d.ts.map +1 -1
  17. package/dist/types/src/symbols.d.ts +0 -1
  18. package/dist/types/src/symbols.d.ts.map +1 -1
  19. package/dist/types/src/trace-processor.d.ts +16 -52
  20. package/dist/types/src/trace-processor.d.ts.map +1 -1
  21. package/dist/types/src/tracing-types.d.ts +67 -0
  22. package/dist/types/src/tracing-types.d.ts.map +1 -0
  23. package/dist/types/tsconfig.tsbuildinfo +1 -1
  24. package/package.json +13 -12
  25. package/src/api.ts +237 -35
  26. package/src/buffering-backend.ts +112 -0
  27. package/src/diagnostic.ts +2 -2
  28. package/src/index.ts +1 -2
  29. package/src/remote/index.ts +0 -1
  30. package/src/symbols.ts +0 -2
  31. package/src/trace-processor.ts +58 -258
  32. package/src/tracing-types.ts +77 -0
  33. package/src/tracing.test.ts +513 -4
  34. package/dist/types/src/remote/tracing.d.ts +0 -23
  35. package/dist/types/src/remote/tracing.d.ts.map +0 -1
  36. package/dist/types/src/trace-sender.d.ts +0 -9
  37. package/dist/types/src/trace-sender.d.ts.map +0 -1
  38. package/src/remote/tracing.ts +0 -53
  39. package/src/trace-sender.ts +0 -88
@@ -1,22 +1,105 @@
1
1
  // src/api.ts
2
- import { Context as Context2 } from "@dxos/context";
2
+ import { Context as Context2, LifecycleState, Resource, TRACE_SPAN_ATTRIBUTE } from "@dxos/context";
3
3
 
4
4
  // src/symbols.ts
5
- var symbolTracingContext = Symbol("dxos.tracing.context");
5
+ var symbolTracingContext = /* @__PURE__ */ 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
- var TRACE_SPAN_ATTRIBUTE = "dxos.trace-span";
14
12
 
15
13
  // src/trace-processor.ts
16
- import { unrefTimeout } from "@dxos/async";
17
- import { LogLevel, getContextFromEntry, log } from "@dxos/log";
14
+ import { LogLevel, log } from "@dxos/log";
18
15
  import { getPrototypeSpecificInstanceId } from "@dxos/util";
19
16
 
17
+ // src/buffering-backend.ts
18
+ var BUFFERED_PREFIX = "buffered-";
19
+ var BufferedSpan = class {
20
+ options;
21
+ spanContext;
22
+ startTime;
23
+ delegate;
24
+ #ended = false;
25
+ #endTime;
26
+ #error;
27
+ #hasError = false;
28
+ constructor(options, id) {
29
+ this.options = options;
30
+ this.spanContext = {
31
+ traceparent: `${BUFFERED_PREFIX}${id}`
32
+ };
33
+ this.startTime = Date.now();
34
+ }
35
+ end(endTime) {
36
+ if (this.delegate) {
37
+ this.delegate.end(endTime);
38
+ return;
39
+ }
40
+ this.#endTime = endTime ?? Date.now();
41
+ this.#ended = true;
42
+ }
43
+ setError(err) {
44
+ if (this.delegate) {
45
+ this.delegate.setError?.(err);
46
+ return;
47
+ }
48
+ this.#error = err;
49
+ this.#hasError = true;
50
+ }
51
+ replay(real) {
52
+ if (this.#hasError) {
53
+ real.setError?.(this.#error);
54
+ }
55
+ if (this.#ended) {
56
+ real.end(this.#endTime);
57
+ } else {
58
+ this.delegate = real;
59
+ }
60
+ }
61
+ };
62
+ var BufferingTracingBackend = class {
63
+ #pending = [];
64
+ #counter = 0;
65
+ startSpan(options) {
66
+ const span2 = new BufferedSpan(options, ++this.#counter);
67
+ this.#pending.push(span2);
68
+ return span2;
69
+ }
70
+ /** Discard all buffered spans without replaying them. */
71
+ clear() {
72
+ this.#pending.length = 0;
73
+ }
74
+ /**
75
+ * Replay all buffered spans into {@link backend}.
76
+ *
77
+ * @returns Map from synthetic buffered traceparent to real {@link TraceContextData},
78
+ * used by the post-drain translating wrapper to resolve stale buffered IDs
79
+ * still present on in-flight {@link Context} objects.
80
+ */
81
+ drain(backend) {
82
+ const idMap = /* @__PURE__ */ new Map();
83
+ for (const buffered of this.#pending) {
84
+ let parentContext = buffered.options.parentContext;
85
+ if (parentContext && parentContext.traceparent.startsWith(BUFFERED_PREFIX)) {
86
+ parentContext = idMap.get(parentContext.traceparent) ?? parentContext;
87
+ }
88
+ const real = backend.startSpan({
89
+ ...buffered.options,
90
+ parentContext,
91
+ startTime: buffered.startTime
92
+ });
93
+ if (real.spanContext) {
94
+ idMap.set(buffered.spanContext.traceparent, real.spanContext);
95
+ }
96
+ buffered.replay(real);
97
+ }
98
+ this.#pending.length = 0;
99
+ return idMap;
100
+ }
101
+ };
102
+
20
103
  // src/diagnostic.ts
21
104
  import { asyncTimeout } from "@dxos/async";
22
105
  import { invariant } from "@dxos/invariant";
@@ -25,37 +108,27 @@ import { invariant } from "@dxos/invariant";
25
108
  var createId = () => Math.random().toString(36).slice(2);
26
109
 
27
110
  // 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
111
  var __dxlog_file = "/__w/dxos/dxos/packages/common/tracing/src/diagnostic.ts";
42
112
  var DIAGNOSTICS_TIMEOUT = 1e4;
43
113
  var TraceDiagnosticImpl = class {
44
- unregister() {
45
- this._onUnregister();
46
- }
114
+ id;
115
+ fetch;
116
+ name;
117
+ _onUnregister;
47
118
  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
119
  this.id = id;
53
120
  this.fetch = fetch;
54
121
  this.name = name;
55
122
  this._onUnregister = _onUnregister;
56
123
  }
124
+ unregister() {
125
+ this._onUnregister();
126
+ }
57
127
  };
58
128
  var DiagnosticsManager = class {
129
+ instanceId = createId();
130
+ registry = /* @__PURE__ */ new Map();
131
+ _instanceTag = null;
59
132
  get instanceTag() {
60
133
  return this._instanceTag;
61
134
  }
@@ -118,37 +191,34 @@ var DiagnosticsManager = class {
118
191
  };
119
192
  }
120
193
  }
121
- constructor() {
122
- _define_property(this, "instanceId", createId());
123
- _define_property(this, "registry", /* @__PURE__ */ new Map());
124
- _define_property(this, "_instanceTag", null);
125
- }
126
194
  };
127
195
 
128
196
  // src/diagnostics-channel.ts
129
197
  import { Trigger, sleep } from "@dxos/async";
130
198
  import { Context } from "@dxos/context";
131
199
  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
200
  var __dxlog_file2 = "/__w/dxos/dxos/packages/common/tracing/src/diagnostics-channel.ts";
146
201
  var DEFAULT_CHANNEL_NAME = "dxos-diagnostics";
147
202
  var DISCOVER_TIME = 500;
148
203
  var DiagnosticsChannel = class _DiagnosticsChannel {
204
+ _channelName;
149
205
  static get supported() {
150
206
  return globalThis.BroadcastChannel != null;
151
207
  }
208
+ _ctx = new Context(void 0, {
209
+ F: __dxlog_file2,
210
+ L: 46
211
+ });
212
+ // Separate channels becauase the client and server may be in the same process.
213
+ _serveChannel = void 0;
214
+ _clientChannel = void 0;
215
+ constructor(_channelName = DEFAULT_CHANNEL_NAME) {
216
+ this._channelName = _channelName;
217
+ if (_DiagnosticsChannel.supported) {
218
+ this._serveChannel = new BroadcastChannel(_channelName);
219
+ this._clientChannel = new BroadcastChannel(_channelName);
220
+ }
221
+ }
152
222
  destroy() {
153
223
  void this._ctx.dispose();
154
224
  this._serveChannel?.close();
@@ -274,40 +344,11 @@ var DiagnosticsChannel = class _DiagnosticsChannel {
274
344
  this._clientChannel.removeEventListener("message", listener);
275
345
  }
276
346
  }
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
347
  };
295
348
 
296
349
  // 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
350
  var RemoteMetrics = class {
351
+ _metrics = /* @__PURE__ */ new Set();
311
352
  registerProcessor(processor) {
312
353
  this._metrics.add(processor);
313
354
  }
@@ -323,214 +364,107 @@ var RemoteMetrics = class {
323
364
  gauge(name, value, data) {
324
365
  return Array.from(this._metrics.values()).map((processor) => processor.gauge(name, value, data));
325
366
  }
326
- constructor() {
327
- _define_property3(this, "_metrics", /* @__PURE__ */ new Set());
328
- }
329
- };
330
-
331
- // 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
- var RemoteTracing = class {
346
- registerProcessor(processor) {
347
- this._tracing = processor;
348
- }
349
- flushSpan(span2) {
350
- if (!this._tracing) {
351
- return;
352
- }
353
- if (!span2.endTs) {
354
- const remoteSpan = this._tracing.startSpan({
355
- name: span2.methodName,
356
- op: span2.op ?? "function",
357
- attributes: span2.attributes
358
- });
359
- this._spanMap.set(span2, remoteSpan);
360
- } else {
361
- const remoteSpan = this._spanMap.get(span2);
362
- if (remoteSpan) {
363
- remoteSpan.end();
364
- this._spanMap.delete(span2);
365
- }
366
- }
367
- }
368
- constructor() {
369
- _define_property4(this, "_tracing", void 0);
370
- _define_property4(this, "_spanMap", /* @__PURE__ */ new Map());
371
- }
372
- };
373
-
374
- // src/trace-sender.ts
375
- 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
- var TraceSender = class {
390
- streamTrace(request) {
391
- return new Stream(({ ctx, next }) => {
392
- const flushEvents = (resources, spans2, logs) => {
393
- const event = {
394
- resourceAdded: [],
395
- resourceRemoved: [],
396
- spanAdded: [],
397
- logAdded: []
398
- };
399
- if (resources) {
400
- for (const id of resources) {
401
- const entry = this._traceProcessor.resources.get(id);
402
- if (entry) {
403
- event.resourceAdded.push({
404
- resource: entry.data
405
- });
406
- } else {
407
- event.resourceRemoved.push({
408
- id
409
- });
410
- }
411
- }
412
- } else {
413
- for (const entry of this._traceProcessor.resources.values()) {
414
- event.resourceAdded.push({
415
- resource: entry.data
416
- });
417
- }
418
- }
419
- if (spans2) {
420
- for (const id of spans2) {
421
- const span2 = this._traceProcessor.spans.get(id);
422
- if (span2) {
423
- event.spanAdded.push({
424
- span: span2
425
- });
426
- }
427
- }
428
- } else {
429
- for (const span2 of this._traceProcessor.spans.values()) {
430
- event.spanAdded.push({
431
- span: span2
432
- });
433
- }
434
- }
435
- if (logs) {
436
- for (const log2 of logs) {
437
- event.logAdded.push({
438
- log: log2
439
- });
440
- }
441
- } else {
442
- for (const log2 of this._traceProcessor.logs) {
443
- event.logAdded.push({
444
- log: log2
445
- });
446
- }
447
- }
448
- if (event.resourceAdded.length > 0 || event.resourceRemoved.length > 0 || event.spanAdded.length > 0) {
449
- next(event);
450
- }
451
- };
452
- const flush = () => {
453
- flushEvents(subscription.dirtyResources, subscription.dirtySpans, subscription.newLogs);
454
- subscription.dirtyResources.clear();
455
- subscription.dirtySpans.clear();
456
- subscription.newLogs.length = 0;
457
- };
458
- const subscription = {
459
- flush,
460
- dirtyResources: /* @__PURE__ */ new Set(),
461
- dirtySpans: /* @__PURE__ */ new Set(),
462
- newLogs: []
463
- };
464
- this._traceProcessor.subscriptions.add(subscription);
465
- ctx.onDispose(() => {
466
- this._traceProcessor.subscriptions.delete(subscription);
467
- });
468
- flushEvents(null, null, null);
469
- });
470
- }
471
- constructor(_traceProcessor) {
472
- _define_property5(this, "_traceProcessor", void 0);
473
- this._traceProcessor = _traceProcessor;
474
- }
475
367
  };
476
368
 
477
369
  // src/weak-ref.ts
478
370
  var WeakRefMock = class {
479
- deref() {
480
- return void 0;
481
- }
482
371
  // eslint-disable-next-line @typescript-eslint/no-useless-constructor
483
372
  constructor(target) {
484
373
  }
374
+ deref() {
375
+ return void 0;
376
+ }
485
377
  };
486
378
  var WeakRef = globalThis.WeakRef ?? WeakRefMock;
487
379
 
488
380
  // 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
381
  var __dxlog_file3 = "/__w/dxos/dxos/packages/common/tracing/src/trace-processor.ts";
504
382
  var ResourceEntry = class {
505
- getMetric(name) {
506
- return this.data.metrics?.find((metric) => metric.name === name);
507
- }
383
+ data;
384
+ instance;
385
+ annotation;
386
+ /**
387
+ * Sometimes bundlers mangle class names: WebFile -> WebFile2.
388
+ *
389
+ * We use a heuristic to remove the suffix.
390
+ */
391
+ sanitizedClassName;
508
392
  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
393
  this.data = data;
514
394
  this.instance = instance;
515
395
  this.annotation = annotation;
516
396
  this.sanitizedClassName = sanitizeClassName(data.className);
517
397
  }
398
+ getMetric(name) {
399
+ return this.data.metrics?.find((metric) => metric.name === name);
400
+ }
518
401
  };
519
402
  var MAX_RESOURCE_RECORDS = 2e3;
520
- var MAX_SPAN_RECORDS = 1e3;
521
403
  var MAX_LOG_RECORDS = 1e3;
522
- var REFRESH_INTERVAL = 1e3;
523
404
  var MAX_INFO_OBJECT_DEPTH = 8;
524
- var IS_CLOUDFLARE_WORKERS = !!globalThis?.navigator?.userAgent?.includes("Cloudflare-Workers");
525
405
  var TraceProcessor = class {
406
+ diagnostics = new DiagnosticsManager();
407
+ diagnosticsChannel = new DiagnosticsChannel();
408
+ remoteMetrics = new RemoteMetrics();
409
+ #bufferingBackend = new BufferingTracingBackend();
410
+ #activeBackend = this.#bufferingBackend;
411
+ /**
412
+ * Tracing backend. Initially a buffering backend that records spans;
413
+ * once the observability package sets a real backend, the buffer is drained
414
+ * and a thin translating wrapper is installed that resolves stale buffered
415
+ * parent IDs still held by in-flight {@link Context} objects.
416
+ *
417
+ * The wrapper only allocates when a `buffered-*` parent is actually encountered;
418
+ * the common path is a single `startsWith` check and direct passthrough.
419
+ */
420
+ get tracingBackend() {
421
+ return this.#activeBackend;
422
+ }
423
+ set tracingBackend(backend) {
424
+ if (!backend || backend === this.#bufferingBackend) {
425
+ this.#bufferingBackend.clear();
426
+ this.#activeBackend = this.#bufferingBackend;
427
+ return;
428
+ }
429
+ const idMap = this.#bufferingBackend.drain(backend);
430
+ this.#activeBackend = {
431
+ startSpan: (options) => {
432
+ const parent = options.parentContext;
433
+ if (parent?.traceparent.startsWith(BUFFERED_PREFIX)) {
434
+ const translated = idMap.get(parent.traceparent);
435
+ if (translated) {
436
+ return backend.startSpan({
437
+ ...options,
438
+ parentContext: translated
439
+ });
440
+ }
441
+ }
442
+ return backend.startSpan(options);
443
+ }
444
+ };
445
+ }
446
+ resources = /* @__PURE__ */ new Map();
447
+ resourceInstanceIndex = /* @__PURE__ */ new WeakMap();
448
+ resourceIdList = [];
449
+ logs = [];
450
+ _instanceTag = null;
451
+ constructor() {
452
+ log.addProcessor(this._logProcessor.bind(this), void 0, {
453
+ F: __dxlog_file3,
454
+ L: 108,
455
+ S: this,
456
+ C: (f, a) => f(...a)
457
+ });
458
+ if (DiagnosticsChannel.supported) {
459
+ this.diagnosticsChannel.serve(this.diagnostics);
460
+ }
461
+ this.diagnosticsChannel.unref();
462
+ }
526
463
  setInstanceTag(tag) {
527
464
  this._instanceTag = tag;
528
465
  this.diagnostics.setInstanceTag(tag);
529
466
  }
530
- /**
531
- * @internal
532
- */
533
- // TODO(burdon): Comment.
467
+ /** @internal */
534
468
  createTraceResource(params) {
535
469
  const id = this.resources.size;
536
470
  const tracingContext = getTracingContext(Object.getPrototypeOf(params.instance));
@@ -551,24 +485,10 @@ var TraceProcessor = class {
551
485
  if (this.resourceIdList.length > MAX_RESOURCE_RECORDS) {
552
486
  this._clearResources();
553
487
  }
554
- this._markResourceDirty(id);
555
- }
556
- createTraceSender() {
557
- return new TraceSender(this);
558
- }
559
- traceSpan(params) {
560
- const span2 = new TracingSpan(this, params);
561
- this._flushSpan(span2);
562
- return span2;
563
488
  }
564
489
  // TODO(burdon): Not implemented.
565
490
  addLink(parent, child, opts) {
566
491
  }
567
- //
568
- // Getters
569
- //
570
- // TODO(burdon): Define type.
571
- // TODO(burdon): Reconcile with system service.
572
492
  getDiagnostics() {
573
493
  this.refresh();
574
494
  return {
@@ -576,7 +496,6 @@ var TraceProcessor = class {
576
496
  `${entry.sanitizedClassName}#${entry.data.instanceId}`,
577
497
  entry.data
578
498
  ])),
579
- spans: Array.from(this.spans.values()),
580
499
  logs: this.logs.filter((log2) => log2.level >= LogLevel.INFO)
581
500
  };
582
501
  }
@@ -631,43 +550,8 @@ var TraceProcessor = class {
631
550
  for (const key of Object.keys(tracingContext.metricsProperties)) {
632
551
  instance[key]._tick?.(time);
633
552
  }
634
- let _changed = false;
635
- const oldInfo = resource2.data.info;
636
553
  resource2.data.info = this.getResourceInfo(instance);
637
- _changed || (_changed = !areEqualShallow(oldInfo, resource2.data.info));
638
- const oldMetrics = resource2.data.metrics;
639
554
  resource2.data.metrics = this.getResourceMetrics(instance);
640
- _changed || (_changed = !areEqualShallow(oldMetrics, resource2.data.metrics));
641
- this._markResourceDirty(resource2.data.id);
642
- }
643
- for (const subscription of this.subscriptions) {
644
- subscription.flush();
645
- }
646
- }
647
- //
648
- // Implementation
649
- //
650
- /**
651
- * @internal
652
- */
653
- _flushSpan(runtimeSpan) {
654
- const span2 = runtimeSpan.serialize();
655
- this.spans.set(span2.id, span2);
656
- this.spanIdList.push(span2.id);
657
- if (this.spanIdList.length > MAX_SPAN_RECORDS) {
658
- this._clearSpans();
659
- }
660
- this._markSpanDirty(span2.id);
661
- this.remoteTracing.flushSpan(runtimeSpan);
662
- }
663
- _markResourceDirty(id) {
664
- for (const subscription of this.subscriptions) {
665
- subscription.dirtyResources.add(id);
666
- }
667
- }
668
- _markSpanDirty(id) {
669
- for (const subscription of this.subscriptions) {
670
- subscription.dirtySpans.add(id);
671
555
  }
672
556
  }
673
557
  _clearResources() {
@@ -676,175 +560,48 @@ var TraceProcessor = class {
676
560
  this.resources.delete(id);
677
561
  }
678
562
  }
679
- _clearSpans() {
680
- while (this.spanIdList.length > MAX_SPAN_RECORDS) {
681
- const id = this.spanIdList.shift();
682
- this.spans.delete(id);
683
- }
684
- }
685
563
  _pushLog(log2) {
686
564
  this.logs.push(log2);
687
565
  if (this.logs.length > MAX_LOG_RECORDS) {
688
566
  this.logs.shift();
689
567
  }
690
- for (const subscription of this.subscriptions) {
691
- subscription.newLogs.push(log2);
692
- }
693
568
  }
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;
569
+ _logProcessor = (config, entry) => {
570
+ switch (entry.level) {
571
+ case LogLevel.ERROR:
572
+ case LogLevel.WARN:
573
+ case LogLevel.TRACE: {
574
+ const scope = entry.meta?.S;
575
+ const resource2 = this.resourceInstanceIndex.get(scope);
576
+ if (!resource2) {
577
+ return;
734
578
  }
735
- default:
736
- }
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);
747
- }
748
- if (DiagnosticsChannel.supported) {
749
- this.diagnosticsChannel.serve(this.diagnostics);
750
- }
751
- this.diagnosticsChannel.unref();
752
- }
753
- };
754
- var TracingSpan = class _TracingSpan {
755
- get name() {
756
- const resource2 = this._traceProcessor.resources.get(this.resourceId);
757
- return resource2 ? `${resource2.sanitizedClassName}#${resource2.data.instanceId}.${this.methodName}` : this.methodName;
758
- }
759
- get ctx() {
760
- return this._ctx;
761
- }
762
- markSuccess() {
763
- this.endTs = performance.now();
764
- this._traceProcessor._flushSpan(this);
765
- if (this._showInBrowserTimeline) {
766
- this._markInBrowserTimeline();
767
- }
768
- }
769
- markError(err) {
770
- this.endTs = performance.now();
771
- this.error = serializeError(err);
772
- this._traceProcessor._flushSpan(this);
773
- if (this._showInBrowserTimeline) {
774
- this._markInBrowserTimeline();
775
- }
776
- }
777
- serialize() {
778
- return {
779
- id: this.id,
780
- resourceId: this.resourceId ?? void 0,
781
- methodName: this.methodName,
782
- parentId: this.parentId ?? void 0,
783
- startTs: this.startTs.toFixed(3),
784
- endTs: this.endTs?.toFixed(3) ?? void 0,
785
- error: this.error ?? void 0
786
- };
787
- }
788
- _markInBrowserTimeline() {
789
- if (typeof globalThis?.performance?.measure === "function") {
790
- performance.measure(this.name, {
791
- start: this.startTs,
792
- end: this.endTs
793
- });
794
- }
795
- }
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
579
+ const context = {
580
+ ...entry.computedContext
581
+ };
582
+ if (entry.computedError !== void 0) {
583
+ context.error = entry.computedError;
826
584
  }
827
- });
828
- const parentId = params.parentCtx.getAttribute(TRACE_SPAN_ATTRIBUTE);
829
- if (typeof parentId === "number") {
830
- this.parentId = parentId;
585
+ const { filename, line } = entry.computedMeta;
586
+ const entryToPush = {
587
+ level: entry.level,
588
+ message: entry.message ?? entry.computedError ?? "",
589
+ context,
590
+ timestamp: new Date(entry.timestamp),
591
+ meta: {
592
+ file: filename ?? "",
593
+ line: line ?? 0,
594
+ resourceId: resource2.data.id
595
+ }
596
+ };
597
+ this._pushLog(entryToPush);
598
+ break;
831
599
  }
600
+ default:
832
601
  }
833
- }
834
- };
835
- _define_property6(TracingSpan, "nextId", 0);
836
- var serializeError = (err) => {
837
- if (err instanceof Error) {
838
- return {
839
- name: err.name,
840
- message: err.message
841
- };
842
- }
843
- return {
844
- message: String(err)
845
602
  };
846
603
  };
847
- var TRACE_PROCESSOR = (_globalThis = globalThis).TRACE_PROCESSOR ?? (_globalThis.TRACE_PROCESSOR = new TraceProcessor());
604
+ var TRACE_PROCESSOR = globalThis.TRACE_PROCESSOR ??= new TraceProcessor();
848
605
  var sanitizeValue = (value, depth, traceProcessor) => {
849
606
  switch (typeof value) {
850
607
  case "string":
@@ -890,46 +647,118 @@ var sanitizeValue = (value, depth, traceProcessor) => {
890
647
  return value.toString();
891
648
  }
892
649
  };
893
- var areEqualShallow = (a, b) => {
894
- for (const key in a) {
895
- if (!(key in b) || a[key] !== b[key]) {
896
- return false;
897
- }
898
- }
899
- for (const key in b) {
900
- if (!(key in a) || a[key] !== b[key]) {
901
- return false;
902
- }
903
- }
904
- return true;
905
- };
906
650
  var sanitizeClassName = (className) => {
651
+ let name = className.replace(/^_+/, "");
907
652
  const SANITIZE_REGEX = /[^_](\d+)$/;
908
- const m = className.match(SANITIZE_REGEX);
909
- if (!m) {
910
- return className;
911
- } else {
912
- return className.slice(0, -m[1].length);
653
+ const m = name.match(SANITIZE_REGEX);
654
+ if (m) {
655
+ name = name.slice(0, -m[1].length);
913
656
  }
657
+ return name;
914
658
  };
915
659
  var isSetLike = (value) => value instanceof Set || typeof value === "object" && value !== null && Object.getPrototypeOf(value).constructor.name === "ComplexSet";
916
660
  var isMapLike = (value) => value instanceof Map || typeof value === "object" && value !== null && Object.getPrototypeOf(value).constructor.name === "ComplexMap";
917
661
 
918
662
  // src/api.ts
919
- 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
- });
663
+ var __dxlog_file4 = "/__w/dxos/dxos/packages/common/tracing/src/api.ts";
664
+ var LIFECYCLE_SPAN = /* @__PURE__ */ Symbol("dxos.tracing.lifecycle-span");
665
+ var TRACE_ALL_KEY = "dxos.debug.traceAll";
666
+ var collectSpanAttributes = (instance, spanAttributes) => {
667
+ const proto = Object.getPrototypeOf(instance);
668
+ if (!proto) {
669
+ return;
670
+ }
671
+ const tracingContext = getTracingContext(proto);
672
+ for (const [key, { options }] of Object.entries(tracingContext.infoProperties)) {
673
+ if (!options.spanAttribute) {
674
+ continue;
675
+ }
676
+ try {
677
+ const value = typeof instance[key] === "function" ? instance[key]() : instance[key];
678
+ if (value != null) {
679
+ const resolved = options.enum ? options.enum[value] : String(value);
680
+ spanAttributes[`ctx.${key}`] = resolved;
929
681
  }
682
+ } catch {
683
+ }
684
+ }
685
+ };
686
+ var resource = (options) => (constructor) => {
687
+ if (options?.lifecycle && !(constructor.prototype instanceof Resource)) {
688
+ throw new Error(`@trace.resource({ lifecycle: true }) requires ${constructor.name} to extend Resource`);
689
+ }
690
+ const klass = /* @__PURE__ */ (() => class extends constructor {
691
+ constructor(...rest) {
692
+ super(...rest);
693
+ TRACE_PROCESSOR.createTraceResource({
694
+ constructor,
695
+ annotation: options?.annotation,
696
+ instance: this
697
+ });
930
698
  }
931
- return _class;
932
699
  })();
700
+ if (options?.lifecycle) {
701
+ const sanitizedName = sanitizeClassName(constructor.name);
702
+ const proto = klass.prototype;
703
+ const originalOpen = proto.open;
704
+ const originalClose = proto.close;
705
+ proto.open = async function(ctx) {
706
+ const self = this;
707
+ if (self._lifecycleState !== LifecycleState.CLOSED) {
708
+ return originalOpen.call(this, ctx);
709
+ }
710
+ const parentSpanContext = ctx?.getAttribute(TRACE_SPAN_ATTRIBUTE);
711
+ const resourceEntry = TRACE_PROCESSOR.resourceInstanceIndex.get(this);
712
+ const spanAttributes = {};
713
+ if (resourceEntry) {
714
+ spanAttributes.entryPoint = resourceEntry.sanitizedClassName;
715
+ }
716
+ const remoteSpan = TRACE_PROCESSOR.tracingBackend?.startSpan({
717
+ name: `${sanitizedName}.lifecycle`,
718
+ op: "lifecycle",
719
+ attributes: spanAttributes,
720
+ parentContext: parentSpanContext
721
+ });
722
+ self[LIFECYCLE_SPAN] = remoteSpan;
723
+ let openCtx = ctx;
724
+ if (remoteSpan?.spanContext != null) {
725
+ const traceAttrs = {
726
+ [TRACE_SPAN_ATTRIBUTE]: remoteSpan.spanContext
727
+ };
728
+ openCtx = ctx ? ctx.derive({
729
+ attributes: traceAttrs
730
+ }) : new Context2({
731
+ attributes: traceAttrs
732
+ }, {
733
+ F: __dxlog_file4,
734
+ L: 104
735
+ });
736
+ }
737
+ try {
738
+ return await originalOpen.call(this, openCtx);
739
+ } catch (err) {
740
+ remoteSpan?.setError?.(err);
741
+ remoteSpan?.end();
742
+ self[LIFECYCLE_SPAN] = void 0;
743
+ throw err;
744
+ }
745
+ };
746
+ proto.close = async function(ctx) {
747
+ const self = this;
748
+ const remoteSpan = self[LIFECYCLE_SPAN];
749
+ try {
750
+ return await originalClose.call(this, ctx);
751
+ } catch (err) {
752
+ remoteSpan?.setError?.(err);
753
+ throw err;
754
+ } finally {
755
+ if (remoteSpan) {
756
+ remoteSpan.end();
757
+ self[LIFECYCLE_SPAN] = void 0;
758
+ }
759
+ }
760
+ };
761
+ }
933
762
  Object.defineProperty(klass, "name", {
934
763
  value: constructor.name
935
764
  });
@@ -943,45 +772,117 @@ var info = (opts = {}) => (target, propertyKey, descriptor) => {
943
772
  var mark = (name) => {
944
773
  performance.mark(name);
945
774
  };
946
- var span = ({ showInBrowserTimeline = false, op, attributes } = {}) => (target, propertyKey, descriptor) => {
775
+ var span = ({ showInBrowserTimeline = false, showInRemoteTracing = true, op, attributes } = {}) => (target, propertyKey, descriptor) => {
947
776
  const method = descriptor.value;
948
777
  descriptor.value = async function(...args) {
949
778
  const parentCtx = args[0] instanceof Context2 ? args[0] : null;
950
- const span2 = TRACE_PROCESSOR.traceSpan({
951
- parentCtx,
952
- methodName: propertyKey,
953
- instance: this,
954
- showInBrowserTimeline,
955
- op,
956
- attributes
957
- });
958
- const callArgs = span2.ctx ? [
959
- span2.ctx,
960
- ...args.slice(1)
961
- ] : args;
779
+ const startTs = performance.now();
780
+ const parentSpanContext = parentCtx?.getAttribute(TRACE_SPAN_ATTRIBUTE);
781
+ const resourceEntry = TRACE_PROCESSOR.resourceInstanceIndex.get(this);
782
+ const className = resourceEntry?.sanitizedClassName ?? sanitizeClassName(target.constructor?.name ?? "unknown");
783
+ const spanName = `${className}.${propertyKey}`;
784
+ const spanAttributes = {};
785
+ if (resourceEntry) {
786
+ spanAttributes.entryPoint = resourceEntry.sanitizedClassName;
787
+ }
788
+ collectSpanAttributes(this, spanAttributes);
789
+ if (attributes) {
790
+ for (const [key, value] of Object.entries(attributes)) {
791
+ spanAttributes[key.startsWith("ctx.") ? key : `ctx.${key}`] = value;
792
+ }
793
+ }
794
+ const remoteSpan = showInRemoteTracing ? TRACE_PROCESSOR.tracingBackend?.startSpan({
795
+ name: spanName,
796
+ op: op ?? "function",
797
+ attributes: spanAttributes,
798
+ parentContext: parentSpanContext
799
+ }) : void 0;
800
+ let callArgs = args;
801
+ if (parentCtx) {
802
+ const childCtx = remoteSpan?.spanContext != null ? parentCtx.derive({
803
+ attributes: {
804
+ [TRACE_SPAN_ATTRIBUTE]: remoteSpan.spanContext
805
+ }
806
+ }) : parentCtx.derive();
807
+ callArgs = [
808
+ childCtx,
809
+ ...args.slice(1)
810
+ ];
811
+ }
962
812
  try {
963
813
  return await method.apply(this, callArgs);
964
814
  } catch (err) {
965
- span2.markError(err);
815
+ remoteSpan?.setError?.(err);
966
816
  throw err;
967
817
  } finally {
968
- span2.markSuccess();
818
+ remoteSpan?.end();
819
+ if (showInBrowserTimeline && typeof globalThis?.performance?.measure === "function") {
820
+ performance.measure(spanName, {
821
+ start: startTs,
822
+ end: performance.now()
823
+ });
824
+ }
969
825
  }
970
826
  };
971
827
  };
972
- var spans = /* @__PURE__ */ new Map();
828
+ var manualSpans = /* @__PURE__ */ new Map();
829
+ var manualSpanTimestamps = /* @__PURE__ */ new Map();
973
830
  var spanStart = (params) => {
974
- if (spans.has(params.id)) {
975
- return;
831
+ if (manualSpans.has(params.id) || manualSpanTimestamps.has(params.id)) {
832
+ return params.parentCtx;
833
+ }
834
+ const resourceEntry = TRACE_PROCESSOR.resourceInstanceIndex.get(params.instance);
835
+ const className = resourceEntry?.sanitizedClassName ?? "unknown";
836
+ const spanName = `${className}.${params.methodName}`;
837
+ if (params.showInBrowserTimeline) {
838
+ manualSpanTimestamps.set(params.id, {
839
+ name: spanName,
840
+ startTs: performance.now()
841
+ });
842
+ }
843
+ if (params.showInRemoteTracing === false || !TRACE_PROCESSOR.tracingBackend) {
844
+ return params.parentCtx;
845
+ }
846
+ const parentSpanContext = params.parentCtx?.getAttribute(TRACE_SPAN_ATTRIBUTE);
847
+ const spanAttributes = {};
848
+ if (resourceEntry) {
849
+ spanAttributes.entryPoint = resourceEntry.sanitizedClassName;
850
+ }
851
+ collectSpanAttributes(params.instance, spanAttributes);
852
+ if (params.attributes) {
853
+ for (const [key, value] of Object.entries(params.attributes)) {
854
+ spanAttributes[key.startsWith("ctx.") ? key : `ctx.${key}`] = value;
855
+ }
976
856
  }
977
- const span2 = TRACE_PROCESSOR.traceSpan(params);
978
- spans.set(params.id, span2);
857
+ const remoteSpan = TRACE_PROCESSOR.tracingBackend.startSpan({
858
+ name: spanName,
859
+ op: params.op ?? "function",
860
+ attributes: spanAttributes,
861
+ parentContext: parentSpanContext
862
+ });
863
+ manualSpans.set(params.id, remoteSpan);
864
+ if (params.parentCtx && remoteSpan.spanContext != null) {
865
+ return params.parentCtx.derive({
866
+ attributes: {
867
+ [TRACE_SPAN_ATTRIBUTE]: remoteSpan.spanContext
868
+ }
869
+ });
870
+ }
871
+ return params.parentCtx;
979
872
  };
980
873
  var spanEnd = (id) => {
981
- const span2 = spans.get(id);
982
- if (span2) {
983
- span2.markSuccess();
984
- spans.delete(id);
874
+ const remoteSpan = manualSpans.get(id);
875
+ if (remoteSpan) {
876
+ remoteSpan.end();
877
+ manualSpans.delete(id);
878
+ }
879
+ const timestamps = manualSpanTimestamps.get(id);
880
+ if (timestamps && typeof globalThis?.performance?.measure === "function") {
881
+ performance.measure(timestamps.name, {
882
+ start: timestamps.startTs,
883
+ end: performance.now()
884
+ });
885
+ manualSpanTimestamps.delete(id);
985
886
  }
986
887
  };
987
888
  var metricsCounter = () => (target, propertyKey, descriptor) => {
@@ -1007,20 +908,12 @@ var trace = {
1007
908
  };
1008
909
 
1009
910
  // 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
911
  var BaseCounter = class {
912
+ /**
913
+ * @internal
914
+ */
915
+ _instance;
916
+ name;
1024
917
  /**
1025
918
  * @internal
1026
919
  */
@@ -1030,27 +923,16 @@ var BaseCounter = class {
1030
923
  }
1031
924
  _tick(time) {
1032
925
  }
1033
- constructor() {
1034
- _define_property7(this, "_instance", void 0);
1035
- _define_property7(this, "name", void 0);
1036
- }
1037
926
  };
1038
927
 
1039
928
  // 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
929
  var UnaryCounter = class extends BaseCounter {
930
+ value = 0;
931
+ units;
932
+ constructor({ units } = {}) {
933
+ super();
934
+ this.units = units;
935
+ }
1054
936
  inc(by = 1) {
1055
937
  this.value += by;
1056
938
  }
@@ -1063,28 +945,19 @@ var UnaryCounter = class extends BaseCounter {
1063
945
  }
1064
946
  };
1065
947
  }
1066
- constructor({ units } = {}) {
1067
- super(), _define_property8(this, "value", 0), _define_property8(this, "units", void 0);
1068
- this.units = units;
1069
- }
1070
948
  };
1071
949
 
1072
950
  // 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
951
  var MAX_BUCKETS = 60;
1087
952
  var TimeSeriesCounter = class extends BaseCounter {
953
+ _currentValue = 0;
954
+ _totalValue = 0;
955
+ _buckets = [];
956
+ units;
957
+ constructor({ units } = {}) {
958
+ super();
959
+ this.units = units;
960
+ }
1088
961
  inc(by = 1) {
1089
962
  this._currentValue += by;
1090
963
  this._totalValue += by;
@@ -1113,28 +986,15 @@ var TimeSeriesCounter = class extends BaseCounter {
1113
986
  }
1114
987
  };
1115
988
  }
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
989
  };
1121
990
 
1122
991
  // 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
992
  var MAX_BUCKETS2 = 60;
1137
993
  var TimeUsageCounter = class extends BaseCounter {
994
+ _currentValue = 0;
995
+ _totalValue = 0;
996
+ _buckets = [];
997
+ _lastTickTime = performance.now();
1138
998
  record(time) {
1139
999
  this._currentValue += time;
1140
1000
  this._totalValue += time;
@@ -1175,26 +1035,16 @@ var TimeUsageCounter = class extends BaseCounter {
1175
1035
  }
1176
1036
  };
1177
1037
  }
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
1038
  };
1182
1039
 
1183
1040
  // 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
1041
  var MapCounter = class extends BaseCounter {
1042
+ values = /* @__PURE__ */ new Map();
1043
+ units;
1044
+ constructor({ units } = {}) {
1045
+ super();
1046
+ this.units = units;
1047
+ }
1198
1048
  inc(key, by = 1) {
1199
1049
  const prev = this.values.get(key) ?? 0;
1200
1050
  this.values.set(key, prev + by);
@@ -1211,27 +1061,14 @@ var MapCounter = class extends BaseCounter {
1211
1061
  }
1212
1062
  };
1213
1063
  }
1214
- constructor({ units } = {}) {
1215
- super(), _define_property11(this, "values", /* @__PURE__ */ new Map()), _define_property11(this, "units", void 0);
1216
- this.units = units;
1217
- }
1218
1064
  };
1219
1065
 
1220
1066
  // 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
1067
  var CustomCounter = class extends BaseCounter {
1068
+ _getData;
1069
+ constructor(_getData) {
1070
+ super(), this._getData = _getData;
1071
+ }
1235
1072
  getData() {
1236
1073
  return {
1237
1074
  name: this.name,
@@ -1240,9 +1077,6 @@ var CustomCounter = class extends BaseCounter {
1240
1077
  }
1241
1078
  };
1242
1079
  }
1243
- constructor(_getData) {
1244
- super(), _define_property12(this, "_getData", void 0), this._getData = _getData;
1245
- }
1246
1080
  };
1247
1081
 
1248
1082
  // src/index.ts
@@ -1266,16 +1100,13 @@ export {
1266
1100
  DiagnosticsManager,
1267
1101
  MapCounter,
1268
1102
  RemoteMetrics,
1269
- RemoteTracing,
1270
1103
  ResourceEntry,
1104
+ TRACE_ALL_KEY,
1271
1105
  TRACE_PROCESSOR,
1272
- TRACE_SPAN_ATTRIBUTE,
1273
1106
  TimeSeriesCounter,
1274
1107
  TimeUsageCounter,
1275
1108
  TraceDiagnosticImpl,
1276
1109
  TraceProcessor,
1277
- TraceSender,
1278
- TracingSpan,
1279
1110
  UnaryCounter,
1280
1111
  getTracingContext,
1281
1112
  sanitizeClassName,