@neat.is/core 0.4.4 → 0.4.6

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
@@ -337,12 +337,15 @@ function parseOtlpRequest(body) {
337
337
  const out = [];
338
338
  for (const rs of body.resourceSpans ?? []) {
339
339
  const resourceAttrs = attrsToRecord(rs.resource?.attributes);
340
- const service = typeof resourceAttrs["service.name"] === "string" ? resourceAttrs["service.name"] : "unknown";
340
+ const rawServiceName = resourceAttrs["service.name"];
341
+ const resourceServiceNamePresent = typeof rawServiceName === "string" && rawServiceName.length > 0;
342
+ const service = resourceServiceNamePresent ? rawServiceName : "unidentified";
341
343
  for (const ss of rs.scopeSpans ?? []) {
342
344
  for (const span of ss.spans ?? []) {
343
345
  const attrs = attrsToRecord(span.attributes);
344
346
  const parsed = {
345
347
  service,
348
+ resourceServiceNamePresent,
346
349
  traceId: span.traceId ?? "",
347
350
  spanId: span.spanId ?? "",
348
351
  parentSpanId: span.parentSpanId || void 0,
@@ -1644,6 +1647,14 @@ function thresholdForEdgeType(edgeType, overrides) {
1644
1647
  function nowIso(ctx) {
1645
1648
  return new Date(ctx.now ? ctx.now() : Date.now()).toISOString();
1646
1649
  }
1650
+ var unidentifiedWarnedProjects = /* @__PURE__ */ new Set();
1651
+ function warnUnidentifiedSpan(project) {
1652
+ if (unidentifiedWarnedProjects.has(project)) return;
1653
+ unidentifiedWarnedProjects.add(project);
1654
+ console.warn(
1655
+ `[neatd] span lacked service.name; routed to 'unidentified' in project ${project}; check your OTel SDK config.`
1656
+ );
1657
+ }
1647
1658
  function pickAttr(span, ...keys) {
1648
1659
  for (const k of keys) {
1649
1660
  const v = span.attributes[k];
@@ -1898,6 +1909,9 @@ async function handleSpan(ctx, span) {
1898
1909
  const ts = span.startTimeIso ?? nowIso(ctx);
1899
1910
  const nowMs = ctx.now ? ctx.now() : Date.now();
1900
1911
  const env = span.env ?? "unknown";
1912
+ if (span.resourceServiceNamePresent === false) {
1913
+ warnUnidentifiedSpan(ctx.project ?? DEFAULT_PROJECT);
1914
+ }
1901
1915
  const sourceId = ensureServiceNode(ctx.graph, span.service, env);
1902
1916
  const isError = span.statusCode === 2;
1903
1917
  cacheSpanService(span, nowMs);
@@ -6076,11 +6090,45 @@ async function startDaemon(opts = {}) {
6076
6090
  });
6077
6091
  };
6078
6092
  process.on("SIGHUP", sighupHandler);
6093
+ const REGISTRY_RELOAD_DEBOUNCE_MS = 500;
6094
+ let registryWatcher = null;
6095
+ let reloadTimer = null;
6096
+ try {
6097
+ const regDir = import_node_path37.default.dirname(regPath);
6098
+ const regBase = import_node_path37.default.basename(regPath);
6099
+ registryWatcher = (0, import_node_fs22.watch)(regDir, (_eventType, filename) => {
6100
+ if (filename !== null && filename !== regBase) return;
6101
+ if (reloadTimer) clearTimeout(reloadTimer);
6102
+ reloadTimer = setTimeout(() => {
6103
+ reloadTimer = null;
6104
+ void reload().catch((err) => {
6105
+ console.warn(
6106
+ `neatd: registry-watch reload failed \u2014 ${err.message}`
6107
+ );
6108
+ });
6109
+ }, REGISTRY_RELOAD_DEBOUNCE_MS);
6110
+ });
6111
+ } catch (err) {
6112
+ console.warn(
6113
+ `neatd: failed to watch registry at ${regPath} \u2014 ${err.message}. Run \`neatd reload\` (or send SIGHUP) after registering new projects.`
6114
+ );
6115
+ }
6079
6116
  let stopped = false;
6080
6117
  const stop = async () => {
6081
6118
  if (stopped) return;
6082
6119
  stopped = true;
6083
6120
  process.off("SIGHUP", sighupHandler);
6121
+ if (reloadTimer) {
6122
+ clearTimeout(reloadTimer);
6123
+ reloadTimer = null;
6124
+ }
6125
+ if (registryWatcher) {
6126
+ try {
6127
+ registryWatcher.close();
6128
+ } catch {
6129
+ }
6130
+ registryWatcher = null;
6131
+ }
6084
6132
  if (otlpApp) await otlpApp.close().catch(() => {
6085
6133
  });
6086
6134
  if (restApp) await restApp.close().catch(() => {