autotel-devtools 6.0.0 → 6.1.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.
@@ -383,6 +383,9 @@ var DevtoolsServer = class {
383
383
  this.onData = options.onData;
384
384
  this.httpServer = options.server ?? http.createServer();
385
385
  this.wss = new ws.WebSocketServer({ server: this.httpServer, path: options.path ?? "/ws" });
386
+ this.wss.on("error", (err) => {
387
+ if (this.httpServer.listening) throw err;
388
+ });
386
389
  this.wss.on("connection", (ws) => {
387
390
  this.clients.add(ws);
388
391
  this.log(`Client connected (${this.clients.size} total)`);
@@ -1390,7 +1393,38 @@ function decodeOtlpMetricsRequest(body) {
1390
1393
  return decodeRequest("opentelemetry.proto.metrics.v1.ExportMetricsServiceRequest", body);
1391
1394
  }
1392
1395
 
1396
+ // src/server/identity.ts
1397
+ var DEVTOOLS_IDENTITY = "autotel-devtools";
1398
+ async function probePortHolder(host, port, timeoutMs = 500) {
1399
+ const authority = host.includes(":") ? `[${host}]` : host;
1400
+ const controller = new AbortController();
1401
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
1402
+ try {
1403
+ const res = await fetch(`http://${authority}:${port}/healthz`, {
1404
+ signal: controller.signal
1405
+ });
1406
+ if (res.headers.get("x-autotel-devtools")) return "autotel-devtools";
1407
+ try {
1408
+ const body = await res.json();
1409
+ if (body && body.service === DEVTOOLS_IDENTITY) return "autotel-devtools";
1410
+ } catch {
1411
+ }
1412
+ return "foreign";
1413
+ } catch {
1414
+ return "none";
1415
+ } finally {
1416
+ clearTimeout(timer);
1417
+ }
1418
+ }
1419
+
1393
1420
  // src/server/http.ts
1421
+ function sendOtlpError(res, req, e) {
1422
+ sendJson(res, 400, {
1423
+ error: "Invalid OTLP payload",
1424
+ message: e instanceof Error ? e.message : String(e),
1425
+ contentType: req.headers["content-type"] ?? null
1426
+ });
1427
+ }
1394
1428
  var PROTOBUF_DECODERS = {
1395
1429
  traces: decodeOtlpTraceRequest,
1396
1430
  logs: decodeOtlpLogsRequest,
@@ -1411,6 +1445,18 @@ function findPackageRoot() {
1411
1445
  return dir;
1412
1446
  }
1413
1447
  var FULLPAGE_HTML = `<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>autotel-devtools</title><style>*{margin:0;padding:0;box-sizing:border-box}html,body{height:100%;width:100%;overflow:hidden}</style></head><body><script src="/widget.js?mode=fullpage"></script></body></html>`;
1448
+ var cachedVersion = null;
1449
+ function getVersion() {
1450
+ if (cachedVersion !== null) return cachedVersion;
1451
+ let version = "unknown";
1452
+ try {
1453
+ const pkg = JSON.parse(fs.readFileSync(path.resolve(findPackageRoot(), "package.json"), "utf8"));
1454
+ if (typeof pkg.version === "string") version = pkg.version;
1455
+ } catch {
1456
+ }
1457
+ cachedVersion = version;
1458
+ return version;
1459
+ }
1414
1460
  var cachedWidgetJs = null;
1415
1461
  function getWidgetJs() {
1416
1462
  if (!cachedWidgetJs) {
@@ -1437,6 +1483,8 @@ function attachDevtoolsRoutes(httpServer, devtools) {
1437
1483
  res.setHeader("Access-Control-Allow-Origin", "*");
1438
1484
  res.setHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, OPTIONS");
1439
1485
  res.setHeader("Access-Control-Allow-Headers", "Content-Type");
1486
+ res.setHeader("x-autotel-devtools", getVersion());
1487
+ res.setHeader("Access-Control-Expose-Headers", "x-autotel-devtools");
1440
1488
  if (req.method === "OPTIONS") {
1441
1489
  res.writeHead(204);
1442
1490
  res.end();
@@ -1455,7 +1503,12 @@ function attachDevtoolsRoutes(httpServer, devtools) {
1455
1503
  return;
1456
1504
  }
1457
1505
  if (req.method === "GET" && url === "/healthz") {
1458
- sendJson(res, 200, { ok: true, clients: devtools.clientCount });
1506
+ sendJson(res, 200, {
1507
+ ok: true,
1508
+ service: DEVTOOLS_IDENTITY,
1509
+ version: getVersion(),
1510
+ clients: devtools.clientCount
1511
+ });
1459
1512
  return;
1460
1513
  }
1461
1514
  if (req.method === "GET" && url === "/v1/traces") {
@@ -1475,7 +1528,7 @@ function attachDevtoolsRoutes(httpServer, devtools) {
1475
1528
  devtools.addTraces(traces);
1476
1529
  sendJson(res, 200, { acceptedTraces: traces.length });
1477
1530
  } catch (e) {
1478
- sendJson(res, 400, { error: "Invalid OTLP payload", message: e instanceof Error ? e.message : String(e) });
1531
+ sendOtlpError(res, req, e);
1479
1532
  }
1480
1533
  return;
1481
1534
  }
@@ -1486,7 +1539,7 @@ function attachDevtoolsRoutes(httpServer, devtools) {
1486
1539
  devtools.addLogs(logs);
1487
1540
  sendJson(res, 200, { acceptedLogs: logs.length });
1488
1541
  } catch (e) {
1489
- sendJson(res, 400, { error: "Invalid OTLP payload", message: e instanceof Error ? e.message : String(e) });
1542
+ sendOtlpError(res, req, e);
1490
1543
  }
1491
1544
  return;
1492
1545
  }
@@ -1496,7 +1549,7 @@ function attachDevtoolsRoutes(httpServer, devtools) {
1496
1549
  const count = countOtlpMetrics(payload);
1497
1550
  sendJson(res, 200, { acceptedMetrics: count });
1498
1551
  } catch (e) {
1499
- sendJson(res, 400, { error: "Invalid OTLP payload", message: e instanceof Error ? e.message : String(e) });
1552
+ sendOtlpError(res, req, e);
1500
1553
  }
1501
1554
  return;
1502
1555
  }
@@ -1509,6 +1562,7 @@ function createDevtoolsHttpServer(devtools, _options = {}) {
1509
1562
  return server;
1510
1563
  }
1511
1564
 
1565
+ exports.DEVTOOLS_IDENTITY = DEVTOOLS_IDENTITY;
1512
1566
  exports.DevtoolsLogExporter = DevtoolsLogExporter;
1513
1567
  exports.DevtoolsRemoteExporter = DevtoolsRemoteExporter;
1514
1568
  exports.DevtoolsServer = DevtoolsServer;
@@ -1525,6 +1579,7 @@ exports.decodeOtlpTraceRequest = decodeOtlpTraceRequest;
1525
1579
  exports.isProtobufContentType = isProtobufContentType;
1526
1580
  exports.parseOtlpLogs = parseOtlpLogs;
1527
1581
  exports.parseOtlpTraces = parseOtlpTraces;
1582
+ exports.probePortHolder = probePortHolder;
1528
1583
  exports.resolveTelemetryLimits = resolveTelemetryLimits;
1529
1584
  //# sourceMappingURL=index.cjs.map
1530
1585
  //# sourceMappingURL=index.cjs.map