autotel 6.5.0 → 7.0.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.
Files changed (166) hide show
  1. package/README.md +30 -23
  2. package/dist/{attribute-redacting-processor-Pk7lAzWd.d.cts → attribute-redacting-processor-CvBE0z1p.d.cts} +33 -1
  3. package/dist/{attribute-redacting-processor-Pk7lAzWd.d.ts → attribute-redacting-processor-CvBE0z1p.d.ts} +33 -1
  4. package/dist/attribute-redacting-processor.cjs +34 -32
  5. package/dist/attribute-redacting-processor.d.cts +1 -1
  6. package/dist/attribute-redacting-processor.d.ts +1 -1
  7. package/dist/attribute-redacting-processor.js +35 -32
  8. package/dist/{attributes-aDmJYral.cjs → attributes-Cxys8tgr.cjs} +34 -35
  9. package/dist/{attributes-B7wix2VG.js → attributes-Dt4YUYbP.js} +34 -35
  10. package/dist/attributes.cjs +1 -1
  11. package/dist/attributes.d.cts +1 -1
  12. package/dist/attributes.d.ts +1 -1
  13. package/dist/attributes.js +1 -1
  14. package/dist/auto.cjs +1 -1
  15. package/dist/auto.js +1 -1
  16. package/dist/business-baggage.cjs +19 -12
  17. package/dist/business-baggage.d.cts +8 -3
  18. package/dist/business-baggage.d.ts +8 -3
  19. package/dist/business-baggage.js +19 -12
  20. package/dist/{canonical-log-line-processor-DxtBGZIi.cjs → canonical-log-line-processor-DolzdawH.cjs} +43 -32
  21. package/dist/{canonical-log-line-processor-B4WgG-VS.d.cts → canonical-log-line-processor-cPB4Axk-.d.ts} +4 -3
  22. package/dist/{canonical-log-line-processor-B0vq_QR6.js → canonical-log-line-processor-hFUmS__K.js} +43 -32
  23. package/dist/{canonical-log-line-processor-CL_J7gb5.d.ts → canonical-log-line-processor-l0Aqe6yp.d.cts} +4 -3
  24. package/dist/config.d.cts +1 -1
  25. package/dist/config.d.ts +1 -1
  26. package/dist/{correlated-events-kSwLo3mi.cjs → correlated-events-CcuknWnU.cjs} +2 -1
  27. package/dist/{correlated-events-Bzh5y-UB.js → correlated-events-DwMMbItg.js} +3 -1
  28. package/dist/correlation-id.cjs +1 -1
  29. package/dist/correlation-id.js +1 -1
  30. package/dist/db.cjs +34 -19
  31. package/dist/db.js +34 -19
  32. package/dist/decorators.cjs +4 -2
  33. package/dist/decorators.d.cts +16 -11
  34. package/dist/decorators.d.ts +16 -11
  35. package/dist/decorators.js +4 -2
  36. package/dist/{define-event-CGG048HE.d.cts → define-event-BNeuKUPv.d.cts} +1 -1
  37. package/dist/{define-event-B2z1SBe7.d.ts → define-event-Bd8f8mST.d.ts} +1 -1
  38. package/dist/diagnostics.cjs +18 -16
  39. package/dist/diagnostics.d.cts +14 -10
  40. package/dist/diagnostics.d.ts +14 -10
  41. package/dist/diagnostics.js +18 -16
  42. package/dist/{event-subscriber-CWh8sTGh.d.cts → event-subscriber-DMACQA-1.d.cts} +19 -9
  43. package/dist/{event-subscriber-CWh8sTGh.d.ts → event-subscriber-DMACQA-1.d.ts} +19 -9
  44. package/dist/event-subscriber.d.cts +2 -2
  45. package/dist/event-subscriber.d.ts +2 -2
  46. package/dist/{event-testing-D0qWfqAy.d.cts → event-testing-CBtnJXE5.d.cts} +1 -1
  47. package/dist/{event-testing-CA2mIx1E.d.ts → event-testing-CkPgV3Ii.d.ts} +1 -1
  48. package/dist/event-testing.d.cts +1 -1
  49. package/dist/event-testing.d.ts +1 -1
  50. package/dist/event.cjs +1 -1
  51. package/dist/event.d.cts +5 -5
  52. package/dist/event.d.ts +5 -5
  53. package/dist/event.js +1 -1
  54. package/dist/exception-fingerprint.cjs +133 -0
  55. package/dist/exception-fingerprint.d.cts +51 -0
  56. package/dist/exception-fingerprint.d.ts +51 -0
  57. package/dist/exception-fingerprint.js +126 -0
  58. package/dist/{functional-e6jw5zQj.d.cts → functional-CJn2zY4o.d.cts} +96 -39
  59. package/dist/{functional-AT22vCw6.d.ts → functional-DXy1cHFF.d.ts} +96 -39
  60. package/dist/{functional-C0uAZq2X.cjs → functional-Da6Yv64r.cjs} +27 -15
  61. package/dist/{functional-DX7Zvag0.js → functional-uSbNnnxK.js} +27 -15
  62. package/dist/functional.cjs +1 -1
  63. package/dist/functional.d.cts +2 -2
  64. package/dist/functional.d.ts +2 -2
  65. package/dist/functional.js +1 -1
  66. package/dist/http.cjs +11 -8
  67. package/dist/http.js +11 -8
  68. package/dist/{index-DolOVX6F.d.ts → index-CwrNAsgk.d.ts} +22 -26
  69. package/dist/{index-BPcxVucm.d.cts → index-DQHf4cNl.d.cts} +22 -26
  70. package/dist/index.cjs +41 -35
  71. package/dist/index.d.cts +45 -30
  72. package/dist/index.d.ts +45 -30
  73. package/dist/index.js +41 -35
  74. package/dist/{init-pPI3JRRf.d.ts → init-BgnYi2sm.d.ts} +6 -6
  75. package/dist/{init-CTtHITlX.cjs → init-D4m5rCmD.cjs} +110 -84
  76. package/dist/{init-ncTMKZ-s.d.cts → init-DrlL1eis.d.cts} +6 -6
  77. package/dist/{init-WHYwyItd.js → init-JtX-KKz_.js} +105 -85
  78. package/dist/instrumentation.cjs +2 -2
  79. package/dist/instrumentation.js +2 -2
  80. package/dist/{logger-D3Ej3DII.js → logger-DdPp__xW.js} +63 -54
  81. package/dist/{logger-CN4xpzMd.d.cts → logger-S1Fgl0g3.d.cts} +0 -20
  82. package/dist/{logger-CN4xpzMd.d.ts → logger-S1Fgl0g3.d.ts} +0 -20
  83. package/dist/{logger-thMPLpOG.cjs → logger-Sm66cjKl.cjs} +63 -54
  84. package/dist/logger.cjs +1 -1
  85. package/dist/logger.d.cts +1 -1
  86. package/dist/logger.d.ts +1 -1
  87. package/dist/logger.js +1 -1
  88. package/dist/messaging-adapters.cjs +26 -12
  89. package/dist/messaging-adapters.d.cts +0 -30
  90. package/dist/messaging-adapters.d.ts +0 -30
  91. package/dist/messaging-adapters.js +26 -12
  92. package/dist/messaging.cjs +37 -34
  93. package/dist/messaging.d.cts +21 -62
  94. package/dist/messaging.d.ts +21 -62
  95. package/dist/messaging.js +37 -34
  96. package/dist/{metric-testing-CpvP3ZIa.d.cts → metric-testing-86WO1wan.d.cts} +1 -1
  97. package/dist/{metric-testing-CWm6UhaR.d.ts → metric-testing-CbCxdPBp.d.ts} +1 -1
  98. package/dist/metric-testing.d.cts +1 -1
  99. package/dist/metric-testing.d.ts +1 -1
  100. package/dist/metric.d.cts +3 -3
  101. package/dist/metric.d.ts +3 -3
  102. package/dist/{node-require-vROmTeJ8.js → node-require-DSPjaw_l.js} +3 -2
  103. package/dist/{node-require-PFqDihze.cjs → node-require-EifOMikz.cjs} +3 -2
  104. package/dist/parse-error.cjs +18 -12
  105. package/dist/parse-error.d.cts +2 -1
  106. package/dist/parse-error.d.ts +2 -1
  107. package/dist/parse-error.js +19 -12
  108. package/dist/policy.cjs +0 -0
  109. package/dist/policy.js +0 -0
  110. package/dist/processors.cjs +1 -1
  111. package/dist/processors.d.cts +1 -1
  112. package/dist/processors.d.ts +1 -1
  113. package/dist/processors.js +1 -1
  114. package/dist/{sampling-BR9fkSwx.d.cts → sampling-CM5S2Lp3.d.ts} +5 -6
  115. package/dist/{sampling-CP3e7-Yr.d.ts → sampling-CmRdnXUi.d.cts} +5 -6
  116. package/dist/sampling.cjs +3 -2
  117. package/dist/sampling.d.cts +1 -1
  118. package/dist/sampling.d.ts +1 -1
  119. package/dist/sampling.js +3 -2
  120. package/dist/semantic-helpers.cjs +9 -9
  121. package/dist/semantic-helpers.d.cts +1 -1
  122. package/dist/semantic-helpers.d.ts +1 -1
  123. package/dist/semantic-helpers.js +9 -9
  124. package/dist/{stable-hash-ChFBIhNt.js → stable-hash-BkoAYVks.js} +4 -3
  125. package/dist/{stable-hash-CS9BxvVQ.cjs → stable-hash-C0pOegH_.cjs} +4 -3
  126. package/dist/{structured-error-CHg7DoIQ.cjs → structured-error--_wXpd_C.cjs} +34 -25
  127. package/dist/{structured-error-9--cxBay.js → structured-error-YIuka-FE.js} +34 -25
  128. package/dist/test-span-collector.cjs +15 -8
  129. package/dist/test-span-collector.js +15 -8
  130. package/dist/testing.cjs +16 -18
  131. package/dist/testing.d.cts +7 -6
  132. package/dist/testing.d.ts +7 -6
  133. package/dist/testing.js +16 -18
  134. package/dist/{trace-context-IuyoPyNq.d.cts → trace-context-C1Cn1q0y.d.cts} +8 -7
  135. package/dist/{trace-context-IuyoPyNq.d.ts → trace-context-f89xPJbK.d.ts} +8 -7
  136. package/dist/trace-helpers.cjs +16 -13
  137. package/dist/trace-helpers.d.cts +9 -4
  138. package/dist/trace-helpers.d.ts +9 -4
  139. package/dist/trace-helpers.js +16 -13
  140. package/dist/tracer-provider.cjs +8 -12
  141. package/dist/tracer-provider.js +8 -12
  142. package/dist/validate.cjs +22 -20
  143. package/dist/validate.d.cts +3 -2
  144. package/dist/validate.d.ts +3 -2
  145. package/dist/validate.js +22 -20
  146. package/dist/values-BenyvWKz.js +141 -0
  147. package/dist/values-CeMH-mYG.d.cts +8 -0
  148. package/dist/values-CeMH-mYG.d.ts +8 -0
  149. package/dist/values-DApyq53y.cjs +267 -0
  150. package/dist/webhook.cjs +3 -3
  151. package/dist/webhook.d.cts +1 -1
  152. package/dist/webhook.d.ts +1 -1
  153. package/dist/webhook.js +3 -3
  154. package/dist/workflow-distributed.cjs +9 -7
  155. package/dist/workflow-distributed.d.cts +9 -8
  156. package/dist/workflow-distributed.d.ts +9 -8
  157. package/dist/workflow-distributed.js +9 -7
  158. package/dist/workflow.cjs +26 -17
  159. package/dist/workflow.d.cts +1 -28
  160. package/dist/workflow.d.ts +1 -28
  161. package/dist/workflow.js +26 -17
  162. package/dist/yaml-config.cjs +26 -11
  163. package/dist/yaml-config.d.cts +9 -3
  164. package/dist/yaml-config.d.ts +9 -3
  165. package/dist/yaml-config.js +26 -11
  166. package/package.json +6 -1
