@neat.is/core 0.9.3 → 0.9.5-dev.20260824

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/neatd.js CHANGED
@@ -2,11 +2,11 @@
2
2
  import {
3
3
  reconcileDaemonRecordSync,
4
4
  startDaemon
5
- } from "./chunk-2D4Y5QHE.js";
5
+ } from "./chunk-TGCWMMF6.js";
6
6
  import {
7
7
  listProjects,
8
8
  registryPath
9
- } from "./chunk-EDE4XP2M.js";
9
+ } from "./chunk-IVVF37OU.js";
10
10
  import {
11
11
  BindAuthorityError,
12
12
  __require
package/dist/server.cjs CHANGED
@@ -4706,6 +4706,64 @@ function latencyPercentiles(hist) {
4706
4706
  return { p50: round(quantile(hist, 0.5)), p95: round(quantile(hist, 0.95)) };
4707
4707
  }
4708
4708
 
4709
+ // src/stacktrace.ts
4710
+ init_cjs_shims();
4711
+ var FRAME_SHAPES = [
4712
+ // `File "<path>", line <N>, in <func>` — the "most recent call last" shape.
4713
+ { re: /File "([^"]+)", line (\d+)(?:, in (\S+))?/, file: 1, line: 2, fn: 3, deepest: "last" },
4714
+ // `at <func> (<path>:<line>:<col>)` — named call frame, most recent first.
4715
+ { re: /\bat\s+(.+?)\s+\((.+?):(\d+):\d+\)/, file: 2, line: 3, fn: 1, deepest: "first" },
4716
+ // `at <path>:<line>:<col>` — anonymous call frame, most recent first.
4717
+ { re: /\bat\s+(.+?):(\d+):\d+/, file: 1, line: 2, deepest: "first" },
4718
+ // `at <qualified.method>(<File.ext>:<line>)` — JVM-style, most recent first.
4719
+ { re: /\bat\s+(.+?)\((\S+\.\w+):(\d+)\)/, file: 2, line: 3, fn: 1, deepest: "first" }
4720
+ ];
4721
+ var VENDOR_MARKERS = [
4722
+ "node_modules",
4723
+ // dependency root
4724
+ "site-packages",
4725
+ // installed-package root
4726
+ "dist-packages",
4727
+ // distro-packaged root
4728
+ "node:"
4729
+ // runtime-internal module scheme (a stdlib/runtime-root frame)
4730
+ ];
4731
+ function matchFrame(line) {
4732
+ for (const shape of FRAME_SHAPES) {
4733
+ const m = shape.re.exec(line);
4734
+ if (!m) continue;
4735
+ const file = m[shape.file];
4736
+ const lineNo = Number(m[shape.line]);
4737
+ if (!file || !Number.isFinite(lineNo)) continue;
4738
+ const fn = shape.fn !== void 0 ? m[shape.fn] : void 0;
4739
+ return { frame: { file, line: lineNo, ...fn ? { fn } : {} }, deepest: shape.deepest };
4740
+ }
4741
+ return null;
4742
+ }
4743
+ function isApplicationFrame(file) {
4744
+ if (file.startsWith("<")) return false;
4745
+ const norm = file.split("\\").join("/");
4746
+ for (const marker of VENDOR_MARKERS) {
4747
+ if (norm.includes(marker)) return false;
4748
+ }
4749
+ return true;
4750
+ }
4751
+ function deepestApplicationFrame(stacktrace) {
4752
+ if (!stacktrace) return null;
4753
+ const appFrames = [];
4754
+ for (const raw of stacktrace.split("\n")) {
4755
+ const matched = matchFrame(raw);
4756
+ if (!matched) continue;
4757
+ if (!isApplicationFrame(matched.frame.file)) continue;
4758
+ appFrames.push(matched);
4759
+ }
4760
+ if (appFrames.length === 0) return null;
4761
+ const orientation = appFrames.some((f) => f.deepest === "last") ? "last" : "first";
4762
+ const oriented = appFrames.filter((f) => f.deepest === orientation);
4763
+ const chosen = orientation === "last" ? oriented[oriented.length - 1] : oriented[0];
4764
+ return chosen ? chosen.frame : null;
4765
+ }
4766
+
4709
4767
  // src/ingest.ts
