@m1212e/rumble 0.23.18 → 0.23.19

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/out/index.cjs CHANGED
@@ -211,7 +211,7 @@ function mapNullFieldsToUndefined(obj) {
211
211
  }
212
212
  //#endregion
213
213
  //#region package.json
214
- var version = "0.23.18";
214
+ var version = "0.23.19";
215
215
  //#endregion
216
216
  //#region lib/helpers/errorLogging.ts
217
217
  function hasMessage(error) {
@@ -592,6 +592,24 @@ function recordSpanErrors(span, errors) {
592
592
  function recordSpanError(span, error) {
593
593
  recordSpanErrors(span, [error]);
594
594
  }
595
+ /**
596
+ * Errors the operation wrapper has already reported.
597
+ *
598
+ * A transport can see the same failure twice: sofa, for instance, hands
599
+ * `result.errors` to its error handler *after* execute has returned, so without
600
+ * this the very same error would produce two log lines and two exception events,
601
+ * which quietly doubles error counts in dashboards. A WeakSet keeps this free of
602
+ * bookkeeping — entries disappear with the errors themselves.
603
+ */
604
+ const reportedErrors = /* @__PURE__ */ new WeakSet();
605
+ function markErrorsReported(errors) {
606
+ for (const error of errors) if (typeof error === "object" && error !== null) reportedErrors.add(error);
607
+ }
608
+ /** True when every error was already reported by the operation wrapper. */
609
+ function errorsAlreadyReported(errors) {
610
+ if (errors.length === 0) return false;
611
+ return errors.every((error) => typeof error === "object" && error !== null && reportedErrors.has(error));
612
+ }
595
613
  function safeJsonStringify(value) {
596
614
  try {
597
615
  return JSON.stringify(value, (_key, inner) => typeof inner === "bigint" ? inner.toString() : inner) ?? "null";
@@ -1632,6 +1650,7 @@ function buildTracedExecute(executeFn, rumbleInput, transport) {
1632
1650
  ...errorsLogField(result.errors)
1633
1651
  }, "graphql execute completed with errors");
1634
1652
  recordSpanErrors(span, result.errors);
1653
+ markErrorsReported(result.errors);
1635
1654
  } else log?.info({
1636
1655
  ...telemetry.logFields,
1637
1656
  [FIELD_DURATION_MS]: durationMs(start)
@@ -1644,6 +1663,7 @@ function buildTracedExecute(executeFn, rumbleInput, transport) {
1644
1663
  ...errorLogField(error)
1645
1664
  }, "graphql execute threw");
1646
1665
  recordSpanError(span, error);
1666
+ markErrorsReported([error]);
1647
1667
  throw error;
1648
1668
  }
1649
1669
  };
@@ -1685,6 +1705,7 @@ function buildTracedSubscribe(subscribeFn, rumbleInput, transport) {
1685
1705
  ...errorsLogField(execResult.errors)
1686
1706
  }, "graphql subscribe completed with errors");
1687
1707
  recordSpanErrors(span, execResult.errors);
1708
+ markErrorsReported(execResult.errors);
1688
1709
  }
1689
1710
  return execResult;
1690
1711
  }
@@ -1706,6 +1727,7 @@ function buildTracedSubscribe(subscribeFn, rumbleInput, transport) {
1706
1727
  ...errorLogField(error)
1707
1728
  }, "graphql subscribe threw");
1708
1729
  recordSpanError(span, error);
1730
+ markErrorsReported([error]);
1709
1731
  throw error;
1710
1732
  }
1711
1733
  };
@@ -2870,12 +2892,14 @@ export const r = rumble({
2870
2892
  execute: buildTracedExecute(args.execute ?? graphql.execute, rumbleInput, "rest"),
2871
2893
  subscribe: buildTracedSubscribe(args.subscribe ?? graphql.subscribe, rumbleInput, "rest"),
2872
2894
  errorHandler(errors) {
2873
- recordSpanErrors(_opentelemetry_api.trace.getActiveSpan(), errors);
2874
- telemetryLogger(rumbleInput)?.error({
2875
- [ATTR_TRANSPORT]: "rest",
2876
- ...traceCorrelationFields(rumbleInput),
2877
- ...errorsLogField(errors)
2878
- }, "rest request failed");
2895
+ if (!errorsAlreadyReported(errors)) {
2896
+ recordSpanErrors(_opentelemetry_api.trace.getActiveSpan(), errors);
2897
+ telemetryLogger(rumbleInput)?.error({
2898
+ [ATTR_TRANSPORT]: "rest",
2899
+ ...traceCorrelationFields(rumbleInput),
2900
+ ...errorsLogField(errors)
2901
+ }, "rest request failed");
2902
+ }
2879
2903
  return userErrorHandler?.(errors) ?? sofaErrorResponse(errors);
2880
2904
  }
2881
2905
  });