autotel 2.22.0 → 2.23.1

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 (126) hide show
  1. package/README.md +112 -6
  2. package/bin/intent.js +6 -0
  3. package/dist/auto.cjs +3 -3
  4. package/dist/auto.js +2 -2
  5. package/dist/{chunk-EWH2542B.js → chunk-3AMR5XLZ.js} +3 -3
  6. package/dist/{chunk-EWH2542B.js.map → chunk-3AMR5XLZ.js.map} +1 -1
  7. package/dist/chunk-3QXBFGKP.js +344 -0
  8. package/dist/chunk-3QXBFGKP.js.map +1 -0
  9. package/dist/{chunk-VQFF2WMP.cjs → chunk-3ZFDJJWZ.cjs} +37 -29
  10. package/dist/chunk-3ZFDJJWZ.cjs.map +1 -0
  11. package/dist/{chunk-CQC6RVLR.cjs → chunk-4RZ4JUBY.cjs} +5 -5
  12. package/dist/{chunk-CQC6RVLR.cjs.map → chunk-4RZ4JUBY.cjs.map} +1 -1
  13. package/dist/{chunk-PAVYKPCQ.js → chunk-5XUEHX7J.js} +3 -3
  14. package/dist/{chunk-PAVYKPCQ.js.map → chunk-5XUEHX7J.js.map} +1 -1
  15. package/dist/chunk-6S5RUKU3.cjs +347 -0
  16. package/dist/chunk-6S5RUKU3.cjs.map +1 -0
  17. package/dist/{chunk-BS757SL2.js → chunk-724XLWR3.js} +9 -4
  18. package/dist/chunk-724XLWR3.js.map +1 -0
  19. package/dist/chunk-7EQ4G4SI.cjs +146 -0
  20. package/dist/chunk-7EQ4G4SI.cjs.map +1 -0
  21. package/dist/{chunk-CQP5SQT4.cjs → chunk-AXFWWJF3.cjs} +7 -7
  22. package/dist/{chunk-CQP5SQT4.cjs.map → chunk-AXFWWJF3.cjs.map} +1 -1
  23. package/dist/{chunk-7NH625MS.cjs → chunk-BSZP4URK.cjs} +5 -5
  24. package/dist/{chunk-7NH625MS.cjs.map → chunk-BSZP4URK.cjs.map} +1 -1
  25. package/dist/{chunk-GZFH6P5U.js → chunk-GY4CRZSV.js} +14 -6
  26. package/dist/chunk-GY4CRZSV.js.map +1 -0
  27. package/dist/{chunk-QKUGUDXJ.cjs → chunk-HSEIUH7F.cjs} +10 -5
  28. package/dist/chunk-HSEIUH7F.cjs.map +1 -0
  29. package/dist/{chunk-DTW3WB7Z.js → chunk-IPKXURBW.js} +3 -3
  30. package/dist/{chunk-DTW3WB7Z.js.map → chunk-IPKXURBW.js.map} +1 -1
  31. package/dist/chunk-J7VGRIAJ.js +64 -0
  32. package/dist/chunk-J7VGRIAJ.js.map +1 -0
  33. package/dist/chunk-KFOHQK7X.js +144 -0
  34. package/dist/chunk-KFOHQK7X.js.map +1 -0
  35. package/dist/{chunk-4UYR46UP.cjs → chunk-MSUHW2I4.cjs} +13 -13
  36. package/dist/{chunk-4UYR46UP.cjs.map → chunk-MSUHW2I4.cjs.map} +1 -1
  37. package/dist/chunk-T4B5LB6E.cjs +66 -0
  38. package/dist/chunk-T4B5LB6E.cjs.map +1 -0
  39. package/dist/{chunk-QHT4MUED.js → chunk-WCIIFRGL.js} +3 -3
  40. package/dist/{chunk-QHT4MUED.js.map → chunk-WCIIFRGL.js.map} +1 -1
  41. package/dist/decorators.cjs +3 -3
  42. package/dist/decorators.js +3 -3
  43. package/dist/drain-pipeline.cjs +13 -0
  44. package/dist/drain-pipeline.cjs.map +1 -0
  45. package/dist/drain-pipeline.d.cts +37 -0
  46. package/dist/drain-pipeline.d.ts +37 -0
  47. package/dist/drain-pipeline.js +4 -0
  48. package/dist/drain-pipeline.js.map +1 -0
  49. package/dist/enrichers.cjs +90 -0
  50. package/dist/enrichers.cjs.map +1 -0
  51. package/dist/enrichers.d.cts +23 -0
  52. package/dist/enrichers.d.ts +23 -0
  53. package/dist/enrichers.js +86 -0
  54. package/dist/enrichers.js.map +1 -0
  55. package/dist/event.cjs +6 -6
  56. package/dist/event.js +3 -3
  57. package/dist/functional.cjs +10 -10
  58. package/dist/functional.js +3 -3
  59. package/dist/index.cjs +274 -41
  60. package/dist/index.cjs.map +1 -1
  61. package/dist/index.d.cts +73 -3
  62. package/dist/index.d.ts +73 -3
  63. package/dist/index.js +227 -11
  64. package/dist/index.js.map +1 -1
  65. package/dist/{init-BMiXSJNM.d.cts → init-BC5aN8bh.d.cts} +18 -0
  66. package/dist/{init-ByRbNTRo.d.ts → init-_FG4IbhF.d.ts} +18 -0
  67. package/dist/instrumentation.cjs +9 -9
  68. package/dist/instrumentation.js +2 -2
  69. package/dist/messaging.cjs +7 -7
  70. package/dist/messaging.js +4 -4
  71. package/dist/parse-error.cjs +13 -0
  72. package/dist/parse-error.cjs.map +1 -0
  73. package/dist/parse-error.d.cts +13 -0
  74. package/dist/parse-error.d.ts +13 -0
  75. package/dist/parse-error.js +4 -0
  76. package/dist/parse-error.js.map +1 -0
  77. package/dist/processors.cjs +2 -2
  78. package/dist/processors.d.cts +40 -4
  79. package/dist/processors.d.ts +40 -4
  80. package/dist/processors.js +1 -1
  81. package/dist/semantic-helpers.cjs +8 -8
  82. package/dist/semantic-helpers.js +4 -4
  83. package/dist/webhook.cjs +4 -4
  84. package/dist/webhook.js +3 -3
  85. package/dist/workflow-distributed.cjs +5 -5
  86. package/dist/workflow-distributed.js +3 -3
  87. package/dist/workflow.cjs +8 -8
  88. package/dist/workflow.js +4 -4
  89. package/dist/yaml-config.d.cts +2 -1
  90. package/dist/yaml-config.d.ts +2 -1
  91. package/package.json +55 -33
  92. package/skills/autotel-core/SKILL.md +162 -0
  93. package/skills/autotel-events/SKILL.md +88 -0
  94. package/skills/autotel-frameworks/SKILL.md +97 -0
  95. package/skills/autotel-instrumentation/SKILL.md +125 -0
  96. package/skills/autotel-request-logging/SKILL.md +100 -0
  97. package/skills/autotel-structured-errors/SKILL.md +130 -0
  98. package/src/drain-pipeline.test.ts +68 -0
  99. package/src/drain-pipeline.ts +199 -0
  100. package/src/enrichers.test.ts +150 -0
  101. package/src/enrichers.ts +145 -0
  102. package/src/flatten-attributes.test.ts +76 -0
  103. package/src/flatten-attributes.ts +80 -0
  104. package/src/functional.test.ts +63 -0
  105. package/src/functional.ts +11 -3
  106. package/src/index.ts +34 -0
  107. package/src/init.ts +22 -0
  108. package/src/package-manifest.test.ts +24 -0
  109. package/src/parse-error.test.ts +73 -0
  110. package/src/parse-error.ts +112 -0
  111. package/src/pretty-log-formatter.test.ts +123 -0
  112. package/src/pretty-log-formatter.ts +210 -0
  113. package/src/processors/canonical-log-line-processor.test.ts +81 -25
  114. package/src/processors/canonical-log-line-processor.ts +130 -42
  115. package/src/request-logger.test.ts +137 -0
  116. package/src/request-logger.ts +150 -0
  117. package/src/structured-error.test.ts +106 -0
  118. package/src/structured-error.ts +97 -0
  119. package/dist/chunk-2RQDNGV3.js +0 -126
  120. package/dist/chunk-2RQDNGV3.js.map +0 -1
  121. package/dist/chunk-BS757SL2.js.map +0 -1
  122. package/dist/chunk-GZFH6P5U.js.map +0 -1
  123. package/dist/chunk-ONK2Y22L.cjs +0 -128
  124. package/dist/chunk-ONK2Y22L.cjs.map +0 -1
  125. package/dist/chunk-QKUGUDXJ.cjs.map +0 -1
  126. package/dist/chunk-VQFF2WMP.cjs.map +0 -1
