@neat.is/core 0.9.1 → 0.9.2-dev.20260822

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,15 +2,15 @@
2
2
  import {
3
3
  reconcileDaemonRecordSync,
4
4
  startDaemon
5
- } from "./chunk-YKQB622D.js";
5
+ } from "./chunk-L4SZIIER.js";
6
6
  import {
7
7
  listProjects,
8
8
  registryPath
9
- } from "./chunk-UN7VFA4H.js";
9
+ } from "./chunk-RQQUI3NQ.js";
10
10
  import {
11
11
  BindAuthorityError,
12
12
  __require
13
- } from "./chunk-UUYCTH2E.js";
13
+ } from "./chunk-GDGUY4T6.js";
14
14
 
15
15
  // src/neatd.ts
16
16
  import { promises as fs } from "fs";
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  reshapeGrpcRequest,
3
3
  startOtelGrpcReceiver
4
- } from "./chunk-FCO5Z3RW.js";
5
- import "./chunk-UUYCTH2E.js";
4
+ } from "./chunk-ERE47MCR.js";
5
+ import "./chunk-GDGUY4T6.js";
6
6
  export {
7
7
  reshapeGrpcRequest,
8
8
  startOtelGrpcReceiver
9
9
  };
10
- //# sourceMappingURL=otel-grpc-CO47JRIN.js.map
10
+ //# sourceMappingURL=otel-grpc-Y5K4WGWO.js.map
package/dist/server.cjs CHANGED
@@ -524,11 +524,42 @@ async function decodeProtobufBody(buf) {
524
524
  const { reshapeGrpcRequest: reshapeGrpcRequest2 } = await Promise.resolve().then(() => (init_otel_grpc(), otel_grpc_exports));
525
525
  return reshapeGrpcRequest2(decoded);
526
526
  }
