autotel 3.0.0 → 3.0.3

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 (108) hide show
  1. package/README.md +21 -4
  2. package/dist/attribute-redacting-processor.cjs +8 -8
  3. package/dist/attribute-redacting-processor.d.cts +10 -1
  4. package/dist/attribute-redacting-processor.d.ts +10 -1
  5. package/dist/attribute-redacting-processor.js +1 -1
  6. package/dist/attributes.cjs +21 -21
  7. package/dist/attributes.js +2 -2
  8. package/dist/auto.cjs +3 -3
  9. package/dist/auto.js +2 -2
  10. package/dist/{chunk-7HNQYHK4.js → chunk-52PUSFC2.js} +3 -3
  11. package/dist/{chunk-7HNQYHK4.js.map → chunk-52PUSFC2.js.map} +1 -1
  12. package/dist/{chunk-L7JDUDJD.cjs → chunk-7SMNC4LS.cjs} +7 -7
  13. package/dist/{chunk-L7JDUDJD.cjs.map → chunk-7SMNC4LS.cjs.map} +1 -1
  14. package/dist/{chunk-563EL6O6.cjs → chunk-BPO2PQ3T.cjs} +12 -8
  15. package/dist/chunk-BPO2PQ3T.cjs.map +1 -0
  16. package/dist/{chunk-ZSABTI3C.cjs → chunk-DAZ7EGR4.cjs} +17 -17
  17. package/dist/{chunk-ZSABTI3C.cjs.map → chunk-DAZ7EGR4.cjs.map} +1 -1
  18. package/dist/{chunk-ER43K7ES.js → chunk-DDXIUZEG.js} +3 -3
  19. package/dist/{chunk-ER43K7ES.js.map → chunk-DDXIUZEG.js.map} +1 -1
  20. package/dist/{chunk-JKIMEPI2.cjs → chunk-DQ2SUROF.cjs} +4 -4
  21. package/dist/{chunk-JKIMEPI2.cjs.map → chunk-DQ2SUROF.cjs.map} +1 -1
  22. package/dist/{chunk-KHGA4OST.cjs → chunk-HKZHUGGN.cjs} +5 -5
  23. package/dist/{chunk-KHGA4OST.cjs.map → chunk-HKZHUGGN.cjs.map} +1 -1
  24. package/dist/{chunk-TDNKIHKT.js → chunk-JVWJDHDB.js} +13 -4
  25. package/dist/chunk-JVWJDHDB.js.map +1 -0
  26. package/dist/{chunk-3QMFLJHJ.js → chunk-K7HSRLP5.js} +3 -3
  27. package/dist/{chunk-3QMFLJHJ.js.map → chunk-K7HSRLP5.js.map} +1 -1
  28. package/dist/{chunk-CJ4PD2TZ.cjs → chunk-KKGM42RQ.cjs} +13 -13
  29. package/dist/{chunk-CJ4PD2TZ.cjs.map → chunk-KKGM42RQ.cjs.map} +1 -1
  30. package/dist/{chunk-DWOBIBLY.cjs → chunk-MOO75VE4.cjs} +5 -5
  31. package/dist/{chunk-DWOBIBLY.cjs.map → chunk-MOO75VE4.cjs.map} +1 -1
  32. package/dist/{chunk-CMNGGTQL.cjs → chunk-NXLRY2CE.cjs} +13 -4
  33. package/dist/chunk-NXLRY2CE.cjs.map +1 -0
  34. package/dist/{chunk-4DAG3RFS.js → chunk-OM4OSBOP.js} +4 -4
  35. package/dist/{chunk-4DAG3RFS.js.map → chunk-OM4OSBOP.js.map} +1 -1
  36. package/dist/{chunk-DAAJLUTO.js → chunk-PMRWMRXY.js} +4 -4
  37. package/dist/{chunk-DAAJLUTO.js.map → chunk-PMRWMRXY.js.map} +1 -1
  38. package/dist/{chunk-MOK3E54E.cjs → chunk-QPH5ZKP5.cjs} +32 -32
  39. package/dist/{chunk-MOK3E54E.cjs.map → chunk-QPH5ZKP5.cjs.map} +1 -1
  40. package/dist/{chunk-IUDXKLS4.js → chunk-TFRZOUTV.js} +3 -3
  41. package/dist/{chunk-IUDXKLS4.js.map → chunk-TFRZOUTV.js.map} +1 -1
  42. package/dist/{chunk-QG3U5ONP.js → chunk-Z7VAOK5X.js} +3 -3
  43. package/dist/{chunk-QG3U5ONP.js.map → chunk-Z7VAOK5X.js.map} +1 -1
  44. package/dist/{chunk-W35FVJBC.js → chunk-ZDPIWKWD.js} +9 -5
  45. package/dist/chunk-ZDPIWKWD.js.map +1 -0
  46. package/dist/correlation-id.cjs +11 -11
  47. package/dist/correlation-id.js +3 -3
  48. package/dist/decorators.cjs +5 -5
  49. package/dist/decorators.js +4 -4
  50. package/dist/event.cjs +7 -7
  51. package/dist/event.js +4 -4
  52. package/dist/functional.cjs +11 -11
  53. package/dist/functional.js +4 -4
  54. package/dist/http.cjs +4 -4
  55. package/dist/http.js +3 -3
  56. package/dist/index.cjs +226 -92
  57. package/dist/index.cjs.map +1 -1
  58. package/dist/index.d.cts +67 -3
  59. package/dist/index.d.ts +67 -3
  60. package/dist/index.js +138 -15
  61. package/dist/index.js.map +1 -1
  62. package/dist/instrumentation.cjs +9 -9
  63. package/dist/instrumentation.js +2 -2
  64. package/dist/messaging.cjs +8 -8
  65. package/dist/messaging.js +5 -5
  66. package/dist/semantic-helpers.cjs +9 -9
  67. package/dist/semantic-helpers.js +5 -5
  68. package/dist/webhook.cjs +6 -6
  69. package/dist/webhook.js +4 -4
  70. package/dist/workflow-distributed.cjs +6 -6
  71. package/dist/workflow-distributed.js +4 -4
  72. package/dist/workflow.cjs +9 -9
  73. package/dist/workflow.js +5 -5
  74. package/package.json +43 -45
  75. package/skills/analyze-traces/SKILL.md +178 -0
  76. package/skills/autotel-core/SKILL.md +0 -7
  77. package/skills/autotel-events/SKILL.md +0 -6
  78. package/skills/autotel-frameworks/SKILL.md +0 -9
  79. package/skills/autotel-instrumentation/SKILL.md +0 -7
  80. package/skills/autotel-request-logging/SKILL.md +0 -8
  81. package/skills/autotel-structured-errors/SKILL.md +0 -7
  82. package/skills/build-audit-trails/SKILL.md +302 -0
  83. package/skills/debug-missing-spans/SKILL.md +248 -0
  84. package/skills/migrate-to-autotel/SKILL.md +268 -0
  85. package/skills/review-otel-patterns/SKILL.md +488 -0
  86. package/skills/review-otel-patterns/references/code-review.md +75 -0
  87. package/skills/review-otel-patterns/references/processor-pipeline.md +205 -0
  88. package/skills/review-otel-patterns/references/structured-errors.md +102 -0
  89. package/skills/review-otel-patterns/references/wide-spans.md +85 -0
  90. package/skills/tune-sampling/SKILL.md +210 -0
  91. package/src/attribute-redacting-processor.test.ts +6 -4
  92. package/src/attribute-redacting-processor.ts +11 -2
  93. package/src/drain-toolkit.test.ts +113 -0
  94. package/src/drain-toolkit.ts +129 -0
  95. package/src/enricher-toolkit.test.ts +67 -0
  96. package/src/enricher-toolkit.ts +79 -0
  97. package/src/index.ts +19 -0
  98. package/src/redact-values.test.ts +24 -10
  99. package/src/redact-values.ts +9 -2
  100. package/src/request-logger.test.ts +91 -0
  101. package/src/request-logger.ts +36 -2
  102. package/src/structured-error.test.ts +4 -1
  103. package/bin/intent.js +0 -6
  104. package/dist/chunk-563EL6O6.cjs.map +0 -1
  105. package/dist/chunk-CMNGGTQL.cjs.map +0 -1
  106. package/dist/chunk-TDNKIHKT.js.map +0 -1
  107. package/dist/chunk-W35FVJBC.js.map +0 -1
  108. package/src/package-manifest.test.ts +0 -24