package/dist/event.js CHANGED
@@ -1,16 +1,16 @@
1
- export { Event, getEvents, resetEvents } from './chunk-PAVYKPCQ.js';
1
+ export { Event, getEvents, resetEvents } from './chunk-5XUEHX7J.js';
2
2
  import './chunk-LITNXTTT.js';
3
3
  import './chunk-BZHG5IZ4.js';
4
4
  import './chunk-WD4RP6IV.js';
5
5
  import './chunk-USSL3D6L.js';
6
- import './chunk-BS757SL2.js';
6
+ import './chunk-724XLWR3.js';
7
7
  import './chunk-YTGF4L2C.js';
8
8
  import './chunk-X4RMFFMR.js';
9
9
  import './chunk-WGWSHJ2N.js';
10
10
  import './chunk-GYR5K654.js';
11
11
  import './chunk-SNINLBEE.js';
12
12
  import './chunk-6UQRVUN3.js';
13
- import './chunk-2RQDNGV3.js';
13
+ import './chunk-3QXBFGKP.js';
14
14
  import './chunk-33WTKH7X.js';
15
15
  import './chunk-XND7WBVX.js';
16
16
  import './chunk-B33XPEKY.js';
@@ -1,18 +1,18 @@
1
1
  'use strict';
2
2
 
