@dxos/tracing 0.8.4-main.dedc0f3 → 0.8.4-main.e00bdcdb52

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