package/dist/index.cjs CHANGED
@@ -1,31 +1,31 @@
1
1
  'use strict';
2
2
 
3
3
  var chunk7EQ4G4SI_cjs = require('./chunk-7EQ4G4SI.cjs');
4
- var chunkDWOBIBLY_cjs = require('./chunk-DWOBIBLY.cjs');
5
- var chunkJKIMEPI2_cjs = require('./chunk-JKIMEPI2.cjs');
4
+ var chunkMOO75VE4_cjs = require('./chunk-MOO75VE4.cjs');
5
+ var chunkDQ2SUROF_cjs = require('./chunk-DQ2SUROF.cjs');
6
6
  var chunk2ZKEORFN_cjs = require('./chunk-2ZKEORFN.cjs');
7
7
  var chunkESMHTKLJ_cjs = require('./chunk-ESMHTKLJ.cjs');
8
8
  var chunkT4B5LB6E_cjs = require('./chunk-T4B5LB6E.cjs');
9
- var chunkKHGA4OST_cjs = require('./chunk-KHGA4OST.cjs');
9
+ var chunkHKZHUGGN_cjs = require('./chunk-HKZHUGGN.cjs');
10
10
  var chunk4P6ZOARG_cjs = require('./chunk-4P6ZOARG.cjs');
11
11
  var chunkINJD3G4K_cjs = require('./chunk-INJD3G4K.cjs');
12
12
  var chunkTC5ZPWM4_cjs = require('./chunk-TC5ZPWM4.cjs');
13
13
  require('./chunk-YTXEZ4SD.cjs');
14
14
  var chunkWJH6IYU2_cjs = require('./chunk-WJH6IYU2.cjs');
15
- var chunkL7JDUDJD_cjs = require('./chunk-L7JDUDJD.cjs');
16
- var chunkMOK3E54E_cjs = require('./chunk-MOK3E54E.cjs');
15
+ var chunk7SMNC4LS_cjs = require('./chunk-7SMNC4LS.cjs');
16
+ var chunkQPH5ZKP5_cjs = require('./chunk-QPH5ZKP5.cjs');
17
17
  var chunkNCSMD3TK_cjs = require('./chunk-NCSMD3TK.cjs');
18
- var chunkZSABTI3C_cjs = require('./chunk-ZSABTI3C.cjs');
18
+ var chunkDAZ7EGR4_cjs = require('./chunk-DAZ7EGR4.cjs');
19
19
  require('./chunk-NZ72VDNY.cjs');
20
20
  require('./chunk-UY3UYPBZ.cjs');
21
21
  var chunkVQTCQKHQ_cjs = require('./chunk-VQTCQKHQ.cjs');
22
- var chunkCJ4PD2TZ_cjs = require('./chunk-CJ4PD2TZ.cjs');
23
- var chunk563EL6O6_cjs = require('./chunk-563EL6O6.cjs');
22
+ var chunkKKGM42RQ_cjs = require('./chunk-KKGM42RQ.cjs');
23
+ var chunkBPO2PQ3T_cjs = require('./chunk-BPO2PQ3T.cjs');
24
24
  require('./chunk-OC6X2VIN.cjs');
25
25
  require('./chunk-CEAQK2QY.cjs');
26
26
  var chunkZNMBW67B_cjs = require('./chunk-ZNMBW67B.cjs');
27
27
  var chunkIOYFAFHJ_cjs = require('./chunk-IOYFAFHJ.cjs');