3
- var chunkVQFF2WMP_cjs = require('./chunk-VQFF2WMP.cjs');
3
+ var chunk3ZFDJJWZ_cjs = require('./chunk-3ZFDJJWZ.cjs');
4
4
  require('./chunk-W4EUTSB2.cjs');
5
5
  require('./chunk-GML3FBOT.cjs');
6
6
  require('./chunk-D5LMF53P.cjs');
7
7
  require('./chunk-XRKAL7WJ.cjs');
8
- require('./chunk-QKUGUDXJ.cjs');
8
+ require('./chunk-HSEIUH7F.cjs');
9
9
  require('./chunk-6YIDHH2S.cjs');
10
10
  require('./chunk-GVLK7YUU.cjs');
11
11
  require('./chunk-ZNMBW67B.cjs');
12
12
  require('./chunk-IOYFAFHJ.cjs');
13
13
  require('./chunk-ELW34S4C.cjs');
14
14
  require('./chunk-CU6IDACR.cjs');
15
- require('./chunk-ONK2Y22L.cjs');
15
+ require('./chunk-6S5RUKU3.cjs');
16
16
  require('./chunk-YS6C2YJE.cjs');
17
17
  require('./chunk-BGVKKL2N.cjs');
18
18
  require('./chunk-AZ24DJAG.cjs');
@@ -24,31 +24,31 @@ require('./chunk-JEQ2X3Z6.cjs');
24
24
 
25
25
  Object.defineProperty(exports, "ctx", {
26
26
  enumerable: true,
27
- get: function () { return chunkVQFF2WMP_cjs.ctx; }
27
+ get: function () { return chunk3ZFDJJWZ_cjs.ctx; }
28
28
  });
29
29
  Object.defineProperty(exports, "instrument", {
30
30
  enumerable: true,
31
- get: function () { return chunkVQFF2WMP_cjs.instrument; }
31
+ get: function () { return chunk3ZFDJJWZ_cjs.instrument; }
32
32
  });
33
33
  Object.defineProperty(exports, "span", {
34
34
  enumerable: true,
35
- get: function () { return chunkVQFF2WMP_cjs.span; }
35
+ get: function () { return chunk3ZFDJJWZ_cjs.span; }
36
36
  });
37
37
  Object.defineProperty(exports, "trace", {
38
38
  enumerable: true,
39
- get: function () { return chunkVQFF2WMP_cjs.trace; }
39
+ get: function () { return chunk3ZFDJJWZ_cjs.trace; }
40
40
  });
41
41
  Object.defineProperty(exports, "withBaggage", {
42
42
  enumerable: true,
43
- get: function () { return chunkVQFF2WMP_cjs.withBaggage; }
43
+ get: function () { return chunk3ZFDJJWZ_cjs.withBaggage; }
44
44
  });
45
45
  Object.defineProperty(exports, "withNewContext", {
46
46
  enumerable: true,
47
- get: function () { return chunkVQFF2WMP_cjs.withNewContext; }
47
+ get: function () { return chunk3ZFDJJWZ_cjs.withNewContext; }
48
48
  });
49
49
  Object.defineProperty(exports, "withTracing", {
50
50
  enumerable: true,
51
- get: function () { return chunkVQFF2WMP_cjs.withTracing; }
51
+ get: function () { return chunk3ZFDJJWZ_cjs.withTracing; }
52
52
  });
53
53
  //# sourceMappingURL=functional.cjs.map
54
54
  //# sourceMappingURL=functional.cjs.map
@@ -1,16 +1,16 @@
1
- export { ctx, instrument, span, trace, withBaggage, withNewContext, withTracing } from './chunk-GZFH6P5U.js';
1
+ export { ctx, instrument, span, trace, withBaggage, withNewContext, withTracing } from './chunk-GY4CRZSV.js';
2
2
  import './chunk-SR35DG5A.js';
3
3
  import './chunk-B3ZHLLMP.js';
4
4
  import './chunk-WD4RP6IV.js';
5
5
  import './chunk-USSL3D6L.js';
6
- import './chunk-BS757SL2.js';
6
+ import './chunk-724XLWR3.js';
7
7
  import './chunk-YTGF4L2C.js';
8
8
  import './chunk-X4RMFFMR.js';
9
9
  import './chunk-WGWSHJ2N.js';
10
10
  import './chunk-GYR5K654.js';
11
11
  import './chunk-SNINLBEE.js';
12
12
  import './chunk-6UQRVUN3.js';
13
- import './chunk-2RQDNGV3.js';
13
+ import './chunk-3QXBFGKP.js';
14
14
  import './chunk-33WTKH7X.js';
15
15
  import './chunk-XND7WBVX.js';
16
16
  import './chunk-B33XPEKY.js';
package/dist/index.cjs CHANGED
@@ -1,37 +1,40 @@
1
1
  'use strict';
2
2
 
3
- var chunk7NH625MS_cjs = require('./chunk-7NH625MS.cjs');
3
+ var chunk7EQ4G4SI_cjs = require('./chunk-7EQ4G4SI.cjs');
4
+ var chunkBSZP4URK_cjs = require('./chunk-BSZP4URK.cjs');
4
5
  var chunkXRBP4RYL_cjs = require('./chunk-XRBP4RYL.cjs');
