@btravstack/observability 0.29.0 → 0.30.0

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
@@ -23,19 +23,43 @@ const logLevel = (options = {}) => {
23
23
  };
24
24
  //#endregion
25
25
  //#region src/json-sink.ts
26
+ const DIAGNOSTIC_FIELDS = [
27
+ "_tag",
28
+ "sqlState",
29
+ "constraint",
30
+ "table",
31
+ "database",
32
+ "role",
33
+ "bypass",
34
+ "port"
35
+ ];
26
36
  /**
27
37
  * An `Error`'s `message` and `stack` are **non-enumerable**, so
28
38
  * `JSON.stringify` renders a thrown one as `{}` — the line that exists to carry
29
39
  * a failure would carry nothing. Walks `cause` chains so a wrapped failure keeps
30
40
  * its origin.
31
41
  */
32
- const renderCause = (cause, depth = 0) => {
33
- if (!(cause instanceof Error)) return cause;
42
+ const renderCause = (cause, depth = 0, parents = /* @__PURE__ */ new Set()) => {
43
+ if (!(cause instanceof Error)) return depth > 0 && cause !== null && (typeof cause === "object" || typeof cause === "function" || typeof cause === "bigint") ? "[non-error]" : cause;
44
+ if (parents.has(cause)) return "[circular]";
45
+ const ancestors = new Set(parents).add(cause);
46
+ const errors = cause instanceof AggregateError ? Object.getOwnPropertyDescriptor(cause, "errors")?.value : void 0;
34
47
  return {
35
48
  name: cause.name,
36
49
  message: cause.message,
37
50
  stack: cause.stack,
38
- ...cause.cause === void 0 || depth >= 4 ? {} : { cause: renderCause(cause.cause, depth + 1) }
51
+ ...Object.fromEntries(DIAGNOSTIC_FIELDS.flatMap((key) => {
52
+ const value = Object.getOwnPropertyDescriptor(cause, key)?.value;
53
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? [[key, value]] : [];
54
+ })),
55
+ ...cause.cause === void 0 || depth >= 4 ? {} : { cause: renderCause(cause.cause, depth + 1, ancestors) },
56
+ ...Array.isArray(errors) && depth < 4 ? {
57
+ errors: Array.from({ length: Math.min(errors.length, 16) }, (_, index) => {
58
+ const member = Object.getOwnPropertyDescriptor(errors, String(index))?.value;
59
+ return renderCause(member, depth + 1, ancestors);
60
+ }),
61
+ ...errors.length > 16 ? { omittedErrors: errors.length - 16 } : {}
62
+ } : {}
39
63
  };
40
64
  };
41
65
  /**
package/dist/index.mjs CHANGED
@@ -22,19 +22,43 @@ const logLevel = (options = {}) => {
22
22
  };
23
23
  //#endregion
24
24
  //#region src/json-sink.ts
25
+ const DIAGNOSTIC_FIELDS = [
26
+ "_tag",
27
+ "sqlState",
28
+ "constraint",
29
+ "table",
30
+ "database",
31
+ "role",
32
+ "bypass",
33
+ "port"
34
+ ];
25
35
  /**
26
36
  * An `Error`'s `message` and `stack` are **non-enumerable**, so
27
37
  * `JSON.stringify` renders a thrown one as `{}` — the line that exists to carry
28
38
  * a failure would carry nothing. Walks `cause` chains so a wrapped failure keeps
29
39
  * its origin.
30
40
  */
31
- const renderCause = (cause, depth = 0) => {
32
- if (!(cause instanceof Error)) return cause;
41
+ const renderCause = (cause, depth = 0, parents = /* @__PURE__ */ new Set()) => {
42
+ if (!(cause instanceof Error)) return depth > 0 && cause !== null && (typeof cause === "object" || typeof cause === "function" || typeof cause === "bigint") ? "[non-error]" : cause;
43
+ if (parents.has(cause)) return "[circular]";
44
+ const ancestors = new Set(parents).add(cause);
45
+ const errors = cause instanceof AggregateError ? Object.getOwnPropertyDescriptor(cause, "errors")?.value : void 0;
33
46
  return {
34
47
  name: cause.name,
35
48
  message: cause.message,
36
49
  stack: cause.stack,
37
- ...cause.cause === void 0 || depth >= 4 ? {} : { cause: renderCause(cause.cause, depth + 1) }
50
+ ...Object.fromEntries(DIAGNOSTIC_FIELDS.flatMap((key) => {
51
+ const value = Object.getOwnPropertyDescriptor(cause, key)?.value;
52
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? [[key, value]] : [];
53
+ })),
54
+ ...cause.cause === void 0 || depth >= 4 ? {} : { cause: renderCause(cause.cause, depth + 1, ancestors) },
55
+ ...Array.isArray(errors) && depth < 4 ? {
56
+ errors: Array.from({ length: Math.min(errors.length, 16) }, (_, index) => {
57
+ const member = Object.getOwnPropertyDescriptor(errors, String(index))?.value;
58
+ return renderCause(member, depth + 1, ancestors);
59
+ }),
60
+ ...errors.length > 16 ? { omittedErrors: errors.length - 16 } : {}
61
+ } : {}
38
62
  };
39
63
  };
40
64
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@btravstack/observability",
3
- "version": "0.29.0",
3
+ "version": "0.30.0",
4
4
  "description": "Observability for @btravstack/core: a strict Logger port correlated with the kernel's units, a dependency-free JSON sink, and the lifecycle events as log lines",
5
5
  "keywords": [
6
6
  "dependency-injection",
@@ -65,10 +65,10 @@
65
65
  "./package.json": "./package.json"
66
66
  },
67
67
  "devDependencies": {
68
- "@btravstack/config": "0.29.0",
69
- "@btravstack/core": "0.29.0",
70
- "@btravstack/di": "0.29.0",
71
- "@btravstack/testing": "0.29.0",
68
+ "@btravstack/config": "0.30.0",
69
+ "@btravstack/core": "0.30.0",
70
+ "@btravstack/di": "0.30.0",
71
+ "@btravstack/testing": "0.30.0",
72
72
  "@btravstack/tsconfig": "0.4.0",
73
73
  "@opentelemetry/api": "1.9.1",
74
74
  "@opentelemetry/sdk-node": "0.222.0",
@@ -83,9 +83,9 @@
83
83
  "vitest": "5.0.3"
84
84
  },
85
85
  "peerDependencies": {
86
- "@btravstack/config": "^0.29.0",
87
- "@btravstack/core": "^0.29.0",
88
- "@btravstack/di": "^0.29.0",
86
+ "@btravstack/config": "^0.30.0",
87
+ "@btravstack/core": "^0.30.0",
88
+ "@btravstack/di": "^0.30.0",
89
89
  "@opentelemetry/api": "^1.9.0",
90
90
  "@opentelemetry/sdk-node": "^0.222.0",
91
91
  "pino": "^10",