autotel-devtools 5.0.1 → 6.0.0

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.
package/dist/index.d.cts CHANGED
@@ -1,9 +1,9 @@
1
- import { D as DevtoolsServer, a as DevtoolsSpanExporter } from './exporter-qIQPDw29.cjs';
2
- export { b as DevtoolsData, E as ErrorGroup, L as LogData, M as MetricData, S as SpanData, T as TraceData } from './exporter-qIQPDw29.cjs';
1
+ import { D as DevtoolsServer, a as DevtoolsSpanExporter } from './exporter-DjLkU621.cjs';
2
+ export { b as DevtoolsData, E as ErrorGroup, L as LogData, M as MetricData, S as SpanData, T as TraceData } from './exporter-DjLkU621.cjs';
3
3
  import { Server } from 'node:http';
4
4
  export { DevtoolsLogExporter } from './server/log-exporter.cjs';
5
5
  export { DevtoolsRemoteExporter } from './server/remote-exporter.cjs';
6
- export { E as ErrorAggregator } from './error-aggregator-CtZmjm-k.cjs';
6
+ export { E as ErrorAggregator } from './error-aggregator-CbLiuot4.cjs';
7
7
  import '@opentelemetry/sdk-trace-base';
8
8
  import '@opentelemetry/core';
9
9
  import '@opentelemetry/sdk-logs';
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { D as DevtoolsServer, a as DevtoolsSpanExporter } from './exporter-qIQPDw29.js';
2
- export { b as DevtoolsData, E as ErrorGroup, L as LogData, M as MetricData, S as SpanData, T as TraceData } from './exporter-qIQPDw29.js';
1
+ import { D as DevtoolsServer, a as DevtoolsSpanExporter } from './exporter-DjLkU621.js';
2
+ export { b as DevtoolsData, E as ErrorGroup, L as LogData, M as MetricData, S as SpanData, T as TraceData } from './exporter-DjLkU621.js';
3
3
  import { Server } from 'node:http';
4
4
  export { DevtoolsLogExporter } from './server/log-exporter.js';
5
5
  export { DevtoolsRemoteExporter } from './server/remote-exporter.js';
6
- export { E as ErrorAggregator } from './error-aggregator-BkO0l8ak.js';
6
+ export { E as ErrorAggregator } from './error-aggregator-CAk_pt3Z.js';
7
7
  import '@opentelemetry/sdk-trace-base';
8
8
  import '@opentelemetry/core';
9
9
  import '@opentelemetry/sdk-logs';
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { WebSocketServer, WebSocket } from 'ws';
3
3
  import { readFileSync, existsSync } from 'fs';
4
4
  import { resolve, dirname } from 'path';
5
5
  import { fileURLToPath } from 'url';
6
- import * as protobuf from 'protobufjs';
6
+ import protobuf from 'protobufjs';
7
7
  import { ExportResultCode } from '@opentelemetry/core';
8
8
 
9
9
  // src/index.ts
@@ -360,10 +360,12 @@ var DevtoolsServer = class {
360
360
  limits;
361
361
  verbose;
362
362
  _port;
363
+ onData;
363
364
  constructor(options = {}) {
364
365
  this.limits = resolveTelemetryLimits(options);
365
366
  this.verbose = options.verbose ?? false;
366
367
  this._port = options.port ?? 4318;
368
+ this.onData = options.onData;
367
369
  this.httpServer = options.server ?? createServer();
368
370
  this.wss = new WebSocketServer({ server: this.httpServer, path: options.path ?? "/ws" });
369
371
  this.wss.on("connection", (ws) => {
@@ -457,6 +459,12 @@ var DevtoolsServer = class {
457
459
  client.send(msg);
458
460
  }
459
461
  }
462
+ if (this.onData) {
463
+ try {
464
+ this.onData(data);
465
+ } catch {
466
+ }
467
+ }
460
468
  }
461
469
  log(message) {
462
470
  if (this.verbose) console.log(`[autotel-devtools] ${message}`);
@@ -510,7 +518,10 @@ function flattenAttributes(attrs) {
510
518
  }
511
519
  function nanoToMs(nano) {
512
520
  if (!nano) return 0;
513
- return Number(BigInt(nano) / 1000000n);
521
+ const ns = BigInt(nano);
522
+ const ms = ns / 1000000n;
523
+ const remNs = ns % 1000000n;
524
+ return Number(ms) + Number(remNs) / 1e6;
514
525
  }
515
526
  var SPAN_KIND_MAP = {
516
527
  0: "INTERNAL",
@@ -548,6 +559,7 @@ function parseOtlpTraces(payload) {
548
559
  const service = String(resourceAttrs["service.name"] || "unknown");
549
560
  const scopeSpans = rs.scopeSpans || [];
550
561
  for (const ss of scopeSpans) {
562
+ const scope = ss.scope?.name ? { name: ss.scope.name, version: ss.scope.version || void 0 } : void 0;
551
563
  for (const span of ss.spans || []) {
552
564
  const traceId = normalizeHexId(span.traceId);
553
565
  if (!traceId) continue;
@@ -572,7 +584,13 @@ function parseOtlpTraces(payload) {
572
584
  name: e.name || "",
573
585
  timestamp: nanoToMs(e.timeUnixNano),
574
586
  attributes: flattenAttributes(e.attributes)
575
- }))
587
+ })),
588
+ links: (span.links || []).map((l) => ({
589
+ traceId: normalizeHexId(l.traceId),
590
+ spanId: normalizeHexId(l.spanId),
591
+ attributes: flattenAttributes(l.attributes)
592
+ })),
593
+ scope
576
594
  };
577
595
  const existing = traceMap.get(traceId);
578
596
  if (existing) {
@@ -1164,6 +1182,11 @@ var DevtoolsSpanExporter = class {
1164
1182
  timestamp: event.time[0] * 1e3 + event.time[1] / 1e6,
1165
1183
  attributes: event.attributes ? Object.fromEntries(Object.entries(event.attributes)) : void 0
1166
1184
  }));
1185
+ const links = span.links.map((link) => ({
1186
+ traceId: link.context.traceId,
1187
+ spanId: link.context.spanId,
1188
+ attributes: link.attributes ? Object.fromEntries(Object.entries(link.attributes)) : void 0
1189
+ }));
1167
1190
  return {
1168
1191
  traceId: spanContext.traceId,
1169
1192
  spanId: spanContext.spanId,
@@ -1178,9 +1201,15 @@ var DevtoolsSpanExporter = class {
1178
1201
  code: status,
1179
1202
  message: span.status.message
1180
1203
  },
1181
- events: events.length > 0 ? events : void 0
1204
+ events: events.length > 0 ? events : void 0,
1205
+ links: links.length > 0 ? links : void 0,
1206
+ scope: this.convertScope(span)
1182
1207
  };
1183
1208
  }
1209
+ convertScope(span) {
1210
+ const s = span.instrumentationScope ?? span.instrumentationLibrary;
1211
+ return s?.name ? { name: s.name, version: s.version || void 0 } : void 0;
1212
+ }
1184
1213
  /**
1185
1214
  * Convert OpenTelemetry SpanKind to string
1186
1215
  */