5
6
  var chunk2ZKEORFN_cjs = require('./chunk-2ZKEORFN.cjs');
6
7
  var chunkESMHTKLJ_cjs = require('./chunk-ESMHTKLJ.cjs');
7
- var chunkCQC6RVLR_cjs = require('./chunk-CQC6RVLR.cjs');
8
+ var chunkT4B5LB6E_cjs = require('./chunk-T4B5LB6E.cjs');
9
+ var chunk4RZ4JUBY_cjs = require('./chunk-4RZ4JUBY.cjs');
8
10
  var chunkINJD3G4K_cjs = require('./chunk-INJD3G4K.cjs');
9
11
  var chunkTC5ZPWM4_cjs = require('./chunk-TC5ZPWM4.cjs');
10
12
  require('./chunk-YTXEZ4SD.cjs');
11
13
  var chunkWJH6IYU2_cjs = require('./chunk-WJH6IYU2.cjs');
12
- var chunkCQP5SQT4_cjs = require('./chunk-CQP5SQT4.cjs');
13
- var chunkVQFF2WMP_cjs = require('./chunk-VQFF2WMP.cjs');
14
+ var chunkAXFWWJF3_cjs = require('./chunk-AXFWWJF3.cjs');
15
+ var chunk3ZFDJJWZ_cjs = require('./chunk-3ZFDJJWZ.cjs');
14
16
  var chunkW4EUTSB2_cjs = require('./chunk-W4EUTSB2.cjs');
15
17
  var chunkGML3FBOT_cjs = require('./chunk-GML3FBOT.cjs');
16
- var chunk4UYR46UP_cjs = require('./chunk-4UYR46UP.cjs');
18
+ var chunkMSUHW2I4_cjs = require('./chunk-MSUHW2I4.cjs');
17
19
  require('./chunk-NZ72VDNY.cjs');
18
20
  require('./chunk-UY3UYPBZ.cjs');
19
21
  var chunkD5LMF53P_cjs = require('./chunk-D5LMF53P.cjs');
20
22
  var chunkXRKAL7WJ_cjs = require('./chunk-XRKAL7WJ.cjs');
21
- var chunkQKUGUDXJ_cjs = require('./chunk-QKUGUDXJ.cjs');
23
+ var chunkHSEIUH7F_cjs = require('./chunk-HSEIUH7F.cjs');
22
24
  require('./chunk-6YIDHH2S.cjs');
23
25
  require('./chunk-GVLK7YUU.cjs');
24
26
  var chunkZNMBW67B_cjs = require('./chunk-ZNMBW67B.cjs');
25
27
  var chunkIOYFAFHJ_cjs = require('./chunk-IOYFAFHJ.cjs');
26
28
  var chunkELW34S4C_cjs = require('./chunk-ELW34S4C.cjs');
27
29
  require('./chunk-CU6IDACR.cjs');
28
- require('./chunk-ONK2Y22L.cjs');
30
+ var chunk6S5RUKU3_cjs = require('./chunk-6S5RUKU3.cjs');
29
31
  require('./chunk-YS6C2YJE.cjs');
30
32
  var chunkBGVKKL2N_cjs = require('./chunk-BGVKKL2N.cjs');
31
33
  require('./chunk-AZ24DJAG.cjs');
32
34
  require('./chunk-ESLWRGAG.cjs');
33
35
  var chunkYREV3LGG_cjs = require('./chunk-YREV3LGG.cjs');
34
36
  require('./chunk-JEQ2X3Z6.cjs');
37
+ var async_hooks = require('async_hooks');
35
38
  var api = require('@opentelemetry/api');
36
39
 
37
40
  // src/shutdown.ts