527
+ function decompressorForEncoding(encoding) {
528
+ switch (encoding) {
529
+ case "gzip":
530
+ case "x-gzip":
531
+ return import_node_zlib.default.createGunzip();
532
+ case "deflate":
533
+ return import_node_zlib.default.createInflate();
534
+ default:
535
+ return null;
536
+ }
537
+ }
527
538
  async function buildOtelReceiver(opts) {
528
539
  const app = (0, import_fastify.default)({
529
540
  logger: false,
530
541
  bodyLimit: opts.bodyLimit ?? 16 * 1024 * 1024
531
542
  });
543
+ app.addHook("preParsing", (req, _reply, payload, done) => {
544
+ const encoding = (req.headers["content-encoding"] ?? "").toString().trim().toLowerCase();
545
+ if (encoding === "" || encoding === "identity") {
546
+ done(null, payload);
547
+ return;
548
+ }
549
+ const decompressor = decompressorForEncoding(encoding);
550
+ if (!decompressor) {
551
+ done(null, payload);
552
+ return;
553
+ }
554
+ const tracked = decompressor;
555
+ tracked.receivedEncodedLength = 0;
556
+ payload.on("data", (chunk) => {
557
+ tracked.receivedEncodedLength = (tracked.receivedEncodedLength ?? 0) + chunk.length;
558
+ });
559
+ payload.on("error", (err) => decompressor.destroy(err));
560
+ payload.pipe(decompressor);
561
+ done(null, decompressor);
562
+ });
532
563
  const REJECT_WARN_INTERVAL_MS = 6e4;
533
564
  let lastRejectWarnAt = 0;
534
565
  const warnRejectedOtlp = () => {
@@ -710,13 +741,14 @@ async function buildOtelReceiver(opts) {
710
741
  };
711
742
  return decorated;
712
743
  }
713
- var import_node_path55, import_node_url2, import_fastify, import_protobufjs, ENV_ATTR_CANONICAL, ENV_ATTR_COMPAT, ENV_FALLBACK, exportTraceServiceRequestType, exportTraceServiceResponseType, cachedProtobufResponseBody;
744
+ var import_node_path55, import_node_url2, import_node_zlib, import_fastify, import_protobufjs, ENV_ATTR_CANONICAL, ENV_ATTR_COMPAT, ENV_FALLBACK, exportTraceServiceRequestType, exportTraceServiceResponseType, cachedProtobufResponseBody;
714
745
  var init_otel = __esm({
715
746
  "src/otel.ts"() {
716
747
  "use strict";
717
748
  init_cjs_shims();
718
749
  import_node_path55 = __toESM(require("path"), 1);
719
750
  import_node_url2 = require("url");
751
+ import_node_zlib = __toESM(require("zlib"), 1);
720
752
  import_fastify = __toESM(require("fastify"), 1);
721
753
  import_protobufjs = __toESM(require("protobufjs"), 1);
722
754
  init_auth();
@@ -4814,6 +4846,14 @@ function grpcStatusCodeFromAttrs(attrs) {
4814
4846
  }
4815
4847
  return void 0;
4816
4848
  }
4849
+ function spanRecordsError(span) {
4850
+ if (span.statusCode === 2) return true;
4851
+ const grpc2 = grpcStatusCodeFromAttrs(span.attributes);
4852
+ if (grpc2 !== void 0 && grpc2 !== 0) return true;
4853
+ const httpStatus = httpResponseStatusFromAttrs(span.attributes);
4854
+ if (httpStatus !== void 0 && httpStatus >= 500) return true;
4855
+ return false;
4856
+ }
4817
4857
  function nonHttpFailureMessageFromAttrs(attrs) {
4818
4858
  const grpc2 = grpcStatusCodeFromAttrs(attrs);
4819
4859
  if (grpc2 !== void 0 && grpc2 !== 0) {
@@ -5587,6 +5627,21 @@ async function recordExceptionIncident(ctx, span, ts) {
5587
5627
  };
5588
5628
  await appendErrorEvent(ctx, ev);
5589
5629
  }
5630
+ async function recordGrpcFailureIncident(ctx, span, ts) {
5631
+ const attrs = sanitizeAttributes(span.attributes);
5632
+ const ev = {
5633
+ id: `${span.traceId}:${span.spanId}`,
5634
+ timestamp: ts,
5635
+ service: span.service,
5636
+ traceId: span.traceId,
5637
+ spanId: span.spanId,
5638
+ errorType: "grpc-failure",
5639
+ errorMessage: incidentMessage(span),
5640
+ ...Object.keys(attrs).length > 0 ? { attributes: attrs } : {},
5641
+ affectedNode: incidentAffectedNode(span, ctx.graph, ctx.scanPath)
5642
+ };
5643
+ await appendErrorEvent(ctx, ev);
5644
+ }
5590
5645
  async function advance4xxBurst(ctx, span, affectedNode, ts, nowMs, status2) {
5591
5646
  const { threshold, windowMs } = loadIncidentThresholdsFromEnv();
5592
5647
  if (!ctx.burstState) ctx.burstState = /* @__PURE__ */ new Map();
@@ -5657,7 +5712,7 @@ async function handleSpan(ctx, span) {
5657
5712
  warnUnidentifiedSpan(ctx.project ?? DEFAULT_PROJECT);
5658
5713
  }
5659
5714
  const sourceId = ensureServiceNode(ctx.graph, span.service, env);
5660
- const isError = span.statusCode === 2;
5715
+ const isError = spanRecordsError(span);
5661
5716
  const durationMs = span.durationNanos > 0n && !spanIsStreaming(span) ? Number(span.durationNanos) / 1e6 : void 0;
5662
5717
  const sourceServiceNode = ctx.graph.getNodeAttributes(sourceId);
5663
5718
  const callSite = callSiteFromSpan(span, sourceServiceNode, ctx.scanPath);
@@ -5893,10 +5948,13 @@ async function handleSpan(ctx, span) {
5893
5948
  }
5894
5949
  if (span.statusCode !== 2) {
5895
5950
  const status2 = httpResponseStatus(span);
5951
+ const grpcStatus = grpcStatusCodeFromAttrs(span.attributes);
5896
5952
  if (span.exception) {
5897
5953
  await recordExceptionIncident(ctx, span, ts);
5898
5954
  } else if (status2 !== void 0 && status2 >= 500) {
5899
5955
  await recordFailingResponseIncident(ctx, span, sourceId, ts, status2, 1);
5956
+ } else if (grpcStatus !== void 0 && grpcStatus !== 0) {
5957
+ await recordGrpcFailureIncident(ctx, span, ts);
5900
5958
  } else if (status2 !== void 0 && status2 >= 400 && spanMintsObservedEdge(span.kind)) {
5901
5959
  await advance4xxBurst(ctx, span, sourceId, ts, nowMs, status2);
5902
5960
  }