28
- var chunkCMNGGTQL_cjs = require('./chunk-CMNGGTQL.cjs');
28
+ var chunkNXLRY2CE_cjs = require('./chunk-NXLRY2CE.cjs');
29
29
  require('./chunk-CU6IDACR.cjs');
30
30
  var chunk6S5RUKU3_cjs = require('./chunk-6S5RUKU3.cjs');
31
31
  require('./chunk-YS6C2YJE.cjs');
@@ -55,7 +55,7 @@ var otelMethods = {
55
55
  setSpanContext: api.trace.setSpanContext
56
56
  };
57
57
  var trace2 = Object.assign(
58
- chunkMOK3E54E_cjs.trace,
58
+ chunkQPH5ZKP5_cjs.trace,
59
59
  otelMethods
60
60
  );
61
61
 
@@ -64,7 +64,7 @@ async function flush(options) {
64
64
  const timeout = options?.timeout ?? 2e3;
65
65
  const forShutdown = options?.forShutdown ?? false;
66
66
  const doFlush = async () => {
67
- const eventsQueue = chunkCJ4PD2TZ_cjs.getEventQueue();
67
+ const eventsQueue = chunkKKGM42RQ_cjs.getEventQueue();
68
68
  if (eventsQueue) {
69
69
  if (forShutdown) {
70
70
  await eventsQueue.shutdown();
@@ -72,7 +72,7 @@ async function flush(options) {
72
72
  await eventsQueue.flush();
73
73
  }
74
74
  }
75
- const sdk = chunk563EL6O6_cjs.getSdk();
75
+ const sdk = chunkBPO2PQ3T_cjs.getSdk();
76
76
  if (sdk) {
77
77
  try {
78
78
  const sdkAny = sdk;
@@ -106,7 +106,7 @@ async function flush(options) {
106
106
  if (timeoutHandle) {
107
107
  clearTimeout(timeoutHandle);
108
108
  }
109
- const logger = chunk563EL6O6_cjs.getLogger();
109
+ const logger = chunkBPO2PQ3T_cjs.getLogger();
110
110
  logger.error(
111
111
  {
112
112
  err: error instanceof Error ? error : new Error(String(error))
@@ -117,7 +117,7 @@ async function flush(options) {
117
117
  }
118
118
  }
119
119
  async function shutdown() {
120
- const logger = chunk563EL6O6_cjs.getLogger();
120
+ const logger = chunkBPO2PQ3T_cjs.getLogger();
121
121
  let shutdownError = null;
122
122
  try {
123
123
  await flush({ forShutdown: true });
@@ -132,7 +132,7 @@ async function shutdown() {
132
132
  );
133
133
  }
134
134
  try {
135
- const sdk = chunk563EL6O6_cjs.getSdk();
135
+ const sdk = chunkBPO2PQ3T_cjs.getSdk();
136
136
  if (sdk) {
137
137
  await sdk.shutdown();
138
138
  }
@@ -146,14 +146,14 @@ async function shutdown() {
146
146
  logger.error({ err }, "[autotel] SDK shutdown failed");
147
147
  }
148
148
  } finally {
149
- await chunk563EL6O6_cjs._closeEmbeddedDevtools();
150
- const eventsQueue = chunkCJ4PD2TZ_cjs.getEventQueue();
149
+ await chunkBPO2PQ3T_cjs._closeEmbeddedDevtools();
150
+ const eventsQueue = chunkKKGM42RQ_cjs.getEventQueue();
151
151
  if (eventsQueue && typeof eventsQueue.cleanup === "function") {
152
152
  eventsQueue.cleanup();
153
153
  }
154
- chunkZSABTI3C_cjs.resetEvents();
154
+ chunkDAZ7EGR4_cjs.resetEvents();
155
155
  chunkTC5ZPWM4_cjs.resetMetrics();
156
- chunkCJ4PD2TZ_cjs.resetEventQueue();
156
+ chunkKKGM42RQ_cjs.resetEventQueue();
157
157
  }
158
158
  if (shutdownError) {
159
159
  throw shutdownError;
@@ -168,7 +168,7 @@ function registerShutdownHooks() {
168
168
  if (shuttingDown) return;
169
169
  shuttingDown = true;
170
170
  if (process.env.NODE_ENV !== "test") {
171
- chunk563EL6O6_cjs.getLogger().info(
171
+ chunkBPO2PQ3T_cjs.getLogger().info(
172
172
  {},
173
173
  `[autotel] Received ${signal}, flushing telemetry...`
174
174
  );
@@ -176,7 +176,7 @@ function registerShutdownHooks() {
176
176
  try {
177
177
  await shutdown();
178
178
  } catch (error) {
179
- chunk563EL6O6_cjs.getLogger().error(
179
+ chunkBPO2PQ3T_cjs.getLogger().error(
180
180
  {
181
181
  err: error instanceof Error ? error : void 0
182
182
  },
@@ -226,7 +226,7 @@ function resolveContext(ctx2) {
226
226
  "[autotel] getRequestLogger() requires an active span or runWithRequestContext(). Wrap your handler with trace() or use runWithRequestContext()."
227
227
  );
228
228
  }
229
- return chunkCJ4PD2TZ_cjs.createTraceContext(span2);
229
+ return chunkKKGM42RQ_cjs.createTraceContext(span2);
230
230
  }
231
231
  function getRequestLogger(ctx2, options) {
232
232
  const activeContext = resolveContext(ctx2);
@@ -234,7 +234,7 @@ function getRequestLogger(ctx2, options) {
234
234
  let emitted = false;
235
235
  let lastSnapshot = null;
236
236
  const addLogEvent = (level, message, fields) => {
237
- const attrs2 = fields ? chunkCJ4PD2TZ_cjs.flattenToAttributes(fields) : void 0;
237
+ const attrs2 = fields ? chunkKKGM42RQ_cjs.flattenToAttributes(fields) : void 0;
238
238
  chunk4P6ZOARG_cjs.emitCorrelatedEvent(activeContext, `log.${level}`, {
239
239
  message,
240
240
  ...attrs2 ?? {}
@@ -253,7 +253,7 @@ function getRequestLogger(ctx2, options) {
253
253
  sealCheck("log.set()", Object.keys(fields));
254
254
  if (emitted) return;
255
255
  mergeInto(contextState, fields);
256
- activeContext.setAttributes(chunkCJ4PD2TZ_cjs.flattenToAttributes(fields));
256
+ activeContext.setAttributes(chunkKKGM42RQ_cjs.flattenToAttributes(fields));
257
257
  },
258
258
  info(message, fields) {
259
259
  const keys = fields ? ["message", ...Object.keys(fields).filter((k) => k !== "requestLogs")] : ["message"];
@@ -262,7 +262,7 @@ function getRequestLogger(ctx2, options) {
262
262
  addLogEvent("info", message, fields);
263
263
  if (fields) {
264
264
  mergeInto(contextState, fields);
265
- activeContext.setAttributes(chunkCJ4PD2TZ_cjs.flattenToAttributes(fields));
265
+ activeContext.setAttributes(chunkKKGM42RQ_cjs.flattenToAttributes(fields));
266
266
  }
267
267
  },
268
268
  warn(message, fields) {
@@ -273,7 +273,7 @@ function getRequestLogger(ctx2, options) {
273
273
  activeContext.setAttribute("autotel.log.level", "warn");
274
274
  if (fields) {
275
275
  mergeInto(contextState, fields);
276
- activeContext.setAttributes(chunkCJ4PD2TZ_cjs.flattenToAttributes(fields));
276
+ activeContext.setAttributes(chunkKKGM42RQ_cjs.flattenToAttributes(fields));
277
277
  }
278
278
  },
279
279
  error(error, fields) {
@@ -281,11 +281,11 @@ function getRequestLogger(ctx2, options) {
281
281
  sealCheck("log.error()", keys);
282
282
  if (emitted) return;
283
283
  const err = typeof error === "string" ? new Error(error) : error;
284
- chunkCJ4PD2TZ_cjs.recordStructuredError(activeContext, err);
284
+ chunkKKGM42RQ_cjs.recordStructuredError(activeContext, err);
285
285
  addLogEvent("error", err.message, fields);
286
286
  if (fields) {
287
287
  mergeInto(contextState, fields);
288
- activeContext.setAttributes(chunkCJ4PD2TZ_cjs.flattenToAttributes(fields));
288
+ activeContext.setAttributes(chunkKKGM42RQ_cjs.flattenToAttributes(fields));
289
289
  }
290
290
  activeContext.setAttribute("autotel.log.level", "error");
291
291
  },
@@ -301,7 +301,7 @@ function getRequestLogger(ctx2, options) {
301
301
  ...contextState,
302
302
  ...overrides ?? {}
303
303
  };
304
- const flattened = chunkCJ4PD2TZ_cjs.flattenToAttributes(mergedContext);
304
+ const flattened = chunkKKGM42RQ_cjs.flattenToAttributes(mergedContext);
305
305
  activeContext.setAttributes(flattened);
306
306
  const snapshot = {
307
307
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
@@ -322,7 +322,7 @@ function getRequestLogger(ctx2, options) {
322
322
  lastSnapshot = snapshot;
323
323
  return snapshot;
324
324
  },
325
- fork(label, fn) {
325
+ fork(label, fn, forkOptions) {
326
326
  const parentRequestId = activeContext.correlationId;
327
327
  if (typeof parentRequestId !== "string" || parentRequestId.length === 0) {
328
328
  throw new Error(
@@ -330,9 +330,10 @@ function getRequestLogger(ctx2, options) {
330
330
  );
331
331
  }
332
332
  const tracer = api.trace.getTracer("autotel.request-logger");
333
+ const lifecycle = forkOptions?.lifecycle;
333
334
  void tracer.startActiveSpan(`request.fork:${label}`, (childSpan) => {
334
335
  const childContext = {
335
- ...chunkCJ4PD2TZ_cjs.createTraceContext(childSpan),
336
+ ...chunkKKGM42RQ_cjs.createTraceContext(childSpan),
336
337
  correlationId: crypto.randomUUID()
337
338
  };
338
339
  requestContextStore.run(childContext, () => {
@@ -341,6 +342,7 @@ function getRequestLogger(ctx2, options) {
341
342
  operation: label,
342
343
  _parentCorrelationId: parentRequestId
343
344
  });
345
+ lifecycle?.onChildEnter?.(childLog);
344
346
  void Promise.resolve().then(() => fn()).then(() => {
345
347
  childLog.emitNow();
346
348
  }).catch((err) => {
@@ -348,6 +350,14 @@ function getRequestLogger(ctx2, options) {
348
350
  childLog.error(error);
349
351
  childLog.emitNow();
350
352
  }).finally(() => {
353
+ try {
354
+ lifecycle?.onChildExit?.(childLog);
355
+ } catch (hookError) {
356
+ console.warn(
357
+ "[autotel] fork onChildExit hook threw:",
358
+ hookError
359
+ );
360
+ }
351
361
  childSpan.end();
352
362
  });
353
363
  });
@@ -355,6 +365,119 @@ function getRequestLogger(ctx2, options) {
355
365
  }
356
366
  };
357
367
  }
368
+
369
+ // src/drain-toolkit.ts
370
+ var DEFAULT_TIMEOUT_MS = 5e3;
371
+ var DEFAULT_RETRIES = 2;
372
+ function delay(ms) {
373
+ return new Promise((resolve) => {
374
+ const t = setTimeout(resolve, ms);
375
+ t.unref?.();
376
+ });
377
+ }
378
+ async function postWithRetry(options) {
379
+ const { name, request: request2, timeoutMs, retries } = options;
380
+ const attempts = Math.max(1, retries);
381
+ let lastError;
382
+ for (let attempt = 1; attempt <= attempts; attempt++) {
383
+ const controller = new AbortController();
384
+ const timeout = setTimeout(() => controller.abort(), timeoutMs);
385
+ timeout.unref?.();
386
+ try {
387
+ const response = await fetch(request2.url, {
388
+ method: "POST",
389
+ headers: request2.headers,
390
+ body: request2.body,
391
+ signal: controller.signal
392
+ });
393
+ if (!response.ok) {
394
+ throw new Error(
395
+ `[autotel/${name}] HTTP ${response.status} draining ${request2.url}`
396
+ );
397
+ }
398
+ return;
399
+ } catch (error) {
400
+ lastError = error;
401
+ if (attempt < attempts) {
402
+ await delay(100 * attempt);
403
+ }
404
+ } finally {
405
+ clearTimeout(timeout);
406
+ }
407
+ }
408
+ throw lastError;
409
+ }
410
+ function defineDrain(options) {
411
+ return async (ctx2) => {
412
+ const contexts = Array.isArray(ctx2) ? ctx2 : [ctx2];
413
+ if (contexts.length === 0) return;
414
+ const config = await options.resolve();
415
+ if (!config) return;
416
+ const payloads = options.transform ? options.transform(contexts) : contexts;
417
+ if (payloads.length === 0) return;
418
+ try {
419
+ await options.send(payloads, config);
420
+ } catch (error) {
421
+ console.error(`[autotel/${options.name}] drain failed:`, error);
422
+ }
423
+ };
424
+ }
425
+ function defineHttpDrain(options) {
426
+ return defineDrain({
427
+ name: options.name,
428
+ resolve: options.resolve,
429
+ transform: options.transform,
430
+ send: async (payloads, config) => {
431
+ const request2 = options.encode(payloads, config);
432
+ if (!request2) return;
433
+ const timeoutMs = options.resolveTimeoutMs?.(config) ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
434
+ const retries = options.resolveRetries?.(config) ?? options.retries ?? DEFAULT_RETRIES;
435
+ await postWithRetry({
436
+ name: options.name,
437
+ request: request2,
438
+ timeoutMs,
439
+ retries
440
+ });
441
+ }
442
+ });
443
+ }
444
+
445
+ // src/enricher-toolkit.ts
446
+ function isPlainObject(value) {
447
+ return value !== null && typeof value === "object" && !Array.isArray(value);
448
+ }
449
+ function mergeInto2(target, source) {
450
+ for (const key in source) {
451
+ const sourceVal = source[key];
452
+ if (sourceVal === void 0) continue;
453
+ const targetVal = target[key];
454
+ if (isPlainObject(sourceVal) && isPlainObject(targetVal)) {
455
+ mergeInto2(targetVal, sourceVal);
456
+ } else {
457
+ target[key] = sourceVal;
458
+ }
459
+ }
460
+ }
461
+ function defineEnricher(def, options = {}) {
462
+ return (ctx2) => {
463
+ let computed;
464
+ try {
465
+ computed = def.compute(ctx2);
466
+ } catch (error) {
467
+ console.error(`[autotel/${def.name}] enrich failed:`, error);
468
+ return;
469
+ }
470
+ if (!computed) return;
471
+ if (options.overwrite || !isPlainObject(ctx2.event[def.field])) {
472
+ ctx2.event[def.field] = computed;
473
+ return;
474
+ }
475
+ mergeInto2(
476
+ ctx2.event[def.field],
477
+ computed
478
+ );
479
+ };
480
+ }
358
481
  var GEN_AI_DURATION_BUCKETS_SECONDS = Object.freeze(
359
482
  [0.01, 0.05, 0.1, 0.25, 0.5, 1, 2, 5, 10, 20, 30, 60, 120, 300]
360
483
  );
@@ -485,83 +608,83 @@ Object.defineProperty(exports, "createDrainPipeline", {
485
608
  });
486
609
  Object.defineProperty(exports, "getCurrentWorkflowContext", {
487
610
  enumerable: true,
488
- get: function () { return chunkDWOBIBLY_cjs.getCurrentWorkflowContext; }
611
+ get: function () { return chunkMOO75VE4_cjs.getCurrentWorkflowContext; }
489
612
  });
490
613
  Object.defineProperty(exports, "isInWorkflow", {
491
614
  enumerable: true,
492
- get: function () { return chunkDWOBIBLY_cjs.isInWorkflow; }
615
+ get: function () { return chunkMOO75VE4_cjs.isInWorkflow; }
493
616
  });
494
617
  Object.defineProperty(exports, "traceStep", {
495
618
  enumerable: true,
496
- get: function () { return chunkDWOBIBLY_cjs.traceStep; }
619
+ get: function () { return chunkMOO75VE4_cjs.traceStep; }
497
620
  });
498
621
  Object.defineProperty(exports, "traceWorkflow", {
499
622
  enumerable: true,
500
- get: function () { return chunkDWOBIBLY_cjs.traceWorkflow; }
623
+ get: function () { return chunkMOO75VE4_cjs.traceWorkflow; }
501
624
  });
502
625
  Object.defineProperty(exports, "attrs", {
503
626
  enumerable: true,
504
- get: function () { return chunkJKIMEPI2_cjs.attrs; }
627
+ get: function () { return chunkDQ2SUROF_cjs.attrs; }
505
628
  });
506
629
  Object.defineProperty(exports, "autoRedactPII", {
507
630
  enumerable: true,
508
- get: function () { return chunkJKIMEPI2_cjs.autoRedactPII; }
631
+ get: function () { return chunkDQ2SUROF_cjs.autoRedactPII; }
509
632
  });
510
633
  Object.defineProperty(exports, "dbClient", {
511
634
  enumerable: true,
512
- get: function () { return chunkJKIMEPI2_cjs.dbClient; }
635
+ get: function () { return chunkDQ2SUROF_cjs.dbClient; }
513
636
  });
514
637
  Object.defineProperty(exports, "httpClient", {
515
638
  enumerable: true,
516
- get: function () { return chunkJKIMEPI2_cjs.httpClient; }
639
+ get: function () { return chunkDQ2SUROF_cjs.httpClient; }
517
640
  });
518
641
  Object.defineProperty(exports, "httpServer", {
519
642
  enumerable: true,
520
- get: function () { return chunkJKIMEPI2_cjs.httpServer; }
643
+ get: function () { return chunkDQ2SUROF_cjs.httpServer; }
521
644
  });
522
645
  Object.defineProperty(exports, "identify", {
523
646
  enumerable: true,
524
- get: function () { return chunkJKIMEPI2_cjs.identify; }
647
+ get: function () { return chunkDQ2SUROF_cjs.identify; }
525
648
  });
526
649
  Object.defineProperty(exports, "mergeAttrs", {
527
650
  enumerable: true,
528
- get: function () { return chunkJKIMEPI2_cjs.mergeAttrs; }
651
+ get: function () { return chunkDQ2SUROF_cjs.mergeAttrs; }
529
652
  });
530
653
  Object.defineProperty(exports, "mergeServiceResource", {
531
654
  enumerable: true,
532
- get: function () { return chunkJKIMEPI2_cjs.mergeServiceResource; }
655
+ get: function () { return chunkDQ2SUROF_cjs.mergeServiceResource; }
533
656
  });
534
657
  Object.defineProperty(exports, "request", {
535
658
  enumerable: true,
536
- get: function () { return chunkJKIMEPI2_cjs.request; }
659
+ get: function () { return chunkDQ2SUROF_cjs.request; }
537
660
  });
538
661
  Object.defineProperty(exports, "safeSetAttributes", {
539
662
  enumerable: true,
540
- get: function () { return chunkJKIMEPI2_cjs.safeSetAttributes; }
663
+ get: function () { return chunkDQ2SUROF_cjs.safeSetAttributes; }
541
664
  });
542
665
  Object.defineProperty(exports, "setDevice", {
543
666
  enumerable: true,
544
- get: function () { return chunkJKIMEPI2_cjs.setDevice; }
667
+ get: function () { return chunkDQ2SUROF_cjs.setDevice; }
545
668
  });
546
669
  Object.defineProperty(exports, "setError", {
547
670
  enumerable: true,
548
- get: function () { return chunkJKIMEPI2_cjs.setError; }
671
+ get: function () { return chunkDQ2SUROF_cjs.setError; }
549
672
  });
550
673
  Object.defineProperty(exports, "setException", {
551
674
  enumerable: true,
552
- get: function () { return chunkJKIMEPI2_cjs.setException; }
675
+ get: function () { return chunkDQ2SUROF_cjs.setException; }
553
676
  });
554
677
  Object.defineProperty(exports, "setSession", {
555
678
  enumerable: true,
556
- get: function () { return chunkJKIMEPI2_cjs.setSession; }
679
+ get: function () { return chunkDQ2SUROF_cjs.setSession; }
557
680
  });
558
681
  Object.defineProperty(exports, "setUser", {
559
682
  enumerable: true,
560
- get: function () { return chunkJKIMEPI2_cjs.setUser; }
683
+ get: function () { return chunkDQ2SUROF_cjs.setUser; }
561
684
  });
562
685
  Object.defineProperty(exports, "validateAttribute", {
563
686
  enumerable: true,
564
- get: function () { return chunkJKIMEPI2_cjs.validateAttribute; }
687
+ get: function () { return chunkDQ2SUROF_cjs.validateAttribute; }
565
688
  });
566
689
  Object.defineProperty(exports, "httpRequestHeaderAttribute", {
567
690
  enumerable: true,
@@ -589,11 +712,11 @@ Object.defineProperty(exports, "parseError", {
589
712
  });
590
713
  Object.defineProperty(exports, "traceConsumer", {
591
714
  enumerable: true,
592
- get: function () { return chunkKHGA4OST_cjs.traceConsumer; }
715
+ get: function () { return chunkHKZHUGGN_cjs.traceConsumer; }
593
716
  });
594
717
  Object.defineProperty(exports, "traceProducer", {
595
718
  enumerable: true,
596
- get: function () { return chunkKHGA4OST_cjs.traceProducer; }
719
+ get: function () { return chunkHKZHUGGN_cjs.traceProducer; }
597
720
  });
598
721
  Object.defineProperty(exports, "BusinessBaggage", {
599
722
  enumerable: true,
@@ -637,43 +760,43 @@ Object.defineProperty(exports, "getMeter", {
637
760
  });
638
761
  Object.defineProperty(exports, "traceDB", {
639
762
  enumerable: true,
640
- get: function () { return chunkL7JDUDJD_cjs.traceDB; }
763
+ get: function () { return chunk7SMNC4LS_cjs.traceDB; }
641
764
  });
642
765
  Object.defineProperty(exports, "traceHTTP", {
643
766
  enumerable: true,
644
- get: function () { return chunkL7JDUDJD_cjs.traceHTTP; }
767
+ get: function () { return chunk7SMNC4LS_cjs.traceHTTP; }
645
768
  });
646
769
  Object.defineProperty(exports, "traceLLM", {
647
770
  enumerable: true,
648
- get: function () { return chunkL7JDUDJD_cjs.traceLLM; }
771
+ get: function () { return chunk7SMNC4LS_cjs.traceLLM; }
649
772
  });
650
773
  Object.defineProperty(exports, "traceMessaging", {
651
774
  enumerable: true,
652
- get: function () { return chunkL7JDUDJD_cjs.traceMessaging; }
775
+ get: function () { return chunk7SMNC4LS_cjs.traceMessaging; }
653
776
  });
654
777
  Object.defineProperty(exports, "ctx", {
655
778
  enumerable: true,
656
- get: function () { return chunkMOK3E54E_cjs.ctx; }
779
+ get: function () { return chunkQPH5ZKP5_cjs.ctx; }
657
780
  });
658
781
  Object.defineProperty(exports, "instrument", {
659
782
  enumerable: true,
660
- get: function () { return chunkMOK3E54E_cjs.instrument; }
783
+ get: function () { return chunkQPH5ZKP5_cjs.instrument; }
661
784
  });
662
785
  Object.defineProperty(exports, "span", {
663
786
  enumerable: true,
664
- get: function () { return chunkMOK3E54E_cjs.span; }
787
+ get: function () { return chunkQPH5ZKP5_cjs.span; }
665
788
  });
666
789
  Object.defineProperty(exports, "withBaggage", {
667
790
  enumerable: true,
668
- get: function () { return chunkMOK3E54E_cjs.withBaggage; }
791
+ get: function () { return chunkQPH5ZKP5_cjs.withBaggage; }
669
792
  });
670
793
  Object.defineProperty(exports, "withNewContext", {
671
794
  enumerable: true,
672
- get: function () { return chunkMOK3E54E_cjs.withNewContext; }
795
+ get: function () { return chunkQPH5ZKP5_cjs.withNewContext; }
673
796
  });
674
797
  Object.defineProperty(exports, "withTracing", {
675
798
  enumerable: true,
676
- get: function () { return chunkMOK3E54E_cjs.withTracing; }
799
+ get: function () { return chunkQPH5ZKP5_cjs.withTracing; }
677
800
  });
678
801
  Object.defineProperty(exports, "createDeterministicTraceId", {
679
802
  enumerable: true,
@@ -721,15 +844,15 @@ Object.defineProperty(exports, "runWithSpan", {
721
844
  });
722
845
  Object.defineProperty(exports, "Event", {
723
846
  enumerable: true,
724
- get: function () { return chunkZSABTI3C_cjs.Event; }
847
+ get: function () { return chunkDAZ7EGR4_cjs.Event; }
725
848
  });
726
849
  Object.defineProperty(exports, "getEvents", {
727
850
  enumerable: true,
728
- get: function () { return chunkZSABTI3C_cjs.getEvents; }
851
+ get: function () { return chunkDAZ7EGR4_cjs.getEvents; }
729
852
  });
730
853
  Object.defineProperty(exports, "resetEvents", {
731
854
  enumerable: true,
732
- get: function () { return chunkZSABTI3C_cjs.resetEvents; }
855
+ get: function () { return chunkDAZ7EGR4_cjs.resetEvents; }
733
856
  });
734
857
  Object.defineProperty(exports, "getOperationContext", {
735
858
  enumerable: true,
@@ -741,87 +864,87 @@ Object.defineProperty(exports, "runInOperationContext", {
741
864
  });
742
865
  Object.defineProperty(exports, "CORRELATION_ID_BAGGAGE_KEY", {
743
866
  enumerable: true,
744
- get: function () { return chunkCJ4PD2TZ_cjs.CORRELATION_ID_BAGGAGE_KEY; }
867
+ get: function () { return chunkKKGM42RQ_cjs.CORRELATION_ID_BAGGAGE_KEY; }
745
868
  });
746
869
  Object.defineProperty(exports, "createStructuredError", {
747
870
  enumerable: true,
748
- get: function () { return chunkCJ4PD2TZ_cjs.createStructuredError; }
871
+ get: function () { return chunkKKGM42RQ_cjs.createStructuredError; }
749
872
  });
750
873
  Object.defineProperty(exports, "defineBaggageSchema", {
751
874
  enumerable: true,
752
- get: function () { return chunkCJ4PD2TZ_cjs.defineBaggageSchema; }
875
+ get: function () { return chunkKKGM42RQ_cjs.defineBaggageSchema; }
753
876
  });
754
877
  Object.defineProperty(exports, "flattenToAttributes", {
755
878
  enumerable: true,
756
- get: function () { return chunkCJ4PD2TZ_cjs.flattenToAttributes; }
879
+ get: function () { return chunkKKGM42RQ_cjs.flattenToAttributes; }
757
880
  });
758
881
  Object.defineProperty(exports, "generateCorrelationId", {
759
882
  enumerable: true,
760
- get: function () { return chunkCJ4PD2TZ_cjs.generateCorrelationId; }
883
+ get: function () { return chunkKKGM42RQ_cjs.generateCorrelationId; }
761
884
  });
762
885
  Object.defineProperty(exports, "getCorrelationId", {
763
886
  enumerable: true,
764
- get: function () { return chunkCJ4PD2TZ_cjs.getCorrelationId; }
887
+ get: function () { return chunkKKGM42RQ_cjs.getCorrelationId; }
765
888
  });
766
889
  Object.defineProperty(exports, "getEventQueue", {
767
890
  enumerable: true,
768
- get: function () { return chunkCJ4PD2TZ_cjs.getEventQueue; }
891
+ get: function () { return chunkKKGM42RQ_cjs.getEventQueue; }
769
892
  });
770
893
  Object.defineProperty(exports, "getOrCreateCorrelationId", {
771
894
  enumerable: true,
772
- get: function () { return chunkCJ4PD2TZ_cjs.getOrCreateCorrelationId; }
895
+ get: function () { return chunkKKGM42RQ_cjs.getOrCreateCorrelationId; }
773
896
  });
774
897
  Object.defineProperty(exports, "getStructuredErrorAttributes", {
775
898
  enumerable: true,
776
- get: function () { return chunkCJ4PD2TZ_cjs.getStructuredErrorAttributes; }
899
+ get: function () { return chunkKKGM42RQ_cjs.getStructuredErrorAttributes; }
777
900
  });
778
901
  Object.defineProperty(exports, "recordStructuredError", {
779
902
  enumerable: true,
780
- get: function () { return chunkCJ4PD2TZ_cjs.recordStructuredError; }
903
+ get: function () { return chunkKKGM42RQ_cjs.recordStructuredError; }
781
904
  });
782
905
  Object.defineProperty(exports, "runWithCorrelationId", {
783
906
  enumerable: true,
784
- get: function () { return chunkCJ4PD2TZ_cjs.runWithCorrelationId; }
907
+ get: function () { return chunkKKGM42RQ_cjs.runWithCorrelationId; }
785
908
  });
786
909
  Object.defineProperty(exports, "setCorrelationId", {
787
910
  enumerable: true,
788
- get: function () { return chunkCJ4PD2TZ_cjs.setCorrelationId; }
911
+ get: function () { return chunkKKGM42RQ_cjs.setCorrelationId; }
789
912
  });
790
913
  Object.defineProperty(exports, "setCorrelationIdInBaggage", {
791
914
  enumerable: true,
792
- get: function () { return chunkCJ4PD2TZ_cjs.setCorrelationIdInBaggage; }
915
+ get: function () { return chunkKKGM42RQ_cjs.setCorrelationIdInBaggage; }
793
916
  });
794
917
  Object.defineProperty(exports, "structuredErrorToJSON", {
795
918
  enumerable: true,
796
- get: function () { return chunkCJ4PD2TZ_cjs.structuredErrorToJSON; }
919
+ get: function () { return chunkKKGM42RQ_cjs.structuredErrorToJSON; }
797
920
  });
798
921
  Object.defineProperty(exports, "toAttributeValue", {
799
922
  enumerable: true,
800
- get: function () { return chunkCJ4PD2TZ_cjs.toAttributeValue; }
923
+ get: function () { return chunkKKGM42RQ_cjs.toAttributeValue; }
801
924
  });
802
925
  Object.defineProperty(exports, "track", {
803
926
  enumerable: true,
804
- get: function () { return chunkCJ4PD2TZ_cjs.track; }
927
+ get: function () { return chunkKKGM42RQ_cjs.track; }
805
928
  });
806
929
  Object.defineProperty(exports, "BaggageSpanProcessor", {
807
930
  enumerable: true,
808
- get: function () { return chunk563EL6O6_cjs.BaggageSpanProcessor; }
931
+ get: function () { return chunkBPO2PQ3T_cjs.BaggageSpanProcessor; }
809
932
  });
810
933
  Object.defineProperty(exports, "createStringRedactor", {
811
934
  enumerable: true,
812
- get: function () { return chunk563EL6O6_cjs.createStringRedactor; }
935
+ get: function () { return chunkBPO2PQ3T_cjs.createStringRedactor; }
813
936
  });
814
937
  Object.defineProperty(exports, "init", {
815
938
  enumerable: true,
816
- get: function () { return chunk563EL6O6_cjs.init; }
939
+ get: function () { return chunkBPO2PQ3T_cjs.init; }
817
940
  });
818
941
  Object.defineProperty(exports, "isLoggerLocked", {
819
942
  enumerable: true,
820
- get: function () { return chunk563EL6O6_cjs.isLoggerLocked; }
943
+ get: function () { return chunkBPO2PQ3T_cjs.isLoggerLocked; }
821
944
  });
822
945
  Object.defineProperty(exports, "lockLogger", {
823
946
  enumerable: true,
824
- get: function () { return chunk563EL6O6_cjs.lockLogger; }
947
+ get: function () { return chunkBPO2PQ3T_cjs.lockLogger; }
825
948
  });
826
949
  Object.defineProperty(exports, "FilteringSpanProcessor", {
827
950
  enumerable: true,
@@ -841,23 +964,31 @@ Object.defineProperty(exports, "SpanNameNormalizingProcessor", {
841
964
  });
842
965
  Object.defineProperty(exports, "AttributeRedactingProcessor", {
843
966
  enumerable: true,
844
- get: function () { return chunkCMNGGTQL_cjs.AttributeRedactingProcessor; }
967
+ get: function () { return chunkNXLRY2CE_cjs.AttributeRedactingProcessor; }
845
968
  });
846
969
  Object.defineProperty(exports, "REDACTOR_PATTERNS", {
847
970
  enumerable: true,
848
- get: function () { return chunkCMNGGTQL_cjs.REDACTOR_PATTERNS; }
971
+ get: function () { return chunkNXLRY2CE_cjs.REDACTOR_PATTERNS; }
849
972
  });
850
973
  Object.defineProperty(exports, "REDACTOR_PRESETS", {
851
974
  enumerable: true,
852
- get: function () { return chunkCMNGGTQL_cjs.REDACTOR_PRESETS; }
975
+ get: function () { return chunkNXLRY2CE_cjs.REDACTOR_PRESETS; }
976
+ });
977
+ Object.defineProperty(exports, "builtinPatterns", {
978
+ enumerable: true,
979
+ get: function () { return chunkNXLRY2CE_cjs.builtinPatterns; }
853
980
  });
854
981
  Object.defineProperty(exports, "createAttributeRedactor", {
855
982
  enumerable: true,
856
- get: function () { return chunkCMNGGTQL_cjs.createAttributeRedactor; }
983
+ get: function () { return chunkNXLRY2CE_cjs.createAttributeRedactor; }
857
984
  });
858
985
  Object.defineProperty(exports, "createRedactedSpan", {
859
986
  enumerable: true,
860
- get: function () { return chunkCMNGGTQL_cjs.createRedactedSpan; }
987
+ get: function () { return chunkNXLRY2CE_cjs.createRedactedSpan; }
988
+ });
989
+ Object.defineProperty(exports, "normalizeAttributeRedactorConfig", {
990
+ enumerable: true,
991
+ get: function () { return chunkNXLRY2CE_cjs.normalizeAttributeRedactorConfig; }
861
992
  });
862
993
  Object.defineProperty(exports, "formatDuration", {
863
994
  enumerable: true,
@@ -946,6 +1077,9 @@ Object.defineProperty(exports, "propagation", {
946
1077
  exports.GEN_AI_COST_USD_BUCKETS = GEN_AI_COST_USD_BUCKETS;
947
1078
  exports.GEN_AI_DURATION_BUCKETS_SECONDS = GEN_AI_DURATION_BUCKETS_SECONDS;
948
1079
  exports.GEN_AI_TOKEN_USAGE_BUCKETS = GEN_AI_TOKEN_USAGE_BUCKETS;
1080
+ exports.defineDrain = defineDrain;
1081
+ exports.defineEnricher = defineEnricher;
1082
+ exports.defineHttpDrain = defineHttpDrain;
949
1083
  exports.flush = flush;
950
1084
  exports.genAiMetricViews = genAiMetricViews;
951
1085
  exports.getRequestLogger = getRequestLogger;