autotel-devtools 5.1.0 → 6.0.1

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.
@@ -368,12 +368,17 @@ var DevtoolsServer = class {
368
368
  limits;
369
369
  verbose;
370
370
  _port;
371
+ onData;
371
372
  constructor(options = {}) {
372
373
  this.limits = resolveTelemetryLimits(options);
373
374
  this.verbose = options.verbose ?? false;
374
375
  this._port = options.port ?? 4318;
376
+ this.onData = options.onData;
375
377
  this.httpServer = options.server ?? createServer();
376
378
  this.wss = new WebSocketServer({ server: this.httpServer, path: options.path ?? "/ws" });
379
+ this.wss.on("error", (err) => {
380
+ if (this.httpServer.listening) throw err;
381
+ });
377
382
  this.wss.on("connection", (ws) => {
378
383
  this.clients.add(ws);
379
384
  this.log(`Client connected (${this.clients.size} total)`);
@@ -465,6 +470,12 @@ var DevtoolsServer = class {
465
470
  client.send(msg);
466
471
  }
467
472
  }
473
+ if (this.onData) {
474
+ try {
475
+ this.onData(data);
476
+ } catch {
477
+ }
478
+ }
468
479
  }
469
480
  log(message) {
470
481
  if (this.verbose) console.log(`[autotel-devtools] ${message}`);
@@ -582,6 +593,11 @@ var DevtoolsSpanExporter = class {
582
593
  timestamp: event.time[0] * 1e3 + event.time[1] / 1e6,
583
594
  attributes: event.attributes ? Object.fromEntries(Object.entries(event.attributes)) : void 0
584
595
  }));
596
+ const links = span.links.map((link) => ({
597
+ traceId: link.context.traceId,
598
+ spanId: link.context.spanId,
599
+ attributes: link.attributes ? Object.fromEntries(Object.entries(link.attributes)) : void 0
600
+ }));
585
601
  return {
586
602
  traceId: spanContext.traceId,
587
603
  spanId: spanContext.spanId,
@@ -596,9 +612,15 @@ var DevtoolsSpanExporter = class {
596
612
  code: status,
597
613
  message: span.status.message
598
614
  },
599
- events: events.length > 0 ? events : void 0
615
+ events: events.length > 0 ? events : void 0,
616
+ links: links.length > 0 ? links : void 0,
617
+ scope: this.convertScope(span)
600
618
  };
601
619
  }
620
+ convertScope(span) {
621
+ const s = span.instrumentationScope ?? span.instrumentationLibrary;
622
+ return s?.name ? { name: s.name, version: s.version || void 0 } : void 0;
623
+ }
602
624
  /**
603
625
  * Convert OpenTelemetry SpanKind to string
604
626
  */
@@ -967,7 +989,10 @@ function flattenAttributes(attrs) {
967
989
  }
968
990
  function nanoToMs(nano) {
969
991
  if (!nano) return 0;
970
- return Number(BigInt(nano) / 1000000n);
992
+ const ns = BigInt(nano);
993
+ const ms = ns / 1000000n;
994
+ const remNs = ns % 1000000n;
995
+ return Number(ms) + Number(remNs) / 1e6;
971
996
  }
972
997
  var SPAN_KIND_MAP = {
973
998
  0: "INTERNAL",
@@ -1005,6 +1030,7 @@ function parseOtlpTraces(payload) {
1005
1030
  const service = String(resourceAttrs["service.name"] || "unknown");
1006
1031
  const scopeSpans = rs.scopeSpans || [];
1007
1032
  for (const ss of scopeSpans) {
1033
+ const scope = ss.scope?.name ? { name: ss.scope.name, version: ss.scope.version || void 0 } : void 0;
1008
1034
  for (const span of ss.spans || []) {
1009
1035
  const traceId = normalizeHexId(span.traceId);
1010
1036
  if (!traceId) continue;
@@ -1029,7 +1055,13 @@ function parseOtlpTraces(payload) {
1029
1055
  name: e.name || "",
1030
1056
  timestamp: nanoToMs(e.timeUnixNano),
1031
1057
  attributes: flattenAttributes(e.attributes)
1032
- }))
1058
+ })),
1059
+ links: (span.links || []).map((l) => ({
1060
+ traceId: normalizeHexId(l.traceId),
1061
+ spanId: normalizeHexId(l.spanId),
1062
+ attributes: flattenAttributes(l.attributes)
1063
+ })),
1064
+ scope
1033
1065
  };
1034
1066
  const existing = traceMap.get(traceId);
1035
1067
  if (existing) {