4710
4768
  var HOUR_MS = 60 * 60 * 1e3;
4711
4769
  var DAY_MS = 24 * HOUR_MS;
@@ -5557,29 +5615,71 @@ async function appendConnectorIncident(errorsPath, input) {
5557
5615
  await import_node_fs9.promises.mkdir(import_node_path10.default.dirname(errorsPath), { recursive: true });
5558
5616
  await import_node_fs9.promises.appendFile(errorsPath, JSON.stringify(ev) + "\n", "utf8");
5559
5617
  }
5560
- function incidentAffectedNode(span, graph, scanPath) {
5618
+ function landIncidentCallSite(span, callSite, trusted, graph) {
5619
+ const relPath = graph ? reconcileObservedRelPath(graph, span.service, callSite.relPath) : callSite.relPath;
5620
+ const canonicalService = serviceNodeName(graph, span) ?? span.service;
5621
+ const recovered = !trusted;
5622
+ if (graph) {
5623
+ const fusedFileId = (0, import_types7.fileId)(canonicalService, relPath);
5624
+ if (graph.hasNode(fusedFileId)) {
5625
+ const node = landObservedSymbol(
5626
+ graph,
5627
+ fusedFileId,
5628
+ canonicalService,
5629
+ relPath,
5630
+ { ...callSite, relPath },
5631
+ false
5632
+ );
5633
+ return {
5634
+ affectedNode: node,
5635
+ ...recovered ? {
5636
+ codeFilepath: relPath,
5637
+ ...callSite.line !== void 0 ? { codeLineno: callSite.line } : {}
5638
+ } : {}
5639
+ };
5640
+ }
5641
+ if (recovered) return null;
5642
+ }
5643
+ return { affectedNode: (0, import_types7.fileId)(span.service, relPath) };
5644
+ }
5645
+ function serviceNodeName(graph, span) {
5646
+ if (!graph) return void 0;
5647
+ const sid = resolveFusedServiceId(graph, span.service, span.env);
5648
+ if (!graph.hasNode(sid)) return void 0;
5649
+ const node = graph.getNodeAttributes(sid);
5650
+ return typeof node.name === "string" ? node.name : void 0;
5651
+ }
5652
+ function stacktraceCallSite(span, serviceNode, scanPath) {
5653
+ const frame = deepestApplicationFrame(span.exception?.stacktrace);
5654
+ if (!frame) return null;
5655
+ const relPath = relPathForRuntimeFile(frame.file, serviceNode, scanPath);
5656
+ if (!relPath) return null;
5657
+ return { relPath, line: frame.line, ...frame.fn ? { fn: frame.fn } : {} };
5658
+ }
5659
+ function incidentLocus(span, graph, scanPath) {
5561
5660
  const sid = graph ? resolveFusedServiceId(graph, span.service, span.env) : (0, import_types7.serviceId)(span.service, span.env);
5562
5661
  const serviceNode = graph && graph.hasNode(sid) ? graph.getNodeAttributes(sid) : void 0;
5563
5662
  const callSite = callSiteFromSpan(span, serviceNode, scanPath);
5564
5663
  if (callSite) {
5565
- const relPath = graph ? reconcileObservedRelPath(graph, span.service, callSite.relPath) : callSite.relPath;
5566
- const canonicalService = serviceNode && typeof serviceNode.name === "string" ? serviceNode.name : span.service;
5567
- if (graph) {
5568
- const fusedFileId = (0, import_types7.fileId)(canonicalService, relPath);
5569
- if (graph.hasNode(fusedFileId)) {
5570
- return landObservedSymbol(
5571
- graph,
5572
- fusedFileId,
5573
- canonicalService,
5574
- relPath,
5575
- { ...callSite, relPath },
5576
- false
5577
- );
5578
- }
5664
+ const landed = landIncidentCallSite(span, callSite, true, graph);
5665
+ if (landed) return landed;
5666
+ } else {
5667
+ const recovered = stacktraceCallSite(span, serviceNode, scanPath);
5668
+ if (recovered) {
5669
+ const landed = landIncidentCallSite(span, recovered, false, graph);
5670
+ if (landed) return landed;
5579
5671
  }
5580
- return (0, import_types7.fileId)(span.service, relPath);
5581
5672
  }
5582
- return sid;
5673
+ return { affectedNode: sid };
5674
+ }
5675
+ function incidentAffectedNode(span, graph, scanPath) {
5676
+ return incidentLocus(span, graph, scanPath).affectedNode;
5677
+ }
5678
+ function withRecoveredCodeAttrs(attrs, locus) {
5679
+ if (locus.codeFilepath === void 0) return attrs;
5680
+ attrs[CODE_FILEPATH_ATTR] = locus.codeFilepath;
5681
+ if (locus.codeLineno !== void 0) attrs[CODE_LINENO_ATTR] = locus.codeLineno;
5682
+ return attrs;
5583
5683
  }
5584
5684
  function sanitizeAttributes(attrs) {
5585
5685
  const out = {};
@@ -5612,7 +5712,8 @@ async function recordFailingResponseIncident(ctx, span, affectedNode, timestamp,
5612
5712
  await appendErrorEvent(ctx, ev);
5613
5713
  }
5614
5714
  async function recordExceptionIncident(ctx, span, ts) {
5615
- const attrs = sanitizeAttributes(span.attributes);
5715
+ const locus = incidentLocus(span, ctx.graph, ctx.scanPath);
5716
+ const attrs = withRecoveredCodeAttrs(sanitizeAttributes(span.attributes), locus);
5616
5717
  const ev = {
5617
5718
  id: `${span.traceId}:${span.spanId}`,
5618
5719
  timestamp: ts,
@@ -5623,7 +5724,7 @@ async function recordExceptionIncident(ctx, span, ts) {
5623
5724
  ...span.exception?.type ? { exceptionType: span.exception.type } : {},
5624
5725
  ...span.exception?.stacktrace ? { exceptionStacktrace: span.exception.stacktrace } : {},
5625
5726
  ...Object.keys(attrs).length > 0 ? { attributes: attrs } : {},
5626
- affectedNode: incidentAffectedNode(span, ctx.graph, ctx.scanPath)
5727
+ affectedNode: locus.affectedNode
5627
5728
  };
5628
5729
  await appendErrorEvent(ctx, ev);
5629
5730
  }
@@ -5926,7 +6027,8 @@ async function handleSpan(ctx, span) {
5926
6027
  if (span.statusCode === 2) {
5927
6028
  stitchTrace(ctx.graph, sourceId, ts);
5928
6029
  if (ctx.writeErrorEventInline !== false) {
5929
- const attrs = sanitizeAttributes(span.attributes);
6030
+ const locus = incidentLocus(span, ctx.graph, ctx.scanPath);
6031
+ const attrs = withRecoveredCodeAttrs(sanitizeAttributes(span.attributes), locus);
5930
6032
  const ev = {
5931
6033
  id: `${span.traceId}:${span.spanId}`,
5932
6034
  timestamp: ts,
@@ -5938,10 +6040,11 @@ async function handleSpan(ctx, span) {
5938
6040
  ...span.exception?.stacktrace ? { exceptionStacktrace: span.exception.stacktrace } : {},
5939
6041
  ...Object.keys(attrs).length > 0 ? { attributes: attrs } : {},
5940
6042
  // Attribute to where the failure originated — the symbol / file / service
5941
- // the throwing span named (incidentAffectedNode, ADR-191) the same
5942
- // source-based attribution the durable receiver write uses, not the
5943
- // outbound edge target this span happened to mint.
5944
- affectedNode: incidentAffectedNode(span, ctx.graph, ctx.scanPath)
6043
+ // the throwing span named (incidentAffectedNode / ADR-191, extended to
6044
+ // recover the locus from the stacktrace when the span stamped no code.*
6045
+ // attrs, ADR-216) the same source-based attribution the durable
6046
+ // receiver write uses, not the outbound edge target this span minted.
6047
+ affectedNode: locus.affectedNode
5945
6048
  };
5946
6049
  await appendErrorEvent(ctx, ev);
5947
6050
  }