@@ -39,7 +42,7 @@ async function flush(options) {
39
42
  const timeout = options?.timeout ?? 2e3;
40
43
  const forShutdown = options?.forShutdown ?? false;
41
44
  const doFlush = async () => {
42
- const eventsQueue = chunkVQFF2WMP_cjs.getEventQueue();
45
+ const eventsQueue = chunk3ZFDJJWZ_cjs.getEventQueue();
43
46
  if (eventsQueue) {
44
47
  if (forShutdown) {
45
48
  await eventsQueue.shutdown();
@@ -47,7 +50,7 @@ async function flush(options) {
47
50
  await eventsQueue.flush();
48
51
  }
49
52
  }
50
- const sdk = chunkQKUGUDXJ_cjs.getSdk();
53
+ const sdk = chunkHSEIUH7F_cjs.getSdk();
51
54
  if (sdk) {
52
55
  try {
53
56
  const sdkAny = sdk;
@@ -81,7 +84,7 @@ async function flush(options) {
81
84
  if (timeoutHandle) {
82
85
  clearTimeout(timeoutHandle);
83
86
  }
84
- const logger = chunkQKUGUDXJ_cjs.getLogger();
87
+ const logger = chunkHSEIUH7F_cjs.getLogger();
85
88
  logger.error(
86
89
  {
87
90
  err: error instanceof Error ? error : new Error(String(error))
@@ -92,7 +95,7 @@ async function flush(options) {
92
95
  }
93
96
  }
94
97
  async function shutdown() {
95
- const logger = chunkQKUGUDXJ_cjs.getLogger();
98
+ const logger = chunkHSEIUH7F_cjs.getLogger();
96
99
  let shutdownError = null;
97
100
  try {
98
101
  await flush({ forShutdown: true });
@@ -107,7 +110,7 @@ async function shutdown() {
107
110
  );
108
111
  }
109
112
  try {
110
- const sdk = chunkQKUGUDXJ_cjs.getSdk();
113
+ const sdk = chunkHSEIUH7F_cjs.getSdk();
111
114
  if (sdk) {
112
115
  await sdk.shutdown();
113
116
  }
@@ -121,13 +124,13 @@ async function shutdown() {
121
124
  logger.error({ err }, "[autotel] SDK shutdown failed");
122
125
  }
123
126
  } finally {
124
- const eventsQueue = chunkVQFF2WMP_cjs.getEventQueue();
127
+ const eventsQueue = chunk3ZFDJJWZ_cjs.getEventQueue();
125
128
  if (eventsQueue && typeof eventsQueue.cleanup === "function") {
126
129
  eventsQueue.cleanup();
127
130
  }
128
- chunk4UYR46UP_cjs.resetEvents();
131
+ chunkMSUHW2I4_cjs.resetEvents();
129
132
  chunkTC5ZPWM4_cjs.resetMetrics();
130
- chunkVQFF2WMP_cjs.resetEventQueue();
133
+ chunk3ZFDJJWZ_cjs.resetEventQueue();
131
134
  }
132
135
  if (shutdownError) {
133
136
  throw shutdownError;
@@ -142,7 +145,7 @@ function registerShutdownHooks() {
142
145
  if (shuttingDown) return;
143
146
  shuttingDown = true;
144
147
  if (process.env.NODE_ENV !== "test") {
145
- chunkQKUGUDXJ_cjs.getLogger().info(
148
+ chunkHSEIUH7F_cjs.getLogger().info(
146
149
  {},
147
150
  `[autotel] Received ${signal}, flushing telemetry...`
148
151
  );
@@ -150,7 +153,7 @@ function registerShutdownHooks() {
150
153
  try {
151
154
  await shutdown();
152
155
  } catch (error) {
153
- chunkQKUGUDXJ_cjs.getLogger().error(
156
+ chunkHSEIUH7F_cjs.getLogger().error(
154
157
  {
155
158
  err: error instanceof Error ? error : void 0
156
159
  },
@@ -164,21 +167,236 @@ function registerShutdownHooks() {
164
167
  }
165
168
  registerShutdownHooks();
166
169
 
170
+ // src/flatten-attributes.ts
171
+ function toAttributeValue(value) {
172
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
173
+ return value;
174
+ }
175
+ if (Array.isArray(value)) {
176
+ if (value.every((v) => typeof v === "string") || value.every((v) => typeof v === "number") || value.every((v) => typeof v === "boolean")) {
177
+ return value;
178
+ }
179
+ try {
180
+ return JSON.stringify(value);
181
+ } catch {
182
+ return "<serialization-failed>";
183
+ }
184
+ }
185
+ if (value instanceof Date) {
186
+ return value.toISOString();
187
+ }
188
+ if (value instanceof Error) {
189
+ return value.message;
190
+ }
191
+ return void 0;
192
+ }
193
+ function flattenToAttributes(fields, prefix = "") {
194
+ const out = {};
195
+ const seen = /* @__PURE__ */ new WeakSet();
196
+ function flatten(obj, currentPrefix) {
197
+ for (const [key, value] of Object.entries(obj)) {
198
+ if (value == null) continue;
199
+ const nextKey = currentPrefix ? `${currentPrefix}.${key}` : key;
200
+ const attr = toAttributeValue(value);
201
+ if (attr !== void 0) {
202
+ out[nextKey] = attr;
203
+ continue;
204
+ }
205
+ if (typeof value === "object" && value.constructor === Object) {
206
+ if (seen.has(value)) {
207
+ out[nextKey] = "<circular-reference>";
208
+ continue;
209
+ }
210
+ seen.add(value);
211
+ flatten(value, nextKey);
212
+ continue;
213
+ }
214
+ try {
215
+ out[nextKey] = JSON.stringify(value);
216
+ } catch {
217
+ out[nextKey] = "<serialization-failed>";
218
+ }
219
+ }
220
+ }
221
+ flatten(fields, prefix);
222
+ return out;
223
+ }
224
+
225
+ // src/structured-error.ts
226
+ function createStructuredError(input) {
227
+ const error = new Error(input.message, {
228
+ cause: input.cause
229
+ });
230
+ error.name = input.name ?? "StructuredError";
231
+ if (input.why !== void 0) error.why = input.why;
232
+ if (input.fix !== void 0) error.fix = input.fix;
233
+ if (input.link !== void 0) error.link = input.link;
234
+ if (input.code !== void 0) error.code = input.code;
235
+ if (input.status !== void 0) error.status = input.status;
236
+ if (input.details !== void 0) error.details = input.details;
237
+ error.toString = () => {
238
+ const lines = [`${error.name}: ${error.message}`];
239
+ if (error.why) lines.push(` Why: ${error.why}`);
240
+ if (error.fix) lines.push(` Fix: ${error.fix}`);
241
+ if (error.link) lines.push(` Link: ${error.link}`);
242
+ if (error.code !== void 0) lines.push(` Code: ${error.code}`);
243
+ if (error.status !== void 0) lines.push(` Status: ${error.status}`);
244
+ if (error.cause) lines.push(` Caused by: ${error.cause}`);
245
+ return lines.join("\n");
246
+ };
247
+ return error;
248
+ }
249
+ function getStructuredErrorAttributes(error) {
250
+ const structured = error;
251
+ const attributes = {
252
+ "error.type": error.name || "Error",
253
+ "error.message": error.message
254
+ };
255
+ if (error.stack) attributes["error.stack"] = error.stack;
256
+ if (structured.why) attributes["error.why"] = structured.why;
257
+ if (structured.fix) attributes["error.fix"] = structured.fix;
258
+ if (structured.link) attributes["error.link"] = structured.link;
259
+ if (structured.code !== void 0) {
260
+ attributes["error.code"] = typeof structured.code === "string" ? structured.code : String(structured.code);
261
+ }
262
+ if (structured.status !== void 0) {
263
+ attributes["error.status"] = structured.status;
264
+ }
265
+ if (structured.details) {
266
+ Object.assign(
267
+ attributes,
268
+ flattenToAttributes(structured.details, "error.details")
269
+ );
270
+ }
271
+ return attributes;
272
+ }
273
+ function recordStructuredError(ctx2, error) {
274
+ ctx2.recordException(error);
275
+ ctx2.setStatus({
276
+ code: api.SpanStatusCode.ERROR,
277
+ message: error.message
278
+ });
279
+ ctx2.setAttributes(getStructuredErrorAttributes(error));
280
+ }
281
+
282
+ // src/request-logger.ts
283
+ var requestContextStore = new async_hooks.AsyncLocalStorage();
284
+ function runWithRequestContext(ctx2, fn) {
285
+ return requestContextStore.run(ctx2, fn);
286
+ }
287
+ function resolveContext(ctx2) {
288
+ if (ctx2) return ctx2;
289
+ const stored = requestContextStore.getStore();
290
+ if (stored) return stored;
291
+ const span2 = api.trace.getActiveSpan();
292
+ if (!span2) {
293
+ throw new Error(
294
+ "[autotel] getRequestLogger() requires an active span or runWithRequestContext(). Wrap your handler with trace() or use runWithRequestContext()."
295
+ );
296
+ }
297
+ return chunkW4EUTSB2_cjs.createTraceContext(span2);
298
+ }
299
+ function getRequestLogger(ctx2, options) {
300
+ const activeContext = resolveContext(ctx2);
301
+ let contextState = {};
302
+ const addLogEvent = (level, message, fields) => {
303
+ const attrs2 = fields ? flattenToAttributes(fields) : void 0;
304
+ activeContext.addEvent(`log.${level}`, {
305
+ message,
306
+ ...attrs2
307
+ });
308
+ };
309
+ return {
310
+ set(fields) {
311
+ contextState = {
312
+ ...contextState,
313
+ ...fields
314
+ };
315
+ activeContext.setAttributes(flattenToAttributes(fields));
316
+ },
317
+ info(message, fields) {
318
+ addLogEvent("info", message, fields);
319
+ if (fields) {
320
+ contextState = {
321
+ ...contextState,
322
+ ...fields
323
+ };
324
+ activeContext.setAttributes(flattenToAttributes(fields));
325
+ }
326
+ },
327
+ warn(message, fields) {
328
+ addLogEvent("warn", message, fields);
329
+ activeContext.setAttribute("autotel.log.level", "warn");
330
+ if (fields) {
331
+ contextState = {
332
+ ...contextState,
333
+ ...fields
334
+ };
335
+ activeContext.setAttributes(flattenToAttributes(fields));
336
+ }
337
+ },
338
+ error(error, fields) {
339
+ const err = typeof error === "string" ? new Error(error) : error;
340
+ recordStructuredError(activeContext, err);
341
+ addLogEvent("error", err.message, fields);
342
+ if (fields) {
343
+ contextState = {
344
+ ...contextState,
345
+ ...fields
346
+ };
347
+ activeContext.setAttributes(flattenToAttributes(fields));
348
+ }
349
+ activeContext.setAttribute("autotel.log.level", "error");
350
+ },
351
+ getContext() {
352
+ return { ...contextState };
353
+ },
354
+ emitNow(overrides) {
355
+ const mergedContext = {
356
+ ...contextState,
357
+ ...overrides ?? {}
358
+ };
359
+ const flattened = flattenToAttributes(mergedContext);
360
+ activeContext.setAttributes(flattened);
361
+ const snapshot = {
362
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
363
+ traceId: activeContext.traceId,
364
+ spanId: activeContext.spanId,
365
+ correlationId: activeContext.correlationId,
366
+ context: mergedContext
367
+ };
368
+ activeContext.addEvent("log.emit.manual", {
369
+ ...flattened
370
+ });
371
+ if (options?.onEmit) {
372
+ Promise.resolve(options.onEmit(snapshot)).catch((error) => {
373
+ console.warn("[autotel] request logger onEmit failed:", error);
374
+ });
375
+ }
376
+ return snapshot;
377
+ }
378
+ };
379
+ }
380
+
381
+ Object.defineProperty(exports, "createDrainPipeline", {
382
+ enumerable: true,
383
+ get: function () { return chunk7EQ4G4SI_cjs.createDrainPipeline; }
384
+ });
167
385
  Object.defineProperty(exports, "getCurrentWorkflowContext", {
168
386
  enumerable: true,
169
- get: function () { return chunk7NH625MS_cjs.getCurrentWorkflowContext; }
387
+ get: function () { return chunkBSZP4URK_cjs.getCurrentWorkflowContext; }
170
388
  });
171
389
  Object.defineProperty(exports, "isInWorkflow", {
172
390
  enumerable: true,
173
- get: function () { return chunk7NH625MS_cjs.isInWorkflow; }
391
+ get: function () { return chunkBSZP4URK_cjs.isInWorkflow; }
174
392
  });
175
393
  Object.defineProperty(exports, "traceStep", {
176
394
  enumerable: true,
177
- get: function () { return chunk7NH625MS_cjs.traceStep; }
395
+ get: function () { return chunkBSZP4URK_cjs.traceStep; }
178
396
  });
179
397
  Object.defineProperty(exports, "traceWorkflow", {
180
398
  enumerable: true,
181
- get: function () { return chunk7NH625MS_cjs.traceWorkflow; }
399
+ get: function () { return chunkBSZP4URK_cjs.traceWorkflow; }
182
400
  });
183
401
  Object.defineProperty(exports, "attrs", {
184
402
  enumerable: true,
@@ -264,13 +482,17 @@ Object.defineProperty(exports, "URLAttributes", {
264
482
  enumerable: true,
265
483
  get: function () { return chunkESMHTKLJ_cjs.URLAttributes; }
266
484
  });
485
+ Object.defineProperty(exports, "parseError", {
486
+ enumerable: true,
487
+ get: function () { return chunkT4B5LB6E_cjs.parseError; }
488
+ });
267
489
  Object.defineProperty(exports, "traceConsumer", {
268
490
  enumerable: true,
269
- get: function () { return chunkCQC6RVLR_cjs.traceConsumer; }
491
+ get: function () { return chunk4RZ4JUBY_cjs.traceConsumer; }
270
492
  });
271
493
  Object.defineProperty(exports, "traceProducer", {
272
494
  enumerable: true,
273
- get: function () { return chunkCQC6RVLR_cjs.traceProducer; }
495
+ get: function () { return chunk4RZ4JUBY_cjs.traceProducer; }
274
496
  });
275
497
  Object.defineProperty(exports, "BusinessBaggage", {
276
498
  enumerable: true,
@@ -314,55 +536,55 @@ Object.defineProperty(exports, "getMeter", {
314
536
  });
315
537
  Object.defineProperty(exports, "traceDB", {
316
538
  enumerable: true,
317
- get: function () { return chunkCQP5SQT4_cjs.traceDB; }
539
+ get: function () { return chunkAXFWWJF3_cjs.traceDB; }
318
540
  });
319
541
  Object.defineProperty(exports, "traceHTTP", {
320
542
  enumerable: true,
321
- get: function () { return chunkCQP5SQT4_cjs.traceHTTP; }
543
+ get: function () { return chunkAXFWWJF3_cjs.traceHTTP; }
322
544
  });
323
545
  Object.defineProperty(exports, "traceLLM", {
324
546
  enumerable: true,
325
- get: function () { return chunkCQP5SQT4_cjs.traceLLM; }
547
+ get: function () { return chunkAXFWWJF3_cjs.traceLLM; }
326
548
  });
327
549
  Object.defineProperty(exports, "traceMessaging", {
328
550
  enumerable: true,
329
- get: function () { return chunkCQP5SQT4_cjs.traceMessaging; }
551
+ get: function () { return chunkAXFWWJF3_cjs.traceMessaging; }
330
552
  });
331
553
  Object.defineProperty(exports, "ctx", {
332
554
  enumerable: true,
333
- get: function () { return chunkVQFF2WMP_cjs.ctx; }
555
+ get: function () { return chunk3ZFDJJWZ_cjs.ctx; }
334
556
  });
335
557
  Object.defineProperty(exports, "getEventQueue", {
336
558
  enumerable: true,
337
- get: function () { return chunkVQFF2WMP_cjs.getEventQueue; }
559
+ get: function () { return chunk3ZFDJJWZ_cjs.getEventQueue; }
338
560
  });
339
561
  Object.defineProperty(exports, "instrument", {
340
562
  enumerable: true,
341
- get: function () { return chunkVQFF2WMP_cjs.instrument; }
563
+ get: function () { return chunk3ZFDJJWZ_cjs.instrument; }
342
564
  });
343
565
  Object.defineProperty(exports, "span", {
344
566
  enumerable: true,
345
- get: function () { return chunkVQFF2WMP_cjs.span; }
567
+ get: function () { return chunk3ZFDJJWZ_cjs.span; }
346
568
  });
347
569
  Object.defineProperty(exports, "trace", {
348
570
  enumerable: true,
349
- get: function () { return chunkVQFF2WMP_cjs.trace; }
571
+ get: function () { return chunk3ZFDJJWZ_cjs.trace; }
350
572
  });
351
573
  Object.defineProperty(exports, "track", {
352
574
  enumerable: true,
353
- get: function () { return chunkVQFF2WMP_cjs.track; }
575
+ get: function () { return chunk3ZFDJJWZ_cjs.track; }
354
576
  });
355
577
  Object.defineProperty(exports, "withBaggage", {
356
578
  enumerable: true,
357
- get: function () { return chunkVQFF2WMP_cjs.withBaggage; }
579
+ get: function () { return chunk3ZFDJJWZ_cjs.withBaggage; }
358
580
  });
359
581
  Object.defineProperty(exports, "withNewContext", {
360
582
  enumerable: true,
361
- get: function () { return chunkVQFF2WMP_cjs.withNewContext; }
583
+ get: function () { return chunk3ZFDJJWZ_cjs.withNewContext; }
362
584
  });
363
585
  Object.defineProperty(exports, "withTracing", {
364
586
  enumerable: true,
365
- get: function () { return chunkVQFF2WMP_cjs.withTracing; }
587
+ get: function () { return chunk3ZFDJJWZ_cjs.withTracing; }
366
588
  });
367
589
  Object.defineProperty(exports, "defineBaggageSchema", {
368
590
  enumerable: true,
@@ -414,15 +636,15 @@ Object.defineProperty(exports, "runWithSpan", {
414
636
  });
415
637
  Object.defineProperty(exports, "Event", {
416
638
  enumerable: true,
417
- get: function () { return chunk4UYR46UP_cjs.Event; }
639
+ get: function () { return chunkMSUHW2I4_cjs.Event; }
418
640
  });
419
641
  Object.defineProperty(exports, "getEvents", {
420
642
  enumerable: true,
421
- get: function () { return chunk4UYR46UP_cjs.getEvents; }
643
+ get: function () { return chunkMSUHW2I4_cjs.getEvents; }
422
644
  });
423
645
  Object.defineProperty(exports, "resetEvents", {
424
646
  enumerable: true,
425
- get: function () { return chunk4UYR46UP_cjs.resetEvents; }
647
+ get: function () { return chunkMSUHW2I4_cjs.resetEvents; }
426
648
  });
427
649
  Object.defineProperty(exports, "getOperationContext", {
428
650
  enumerable: true,
@@ -462,11 +684,11 @@ Object.defineProperty(exports, "setCorrelationIdInBaggage", {
462
684
  });
463
685
  Object.defineProperty(exports, "BaggageSpanProcessor", {
464
686
  enumerable: true,
465
- get: function () { return chunkQKUGUDXJ_cjs.BaggageSpanProcessor; }
687
+ get: function () { return chunkHSEIUH7F_cjs.BaggageSpanProcessor; }
466
688
  });
467
689
  Object.defineProperty(exports, "init", {
468
690
  enumerable: true,
469
- get: function () { return chunkQKUGUDXJ_cjs.init; }
691
+ get: function () { return chunkHSEIUH7F_cjs.init; }
470
692
  });
471
693
  Object.defineProperty(exports, "FilteringSpanProcessor", {
472
694
  enumerable: true,
@@ -500,6 +722,10 @@ Object.defineProperty(exports, "createRedactedSpan", {
500
722
  enumerable: true,
501
723
  get: function () { return chunkELW34S4C_cjs.createRedactedSpan; }
502
724
  });
725
+ Object.defineProperty(exports, "formatDuration", {
726
+ enumerable: true,
727
+ get: function () { return chunk6S5RUKU3_cjs.formatDuration; }
728
+ });
503
729
  Object.defineProperty(exports, "AdaptiveSampler", {
504
730
  enumerable: true,
505
731
  get: function () { return chunkBGVKKL2N_cjs.AdaptiveSampler; }
@@ -564,7 +790,14 @@ Object.defineProperty(exports, "propagation", {
564
790
  enumerable: true,
565
791
  get: function () { return api.propagation; }
566
792
  });
793
+ exports.createStructuredError = createStructuredError;
794
+ exports.flattenToAttributes = flattenToAttributes;
567
795
  exports.flush = flush;
796
+ exports.getRequestLogger = getRequestLogger;
797
+ exports.getStructuredErrorAttributes = getStructuredErrorAttributes;
798
+ exports.recordStructuredError = recordStructuredError;
799
+ exports.runWithRequestContext = runWithRequestContext;
568
800
  exports.shutdown = shutdown;
801
+ exports.toAttributeValue = toAttributeValue;
569
802
  //# sourceMappingURL=index.cjs.map
570
803
  //# sourceMappingURL=index.cjs.map