@@ -1,3 +1,4 @@
1
+ import { i as asNumber, l as asString, p as hasProcess, s as asRecord, t as asBoolean, x as toError } from "./values-BenyvWKz.js";
1
2
  import { SeverityNumber, logs } from "@opentelemetry/api-logs";
2
3
 
3
4
  //#region src/pretty-log-formatter.ts
@@ -8,12 +9,12 @@ const RED = "\x1B[31m";
8
9
  const YELLOW = "\x1B[33m";
9
10
  const GREEN = "\x1B[32m";
10
11
  const CYAN = "\x1B[36m";
11
- const LEVEL_COLORS = {
12
- debug: "\x1B[90m",
13
- info: GREEN,
14
- warn: YELLOW,
15
- error: RED
16
- };
12
+ const LEVEL_COLORS = /* @__PURE__ */ new Map([
13
+ ["debug", "\x1B[90m"],
14
+ ["info", GREEN],
15
+ ["warn", YELLOW],
16
+ ["error", RED]
17
+ ]);
17
18
  /** Internal OTel attributes to skip in pretty output. */
18
19
  const SKIP_PREFIXES = [
19
20
  "telemetry.",
@@ -40,12 +41,10 @@ const SKIP_KEYS = /* @__PURE__ */ new Set([
40
41
  "http.response.status_code"
41
42
  ]);
42
43
  function useColor() {
43
- if (typeof process !== "undefined") {
44
- if (process.env.NO_COLOR) return false;
45
- if (process.env.FORCE_COLOR) return true;
46
- if (process.stdout?.isTTY) return true;
47
- }
48
- return false;
44
+ if (!hasProcess()) return false;
45
+ if (process.env.NO_COLOR) return false;
46
+ if (process.env.FORCE_COLOR) return true;
47
+ return process.stdout?.isTTY === true;
49
48
  }
50
49
  function c(color, text) {
51
50
  return useColor() ? `${color}${text}${RESET}` : text;
@@ -76,8 +75,10 @@ function formatTime(iso) {
76
75
  }
77
76
  }
78
77
  function formatValue(value) {
79
- if (typeof value === "string") return value;
80
- if (typeof value === "number" || typeof value === "boolean") return String(value);
78
+ const text = asString(value);
79
+ if (text !== void 0) return text;
80
+ const scalar = asNumber(value) ?? asBoolean(value);
81
+ if (scalar !== void 0) return String(scalar);
81
82
  if (value == null) return "";
82
83
  try {
83
84
  return JSON.stringify(value);
@@ -101,8 +102,13 @@ function groupAttributes(event) {
101
102
  let current = tree;
102
103
  for (let i = 0; i < parts.length - 1; i++) {
103
104
  const part = parts[i];
104
- if (!(part in current) || typeof current[part] !== "object") current[part] = {};
105
- current = current[part];
105
+ const branch = asRecord(current[part]);
106
+ if (branch) current = branch;
107
+ else {
108
+ const created = {};
109
+ current[part] = created;
110
+ current = created;
111
+ }
106
112
  }
107
113
  current[parts.at(-1)] = value;
108
114
  }
@@ -115,10 +121,11 @@ function renderTree(obj, indent, isLast) {
115
121
  for (const [idx, [key, value]] of entries.entries()) {
116
122
  const last = idx === entries.length - 1;
117
123
  const prefix = indent + (last ? "└─" : "├─") + " ";
118
- if (value && typeof value === "object" && !Array.isArray(value)) {
119
- const nested = value;
120
- const flatValues = Object.entries(nested).filter(([, v]) => typeof v !== "object" || v === null);
121
- if (Object.entries(nested).filter(([, v]) => typeof v === "object" && v !== null && !Array.isArray(v)).length === 0) {
124
+ const nested = asRecord(value);
125
+ if (nested) {
126
+ const nestedObjs = Object.entries(nested).filter(([, v]) => asRecord(v));
127
+ const flatValues = Object.entries(nested).filter(([, v]) => asRecord(v) === void 0);
128
+ if (nestedObjs.length === 0) {
122
129
  const inline = flatValues.map(([k, v]) => `${c(CYAN, k)}=${formatValue(v)}`).join(" ");
123
130
  lines.push(`${prefix}${c(BOLD, key)}: ${inline}`);
124
131
  } else {
@@ -141,7 +148,7 @@ function formatPrettyLogLine(ctx) {
141
148
  const path = event["http.route"] || event["url.path"] || "";
142
149
  const status = event["http.response.status_code"] || "";
143
150
  const duration = formatDuration(Number(event.duration_ms ?? 0));
144
- const levelStr = c(LEVEL_COLORS[level] ?? "", level.toUpperCase().padEnd(5));
151
+ const levelStr = c(LEVEL_COLORS.get(level) ?? "", level.toUpperCase().padEnd(5));
145
152
  const parts = [c(DIM, timestamp), levelStr];
146
153
  if (service) parts.push(c(DIM, `[${service}]`));
147
154
  if (method) parts.push(c(BOLD, String(method)));
@@ -162,6 +169,12 @@ function formatPrettyLogLine(ctx) {
162
169
 
163
170
  //#endregion
164
171
  //#region src/processors/canonical-log-line-processor.ts
172
+ const SEVERITY_NUMBERS = /* @__PURE__ */ new Map([
173
+ ["debug", SeverityNumber.DEBUG],
174
+ ["info", SeverityNumber.INFO],
175
+ ["warn", SeverityNumber.WARN],
176
+ ["error", SeverityNumber.ERROR]
177
+ ]);
165
178
  /**
166
179
  * Span processor that automatically emits spans as canonical log lines
167
180
  *
@@ -241,7 +254,7 @@ var CanonicalLogLineProcessor = class {
241
254
  this.shouldEmit = options.shouldEmit ?? this.buildKeepPredicate(options.keep);
242
255
  this.drain = options.drain;
243
256
  this.onDrainError = options.onDrainError;
244
- this.pretty = options.pretty ?? (typeof process !== "undefined" && process.env.NODE_ENV === "development");
257
+ this.pretty = options.pretty ?? (hasProcess() && process.env.NODE_ENV === "development");
245
258
  if (!this.logger) this.getOTelLogger = () => logs.getLogger("autotel.canonical-log-line");
246
259
  }
247
260
  buildKeepPredicate(keep) {
@@ -319,8 +332,11 @@ var CanonicalLogLineProcessor = class {
319
332
  }
320
333
  emitViaOTel(level, message, canonicalLogLine, otelLogger) {
321
334
  const otelAttributes = {};
322
- for (const [key, value] of Object.entries(canonicalLogLine)) if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") otelAttributes[key] = value;
323
- else if (value !== null && value !== void 0) otelAttributes[key] = String(value);
335
+ for (const [key, value] of Object.entries(canonicalLogLine)) {
336
+ const scalar = asString(value) ?? asNumber(value) ?? asBoolean(value);
337
+ if (scalar !== void 0) otelAttributes[key] = scalar;
338
+ else if (value !== null && value !== void 0) otelAttributes[key] = String(value);
339
+ }
324
340
  otelLogger.emit({
325
341
  severityNumber: this.getSeverityNumber(level),
326
342
  severityText: level.toUpperCase(),
@@ -344,15 +360,10 @@ var CanonicalLogLineProcessor = class {
344
360
  return levels.indexOf(level) >= levels.indexOf(this.minLevel);
345
361
  }
346
362
  getSeverityNumber(level) {
347
- return {
348
- debug: SeverityNumber.DEBUG,
349
- info: SeverityNumber.INFO,
350
- warn: SeverityNumber.WARN,
351
- error: SeverityNumber.ERROR
352
- }[level] ?? SeverityNumber.INFO;
363
+ return SEVERITY_NUMBERS.get(level) ?? SeverityNumber.INFO;
353
364
  }
354
- reportInternalWarning(message, error) {
355
- const err = error instanceof Error ? error.message : String(error ?? "unknown error");
365
+ reportInternalWarning(message, cause) {
366
+ const err = cause === void 0 ? "unknown error" : toError(cause).message;
356
367
  if (this.logger) {
357
368
  this.logger.warn({ error: err }, `[autotel] ${message}`);
358
369
  return;
@@ -1,4 +1,5 @@
1
- import { s as Logger } from "./logger-CN4xpzMd.js";
1
+ import { t as UnknownRecord } from "./values-CeMH-mYG.cjs";
2
+ import { s as Logger } from "./logger-S1Fgl0g3.cjs";
2
3
  import { ReadableSpan, SpanProcessor } from "@opentelemetry/sdk-trace-base";
3
4
  import { AttributeValue } from "@opentelemetry/api";
4
5
  //#region src/processors/canonical-log-line-processor.d.ts
@@ -10,7 +11,7 @@ interface CanonicalLogLineEvent {
10
11
  span: ReadableSpan;
11
12
  level: 'debug' | 'info' | 'warn' | 'error';
12
13
  message: string;
13
- event: Record<string, unknown>;
14
+ event: UnknownRecord;
14
15
  }
15
16
  interface KeepCondition {
16
17
  /** Keep events where HTTP status >= this value. */
@@ -50,7 +51,7 @@ interface CanonicalLogLineOptions {
50
51
  /** Callback invoked after emit for custom fan-out. */
51
52
  drain?: (ctx: CanonicalLogLineEvent) => void | Promise<void>;
52
53
  /** Handler for drain failures. */
53
- onDrainError?: (error: unknown, ctx: CanonicalLogLineEvent) => void;
54
+ onDrainError?: (cause: unknown, ctx: CanonicalLogLineEvent) => void;
54
55
  /**
55
56
  * Pretty-print canonical log lines to console in a tree format.
56
57
  * Defaults to true when NODE_ENV is 'development'.
package/dist/config.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as ILogger } from "./logger-CN4xpzMd.cjs";
1
+ import { t as ILogger } from "./logger-S1Fgl0g3.cjs";
2
2
  import { Meter, Tracer } from "@opentelemetry/api";
3
3
  //#region src/config.d.ts
4
4
  declare const FEATURE_FLAGS: {
package/dist/config.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as ILogger } from "./logger-CN4xpzMd.js";
1
+ import { t as ILogger } from "./logger-S1Fgl0g3.js";
2
2
  import { Meter, Tracer } from "@opentelemetry/api";
3
3
  //#region src/config.d.ts
4
4
  declare const FEATURE_FLAGS: {
@@ -1,3 +1,4 @@
1
+ const require_values = require('./values-DApyq53y.cjs');
1
2
 
2
3
  //#region src/correlated-events.ts
3
4
  function sanitizeEventKey(input) {
@@ -11,7 +12,7 @@ function nextSequence(target) {
11
12
  }
12
13
  function emitCorrelatedEvent(ctx, name, attrs = {}) {
13
14
  const eventName = sanitizeEventKey(name);
14
- if (typeof ctx.addEvent === "function") {
15
+ if (require_values.isFunction(ctx.addEvent)) {
15
16
  ctx.addEvent.call(ctx, eventName, attrs);
16
17
  return;
17
18
  }
@@ -1,3 +1,5 @@
1
+ import { h as isFunction } from "./values-BenyvWKz.js";
2
+
1
3
  //#region src/correlated-events.ts
2
4
  function sanitizeEventKey(input) {
3
5
  return input.replaceAll(/[^a-zA-Z0-9_.-]/g, "_");
@@ -10,7 +12,7 @@ function nextSequence(target) {
10
12
  }
11
13
  function emitCorrelatedEvent(ctx, name, attrs = {}) {
12
14
  const eventName = sanitizeEventKey(name);
13
- if (typeof ctx.addEvent === "function") {
15
+ if (isFunction(ctx.addEvent)) {
14
16
  ctx.addEvent.call(ctx, eventName, attrs);
15
17
  return;
16
18
  }
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_init = require('./init-CTtHITlX.cjs');
2
+ const require_init = require('./init-D4m5rCmD.cjs');
3
3
 
4
4
  exports.CORRELATION_ID_BAGGAGE_KEY = require_init.CORRELATION_ID_BAGGAGE_KEY;
5
5
  exports.generateCorrelationId = require_init.generateCorrelationId;
@@ -1,3 +1,3 @@
1
- import { C as setCorrelationId, S as runWithCorrelationId, _ as CORRELATION_ID_BAGGAGE_KEY, b as getCorrelationStorage, v as generateCorrelationId, w as setCorrelationIdInBaggage, x as getOrCreateCorrelationId, y as getCorrelationId } from "./init-WHYwyItd.js";
1
+ import { C as setCorrelationId, S as runWithCorrelationId, _ as CORRELATION_ID_BAGGAGE_KEY, b as getCorrelationStorage, v as generateCorrelationId, w as setCorrelationIdInBaggage, x as getOrCreateCorrelationId, y as getCorrelationId } from "./init-JtX-KKz_.js";
2
2
 
3
3
  export { CORRELATION_ID_BAGGAGE_KEY, generateCorrelationId, getCorrelationId, getCorrelationStorage, getOrCreateCorrelationId, runWithCorrelationId, setCorrelationId, setCorrelationIdInBaggage };
package/dist/db.cjs CHANGED
@@ -1,4 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_values = require('./values-DApyq53y.cjs');
2
3
  const require_config = require('./config.cjs');
3
4
  let _opentelemetry_api = require("@opentelemetry/api");
4
5
 
@@ -167,7 +168,8 @@ const INSTRUMENTED_SYMBOL = Symbol.for("autotel.db.instrumented");
167
168
  * ```
168
169
  */
169
170
  function instrumentDatabase(client, options) {
170
- if (client[INSTRUMENTED_SYMBOL]) return client;
171
+ const target = clientMembers(client);
172
+ if (target[INSTRUMENTED_SYMBOL]) return client;
171
173
  const { dbSystem, dbName, methods, skipMethods = [], sanitizeQuery = true, slowQueryThresholdMs = 1e3 } = options;
172
174
  const tracer = require_config.getConfig().tracer;
173
175
  const methodsToInstrument = methods || extractDatabaseMethods(client);
@@ -175,10 +177,10 @@ function instrumentDatabase(client, options) {
175
177
  for (const methodName of methodsToInstrument) {
176
178
  if (skipSet.has(methodName)) continue;
177
179
  if (methodName.startsWith("_")) continue;
178
- const method = client[methodName];
179
- if (typeof method !== "function") continue;
180
+ const method = require_values.asFunction(target[methodName]);
181
+ if (!method) continue;
180
182
  const originalMethod = method;
181
- client[methodName] = async function(...args) {
183
+ target[methodName] = async function(...args) {
182
184
  const operation = inferDbOperation(methodName);
183
185
  const table = inferTableName(methodName);
184
186
  const spanName = table ? `${dbSystem}.${operation} ${table}` : `${dbSystem}.${operation}`;
@@ -221,12 +223,24 @@ function instrumentDatabase(client, options) {
221
223
  }
222
224
  });
223
225
  };
224
- Object.defineProperty(client[methodName], "name", {
226
+ Object.defineProperty(target[methodName], "name", {
225
227
  value: methodName,
226
228
  configurable: true
227
229
  });
228
230
  }
229
- client[INSTRUMENTED_SYMBOL] = true;
231
+ target[INSTRUMENTED_SYMBOL] = true;
232
+ return client;
233
+ }
234
+ /**
235
+ * A client's members, so the wrapper can read a method off it and write the
236
+ * wrapped one back.
237
+ *
238
+ * SAFETY: instrumentDatabase's whole job is to replace named methods on a
239
+ * client it was handed. TypeScript describes that client by the methods the
240
+ * caller declared, which is precisely the set being rewritten - so this says
241
+ * once that the client is being addressed by name.
242
+ */
243
+ function clientMembers(client) {
230
244
  return client;
231
245
  }
232
246
  /**
@@ -234,11 +248,10 @@ function instrumentDatabase(client, options) {
234
248
  */
235
249
  function extractDatabaseMethods(client) {
236
250
  const methods = [];
237
- const proto = Object.getPrototypeOf(client);
238
- for (const key of Object.getOwnPropertyNames(client)) if (typeof client[key] === "function" && !key.startsWith("_")) methods.push(key);
239
- if (proto) {
240
- for (const key of Object.getOwnPropertyNames(proto)) if (typeof proto[key] === "function" && !key.startsWith("_") && key !== "constructor") methods.push(key);
241
- }
251
+ const own = clientMembers(client);
252
+ const proto = clientMembers(Object.getPrototypeOf(client) ?? {});
253
+ for (const key of Object.getOwnPropertyNames(client)) if (require_values.isFunction(own[key]) && !key.startsWith("_")) methods.push(key);
254
+ for (const key of Object.getOwnPropertyNames(proto)) if (require_values.isFunction(proto[key]) && !key.startsWith("_") && key !== "constructor") methods.push(key);
242
255
  return [...new Set(methods)];
243
256
  }
244
257
  /**
@@ -247,14 +260,16 @@ function extractDatabaseMethods(client) {
247
260
  function extractQueryFromArgs(args) {
248
261
  if (args.length === 0) return void 0;
249
262
  const firstArg = args[0];
250
- if (typeof firstArg === "string") return firstArg;
251
- if (firstArg && typeof firstArg === "object") {
252
- if ("sql" in firstArg && typeof firstArg.sql === "string") return firstArg.sql;
253
- if ("text" in firstArg && typeof firstArg.text === "string") return firstArg.text;
254
- if ("toQuery" in firstArg && typeof firstArg.toQuery === "function") try {
255
- const queryResult = firstArg.toQuery();
256
- if (typeof queryResult === "string") return queryResult;
257
- if (queryResult && typeof queryResult === "object" && "sql" in queryResult) return queryResult.sql;
263
+ const rawSql = require_values.asString(firstArg);
264
+ if (rawSql !== void 0) return rawSql;
265
+ const query = require_values.asRecord(firstArg);
266
+ if (query) {
267
+ const stated = require_values.asString(query.sql) ?? require_values.asString(query.text);
268
+ if (stated !== void 0) return stated;
269
+ if (require_values.isFunction(query.toQuery)) try {
270
+ const queryResult = query.toQuery();
271
+ const built = require_values.asString(queryResult) ?? require_values.asString(require_values.readProperty(queryResult, "sql"));
272
+ if (built !== void 0) return built;
258
273
  } catch {}
259
274
  }
260
275
  }
package/dist/db.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { _ as readProperty, h as isFunction, l as asString, r as asFunction, s as asRecord } from "./values-BenyvWKz.js";
1
2
  import { getConfig } from "./config.js";
2
3
  import { SpanStatusCode } from "@opentelemetry/api";
3
4
 
@@ -166,7 +167,8 @@ const INSTRUMENTED_SYMBOL = Symbol.for("autotel.db.instrumented");
166
167
  * ```
167
168
  */
168
169
  function instrumentDatabase(client, options) {
169
- if (client[INSTRUMENTED_SYMBOL]) return client;
170
+ const target = clientMembers(client);
171
+ if (target[INSTRUMENTED_SYMBOL]) return client;
170
172
  const { dbSystem, dbName, methods, skipMethods = [], sanitizeQuery = true, slowQueryThresholdMs = 1e3 } = options;
171
173
  const tracer = getConfig().tracer;
172
174
  const methodsToInstrument = methods || extractDatabaseMethods(client);
@@ -174,10 +176,10 @@ function instrumentDatabase(client, options) {
174
176
  for (const methodName of methodsToInstrument) {
175
177
  if (skipSet.has(methodName)) continue;
176
178
  if (methodName.startsWith("_")) continue;
177
- const method = client[methodName];
178
- if (typeof method !== "function") continue;
179
+ const method = asFunction(target[methodName]);
180
+ if (!method) continue;
179
181
  const originalMethod = method;
180
- client[methodName] = async function(...args) {
182
+ target[methodName] = async function(...args) {
181
183
  const operation = inferDbOperation(methodName);
182
184
  const table = inferTableName(methodName);
183
185
  const spanName = table ? `${dbSystem}.${operation} ${table}` : `${dbSystem}.${operation}`;
@@ -220,12 +222,24 @@ function instrumentDatabase(client, options) {
220
222
  }
221
223
  });
222
224
  };
223
- Object.defineProperty(client[methodName], "name", {
225
+ Object.defineProperty(target[methodName], "name", {
224
226
  value: methodName,
225
227
  configurable: true
226
228
  });
227
229
  }
228
- client[INSTRUMENTED_SYMBOL] = true;
230
+ target[INSTRUMENTED_SYMBOL] = true;
231
+ return client;
232
+ }
233
+ /**
234
+ * A client's members, so the wrapper can read a method off it and write the
235
+ * wrapped one back.
236
+ *
237
+ * SAFETY: instrumentDatabase's whole job is to replace named methods on a
238
+ * client it was handed. TypeScript describes that client by the methods the
239
+ * caller declared, which is precisely the set being rewritten - so this says
240
+ * once that the client is being addressed by name.
241
+ */
242
+ function clientMembers(client) {
229
243
  return client;
230
244
  }
231
245
  /**
@@ -233,11 +247,10 @@ function instrumentDatabase(client, options) {
233
247
  */
234
248
  function extractDatabaseMethods(client) {
235
249
  const methods = [];
236
- const proto = Object.getPrototypeOf(client);
237
- for (const key of Object.getOwnPropertyNames(client)) if (typeof client[key] === "function" && !key.startsWith("_")) methods.push(key);
238
- if (proto) {
239
- for (const key of Object.getOwnPropertyNames(proto)) if (typeof proto[key] === "function" && !key.startsWith("_") && key !== "constructor") methods.push(key);
240
- }
250
+ const own = clientMembers(client);
251
+ const proto = clientMembers(Object.getPrototypeOf(client) ?? {});
252
+ for (const key of Object.getOwnPropertyNames(client)) if (isFunction(own[key]) && !key.startsWith("_")) methods.push(key);
253
+ for (const key of Object.getOwnPropertyNames(proto)) if (isFunction(proto[key]) && !key.startsWith("_") && key !== "constructor") methods.push(key);
241
254
  return [...new Set(methods)];
242
255
  }
243
256
  /**
@@ -246,14 +259,16 @@ function extractDatabaseMethods(client) {
246
259
  function extractQueryFromArgs(args) {
247
260
  if (args.length === 0) return void 0;
248
261
  const firstArg = args[0];
249
- if (typeof firstArg === "string") return firstArg;
250
- if (firstArg && typeof firstArg === "object") {
251
- if ("sql" in firstArg && typeof firstArg.sql === "string") return firstArg.sql;
252
- if ("text" in firstArg && typeof firstArg.text === "string") return firstArg.text;
253
- if ("toQuery" in firstArg && typeof firstArg.toQuery === "function") try {
254
- const queryResult = firstArg.toQuery();
255
- if (typeof queryResult === "string") return queryResult;
256
- if (queryResult && typeof queryResult === "object" && "sql" in queryResult) return queryResult.sql;
262
+ const rawSql = asString(firstArg);
263
+ if (rawSql !== void 0) return rawSql;
264
+ const query = asRecord(firstArg);
265
+ if (query) {
266
+ const stated = asString(query.sql) ?? asString(query.text);
267
+ if (stated !== void 0) return stated;
268
+ if (isFunction(query.toQuery)) try {
269
+ const queryResult = query.toQuery();
270
+ const built = asString(queryResult) ?? asString(readProperty(queryResult, "sql"));
271
+ if (built !== void 0) return built;
257
272
  } catch {}
258
273
  }
259
274
  }
@@ -1,11 +1,13 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_values = require('./values-DApyq53y.cjs');
2
3
  const require_config = require('./config.cjs');
3
- const require_init = require('./init-CTtHITlX.cjs');
4
+ const require_init = require('./init-D4m5rCmD.cjs');
4
5
  let _opentelemetry_api = require("@opentelemetry/api");
5
6
 
6
7
  //#region src/decorators.ts
7
8
  function Trace(nameOrOptions, maybeOptions) {
8
- const name = typeof nameOrOptions === "string" ? nameOrOptions : nameOrOptions?.name;
9
+ const { name: nameArgument, options } = require_values.splitNameOrOptions(nameOrOptions);
10
+ const name = nameArgument ?? options?.name;
9
11
  return function(originalMethod, context) {
10
12
  const methodName = String(context.name);
11
13
  const methodStr = originalMethod?.toString() || "";
@@ -1,5 +1,5 @@
1
- import { n as TraceContext } from "./trace-context-IuyoPyNq.cjs";
2
- import { m as TracingOptions } from "./functional-e6jw5zQj.cjs";
1
+ import { n as TraceContext } from "./trace-context-C1Cn1q0y.cjs";
2
+ import { m as TracingOptions } from "./functional-CJn2zY4o.cjs";
3
3
  //#region src/decorators.d.ts
4
4
  /**
5
5
  * Options for @Trace method decorator
@@ -10,6 +10,15 @@ interface TraceDecoratorOptions extends Omit<TracingOptions, 'name'> {
10
10
  */
11
11
  name?: string;
12
12
  }
13
+ /**
14
+ * The receiver of a decorated method. `@Trace` lends the method its span's
15
+ * context for the duration of the call, and puts back whatever was there.
16
+ */
17
+ interface WithTraceContext {
18
+ ctx?: TraceContext;
19
+ }
20
+ /** The decorator a `@Trace(...)` call produces. */
21
+ type TraceDecorator = <TArgs extends unknown[], TResult>(originalMethod: (...args: TArgs) => Promise<TResult>, context: ClassMethodDecoratorContext) => (...args: TArgs) => Promise<TResult>;
13
22
  /**
14
23
  * @Trace - Method decorator for fine-grained tracing
15
24
  *
@@ -39,15 +48,11 @@ interface TraceDecoratorOptions extends Omit<TracingOptions, 'name'> {
39
48
  *
40
49
  * @example Accessing ctx
41
50
  * ```typescript
42
- * interface WithTraceContext {
43
- * ctx?: TraceContext
44
- * }
45
- *
46
51
  * class UserService {
47
52
  * @Trace()
48
- * async createUser(data: UserData) {
53
+ * async createUser(this: WithTraceContext, data: UserData) {
49
54
  * // Access ctx via this.ctx (available during execution)
50
- * const ctx = (this as unknown as WithTraceContext).ctx
55
+ * const ctx = this.ctx
51
56
  * if (ctx) {
52
57
  * ctx.setAttribute('user.id', data.id)
53
58
  * }
@@ -56,7 +61,7 @@ interface TraceDecoratorOptions extends Omit<TracingOptions, 'name'> {
56
61
  * }
57
62
  * ```
58
63
  */
59
- declare function Trace(options?: TraceDecoratorOptions): <T extends (...args: unknown[]) => Promise<unknown>>(originalMethod: T, context: ClassMethodDecoratorContext) => T;
60
- declare function Trace(name?: string, options?: TraceDecoratorOptions): <T extends (...args: unknown[]) => Promise<unknown>>(originalMethod: T, context: ClassMethodDecoratorContext) => T;
64
+ declare function Trace(options?: TraceDecoratorOptions): TraceDecorator;
65
+ declare function Trace(name?: string, options?: TraceDecoratorOptions): TraceDecorator;
61
66
  //#endregion
62
- export { Trace, type TraceContext, TraceDecoratorOptions, type TracingOptions };
67
+ export { Trace, type TraceContext, TraceDecorator, TraceDecoratorOptions, type TracingOptions, WithTraceContext };
@@ -1,5 +1,5 @@
1
- import { n as TraceContext } from "./trace-context-IuyoPyNq.js";
2
- import { m as TracingOptions } from "./functional-AT22vCw6.js";
1
+ import { n as TraceContext } from "./trace-context-f89xPJbK.js";
2
+ import { m as TracingOptions } from "./functional-DXy1cHFF.js";
3
3
  //#region src/decorators.d.ts
4
4
  /**
5
5
  * Options for @Trace method decorator
@@ -10,6 +10,15 @@ interface TraceDecoratorOptions extends Omit<TracingOptions, 'name'> {
10
10
  */
11
11
  name?: string;
12
12
  }
13
+ /**
14
+ * The receiver of a decorated method. `@Trace` lends the method its span's
15
+ * context for the duration of the call, and puts back whatever was there.
16
+ */
17
+ interface WithTraceContext {
18
+ ctx?: TraceContext;
19
+ }
20
+ /** The decorator a `@Trace(...)` call produces. */
21
+ type TraceDecorator = <TArgs extends unknown[], TResult>(originalMethod: (...args: TArgs) => Promise<TResult>, context: ClassMethodDecoratorContext) => (...args: TArgs) => Promise<TResult>;
13
22
  /**
14
23
  * @Trace - Method decorator for fine-grained tracing
15
24
  *
@@ -39,15 +48,11 @@ interface TraceDecoratorOptions extends Omit<TracingOptions, 'name'> {
39
48
  *
40
49
  * @example Accessing ctx
41
50
  * ```typescript
42
- * interface WithTraceContext {
43
- * ctx?: TraceContext
44
- * }
45
- *
46
51
  * class UserService {
47
52
  * @Trace()
48
- * async createUser(data: UserData) {
53
+ * async createUser(this: WithTraceContext, data: UserData) {
49
54
  * // Access ctx via this.ctx (available during execution)
50
- * const ctx = (this as unknown as WithTraceContext).ctx
55
+ * const ctx = this.ctx
51
56
  * if (ctx) {
52
57
  * ctx.setAttribute('user.id', data.id)
53
58
  * }
@@ -56,7 +61,7 @@ interface TraceDecoratorOptions extends Omit<TracingOptions, 'name'> {
56
61
  * }
57
62
  * ```
58
63
  */
59
- declare function Trace(options?: TraceDecoratorOptions): <T extends (...args: unknown[]) => Promise<unknown>>(originalMethod: T, context: ClassMethodDecoratorContext) => T;
60
- declare function Trace(name?: string, options?: TraceDecoratorOptions): <T extends (...args: unknown[]) => Promise<unknown>>(originalMethod: T, context: ClassMethodDecoratorContext) => T;
64
+ declare function Trace(options?: TraceDecoratorOptions): TraceDecorator;
65
+ declare function Trace(name?: string, options?: TraceDecoratorOptions): TraceDecorator;
61
66
  //#endregion
62
- export { Trace, type TraceContext, TraceDecoratorOptions, type TracingOptions };
67
+ export { Trace, type TraceContext, TraceDecorator, TraceDecoratorOptions, type TracingOptions, WithTraceContext };
@@ -1,10 +1,12 @@
1
+ import { y as splitNameOrOptions } from "./values-BenyvWKz.js";
1
2
  import { getConfig } from "./config.js";
2
- import { T as createTraceContext } from "./init-WHYwyItd.js";
3
+ import { T as createTraceContext } from "./init-JtX-KKz_.js";
3
4
  import { SpanStatusCode } from "@opentelemetry/api";
4
5
 
5
6
  //#region src/decorators.ts
6
7
  function Trace(nameOrOptions, maybeOptions) {
7
- const name = typeof nameOrOptions === "string" ? nameOrOptions : nameOrOptions?.name;
8
+ const { name: nameArgument, options } = splitNameOrOptions(nameOrOptions);
9
+ const name = nameArgument ?? options?.name;
8
10
  return function(originalMethod, context) {
9
11
  const methodName = String(context.name);
10
12
  const methodStr = originalMethod?.toString() || "";
@@ -1,4 +1,4 @@
1
- import { i as EventSchemaMetadata } from "./event-subscriber-CWh8sTGh.cjs";
1
+ import { a as EventSchemaMetadata } from "./event-subscriber-DMACQA-1.cjs";
2
2
  //#region src/define-event.d.ts
3
3
  type SafeParseResult<T> = {
4
4
  success: true;
@@ -1,4 +1,4 @@
1
- import { i as EventSchemaMetadata } from "./event-subscriber-CWh8sTGh.js";
1
+ import { a as EventSchemaMetadata } from "./event-subscriber-DMACQA-1.js";
2
2
  //#region src/define-event.d.ts
3
3
  type SafeParseResult<T> = {
4
4
  success: true;