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.js CHANGED
@@ -425,13 +425,16 @@ var DevtoolsServer = class {
425
425
  addTraces(traces) {
426
426
  for (const trace of traces) this.addTrace(trace);
427
427
  }
428
+ // `errors` is full-state on every broadcast (the client replaces, not appends),
429
+ // so non-trace broadcasts must echo the current error groups rather than `[]` —
430
+ // otherwise a log/metric arriving after an error would wipe it from the UI.
428
431
  addLog(log) {
429
432
  this.logs = appendWithLimit(this.logs, log, this.limits.maxLogCount);
430
- this.broadcast({ traces: [], metrics: [], logs: [log], errors: [] });
433
+ this.broadcast({ traces: [], metrics: [], logs: [log], errors: this.errorAggregator.getErrorGroups() });
431
434
  }
432
435
  addLogs(logs) {
433
436
  this.logs = appendManyWithLimit(this.logs, logs, this.limits.maxLogCount);
434
- this.broadcast({ traces: [], metrics: [], logs, errors: [] });
437
+ this.broadcast({ traces: [], metrics: [], logs, errors: this.errorAggregator.getErrorGroups() });
435
438
  }
436
439
  addMetric(metric) {
437
440
  this.metrics = appendWithLimit(
@@ -439,7 +442,7 @@ var DevtoolsServer = class {
439
442
  metric,
440
443
  this.limits.maxMetricCount
441
444
  );
442
- this.broadcast({ traces: [], metrics: [metric], logs: [], errors: [] });
445
+ this.broadcast({ traces: [], metrics: [metric], logs: [], errors: this.errorAggregator.getErrorGroups() });
443
446
  }
444
447
  getCurrentData() {
445
448
  return {
@@ -918,7 +921,17 @@ function decodeOtlpMetricsRequest(body) {
918
921
  return decodeRequest("opentelemetry.proto.metrics.v1.ExportMetricsServiceRequest", body);
919
922
  }
920
923
 
924
+ // src/server/identity.ts
925
+ var DEVTOOLS_IDENTITY = "autotel-devtools";
926
+
921
927
  // src/server/http.ts
928
+ function sendOtlpError(res, req, e) {
929
+ sendJson(res, 400, {
930
+ error: "Invalid OTLP payload",
931
+ message: e instanceof Error ? e.message : String(e),
932
+ contentType: req.headers["content-type"] ?? null
933
+ });
934
+ }
922
935
  var PROTOBUF_DECODERS = {
923
936
  traces: decodeOtlpTraceRequest,
924
937
  logs: decodeOtlpLogsRequest,
@@ -939,6 +952,18 @@ function findPackageRoot() {
939
952
  return dir;
940
953
  }
941
954
  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>`;
955
+ var cachedVersion = null;
956
+ function getVersion() {
957
+ if (cachedVersion !== null) return cachedVersion;
958
+ let version = "unknown";
959
+ try {
960
+ const pkg = JSON.parse(readFileSync(resolve(findPackageRoot(), "package.json"), "utf8"));
961
+ if (typeof pkg.version === "string") version = pkg.version;
962
+ } catch {
963
+ }
964
+ cachedVersion = version;
965
+ return version;
966
+ }
942
967
  var cachedWidgetJs = null;
943
968
  function getWidgetJs() {
944
969
  if (!cachedWidgetJs) {
@@ -965,6 +990,8 @@ function attachDevtoolsRoutes(httpServer, devtools) {
965
990
  res.setHeader("Access-Control-Allow-Origin", "*");
966
991
  res.setHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, OPTIONS");
967
992
  res.setHeader("Access-Control-Allow-Headers", "Content-Type");
993
+ res.setHeader("x-autotel-devtools", getVersion());
994
+ res.setHeader("Access-Control-Expose-Headers", "x-autotel-devtools");
968
995
  if (req.method === "OPTIONS") {
969
996
  res.writeHead(204);
970
997
  res.end();
@@ -983,7 +1010,12 @@ function attachDevtoolsRoutes(httpServer, devtools) {
983
1010
  return;
984
1011
  }
985
1012
  if (req.method === "GET" && url === "/healthz") {
986
- sendJson(res, 200, { ok: true, clients: devtools.clientCount });
1013
+ sendJson(res, 200, {
1014
+ ok: true,
1015
+ service: DEVTOOLS_IDENTITY,
1016
+ version: getVersion(),
1017
+ clients: devtools.clientCount
1018
+ });
987
1019
  return;
988
1020
  }
989
1021
  if (req.method === "GET" && url === "/v1/traces") {
@@ -1003,7 +1035,7 @@ function attachDevtoolsRoutes(httpServer, devtools) {
1003
1035
  devtools.addTraces(traces);
1004
1036
  sendJson(res, 200, { acceptedTraces: traces.length });
1005
1037
  } catch (e) {
1006
- sendJson(res, 400, { error: "Invalid OTLP payload", message: e instanceof Error ? e.message : String(e) });
1038
+ sendOtlpError(res, req, e);
1007
1039
  }
1008
1040
  return;
1009
1041
  }
@@ -1014,7 +1046,7 @@ function attachDevtoolsRoutes(httpServer, devtools) {
1014
1046
  devtools.addLogs(logs);
1015
1047
  sendJson(res, 200, { acceptedLogs: logs.length });
1016
1048
  } catch (e) {
1017
- sendJson(res, 400, { error: "Invalid OTLP payload", message: e instanceof Error ? e.message : String(e) });
1049
+ sendOtlpError(res, req, e);
1018
1050
  }
1019
1051
  return;
1020
1052
  }
@@ -1024,7 +1056,7 @@ function attachDevtoolsRoutes(httpServer, devtools) {
1024
1056
  const count = countOtlpMetrics(payload);
1025
1057
  sendJson(res, 200, { acceptedMetrics: count });
1026
1058
  } catch (e) {
1027
- sendJson(res, 400, { error: "Invalid OTLP payload", message: e instanceof Error ? e.message : String(e) });
1059
+ sendOtlpError(res, req, e);
1028
1060
  }
1029
1061
  return;
1030
1062
  }