autotel-devtools 6.0.1 → 6.1.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.
package/dist/index.cjs CHANGED
@@ -432,13 +432,16 @@ var DevtoolsServer = class {
432
432
  addTraces(traces) {
433
433
  for (const trace of traces) this.addTrace(trace);
434
434
  }
435
+ // `errors` is full-state on every broadcast (the client replaces, not appends),
436
+ // so non-trace broadcasts must echo the current error groups rather than `[]` —
437
+ // otherwise a log/metric arriving after an error would wipe it from the UI.
435
438
  addLog(log) {
436
439
  this.logs = appendWithLimit(this.logs, log, this.limits.maxLogCount);
437
- this.broadcast({ traces: [], metrics: [], logs: [log], errors: [] });
440
+ this.broadcast({ traces: [], metrics: [], logs: [log], errors: this.errorAggregator.getErrorGroups() });
438
441
  }
439
442
  addLogs(logs) {
440
443
  this.logs = appendManyWithLimit(this.logs, logs, this.limits.maxLogCount);
441
- this.broadcast({ traces: [], metrics: [], logs, errors: [] });
444
+ this.broadcast({ traces: [], metrics: [], logs, errors: this.errorAggregator.getErrorGroups() });
442
445
  }
443
446
  addMetric(metric) {
444
447
  this.metrics = appendWithLimit(
@@ -446,7 +449,7 @@ var DevtoolsServer = class {
446
449
  metric,
447
450
  this.limits.maxMetricCount
448
451
  );
449
- this.broadcast({ traces: [], metrics: [metric], logs: [], errors: [] });
452
+ this.broadcast({ traces: [], metrics: [metric], logs: [], errors: this.errorAggregator.getErrorGroups() });
450
453
  }
451
454
  getCurrentData() {
452
455
  return {
@@ -925,7 +928,17 @@ function decodeOtlpMetricsRequest(body) {
925
928
  return decodeRequest("opentelemetry.proto.metrics.v1.ExportMetricsServiceRequest", body);
926
929
  }
927
930
 
931
+ // src/server/identity.ts
932
+ var DEVTOOLS_IDENTITY = "autotel-devtools";
933
+
928
934
  // src/server/http.ts
935
+ function sendOtlpError(res, req, e) {
936
+ sendJson(res, 400, {
937
+ error: "Invalid OTLP payload",
938
+ message: e instanceof Error ? e.message : String(e),
939
+ contentType: req.headers["content-type"] ?? null
940
+ });
941
+ }
929
942
  var PROTOBUF_DECODERS = {
930
943
  traces: decodeOtlpTraceRequest,
931
944
  logs: decodeOtlpLogsRequest,
@@ -946,6 +959,18 @@ function findPackageRoot() {
946
959
  return dir;
947
960
  }
948
961
  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>`;
962
+ var cachedVersion = null;
963
+ function getVersion() {
964
+ if (cachedVersion !== null) return cachedVersion;
965
+ let version = "unknown";
966
+ try {
967
+ const pkg = JSON.parse(fs.readFileSync(path.resolve(findPackageRoot(), "package.json"), "utf8"));
968
+ if (typeof pkg.version === "string") version = pkg.version;
969
+ } catch {
970
+ }
971
+ cachedVersion = version;
972
+ return version;
973
+ }
949
974
  var cachedWidgetJs = null;
950
975
  function getWidgetJs() {
951
976
  if (!cachedWidgetJs) {
@@ -972,6 +997,8 @@ function attachDevtoolsRoutes(httpServer, devtools) {
972
997
  res.setHeader("Access-Control-Allow-Origin", "*");
973
998
  res.setHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, OPTIONS");
974
999
  res.setHeader("Access-Control-Allow-Headers", "Content-Type");
1000
+ res.setHeader("x-autotel-devtools", getVersion());
1001
+ res.setHeader("Access-Control-Expose-Headers", "x-autotel-devtools");
975
1002
  if (req.method === "OPTIONS") {
976
1003
  res.writeHead(204);
977
1004
  res.end();
@@ -990,7 +1017,12 @@ function attachDevtoolsRoutes(httpServer, devtools) {
990
1017
  return;
991
1018
  }
992
1019
  if (req.method === "GET" && url === "/healthz") {
993
- sendJson(res, 200, { ok: true, clients: devtools.clientCount });
1020
+ sendJson(res, 200, {
1021
+ ok: true,
1022
+ service: DEVTOOLS_IDENTITY,
1023
+ version: getVersion(),
1024
+ clients: devtools.clientCount
1025
+ });
994
1026
  return;
995
1027
  }
996
1028
  if (req.method === "GET" && url === "/v1/traces") {
@@ -1010,7 +1042,7 @@ function attachDevtoolsRoutes(httpServer, devtools) {
1010
1042
  devtools.addTraces(traces);
1011
1043
  sendJson(res, 200, { acceptedTraces: traces.length });
1012
1044
  } catch (e) {
1013
- sendJson(res, 400, { error: "Invalid OTLP payload", message: e instanceof Error ? e.message : String(e) });
1045
+ sendOtlpError(res, req, e);
1014
1046
  }
1015
1047
  return;
1016
1048
  }
@@ -1021,7 +1053,7 @@ function attachDevtoolsRoutes(httpServer, devtools) {
1021
1053
  devtools.addLogs(logs);
1022
1054
  sendJson(res, 200, { acceptedLogs: logs.length });
1023
1055
  } catch (e) {
1024
- sendJson(res, 400, { error: "Invalid OTLP payload", message: e instanceof Error ? e.message : String(e) });
1056
+ sendOtlpError(res, req, e);
1025
1057
  }
1026
1058
  return;
1027
1059
  }
@@ -1031,7 +1063,7 @@ function attachDevtoolsRoutes(httpServer, devtools) {
1031
1063
  const count = countOtlpMetrics(payload);
1032
1064
  sendJson(res, 200, { acceptedMetrics: count });
1033
1065
  } catch (e) {
1034
- sendJson(res, 400, { error: "Invalid OTLP payload", message: e instanceof Error ? e.message : String(e) });
1066
+ sendOtlpError(res, req, e);
1035
1067
  }
1036
1068
  return;
1037
1069
  }