@autter/runtime-node 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -46,15 +46,15 @@
46
46
 
47
47
 
48
48
 
49
- var _chunk37W7YYXOcjs = require('./chunk-37W7YYXO.cjs');
50
49
 
51
50
 
52
- var _chunk7H3FCV4Pcjs = require('./chunk-7H3FCV4P.cjs');
53
51
 
54
52
 
55
53
 
54
+ var _chunkYWTIKZSIcjs = require('./chunk-YWTIKZSI.cjs');
56
55
 
57
56
 
57
+ var _chunkAN45KLWDcjs = require('./chunk-AN45KLWD.cjs');
58
58
 
59
59
 
60
60
 
@@ -71,7 +71,12 @@ var _chunk7H3FCV4Pcjs = require('./chunk-7H3FCV4P.cjs');
71
71
 
72
72
 
73
73
 
74
- var _chunkMOZOUEMAcjs = require('./chunk-MOZOUEMA.cjs');
74
+
75
+
76
+
77
+
78
+
79
+ var _chunkBHYHORUDcjs = require('./chunk-BHYHORUD.cjs');
75
80
 
76
81
  // src/relay.ts
77
82
  var IpWindow = (_class = class {
@@ -96,6 +101,112 @@ function firstForwardedFor(value) {
96
101
  const raw = Array.isArray(value) ? value[0] : value;
97
102
  return raw ? (_nullishCoalesce(raw.split(",")[0], () => ( ""))).trim() : "";
98
103
  }
104
+ var TRUST_AUTO = { mode: "auto" };
105
+ var warnedTrustProxy = false;
106
+ function resolveTrustProxy(value) {
107
+ if (value === void 0 || value === null || value === "auto") return TRUST_AUTO;
108
+ if (value === true) return { mode: "all" };
109
+ if (value === false || value === 0) return { mode: "never" };
110
+ if (typeof value === "number" && Number.isInteger(value) && value >= 1 && value <= 100) {
111
+ return { mode: "hops", hops: value };
112
+ }
113
+ if (typeof value === "string") {
114
+ const v = value.trim().toLowerCase();
115
+ if (v === "" || v === "auto") return TRUST_AUTO;
116
+ if (v === "false" || v === "0" || v === "no" || v === "off") return { mode: "never" };
117
+ if (v === "true" || v === "yes" || v === "on") return { mode: "all" };
118
+ if (/^[1-9][0-9]?$/.test(v)) return { mode: "hops", hops: Number(v) };
119
+ }
120
+ if (!warnedTrustProxy) {
121
+ warnedTrustProxy = true;
122
+ console.warn(
123
+ `[autter-runtime] relay: trustProxy ${JSON.stringify(value)} is not recognised; using "auto".`
124
+ );
125
+ }
126
+ return TRUST_AUTO;
127
+ }
128
+ var IPV4_RE = /^(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}$/;
129
+ function normalizeAddress(entry) {
130
+ if (!entry) return null;
131
+ let a = entry.trim();
132
+ if (!a || a.length > 64) return null;
133
+ const bracketed = /^\[([0-9A-Fa-f:.]+)\](?::\d{1,5})?$/.exec(a);
134
+ if (bracketed) a = _nullishCoalesce(bracketed[1], () => ( ""));
135
+ else if (/^[\d.]+:\d{1,5}$/.test(a)) a = a.slice(0, a.lastIndexOf(":"));
136
+ a = a.toLowerCase();
137
+ if (a.startsWith("::ffff:") && IPV4_RE.test(a.slice(7))) a = a.slice(7);
138
+ if (IPV4_RE.test(a)) return a;
139
+ if (/^[0-9a-f:]+(:(\d{1,3}\.){3}\d{1,3})?$/.test(a) && a.includes(":") && a.split(":").length <= 9) {
140
+ return a;
141
+ }
142
+ return null;
143
+ }
144
+ function isPrivateAddress(a) {
145
+ if (IPV4_RE.test(a)) {
146
+ const [x, y] = a.split(".").map(Number);
147
+ return x === 10 || x === 127 || x === 0 || x === 169 && y === 254 || x === 172 && y >= 16 && y <= 31 || x === 192 && y === 168 || x === 100 && y >= 64 && y <= 127;
148
+ }
149
+ return a === "::1" || a === "::" || /^f[cd]/.test(a) || /^fe[89ab]/.test(a);
150
+ }
151
+ function forwardedEntries(value) {
152
+ const raw = Array.isArray(value) ? value.join(",") : value;
153
+ if (!raw) return [];
154
+ const out = [];
155
+ for (const part of raw.split(",")) {
156
+ const a = normalizeAddress(part);
157
+ if (a) out.push(a);
158
+ }
159
+ return out;
160
+ }
161
+ function rightmostPublic(entries) {
162
+ for (let i = entries.length - 1; i >= 0; i--) {
163
+ const a = entries[i];
164
+ if (a && !isPrivateAddress(a)) return a;
165
+ }
166
+ return null;
167
+ }
168
+ function fromCustom(opts, request) {
169
+ if (!opts.clientIp) return null;
170
+ try {
171
+ const v = opts.clientIp(request);
172
+ return typeof v === "string" && v.trim() ? v.trim().slice(0, 64) : null;
173
+ } catch (e2) {
174
+ return null;
175
+ }
176
+ }
177
+ function fetchClientKey(request, opts) {
178
+ const custom = fromCustom(opts, request);
179
+ if (custom) return custom;
180
+ const trust = resolveTrustProxy(opts.trustProxy);
181
+ if (trust.mode === "never") return "shared";
182
+ const header = request.headers.get("x-forwarded-for");
183
+ if (trust.mode === "all") return firstForwardedFor(header) || "shared";
184
+ const entries = forwardedEntries(header);
185
+ if (trust.mode === "hops") {
186
+ return _nullishCoalesce(entries[Math.max(0, entries.length - trust.hops)], () => ( "shared"));
187
+ }
188
+ const cf = request.cf;
189
+ if (cf !== null && typeof cf === "object") {
190
+ const viaCf = normalizeAddress(request.headers.get("cf-connecting-ip"));
191
+ if (viaCf) return viaCf;
192
+ }
193
+ return _nullishCoalesce(_nullishCoalesce(rightmostPublic(entries), () => ( entries[entries.length - 1])), () => ( "shared"));
194
+ }
195
+ function nodeClientKey(req, opts) {
196
+ const custom = fromCustom(opts, req);
197
+ if (custom) return custom;
198
+ const trust = resolveTrustProxy(opts.trustProxy);
199
+ const peer = normalizeAddress(_optionalChain([req, 'access', _ => _.socket, 'optionalAccess', _2 => _2.remoteAddress]));
200
+ if (trust.mode === "never") return _nullishCoalesce(peer, () => ( "unknown"));
201
+ const header = req.headers["x-forwarded-for"];
202
+ if (trust.mode === "all") return firstForwardedFor(header) || peer || "unknown";
203
+ const entries = forwardedEntries(header);
204
+ if (trust.mode === "hops") {
205
+ return _nullishCoalesce(_nullishCoalesce(entries[Math.max(0, entries.length - trust.hops)], () => ( peer)), () => ( "unknown"));
206
+ }
207
+ if (peer && !isPrivateAddress(peer)) return peer;
208
+ return _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(rightmostPublic(entries), () => ( peer)), () => ( entries[entries.length - 1])), () => ( "unknown"));
209
+ }
99
210
  var DEFAULT_ENDPOINT = "https://otlp.autter.dev";
100
211
  var DEFAULT_MAX_BODY = 64 * 1024;
101
212
  var MAX_EVENTS = 50;
@@ -136,7 +247,7 @@ function boundContext(value) {
136
247
  let isArr = false;
137
248
  try {
138
249
  isArr = Array.isArray(v);
139
- } catch (e2) {
250
+ } catch (e3) {
140
251
  return void 0;
141
252
  }
142
253
  if (isArr) {
@@ -145,7 +256,7 @@ function boundContext(value) {
145
256
  let len = 0;
146
257
  try {
147
258
  len = arr.length;
148
- } catch (e3) {
259
+ } catch (e4) {
149
260
  return out2;
150
261
  }
151
262
  for (let i = 0; i < len && i < CONTEXT_MAX_ARRAY; i++) {
@@ -154,7 +265,7 @@ function boundContext(value) {
154
265
  let el;
155
266
  try {
156
267
  el = walk(arr[i], depth + 1);
157
- } catch (e4) {
268
+ } catch (e5) {
158
269
  el = void 0;
159
270
  }
160
271
  if (el !== void 0) out2.push(el);
@@ -164,7 +275,7 @@ function boundContext(value) {
164
275
  let keys;
165
276
  try {
166
277
  keys = Object.keys(obj);
167
- } catch (e5) {
278
+ } catch (e6) {
168
279
  return void 0;
169
280
  }
170
281
  const out = {};
@@ -176,7 +287,7 @@ function boundContext(value) {
176
287
  let child;
177
288
  try {
178
289
  child = walk(obj[key], depth + 1);
179
- } catch (e6) {
290
+ } catch (e7) {
180
291
  child = void 0;
181
292
  }
182
293
  if (child !== void 0) out[key] = child;
@@ -186,7 +297,7 @@ function boundContext(value) {
186
297
  let result;
187
298
  try {
188
299
  result = walk(value, 0);
189
- } catch (e7) {
300
+ } catch (e8) {
190
301
  result = void 0;
191
302
  }
192
303
  return result && typeof result === "object" ? result : {};
@@ -225,7 +336,7 @@ function relayContext(raw, redactor) {
225
336
  return Array.isArray(bounded) ? {} : { context: redactor(bounded) };
226
337
  }
227
338
  function relayBreadcrumbs(raw, redactor) {
228
- const breadcrumbs = _chunk37W7YYXOcjs.sanitizeBreadcrumbs.call(void 0, raw, redactor);
339
+ const breadcrumbs = _chunkYWTIKZSIcjs.sanitizeBreadcrumbs.call(void 0, raw, redactor);
229
340
  return breadcrumbs ? { breadcrumbs } : {};
230
341
  }
231
342
  var DEBUG_ID_RE = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
@@ -242,10 +353,10 @@ function relayDebugIds(raw, redactor) {
242
353
  return count ? { debugIds } : {};
243
354
  }
244
355
  function relayFingerprint(raw, redactor) {
245
- const values = _chunk37W7YYXOcjs.fingerprintValues.call(void 0, raw, redactor.text);
356
+ const values = _chunkYWTIKZSIcjs.fingerprintValues.call(void 0, raw, redactor.text);
246
357
  return values ? { fingerprint: Array.isArray(raw) ? values : values[0] } : {};
247
358
  }
248
- var defaultRelayRedactor = _chunk37W7YYXOcjs.makeRedactor.call(void 0, true);
359
+ var defaultRelayRedactor = _chunkYWTIKZSIcjs.makeRedactor.call(void 0, true);
249
360
  function sanitizeBrowserPayload(raw, redactor = defaultRelayRedactor) {
250
361
  if (typeof raw !== "object" || raw === null) return null;
251
362
  const p = raw;
@@ -294,7 +405,7 @@ function forward(payload, opts) {
294
405
  const endpoint = (_nullishCoalesce(opts.endpoint, () => ( DEFAULT_ENDPOINT))).replace(/\/$/, "");
295
406
  const url = `${endpoint}/v1/browser`;
296
407
  const compat = opts.compatCheck !== false;
297
- if (compat) _chunkMOZOUEMAcjs.ensureCompatConfigured.call(void 0, endpoint);
408
+ if (compat) _chunkBHYHORUDcjs.ensureCompatConfigured.call(void 0, endpoint);
298
409
  void fetch(url, {
299
410
  method: "POST",
300
411
  headers: {
@@ -308,12 +419,12 @@ function forward(payload, opts) {
308
419
  const types = new Set(
309
420
  (_nullishCoalesce(payload.events, () => ( []))).map((e) => String(e.type))
310
421
  );
311
- _chunkMOZOUEMAcjs.observeIngesterResponse.call(void 0, { status: response.status, headers: response.headers });
312
- for (const feature of _chunkMOZOUEMAcjs.featuresForBrowserEvents.call(void 0, types)) _chunkMOZOUEMAcjs.noteCompatFeature.call(void 0, feature);
422
+ _chunkBHYHORUDcjs.observeIngesterResponse.call(void 0, { status: response.status, headers: response.headers });
423
+ for (const feature of _chunkBHYHORUDcjs.featuresForBrowserEvents.call(void 0, types)) _chunkBHYHORUDcjs.noteCompatFeature.call(void 0, feature);
313
424
  if ((_nullishCoalesce(payload.events, () => ( []))).some((e) => e.traceId)) {
314
- _chunkMOZOUEMAcjs.noteCompatFeature.call(void 0, "browser_trace_propagation");
425
+ _chunkBHYHORUDcjs.noteCompatFeature.call(void 0, "browser_trace_propagation");
315
426
  }
316
- _chunkMOZOUEMAcjs.noteRelayRejection.call(void 0, types, response.status, response.headers);
427
+ _chunkBHYHORUDcjs.noteRelayRejection.call(void 0, types, response.status, response.headers);
317
428
  }).catch((err) => {
318
429
  (_nullishCoalesce(opts.onError, () => ( ((e) => console.warn("autter relay forward failed:", e)))))(
319
430
  err
@@ -322,14 +433,14 @@ function forward(payload, opts) {
322
433
  }
323
434
  function createBrowserRelayFetchHandler(opts) {
324
435
  const maxBody = _nullishCoalesce(opts.maxBodyBytes, () => ( DEFAULT_MAX_BODY));
325
- const redactor = opts.redact === void 0 || opts.redact === true ? defaultRelayRedactor : _chunk37W7YYXOcjs.makeRedactor.call(void 0, opts.redact);
436
+ const redactor = opts.redact === void 0 || opts.redact === true ? defaultRelayRedactor : _chunkYWTIKZSIcjs.makeRedactor.call(void 0, opts.redact);
326
437
  const limiter = opts.perIpRateLimit === false ? null : new IpWindow(_nullishCoalesce(opts.perIpRateLimit, () => ( 120)));
327
438
  return async (request) => {
328
439
  if (request.method !== "POST") {
329
440
  return new Response(null, { status: 405 });
330
441
  }
331
442
  if (limiter) {
332
- const ip = firstForwardedFor(request.headers.get("x-forwarded-for")) || "unknown";
443
+ const ip = fetchClientKey(request, opts);
333
444
  if (!limiter.allow(ip)) {
334
445
  return new Response(JSON.stringify({ error: "rate limit exceeded" }), {
335
446
  status: 429
@@ -339,7 +450,7 @@ function createBrowserRelayFetchHandler(opts) {
339
450
  let bounded;
340
451
  try {
341
452
  bounded = await readBodyBounded(request, maxBody);
342
- } catch (e8) {
453
+ } catch (e9) {
343
454
  return new Response(JSON.stringify({ error: "invalid json" }), {
344
455
  status: 400
345
456
  });
@@ -352,7 +463,7 @@ function createBrowserRelayFetchHandler(opts) {
352
463
  let raw;
353
464
  try {
354
465
  raw = JSON.parse(bounded.text);
355
- } catch (e9) {
466
+ } catch (e10) {
356
467
  return new Response(JSON.stringify({ error: "invalid json" }), {
357
468
  status: 400
358
469
  });
@@ -369,7 +480,7 @@ function createBrowserRelayFetchHandler(opts) {
369
480
  }
370
481
  function createBrowserRelayHandler(opts) {
371
482
  const maxBody = _nullishCoalesce(opts.maxBodyBytes, () => ( DEFAULT_MAX_BODY));
372
- const redactor = opts.redact === void 0 || opts.redact === true ? defaultRelayRedactor : _chunk37W7YYXOcjs.makeRedactor.call(void 0, opts.redact);
483
+ const redactor = opts.redact === void 0 || opts.redact === true ? defaultRelayRedactor : _chunkYWTIKZSIcjs.makeRedactor.call(void 0, opts.redact);
373
484
  const limiter = opts.perIpRateLimit === false ? null : new IpWindow(_nullishCoalesce(opts.perIpRateLimit, () => ( 120)));
374
485
  function respond(res, status, body) {
375
486
  res.statusCode = status;
@@ -395,7 +506,7 @@ function createBrowserRelayHandler(opts) {
395
506
  return;
396
507
  }
397
508
  if (limiter) {
398
- const ip = firstForwardedFor(req.headers["x-forwarded-for"]) || _optionalChain([req, 'access', _ => _.socket, 'optionalAccess', _2 => _2.remoteAddress]) || "unknown";
509
+ const ip = nodeClientKey(req, opts);
399
510
  if (!limiter.allow(ip)) {
400
511
  respond(res, 429, { error: "rate limit exceeded" });
401
512
  return;
@@ -406,7 +517,7 @@ function createBrowserRelayHandler(opts) {
406
517
  if (typeof raw === "string" || Buffer.isBuffer(raw)) {
407
518
  try {
408
519
  raw = JSON.parse(raw.toString());
409
- } catch (e10) {
520
+ } catch (e11) {
410
521
  respond(res, 400, { error: "invalid json" });
411
522
  return;
412
523
  }
@@ -431,7 +542,7 @@ function createBrowserRelayHandler(opts) {
431
542
  if (aborted) return;
432
543
  try {
433
544
  handleParsed(JSON.parse(Buffer.concat(chunks).toString()), res);
434
- } catch (e11) {
545
+ } catch (e12) {
435
546
  respond(res, 400, { error: "invalid json" });
436
547
  }
437
548
  });
@@ -502,7 +613,7 @@ function splitUrl(value) {
502
613
  function decodeName(raw) {
503
614
  try {
504
615
  return decodeURIComponent(raw.replace(/\+/g, " "));
505
- } catch (e12) {
616
+ } catch (e13) {
506
617
  return raw;
507
618
  }
508
619
  }
@@ -636,7 +747,7 @@ var RedactingSpanExporter = class {
636
747
  for (const span of spans) {
637
748
  try {
638
749
  scrubbed.push(redactSpan(span, redactor, this.query));
639
- } catch (e13) {
750
+ } catch (e14) {
640
751
  failed++;
641
752
  }
642
753
  }
@@ -746,7 +857,6 @@ var _async_hooks = require('async_hooks');
746
857
 
747
858
  var REQUEST_STATE = /* @__PURE__ */ Symbol.for("autter.runtime.request");
748
859
  var BOUND = /* @__PURE__ */ Symbol.for("autter.runtime.bound");
749
- var CAPTURED = _chunkMOZOUEMAcjs.sharedSlot.call(void 0, "requests", () => ({ captured: /* @__PURE__ */ new WeakSet() })).captured;
750
860
  var capturer = () => {
751
861
  };
752
862
  function setRequestExceptionCapturer(fn) {
@@ -757,8 +867,14 @@ var annotator = () => {
757
867
  function setRequestSpanAnnotator(fn) {
758
868
  annotator = fn;
759
869
  }
760
- function markCaptured(error) {
761
- if (error && typeof error === "object") CAPTURED.add(error);
870
+ function decide(rule, error, fallback) {
871
+ if (rule === void 0) return fallback;
872
+ if (typeof rule !== "function") return rule;
873
+ try {
874
+ return rule(error) === true;
875
+ } catch (e15) {
876
+ return false;
877
+ }
762
878
  }
763
879
  function expressRouteOf(req) {
764
880
  const props = req;
@@ -769,7 +885,7 @@ function expressRouteOf(req) {
769
885
  return route.startsWith("/") ? route : null;
770
886
  }
771
887
  function defaultShouldCapture(error) {
772
- return error instanceof _chunk37W7YYXOcjs.RuntimeError || _chunk37W7YYXOcjs.errorCodeOf.call(void 0, error) !== void 0 || _chunk37W7YYXOcjs.responseStatusOf.call(void 0, error) >= 500;
888
+ return error instanceof _chunkYWTIKZSIcjs.RuntimeError || _chunkYWTIKZSIcjs.errorCodeOf.call(void 0, error) !== void 0 || _chunkYWTIKZSIcjs.responseStatusOf.call(void 0, error) >= 500;
773
889
  }
774
890
  function onRequestSpan(fn) {
775
891
  const active = _api.context.active();
@@ -785,17 +901,17 @@ function captureAtBoundary(error, state, rule = void 0, attributes) {
785
901
  let wanted;
786
902
  try {
787
903
  wanted = typeof rule === "function" ? rule(error) : rule === void 0 ? defaultShouldCapture(error) : rule;
788
- } catch (e14) {
904
+ } catch (e16) {
789
905
  wanted = false;
790
906
  }
791
907
  if (!wanted) return;
792
- if (error && typeof error === "object" && CAPTURED.has(error)) return;
793
- markCaptured(error);
908
+ if (_chunkYWTIKZSIcjs.isCaptured.call(void 0, error)) return;
909
+ _chunkYWTIKZSIcjs.markCaptured.call(void 0, error);
794
910
  try {
795
911
  const run = () => onRequestSpan(() => capturer(error, attributes));
796
- if (state && !state.sealed) _chunk37W7YYXOcjs.local.run(state, run);
912
+ if (state && !state.sealed) _chunkYWTIKZSIcjs.local.run(state, run);
797
913
  else run();
798
- } catch (e15) {
914
+ } catch (e17) {
799
915
  }
800
916
  }
801
917
  function requestStateOf(req) {
@@ -803,15 +919,15 @@ function requestStateOf(req) {
803
919
  return req[REQUEST_STATE];
804
920
  }
805
921
  function captureRequestError(error, attributes) {
806
- if (error && typeof error === "object" && CAPTURED.has(error)) {
922
+ if (_chunkYWTIKZSIcjs.isCaptured.call(void 0, error)) {
807
923
  if (!attributes) return;
808
924
  try {
809
925
  onRequestSpan(() => annotator(attributes));
810
- } catch (e16) {
926
+ } catch (e18) {
811
927
  }
812
928
  return;
813
929
  }
814
- captureAtBoundary(error, _chunk37W7YYXOcjs.currentOperation.call(void 0, ), true, attributes);
930
+ captureAtBoundary(error, _chunkYWTIKZSIcjs.currentOperation.call(void 0, ), true, attributes);
815
931
  }
816
932
  function bindEmitter(emitter, state) {
817
933
  const target = emitter;
@@ -823,7 +939,7 @@ function bindEmitter(emitter, state) {
823
939
  let wrapped = wrappers.get(listener);
824
940
  if (!wrapped) {
825
941
  wrapped = function(...args) {
826
- return _chunk37W7YYXOcjs.local.run(
942
+ return _chunkYWTIKZSIcjs.local.run(
827
943
  state,
828
944
  () => listener.apply(this, args)
829
945
  );
@@ -878,7 +994,7 @@ function exposeOnCors(res, header) {
878
994
  if (value && key && inline) inline[key] = value;
879
995
  else if (value) res.setHeader("access-control-expose-headers", value);
880
996
  }
881
- } catch (e17) {
997
+ } catch (e19) {
882
998
  }
883
999
  return original.apply(this, args);
884
1000
  };
@@ -890,12 +1006,13 @@ function pathOf(req) {
890
1006
  function finishRequest(state, input) {
891
1007
  if (state.sealed) return;
892
1008
  state.name = (_nullishCoalesce(input.name, () => ( `${input.method} ${input.route}`))).slice(0, 200);
893
- state.outcome = _chunk37W7YYXOcjs.requestOutcome.call(void 0, {
1009
+ state.outcome = _chunkYWTIKZSIcjs.requestOutcome.call(void 0, {
894
1010
  ...state.explicitOutcome ? { explicit: state.outcome } : {},
895
1011
  ...state.error !== void 0 ? { error: state.error } : {},
896
1012
  ...state.errorThrown ? { thrown: true } : {},
897
1013
  status: input.status,
898
- aborted: input.aborted
1014
+ aborted: input.aborted,
1015
+ ...state.degraded ? { degraded: true } : {}
899
1016
  });
900
1017
  const span = _api.trace.getActiveSpan();
901
1018
  if (_optionalChain([span, 'optionalAccess', _14 => _14.isRecording, 'call', _15 => _15()])) span.setAttribute("autter.operation.outcome", state.outcome);
@@ -903,10 +1020,10 @@ function finishRequest(state, input) {
903
1020
  const remote = _api.trace.wrapSpanContext(input.span);
904
1021
  _api.context.with(
905
1022
  _api.trace.setSpan(_api.context.active(), remote),
906
- () => _chunk37W7YYXOcjs.reportExplicitFailure.call(void 0, state)
1023
+ () => _chunkYWTIKZSIcjs.reportExplicitFailure.call(void 0, state)
907
1024
  );
908
- } else _chunk37W7YYXOcjs.reportExplicitFailure.call(void 0, state);
909
- _chunk37W7YYXOcjs.emitSummary.call(void 0, state, {
1025
+ } else _chunkYWTIKZSIcjs.reportExplicitFailure.call(void 0, state);
1026
+ _chunkYWTIKZSIcjs.emitSummary.call(void 0, state, {
910
1027
  http: {
911
1028
  "http.request.method": input.method,
912
1029
  "http.route": input.route,
@@ -917,14 +1034,14 @@ function finishRequest(state, input) {
917
1034
  });
918
1035
  }
919
1036
  function beginNodeRequest(req, res, options, route) {
920
- const header = (_nullishCoalesce(options.requestIdHeader, () => ( _chunk37W7YYXOcjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
921
- const requestId = _chunk37W7YYXOcjs.resolveRequestId.call(void 0,
1037
+ const header = (_nullishCoalesce(options.requestIdHeader, () => ( _chunkYWTIKZSIcjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
1038
+ const requestId = _chunkYWTIKZSIcjs.resolveRequestId.call(void 0,
922
1039
  options.trustRequestId === false ? void 0 : req.headers[header]
923
1040
  );
924
1041
  const method = (_nullishCoalesce(req.method, () => ( "GET"))).toUpperCase();
925
1042
  const path = pathOf(req);
926
- const state = _chunk37W7YYXOcjs.createRequestState.call(void 0, {
927
- name: `${method} ${_chunk37W7YYXOcjs.normalizeRoutePath.call(void 0, path)}`,
1043
+ const state = _chunkYWTIKZSIcjs.createRequestState.call(void 0, {
1044
+ name: `${method} ${_chunkYWTIKZSIcjs.normalizeRoutePath.call(void 0, path)}`,
928
1045
  requestId,
929
1046
  req,
930
1047
  res
@@ -933,7 +1050,7 @@ function beginNodeRequest(req, res, options, route) {
933
1050
  try {
934
1051
  if (!res.headersSent) res.setHeader(header, requestId);
935
1052
  exposeOnCors(res, header);
936
- } catch (e18) {
1053
+ } catch (e20) {
937
1054
  }
938
1055
  const span = _api.trace.getActiveSpan();
939
1056
  if (_optionalChain([span, 'optionalAccess', _16 => _16.isRecording, 'call', _17 => _17()]))
@@ -948,7 +1065,7 @@ function beginNodeRequest(req, res, options, route) {
948
1065
  const done = () => {
949
1066
  finishRequest(state, {
950
1067
  method,
951
- route: _nullishCoalesce(_nullishCoalesce(_optionalChain([route, 'optionalCall', _20 => _20()]), () => ( expressRouteOf(req))), () => ( _chunk37W7YYXOcjs.normalizeRoutePath.call(void 0, path))),
1068
+ route: _nullishCoalesce(_nullishCoalesce(_optionalChain([route, 'optionalCall', _20 => _20()]), () => ( expressRouteOf(req))), () => ( _chunkYWTIKZSIcjs.normalizeRoutePath.call(void 0, path))),
952
1069
  status: res.statusCode,
953
1070
  aborted: !finished,
954
1071
  ...spanContext ? { span: spanContext } : {}
@@ -962,50 +1079,50 @@ function beginNodeRequest(req, res, options, route) {
962
1079
  return state;
963
1080
  }
964
1081
  function autterRequests(options = {}) {
965
- const ignored = _chunk37W7YYXOcjs.compileIgnore.call(void 0, options.ignore);
1082
+ const ignored = _chunkYWTIKZSIcjs.compileIgnore.call(void 0, options.ignore);
966
1083
  return function autterRequestsMiddleware(req, res, next) {
967
1084
  if (req[REQUEST_STATE] || ignored(pathOf(req))) {
968
1085
  next();
969
1086
  return;
970
1087
  }
971
1088
  const state = beginNodeRequest(req, res, options);
972
- _chunk37W7YYXOcjs.local.run(state, () => next());
1089
+ _chunkYWTIKZSIcjs.local.run(state, () => next());
973
1090
  };
974
1091
  }
975
1092
  function autterErrorResponse(options = {}) {
976
1093
  return function autterErrorResponseMiddleware(error, req, res, next) {
977
1094
  const state = req[REQUEST_STATE];
978
- if (state) _chunk37W7YYXOcjs.noteOperationError.call(void 0, error, true, state);
1095
+ if (state) _chunkYWTIKZSIcjs.noteOperationError.call(void 0, error, true, state);
979
1096
  captureAtBoundary(error, state, options.capture);
980
1097
  if (res.headersSent) {
981
1098
  next(error);
982
1099
  return;
983
1100
  }
984
- const header = (_nullishCoalesce(options.requestIdHeader, () => ( _chunk37W7YYXOcjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
1101
+ const header = (_nullishCoalesce(options.requestIdHeader, () => ( _chunkYWTIKZSIcjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
985
1102
  const inbound = _optionalChain([req, 'access', _21 => _21.headers, 'optionalAccess', _22 => _22[header]]);
986
1103
  const requestId = _nullishCoalesce(_optionalChain([state, 'optionalAccess', _23 => _23.requestId]), () => ( (typeof inbound === "string" ? inbound.slice(0, 128) : void 0)));
987
- res.statusCode = _chunk37W7YYXOcjs.responseStatusOf.call(void 0, error);
1104
+ res.statusCode = _chunkYWTIKZSIcjs.responseStatusOf.call(void 0, error);
988
1105
  res.setHeader("content-type", "application/json; charset=utf-8");
989
- res.end(JSON.stringify(_chunk37W7YYXOcjs.toClientError.call(void 0, error, requestId)));
1106
+ res.end(JSON.stringify(_chunkYWTIKZSIcjs.toClientError.call(void 0, error, requestId)));
990
1107
  };
991
1108
  }
992
1109
  var RESOURCE = /* @__PURE__ */ Symbol.for("autter.runtime.resource");
993
1110
  function autterFastify(fastify, options, done) {
994
1111
  const opts = _nullishCoalesce(options, () => ( {}));
995
- const header = (_nullishCoalesce(opts.requestIdHeader, () => ( _chunk37W7YYXOcjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
996
- const ignored = _chunk37W7YYXOcjs.compileIgnore.call(void 0, opts.ignore);
1112
+ const header = (_nullishCoalesce(opts.requestIdHeader, () => ( _chunkYWTIKZSIcjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
1113
+ const ignored = _chunkYWTIKZSIcjs.compileIgnore.call(void 0, opts.ignore);
997
1114
  const stateOf = (request) => request[REQUEST_STATE];
998
1115
  fastify.addHook("onRequest", ((request, reply, next) => {
999
1116
  if (ignored(request.url) || request.raw[REQUEST_STATE]) {
1000
1117
  next();
1001
1118
  return;
1002
1119
  }
1003
- const requestId = _chunk37W7YYXOcjs.resolveRequestId.call(void 0,
1120
+ const requestId = _chunkYWTIKZSIcjs.resolveRequestId.call(void 0,
1004
1121
  opts.trustRequestId === false ? void 0 : request.headers[header]
1005
1122
  );
1006
1123
  const method = String(_nullishCoalesce(request.method, () => ( "GET"))).toUpperCase();
1007
- const state = _chunk37W7YYXOcjs.createRequestState.call(void 0, {
1008
- name: `${method} ${_chunk37W7YYXOcjs.normalizeRoutePath.call(void 0, request.url)}`,
1124
+ const state = _chunkYWTIKZSIcjs.createRequestState.call(void 0, {
1125
+ name: `${method} ${_chunkYWTIKZSIcjs.normalizeRoutePath.call(void 0, request.url)}`,
1009
1126
  requestId,
1010
1127
  req: request.raw,
1011
1128
  res: reply.raw
@@ -1025,7 +1142,7 @@ function autterFastify(fastify, options, done) {
1025
1142
  let finished = false;
1026
1143
  const finish = (aborted) => finishRequest(state, {
1027
1144
  method,
1028
- route: _nullishCoalesce(_nullishCoalesce(_optionalChain([request, 'access', _28 => _28.routeOptions, 'optionalAccess', _29 => _29.url]), () => ( request.routerPath)), () => ( _chunk37W7YYXOcjs.normalizeRoutePath.call(void 0, request.url))),
1145
+ route: _nullishCoalesce(_nullishCoalesce(_optionalChain([request, 'access', _28 => _28.routeOptions, 'optionalAccess', _29 => _29.url]), () => ( request.routerPath)), () => ( _chunkYWTIKZSIcjs.normalizeRoutePath.call(void 0, request.url))),
1029
1146
  status: reply.raw.statusCode || reply.statusCode,
1030
1147
  aborted,
1031
1148
  ...spanContext ? { span: spanContext } : {}
@@ -1035,7 +1152,7 @@ function autterFastify(fastify, options, done) {
1035
1152
  finish(false);
1036
1153
  });
1037
1154
  reply.raw.once("close", () => finish(!finished));
1038
- _chunk37W7YYXOcjs.local.run(state, () => {
1155
+ _chunkYWTIKZSIcjs.local.run(state, () => {
1039
1156
  request[RESOURCE] = new (0, _async_hooks.AsyncResource)("autter-request");
1040
1157
  next();
1041
1158
  });
@@ -1051,13 +1168,13 @@ function autterFastify(fastify, options, done) {
1051
1168
  const value = exposeHeaderValue(reply.getHeader("access-control-expose-headers"), header);
1052
1169
  if (value) reply.header("access-control-expose-headers", value);
1053
1170
  }
1054
- } catch (e19) {
1171
+ } catch (e21) {
1055
1172
  }
1056
1173
  next(null, payload);
1057
1174
  }));
1058
1175
  fastify.addHook("onError", ((request, _reply, error, next) => {
1059
1176
  const state = stateOf(request);
1060
- if (state) _chunk37W7YYXOcjs.noteOperationError.call(void 0, error, true, state);
1177
+ if (state) _chunkYWTIKZSIcjs.noteOperationError.call(void 0, error, true, state);
1061
1178
  captureAtBoundary(error, state);
1062
1179
  next();
1063
1180
  }));
@@ -1079,30 +1196,30 @@ function withHeaders(response, header, requestId) {
1079
1196
  };
1080
1197
  try {
1081
1198
  return apply(response);
1082
- } catch (e20) {
1199
+ } catch (e22) {
1083
1200
  try {
1084
1201
  return apply(new Response(response.body, response));
1085
- } catch (e21) {
1202
+ } catch (e23) {
1086
1203
  return response;
1087
1204
  }
1088
1205
  }
1089
1206
  }
1090
1207
  function withRuntimeRequest(handler, options = {}) {
1091
- const header = (_nullishCoalesce(options.requestIdHeader, () => ( _chunk37W7YYXOcjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
1092
- const ignored = _chunk37W7YYXOcjs.compileIgnore.call(void 0, options.ignore);
1208
+ const header = (_nullishCoalesce(options.requestIdHeader, () => ( _chunkYWTIKZSIcjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
1209
+ const ignored = _chunkYWTIKZSIcjs.compileIgnore.call(void 0, options.ignore);
1093
1210
  return async (request, ...rest) => {
1094
1211
  let pathname = "/";
1095
1212
  try {
1096
1213
  pathname = new URL(request.url, "http://localhost").pathname;
1097
- } catch (e22) {
1214
+ } catch (e24) {
1098
1215
  }
1099
1216
  if (ignored(pathname)) return handler(request, ...rest);
1100
- const requestId = _chunk37W7YYXOcjs.resolveRequestId.call(void 0,
1217
+ const requestId = _chunkYWTIKZSIcjs.resolveRequestId.call(void 0,
1101
1218
  options.trustRequestId === false ? void 0 : request.headers.get(header)
1102
1219
  );
1103
1220
  const method = String(_nullishCoalesce(request.method, () => ( "GET"))).toUpperCase();
1104
- const route = _nullishCoalesce(options.route, () => ( _chunk37W7YYXOcjs.normalizeRoutePath.call(void 0, pathname)));
1105
- const state = _chunk37W7YYXOcjs.createRequestState.call(void 0, {
1221
+ const route = _nullishCoalesce(options.route, () => ( _chunkYWTIKZSIcjs.normalizeRoutePath.call(void 0, pathname)));
1222
+ const state = _chunkYWTIKZSIcjs.createRequestState.call(void 0, {
1106
1223
  name: `${method} ${_nullishCoalesce(options.name, () => ( route))}`,
1107
1224
  requestId,
1108
1225
  req: request
@@ -1116,13 +1233,19 @@ function withRuntimeRequest(handler, options = {}) {
1116
1233
  const spanContext = _optionalChain([span, 'optionalAccess', _32 => _32.spanContext, 'call', _33 => _33()]);
1117
1234
  let status = 500;
1118
1235
  try {
1119
- const response = await _chunk37W7YYXOcjs.local.run(state, async () => {
1236
+ const response = await _chunkYWTIKZSIcjs.local.run(state, async () => {
1120
1237
  try {
1121
1238
  return await handler(request, ...rest);
1122
1239
  } catch (error) {
1123
- _chunk37W7YYXOcjs.noteOperationError.call(void 0, error, true, state);
1124
- captureAtBoundary(error, state, true);
1125
- throw error;
1240
+ if (decide(options.capture, error, true)) {
1241
+ _chunkYWTIKZSIcjs.noteOperationError.call(void 0, error, true, state);
1242
+ captureAtBoundary(error, state, true);
1243
+ }
1244
+ if (!decide(options.errorResponse, error, false)) throw error;
1245
+ return new Response(JSON.stringify(_chunkYWTIKZSIcjs.toClientError.call(void 0, error, requestId)), {
1246
+ status: _chunkYWTIKZSIcjs.responseStatusOf.call(void 0, error),
1247
+ headers: { "content-type": "application/json; charset=utf-8" }
1248
+ });
1126
1249
  }
1127
1250
  });
1128
1251
  status = response.status;
@@ -1139,9 +1262,9 @@ function withRuntimeRequest(handler, options = {}) {
1139
1262
  });
1140
1263
  if (options.waitUntil) {
1141
1264
  try {
1142
- options.waitUntil(_chunk37W7YYXOcjs.flushRuntimeLogs.call(void 0, ).catch(() => {
1265
+ options.waitUntil(_chunkYWTIKZSIcjs.flushRuntimeLogs.call(void 0, ).catch(() => {
1143
1266
  }));
1144
- } catch (e23) {
1267
+ } catch (e25) {
1145
1268
  }
1146
1269
  }
1147
1270
  }
@@ -1151,7 +1274,7 @@ function startHookRequest(res) {
1151
1274
  const req = res.req;
1152
1275
  if (!req || req[REQUEST_STATE]) return;
1153
1276
  const state = beginNodeRequest(req, res, {});
1154
- _chunk37W7YYXOcjs.local.enterWith(state);
1277
+ _chunkYWTIKZSIcjs.local.enterWith(state);
1155
1278
  }
1156
1279
 
1157
1280
  // src/unhandled-rejections.ts
@@ -1203,7 +1326,7 @@ function unhandledRejectionsMode(execArgv = process.execArgv, nodeOptions = proc
1203
1326
  function isErrorLike(value) {
1204
1327
  try {
1205
1328
  return typeof value === "object" && value !== null && Object.prototype.hasOwnProperty.call(value, "stack");
1206
- } catch (e24) {
1329
+ } catch (e26) {
1207
1330
  return false;
1208
1331
  }
1209
1332
  }
@@ -1211,7 +1334,7 @@ function describeReason(reason) {
1211
1334
  if (typeof reason !== "object" && typeof reason !== "function" || reason === null) {
1212
1335
  try {
1213
1336
  return String(reason);
1214
- } catch (e25) {
1337
+ } catch (e27) {
1215
1338
  return typeof reason;
1216
1339
  }
1217
1340
  }
@@ -1220,7 +1343,7 @@ function describeReason(reason) {
1220
1343
  const ctor = _optionalChain([proto, 'optionalAccess', _39 => _39.constructor]);
1221
1344
  const name = typeof ctor === "function" ? ctor.name : "";
1222
1345
  return name ? `#<${name}>` : "[object Object]";
1223
- } catch (e26) {
1346
+ } catch (e28) {
1224
1347
  return "[object Object]";
1225
1348
  }
1226
1349
  }
@@ -1243,7 +1366,7 @@ function emitNodeWarning(reason) {
1243
1366
  `Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag \`--unhandled-rejections=strict\` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: ${++warningId})`,
1244
1367
  "UnhandledPromiseRejectionWarning"
1245
1368
  );
1246
- } catch (e27) {
1369
+ } catch (e29) {
1247
1370
  }
1248
1371
  }
1249
1372
  function installUnhandledRejectionCapture(capture, mode = unhandledRejectionsMode()) {
@@ -1270,7 +1393,7 @@ function installUnhandledRejectionCapture(capture, mode = unhandledRejectionsMod
1270
1393
  }
1271
1394
  markRecorded(reason);
1272
1395
  capture(reason);
1273
- } catch (e28) {
1396
+ } catch (e30) {
1274
1397
  }
1275
1398
  };
1276
1399
  listener[LISTENER_MARK] = true;
@@ -1305,7 +1428,7 @@ var RouteLabelSampler = class {
1305
1428
  shouldSample(ctx, traceId, spanName, spanKind, attributes, links) {
1306
1429
  try {
1307
1430
  noteFrameworkRoute(ctx, attributes);
1308
- } catch (e29) {
1431
+ } catch (e31) {
1309
1432
  }
1310
1433
  return this.delegate.shouldSample(ctx, traceId, spanName, spanKind, attributes, links);
1311
1434
  }
@@ -1315,11 +1438,13 @@ var RouteLabelSampler = class {
1315
1438
  };
1316
1439
 
1317
1440
  // src/server.ts
1318
- var S = _chunkMOZOUEMAcjs.sharedSlot.call(void 0, "server", () => ({
1441
+ var S = _chunkBHYHORUDcjs.sharedSlot.call(void 0, "server", () => ({
1319
1442
  active: null,
1320
1443
  alwaysOnProvider: null,
1321
- redactor: _chunk37W7YYXOcjs.makeRedactor.call(void 0, true),
1444
+ redactor: _chunkYWTIKZSIcjs.makeRedactor.call(void 0, true),
1322
1445
  loggerOnlyCapture: null,
1446
+ handled: null,
1447
+ loggerOnlyHandled: null,
1323
1448
  hookRequests: false
1324
1449
  }));
1325
1450
  var LLM_MARKER_ATTRIBUTES = [
@@ -1570,15 +1695,15 @@ async function runLlmSpan(tracer, info, fn) {
1570
1695
  return result;
1571
1696
  } catch (err) {
1572
1697
  recordError(span, err);
1573
- if (_chunk37W7YYXOcjs.isError.call(void 0, err)) span.setAttribute("error.type", err.name);
1698
+ if (_chunkYWTIKZSIcjs.isError.call(void 0, err)) span.setAttribute("error.type", err.name);
1574
1699
  throw err;
1575
1700
  } finally {
1576
1701
  span.end();
1577
- _chunk37W7YYXOcjs.recordOperationAiUsage.call(void 0, { ...usage, model: _nullishCoalesce(responseModel, () => ( info.model)) });
1702
+ _chunkYWTIKZSIcjs.recordOperationAiUsage.call(void 0, { ...usage, model: _nullishCoalesce(responseModel, () => ( info.model)) });
1578
1703
  }
1579
1704
  }
1580
1705
  function recordLlmCall(tracer, call) {
1581
- _chunk37W7YYXOcjs.recordOperationAiUsage.call(void 0, { ...call, model: call.model });
1706
+ _chunkYWTIKZSIcjs.recordOperationAiUsage.call(void 0, { ...call, model: call.model });
1582
1707
  const durationMs = Math.max(0, _nullishCoalesce(call.durationMs, () => ( 0)));
1583
1708
  const endTime = /* @__PURE__ */ new Date();
1584
1709
  const startTime = new Date(endTime.getTime() - durationMs);
@@ -1592,7 +1717,7 @@ function recordLlmCall(tracer, call) {
1592
1717
  );
1593
1718
  if (call.error !== void 0 && call.error !== null) {
1594
1719
  recordError(span, call.error);
1595
- if (_chunk37W7YYXOcjs.isError.call(void 0, call.error)) {
1720
+ if (_chunkYWTIKZSIcjs.isError.call(void 0, call.error)) {
1596
1721
  span.setAttribute("error.type", call.error.name);
1597
1722
  }
1598
1723
  } else {
@@ -1620,14 +1745,14 @@ async function runWithSpan(tracer, name, fn, attributes, links) {
1620
1745
  }
1621
1746
  }
1622
1747
  function recordError(span, err) {
1623
- const isErr = _chunk37W7YYXOcjs.isError.call(void 0, err);
1748
+ const isErr = _chunkYWTIKZSIcjs.isError.call(void 0, err);
1624
1749
  const message = S.redactor.text(isErr ? err.message : String(err));
1625
1750
  if (isErr) {
1626
1751
  span.addEvent("exception", {
1627
1752
  "exception.type": err.name,
1628
1753
  "exception.message": message,
1629
1754
  ...err.stack ? { "exception.stacktrace": S.redactor.text(err.stack) } : {},
1630
- ..._chunk37W7YYXOcjs.breadcrumbEventAttributes.call(void 0, S.redactor.text, err)
1755
+ ..._chunkYWTIKZSIcjs.breadcrumbEventAttributes.call(void 0, S.redactor.text, err)
1631
1756
  });
1632
1757
  }
1633
1758
  span.setStatus({ code: _api.SpanStatusCode.ERROR, message });
@@ -1640,7 +1765,7 @@ function patchLoadedHttpModules() {
1640
1765
  const load = _module.createRequire.call(void 0, _path.join.call(void 0, process.cwd(), "autter-runtime-http.cjs"));
1641
1766
  load("http");
1642
1767
  load("https");
1643
- } catch (e30) {
1768
+ } catch (e32) {
1644
1769
  }
1645
1770
  }
1646
1771
  var METRIC_ROUTE_ATTR = "autter.metric_has_route";
@@ -1665,14 +1790,14 @@ function captureRequestRoute(span, response) {
1665
1790
  if (S.hookRequests) startHookRequest(response);
1666
1791
  }
1667
1792
  function structuredErrorAttributes(error) {
1668
- const attrs = { ..._chunk37W7YYXOcjs.errorAttributes.call(void 0, error, { causes: false }) };
1669
- const internal = _chunk37W7YYXOcjs.errorInternal.call(void 0, error);
1793
+ const attrs = { ..._chunkYWTIKZSIcjs.errorAttributes.call(void 0, error, { causes: false }) };
1794
+ const internal = _chunkYWTIKZSIcjs.errorInternal.call(void 0, error);
1670
1795
  if (internal) {
1671
1796
  try {
1672
1797
  attrs["autter.error.internal"] = JSON.stringify(
1673
1798
  S.redactor(internal)
1674
1799
  ).slice(0, 4e3);
1675
- } catch (e31) {
1800
+ } catch (e33) {
1676
1801
  }
1677
1802
  }
1678
1803
  return attrs;
@@ -1684,9 +1809,9 @@ function initAutterServer(options) {
1684
1809
  ""
1685
1810
  );
1686
1811
  const headers = { authorization: `Bearer ${options.apiKey}` };
1687
- const redactor = _chunk37W7YYXOcjs.makeRedactor.call(void 0, _nullishCoalesce(options.redactAttributes, () => ( true)));
1812
+ const redactor = _chunkYWTIKZSIcjs.makeRedactor.call(void 0, _nullishCoalesce(options.redactAttributes, () => ( true)));
1688
1813
  const queryPolicy = makeUrlQueryPolicy(options.keepQueryParams);
1689
- const traceExporter = () => new (0, _chunkMOZOUEMAcjs.CountingExporter)(
1814
+ const traceExporter = () => new (0, _chunkBHYHORUDcjs.CountingExporter)(
1690
1815
  new RedactingSpanExporter(
1691
1816
  new (0, _exportertraceotlphttp.OTLPTraceExporter)({ url: `${endpoint}/v1/traces`, headers }),
1692
1817
  () => redactor,
@@ -1694,11 +1819,11 @@ function initAutterServer(options) {
1694
1819
  )
1695
1820
  );
1696
1821
  const environment = _nullishCoalesce(_nullishCoalesce(options.environment, () => ( process.env.NODE_ENV)), () => ( "production"));
1697
- if (_chunkMOZOUEMAcjs.isDebugEnabled.call(void 0, ) || options.debug === true) _chunkMOZOUEMAcjs.setDebugMode.call(void 0, true);
1698
- _chunkMOZOUEMAcjs.debugLog.call(void 0, `initialising service=${options.service} endpoint=${endpoint}`);
1822
+ if (_chunkBHYHORUDcjs.isDebugEnabled.call(void 0, ) || options.debug === true) _chunkBHYHORUDcjs.setDebugMode.call(void 0, true);
1823
+ _chunkBHYHORUDcjs.debugLog.call(void 0, `initialising service=${options.service} endpoint=${endpoint}`);
1699
1824
  S.redactor = redactor;
1700
- const distro = _nullishCoalesce(options.distro, () => ( _chunkMOZOUEMAcjs.SDK_IDENTITY));
1701
- _chunkMOZOUEMAcjs.configureCompatCheck.call(void 0, { endpoint, enabled: options.compatCheck !== false, sdk: distro });
1825
+ const distro = _nullishCoalesce(options.distro, () => ( _chunkBHYHORUDcjs.SDK_IDENTITY));
1826
+ _chunkBHYHORUDcjs.configureCompatCheck.call(void 0, { endpoint, enabled: options.compatCheck !== false, sdk: distro });
1702
1827
  const resource = new (0, _resources.Resource)({
1703
1828
  [_semanticconventions.ATTR_SERVICE_NAME]: options.service,
1704
1829
  "service.instance.id": (options.instanceId || process.env.AUTTER_RUNTIME_INSTANCE_ID || _crypto.randomUUID.call(void 0, )).slice(0, 128),
@@ -1719,7 +1844,7 @@ function initAutterServer(options) {
1719
1844
  // its span-fed per-route counts.
1720
1845
  "autter.metrics_routes": true
1721
1846
  });
1722
- const errorFilter = _chunk37W7YYXOcjs.createErrorFilter.call(void 0, { ignoreErrors: options.ignoreErrors, sampleRate: options.sampleRate });
1847
+ const errorFilter = _chunkYWTIKZSIcjs.createErrorFilter.call(void 0, { ignoreErrors: options.ignoreErrors, sampleRate: options.sampleRate });
1723
1848
  const rootSampler = new (0, _sdktracebase.TraceIdRatioBasedSampler)(_nullishCoalesce(options.traceSampleRate, () => ( 0.01)));
1724
1849
  const headSampler = new (0, _sdktracebase.ParentBasedSampler)({
1725
1850
  root: rootSampler,
@@ -1781,9 +1906,9 @@ function initAutterServer(options) {
1781
1906
  sdk.start();
1782
1907
  patchLoadedHttpModules();
1783
1908
  const stopMemoryMetrics = options.memoryMetrics === false ? null : startMemoryMetrics();
1784
- _chunkMOZOUEMAcjs.noteCompatFeature.call(void 0, "endpoint_latency");
1785
- if (stopMemoryMetrics) _chunkMOZOUEMAcjs.noteCompatFeature.call(void 0, "memory_metrics");
1786
- if (options.llmTracing !== false) _chunkMOZOUEMAcjs.noteCompatFeature.call(void 0, "llm_calls");
1909
+ _chunkBHYHORUDcjs.noteCompatFeature.call(void 0, "endpoint_latency");
1910
+ if (stopMemoryMetrics) _chunkBHYHORUDcjs.noteCompatFeature.call(void 0, "memory_metrics");
1911
+ if (options.llmTracing !== false) _chunkBHYHORUDcjs.noteCompatFeature.call(void 0, "llm_calls");
1787
1912
  const alwaysOnProvider = new (0, _sdktracebase.BasicTracerProvider)({
1788
1913
  resource,
1789
1914
  sampler: new (0, _sdktracebase.AlwaysOnSampler)(),
@@ -1795,44 +1920,44 @@ function initAutterServer(options) {
1795
1920
  const processTracer = alwaysOnProvider.getTracer("autter-processes");
1796
1921
  const llmTracer = alwaysOnProvider.getTracer("autter-llm");
1797
1922
  function captureException2(error, attributes) {
1798
- const isErrValue = _chunk37W7YYXOcjs.isError.call(void 0, error);
1923
+ const isErrValue = _chunkYWTIKZSIcjs.isError.call(void 0, error);
1799
1924
  const reported = errorFilter({
1800
1925
  type: isErrValue ? String(_nullishCoalesce(error.name, () => ( ""))) : "Error",
1801
1926
  message: isErrValue ? String(_nullishCoalesce(error.message, () => ( ""))) : String(error),
1802
1927
  crash: _optionalChain([attributes, 'optionalAccess', _53 => _53["autter.unhandled"]]) === true || _optionalChain([attributes, 'optionalAccess', _54 => _54["autter.unhandled_rejection"]]) === true
1803
1928
  });
1804
1929
  if (!reported) {
1805
- markCaptured(error);
1930
+ _chunkYWTIKZSIcjs.markCaptured.call(void 0, error);
1806
1931
  return;
1807
1932
  }
1808
1933
  _optionalChain([errorTraceBuffer, 'optionalAccess', _55 => _55.retainActiveTrace, 'call', _56 => _56()]);
1809
- _chunkMOZOUEMAcjs.telemetryStats.markCaptured();
1810
- const isErr = _chunk37W7YYXOcjs.isError.call(void 0, error);
1934
+ _chunkBHYHORUDcjs.telemetryStats.markCaptured();
1935
+ const isErr = _chunkYWTIKZSIcjs.isError.call(void 0, error);
1811
1936
  const message = redactor.text(isErr ? error.message : String(error));
1812
1937
  const stackText = isErr && error.stack ? redactor.text(error.stack) : "";
1813
- const split = _chunk37W7YYXOcjs.splitFingerprint.call(void 0, attributes);
1814
- const fingerprint = _chunk37W7YYXOcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, redactor.text);
1815
- if (fingerprint["autter.fingerprint"]) _chunkMOZOUEMAcjs.noteCompatFeature.call(void 0, "fingerprint_override");
1938
+ const split = _chunkYWTIKZSIcjs.splitFingerprint.call(void 0, attributes);
1939
+ const fingerprint = _chunkYWTIKZSIcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, redactor.text);
1940
+ if (fingerprint["autter.fingerprint"]) _chunkBHYHORUDcjs.noteCompatFeature.call(void 0, "fingerprint_override");
1816
1941
  const redacted = redactor(split.attributes);
1817
1942
  const activeSpan = _api.trace.getActiveSpan();
1818
1943
  const reuseActive = _optionalChain([activeSpan, 'optionalAccess', _57 => _57.isRecording, 'call', _58 => _58()]) === true;
1819
1944
  const span = reuseActive ? activeSpan : errorTracer.startSpan(isErr ? error.name : "Error");
1820
1945
  const structured = structuredErrorAttributes(error);
1821
- const causes = _chunk37W7YYXOcjs.errorAttributes.call(void 0, error);
1946
+ const causes = _chunkYWTIKZSIcjs.errorAttributes.call(void 0, error);
1822
1947
  const declared = {
1823
1948
  ...Object.fromEntries(Object.entries(causes).filter(([key]) => key !== "autter.error.internal")),
1824
1949
  ...fingerprint
1825
1950
  };
1826
- const requestId = _optionalChain([_chunk37W7YYXOcjs.currentOperation.call(void 0, ), 'optionalAccess', _59 => _59.requestId]);
1951
+ const requestId = _optionalChain([_chunkYWTIKZSIcjs.currentOperation.call(void 0, ), 'optionalAccess', _59 => _59.requestId]);
1827
1952
  span.setAttributes({
1828
1953
  "autter.severity": "error",
1829
1954
  ...redacted,
1830
1955
  ...structured,
1831
1956
  ...requestId ? { "autter.request.id": requestId } : {}
1832
1957
  });
1833
- markCaptured(error);
1834
- _chunk37W7YYXOcjs.noteOperationError.call(void 0, error);
1835
- _chunk37W7YYXOcjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint });
1958
+ _chunkYWTIKZSIcjs.markCaptured.call(void 0, error);
1959
+ _chunkYWTIKZSIcjs.noteOperationError.call(void 0, error);
1960
+ _chunkYWTIKZSIcjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint });
1836
1961
  if (isErr && stackText) {
1837
1962
  span.addEvent("exception", {
1838
1963
  "exception.type": error.name,
@@ -1840,7 +1965,7 @@ function initAutterServer(options) {
1840
1965
  "exception.stacktrace": stackText,
1841
1966
  ...redacted["autter.handled"] === true ? { "autter.handled": true, "autter.sampled": redacted["autter.sampled"] === true } : {},
1842
1967
  ...declared,
1843
- ..._chunk37W7YYXOcjs.breadcrumbEventAttributes.call(void 0, redactor.text, error)
1968
+ ..._chunkYWTIKZSIcjs.breadcrumbEventAttributes.call(void 0, redactor.text, error)
1844
1969
  });
1845
1970
  } else {
1846
1971
  const stack = _optionalChain([new Error(), 'access', _60 => _60.stack, 'optionalAccess', _61 => _61.split, 'call', _62 => _62("\n"), 'access', _63 => _63.filter, 'call', _64 => _64((line, i) => i === 0 || !line.includes("captureException")), 'access', _65 => _65.join, 'call', _66 => _66("\n")]);
@@ -1850,7 +1975,7 @@ function initAutterServer(options) {
1850
1975
  ...stack ? { "exception.stacktrace": redactor.text(stack) } : {},
1851
1976
  ...redacted["autter.handled"] === true ? { "autter.handled": true, "autter.sampled": redacted["autter.sampled"] === true } : {},
1852
1977
  ...declared,
1853
- ..._chunk37W7YYXOcjs.breadcrumbEventAttributes.call(void 0, redactor.text, error)
1978
+ ..._chunkYWTIKZSIcjs.breadcrumbEventAttributes.call(void 0, redactor.text, error)
1854
1979
  });
1855
1980
  }
1856
1981
  span.setStatus({ code: _api.SpanStatusCode.ERROR, message });
@@ -1861,7 +1986,7 @@ function initAutterServer(options) {
1861
1986
  if (severity === "error" || severity === "fatal") {
1862
1987
  _optionalChain([errorTraceBuffer, 'optionalAccess', _67 => _67.retainActiveTrace, 'call', _68 => _68()]);
1863
1988
  }
1864
- _chunkMOZOUEMAcjs.telemetryStats.markCaptured();
1989
+ _chunkBHYHORUDcjs.telemetryStats.markCaptured();
1865
1990
  const stack = _optionalChain([new Error(), 'access', _69 => _69.stack, 'optionalAccess', _70 => _70.split, 'call', _71 => _71("\n"), 'access', _72 => _72.filter, 'call', _73 => _73((line, i) => i === 0 || !line.includes("captureMessage")), 'access', _74 => _74.join, 'call', _75 => _75("\n")]);
1866
1991
  const safeMessage = redactor.text(message);
1867
1992
  const span = errorTracer.startSpan("Message", {
@@ -1872,7 +1997,7 @@ function initAutterServer(options) {
1872
1997
  "exception.message": safeMessage,
1873
1998
  ...stack ? { "exception.stacktrace": redactor.text(stack) } : {},
1874
1999
  "autter.severity": severity,
1875
- ..._chunk37W7YYXOcjs.breadcrumbEventAttributes.call(void 0, redactor.text)
2000
+ ..._chunkYWTIKZSIcjs.breadcrumbEventAttributes.call(void 0, redactor.text)
1876
2001
  });
1877
2002
  span.setStatus({ code: _api.SpanStatusCode.ERROR, message: safeMessage });
1878
2003
  span.end();
@@ -1880,7 +2005,7 @@ function initAutterServer(options) {
1880
2005
  function reportOutcome2(name, message, attributes) {
1881
2006
  if (!errorFilter({ type: "OutcomeFailure", message: `${name}: ${message}` })) return;
1882
2007
  _optionalChain([errorTraceBuffer, 'optionalAccess', _76 => _76.retainActiveTrace, 'call', _77 => _77()]);
1883
- _chunkMOZOUEMAcjs.telemetryStats.markCaptured();
2008
+ _chunkBHYHORUDcjs.telemetryStats.markCaptured();
1884
2009
  const activeSpan = _api.trace.getActiveSpan();
1885
2010
  const reuseActive = _optionalChain([activeSpan, 'optionalAccess', _78 => _78.isRecording, 'call', _79 => _79()]) === true;
1886
2011
  const span = reuseActive ? activeSpan : errorTracer.startSpan("OutcomeFailure");
@@ -1896,7 +2021,38 @@ function initAutterServer(options) {
1896
2021
  span.setStatus({ code: _api.SpanStatusCode.ERROR, message: safeMessage });
1897
2022
  if (!reuseActive) span.end();
1898
2023
  }
1899
- _chunk37W7YYXOcjs.configureRuntimeLogger.call(void 0, {
2024
+ function captureHandled(error, attributes, severity) {
2025
+ const isErr = _chunkYWTIKZSIcjs.isError.call(void 0, error);
2026
+ if (!errorFilter({
2027
+ type: isErr ? String(_nullishCoalesce(error.name, () => ( ""))) : "Error",
2028
+ message: isErr ? String(_nullishCoalesce(error.message, () => ( ""))) : String(error),
2029
+ severity
2030
+ })) return;
2031
+ if (severity === "error") _optionalChain([errorTraceBuffer, 'optionalAccess', _80 => _80.retainActiveTrace, 'call', _81 => _81()]);
2032
+ _chunkBHYHORUDcjs.telemetryStats.markCaptured();
2033
+ const message = redactor.text(isErr ? error.message : String(error));
2034
+ const stack = isErr && error.stack ? error.stack : _optionalChain([new Error(), 'access', _82 => _82.stack, 'optionalAccess', _83 => _83.split, 'call', _84 => _84("\n"), 'access', _85 => _85.filter, 'call', _86 => _86((line, i) => i === 0 || !/captureHandled|report(?:Degraded|LoggedError)/.test(line)), 'access', _87 => _87.join, 'call', _88 => _88("\n")]);
2035
+ const split = _chunkYWTIKZSIcjs.splitFingerprint.call(void 0, attributes);
2036
+ const fingerprint = _chunkYWTIKZSIcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, redactor.text);
2037
+ const redacted = redactor(split.attributes);
2038
+ const activeSpan = _api.trace.getActiveSpan();
2039
+ const reuseActive = _optionalChain([activeSpan, 'optionalAccess', _89 => _89.isRecording, 'call', _90 => _90()]) === true;
2040
+ const span = reuseActive ? activeSpan : errorTracer.startSpan(isErr ? error.name : "Error");
2041
+ _chunkYWTIKZSIcjs.markCaptured.call(void 0, error);
2042
+ _chunkYWTIKZSIcjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint, "autter.severity": severity });
2043
+ span.addEvent("exception", {
2044
+ ...redacted,
2045
+ "exception.type": isErr ? error.name : "Error",
2046
+ "exception.message": message,
2047
+ ...stack ? { "exception.stacktrace": redactor.text(stack) } : {},
2048
+ "autter.severity": severity,
2049
+ ..._chunkYWTIKZSIcjs.errorAttributes.call(void 0, error),
2050
+ ...fingerprint,
2051
+ ..._chunkYWTIKZSIcjs.breadcrumbEventAttributes.call(void 0, redactor.text, error)
2052
+ });
2053
+ if (!reuseActive) span.end();
2054
+ }
2055
+ _chunkYWTIKZSIcjs.configureRuntimeLogger.call(void 0, {
1900
2056
  endpoint,
1901
2057
  apiKey: options.apiKey,
1902
2058
  service: options.service,
@@ -1908,7 +2064,9 @@ function initAutterServer(options) {
1908
2064
  run: (name, fn, attributes, links) => runWithSpan(processTracer, name, fn, redactor(attributes), links),
1909
2065
  reportOutcome: reportOutcome2
1910
2066
  });
1911
- S.hookRequests = _optionalChain([options, 'access', _80 => _80.logging, 'optionalAccess', _81 => _81.requests]) === true;
2067
+ S.hookRequests = _optionalChain([options, 'access', _91 => _91.logging, 'optionalAccess', _92 => _92.requests]) === true;
2068
+ S.handled = captureHandled;
2069
+ _chunkYWTIKZSIcjs.startLoggedErrorCapture.call(void 0, options.captureLoggedErrors);
1912
2070
  let onCrash = null;
1913
2071
  let uninstallRejections = null;
1914
2072
  if (options.captureGlobalErrors !== false) {
@@ -1928,7 +2086,7 @@ function initAutterServer(options) {
1928
2086
  const flushTarget = {
1929
2087
  forceFlush: async () => {
1930
2088
  const results = await Promise.allSettled([
1931
- _chunk37W7YYXOcjs.flushRuntimeLogs.call(void 0, ),
2089
+ _chunkYWTIKZSIcjs.flushRuntimeLogs.call(void 0, ),
1932
2090
  Promise.resolve().then(() => alwaysOnProvider.forceFlush()),
1933
2091
  Promise.resolve().then(() => mainSpanProcessor.forceFlush()),
1934
2092
  ...errorTraceBuffer ? [Promise.resolve().then(() => errorTraceBuffer.forceFlush())] : [],
@@ -1942,10 +2100,10 @@ function initAutterServer(options) {
1942
2100
  }
1943
2101
  }
1944
2102
  };
1945
- _chunkMOZOUEMAcjs.registerFlushTarget.call(void 0, "active-server", flushTarget);
2103
+ _chunkBHYHORUDcjs.registerFlushTarget.call(void 0, "active-server", flushTarget);
1946
2104
  let autoFlushHandle = null;
1947
2105
  if (options.autoFlush !== false) {
1948
- autoFlushHandle = _chunkMOZOUEMAcjs.installAutterAutoFlush.call(void 0, );
2106
+ autoFlushHandle = _chunkBHYHORUDcjs.installAutterAutoFlush.call(void 0, );
1949
2107
  }
1950
2108
  const server = {
1951
2109
  captureException: captureException2,
@@ -1955,22 +2113,24 @@ function initAutterServer(options) {
1955
2113
  withLlmCall: (info, fn) => runLlmSpan(llmTracer, info, fn),
1956
2114
  trackLlmCall: (call) => recordLlmCall(llmTracer, call),
1957
2115
  shutdown: async () => {
1958
- const logShutdown = await Promise.allSettled([_chunk37W7YYXOcjs.shutdownRuntimeLogger.call(void 0, )]);
2116
+ if (S.active === server) _chunkYWTIKZSIcjs.stopLoggedErrorCapture.call(void 0, );
2117
+ const logShutdown = await Promise.allSettled([_chunkYWTIKZSIcjs.shutdownRuntimeLogger.call(void 0, )]);
1959
2118
  if (onCrash) process.off("uncaughtExceptionMonitor", onCrash);
1960
- _optionalChain([uninstallRejections, 'optionalCall', _82 => _82()]);
1961
- _optionalChain([stopMemoryMetrics, 'optionalCall', _83 => _83()]);
2119
+ _optionalChain([uninstallRejections, 'optionalCall', _93 => _93()]);
2120
+ _optionalChain([stopMemoryMetrics, 'optionalCall', _94 => _94()]);
1962
2121
  if (S.active === server) {
1963
2122
  S.active = null;
1964
2123
  S.alwaysOnProvider = null;
2124
+ S.handled = null;
1965
2125
  S.hookRequests = false;
1966
- S.redactor = _chunk37W7YYXOcjs.makeRedactor.call(void 0, true);
2126
+ S.redactor = _chunkYWTIKZSIcjs.makeRedactor.call(void 0, true);
1967
2127
  }
1968
- _optionalChain([autoFlushHandle, 'optionalAccess', _84 => _84.dispose, 'call', _85 => _85()]);
2128
+ _optionalChain([autoFlushHandle, 'optionalAccess', _95 => _95.dispose, 'call', _96 => _96()]);
1969
2129
  autoFlushHandle = null;
1970
- _chunkMOZOUEMAcjs.unregisterFlushTargets.call(void 0, );
1971
- _chunkMOZOUEMAcjs.telemetryStats.markAllFlushed();
2130
+ _chunkBHYHORUDcjs.unregisterFlushTargets.call(void 0, );
2131
+ _chunkBHYHORUDcjs.telemetryStats.markAllFlushed();
1972
2132
  await Promise.allSettled([alwaysOnProvider.shutdown(), sdk.shutdown()]);
1973
- if (_optionalChain([logShutdown, 'access', _86 => _86[0], 'optionalAccess', _87 => _87.status]) === "rejected") throw logShutdown[0].reason;
2133
+ if (_optionalChain([logShutdown, 'access', _97 => _97[0], 'optionalAccess', _98 => _98.status]) === "rejected") throw logShutdown[0].reason;
1974
2134
  }
1975
2135
  };
1976
2136
  S.active = server;
@@ -1986,27 +2146,53 @@ function captureException(error, attributes) {
1986
2146
  S.loggerOnlyCapture(error, attributes);
1987
2147
  return;
1988
2148
  }
1989
- markCaptured(error);
1990
- _chunk37W7YYXOcjs.noteOperationError.call(void 0, error);
1991
- const split = _chunk37W7YYXOcjs.splitFingerprint.call(void 0, attributes);
1992
- const fingerprint = _chunk37W7YYXOcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, S.redactor.text);
1993
- _chunk37W7YYXOcjs.notifyException.call(void 0, error, { ...split.attributes, ...fingerprint });
1994
- const span = _api.trace.getTracer("autter-errors").startSpan(_chunk37W7YYXOcjs.isError.call(void 0, error) ? error.name : "Error", {
2149
+ _chunkYWTIKZSIcjs.markCaptured.call(void 0, error);
2150
+ _chunkYWTIKZSIcjs.noteOperationError.call(void 0, error);
2151
+ const split = _chunkYWTIKZSIcjs.splitFingerprint.call(void 0, attributes);
2152
+ const fingerprint = _chunkYWTIKZSIcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, S.redactor.text);
2153
+ _chunkYWTIKZSIcjs.notifyException.call(void 0, error, { ...split.attributes, ...fingerprint });
2154
+ const span = _api.trace.getTracer("autter-errors").startSpan(_chunkYWTIKZSIcjs.isError.call(void 0, error) ? error.name : "Error", {
1995
2155
  attributes: { ...S.redactor(split.attributes), ...fingerprint }
1996
2156
  });
1997
2157
  recordError(span, error);
1998
2158
  span.end();
1999
2159
  }
2000
- function setLoggerOnlyCapture(fn) {
2160
+ function setLoggerOnlyCapture(fn, handled = null) {
2001
2161
  S.loggerOnlyCapture = fn;
2162
+ S.loggerOnlyHandled = handled;
2163
+ }
2164
+ function captureHandledError(error, attributes, severity) {
2165
+ if (S.active) {
2166
+ _optionalChain([S, 'access', _99 => _99.handled, 'optionalCall', _100 => _100(error, attributes, severity)]);
2167
+ return;
2168
+ }
2169
+ if (S.loggerOnlyHandled) {
2170
+ S.loggerOnlyHandled(error, attributes, severity);
2171
+ return;
2172
+ }
2173
+ _chunkYWTIKZSIcjs.markCaptured.call(void 0, error);
2174
+ const split = _chunkYWTIKZSIcjs.splitFingerprint.call(void 0, attributes);
2175
+ _chunkYWTIKZSIcjs.notifyException.call(void 0, error, { ...split.attributes, "autter.severity": severity });
2176
+ const span = _api.trace.getTracer("autter-errors").startSpan(_chunkYWTIKZSIcjs.isError.call(void 0, error) ? error.name : "Error");
2177
+ span.addEvent("exception", {
2178
+ ...S.redactor(split.attributes),
2179
+ "exception.type": _chunkYWTIKZSIcjs.isError.call(void 0, error) ? error.name : "Error",
2180
+ "exception.message": S.redactor.text(_chunkYWTIKZSIcjs.isError.call(void 0, error) ? error.message : String(error)),
2181
+ ..._chunkYWTIKZSIcjs.isError.call(void 0, error) && error.stack ? { "exception.stacktrace": S.redactor.text(error.stack) } : {},
2182
+ "autter.severity": severity,
2183
+ ..._chunkYWTIKZSIcjs.errorAttributes.call(void 0, error),
2184
+ ..._chunkYWTIKZSIcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, S.redactor.text)
2185
+ });
2186
+ span.end();
2002
2187
  }
2003
2188
  function serverActive() {
2004
2189
  return S.active !== null;
2005
2190
  }
2006
2191
  setRequestExceptionCapturer((error, attributes) => captureException(error, attributes));
2192
+ _chunkYWTIKZSIcjs.setHandledCapture.call(void 0, captureHandledError);
2007
2193
  setRequestSpanAnnotator((attributes) => {
2008
2194
  const span = _api.trace.getActiveSpan();
2009
- if (_optionalChain([span, 'optionalAccess', _88 => _88.isRecording, 'call', _89 => _89()])) span.setAttributes(S.redactor(_chunk37W7YYXOcjs.splitFingerprint.call(void 0, attributes).attributes));
2195
+ if (_optionalChain([span, 'optionalAccess', _101 => _101.isRecording, 'call', _102 => _102()])) span.setAttributes(S.redactor(_chunkYWTIKZSIcjs.splitFingerprint.call(void 0, attributes).attributes));
2010
2196
  });
2011
2197
  function withProcessSpan(name, fn, attributes) {
2012
2198
  if (S.active) return S.active.withProcessSpan(name, fn, attributes);
@@ -2041,7 +2227,7 @@ function captureMessage(message, severity = "warning", attributes) {
2041
2227
  "exception.type": "Message",
2042
2228
  "exception.message": safeMessage,
2043
2229
  "autter.severity": severity,
2044
- ..._chunk37W7YYXOcjs.breadcrumbEventAttributes.call(void 0, S.redactor.text)
2230
+ ..._chunkYWTIKZSIcjs.breadcrumbEventAttributes.call(void 0, S.redactor.text)
2045
2231
  });
2046
2232
  span.setStatus({ code: _api.SpanStatusCode.ERROR, message: safeMessage });
2047
2233
  span.end();
@@ -2049,11 +2235,11 @@ function captureMessage(message, severity = "warning", attributes) {
2049
2235
  function reportOutcome(name, message, attributes) {
2050
2236
  if (S.active) return S.active.reportOutcome(name, message, attributes);
2051
2237
  const span = _api.trace.getTracer("autter-outcomes").startSpan("OutcomeFailure");
2052
- const safeOutcome = _chunk37W7YYXOcjs.redactAttributes.call(void 0, { "autter.outcome.name": name.slice(0, 200), "autter.outcome.message": message.slice(0, 1e3) });
2238
+ const safeOutcome = _chunkYWTIKZSIcjs.redactAttributes.call(void 0, { "autter.outcome.name": name.slice(0, 200), "autter.outcome.message": message.slice(0, 1e3) });
2053
2239
  const safeName = String(_nullishCoalesce(safeOutcome["autter.outcome.name"], () => ( "operation")));
2054
2240
  const safeMessage = String(_nullishCoalesce(safeOutcome["autter.outcome.message"], () => ( "failed")));
2055
2241
  span.addEvent("autter.outcome", {
2056
- ..._chunk37W7YYXOcjs.redactAttributes.call(void 0, attributes),
2242
+ ..._chunkYWTIKZSIcjs.redactAttributes.call(void 0, attributes),
2057
2243
  "autter.outcome.status": "error",
2058
2244
  "autter.outcome.name": safeName,
2059
2245
  "autter.outcome.message": safeMessage
@@ -2062,7 +2248,7 @@ function reportOutcome(name, message, attributes) {
2062
2248
  span.end();
2063
2249
  }
2064
2250
  function makeSafeCapture(options) {
2065
- const clean = (attributes) => attributes ? { ..._chunk37W7YYXOcjs.redactAttributes.call(void 0, attributes, options) } : void 0;
2251
+ const clean = (attributes) => attributes ? { ..._chunkYWTIKZSIcjs.redactAttributes.call(void 0, attributes, options) } : void 0;
2066
2252
  return {
2067
2253
  captureException: (error, attributes) => captureException(error, clean(attributes)),
2068
2254
  captureMessage: (message, severity, attributes) => captureMessage(message, _nullishCoalesce(severity, () => ( "warning")), clean(attributes))
@@ -2089,7 +2275,7 @@ async function emitLlmSelftestTrace() {
2089
2275
  attributes: { "autter.selftest": true }
2090
2276
  },
2091
2277
  (llm) => {
2092
- traceId = _nullishCoalesce(_optionalChain([_api.trace, 'access', _90 => _90.getActiveSpan, 'call', _91 => _91(), 'optionalAccess', _92 => _92.spanContext, 'call', _93 => _93(), 'access', _94 => _94.traceId]), () => ( ""));
2278
+ traceId = _nullishCoalesce(_optionalChain([_api.trace, 'access', _103 => _103.getActiveSpan, 'call', _104 => _104(), 'optionalAccess', _105 => _105.spanContext, 'call', _106 => _106(), 'access', _107 => _107.traceId]), () => ( ""));
2093
2279
  llm.setUsage({ inputTokens: 1, outputTokens: 1 });
2094
2280
  llm.setCost(0);
2095
2281
  }
@@ -2117,7 +2303,7 @@ var CALL_METHODS = /* @__PURE__ */ new Set([
2117
2303
  // openai beta structured outputs
2118
2304
  ]);
2119
2305
  function detectProvider(client) {
2120
- const name = _nullishCoalesce(_optionalChain([client, 'access', _95 => _95.constructor, 'optionalAccess', _96 => _96.name, 'optionalAccess', _97 => _97.toLowerCase, 'call', _98 => _98()]), () => ( ""));
2306
+ const name = _nullishCoalesce(_optionalChain([client, 'access', _108 => _108.constructor, 'optionalAccess', _109 => _109.name, 'optionalAccess', _110 => _110.toLowerCase, 'call', _111 => _111()]), () => ( ""));
2121
2307
  for (const known of ["openai", "anthropic", "mistral", "groq", "cohere"]) {
2122
2308
  if (name.includes(known)) return known;
2123
2309
  }
@@ -2125,7 +2311,7 @@ function detectProvider(client) {
2125
2311
  const baseUrl = String(
2126
2312
  _nullishCoalesce(_nullishCoalesce(client.baseURL, () => ( client.baseUrl)), () => ( ""))
2127
2313
  );
2128
- const host = _nullishCoalesce(_optionalChain([baseUrl, 'access', _99 => _99.match, 'call', _100 => _100(/https?:\/\/([^/]+)/), 'optionalAccess', _101 => _101[1]]), () => ( ""));
2314
+ const host = _nullishCoalesce(_optionalChain([baseUrl, 'access', _112 => _112.match, 'call', _113 => _113(/https?:\/\/([^/]+)/), 'optionalAccess', _114 => _114[1]]), () => ( ""));
2129
2315
  if (host.includes("openai")) return "openai";
2130
2316
  if (host.includes("anthropic")) return "anthropic";
2131
2317
  if (host.includes("googleapis")) return "google";
@@ -2135,13 +2321,13 @@ function detectProvider(client) {
2135
2321
  }
2136
2322
  function extractUsage(result) {
2137
2323
  const r = result;
2138
- const usage = _nullishCoalesce(_optionalChain([r, 'optionalAccess', _102 => _102.usage]), () => ( _optionalChain([r, 'optionalAccess', _103 => _103.message, 'optionalAccess', _104 => _104.usage])));
2139
- const meta = _optionalChain([r, 'optionalAccess', _105 => _105.usageMetadata]);
2140
- const details = _optionalChain([usage, 'optionalAccess', _106 => _106.prompt_tokens_details]);
2141
- const cached = _nullishCoalesce(_nullishCoalesce(_optionalChain([usage, 'optionalAccess', _107 => _107.cache_read_input_tokens]), () => ( (typeof _optionalChain([details, 'optionalAccess', _108 => _108.cached_tokens]) === "number" ? details.cached_tokens : void 0))), () => ( _optionalChain([meta, 'optionalAccess', _109 => _109.cachedContentTokenCount])));
2142
- const input = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([usage, 'optionalAccess', _110 => _110.prompt_tokens]), () => ( _optionalChain([usage, 'optionalAccess', _111 => _111.input_tokens]))), () => ( _optionalChain([meta, 'optionalAccess', _112 => _112.promptTokenCount]))), () => ( void 0));
2143
- const output = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([usage, 'optionalAccess', _113 => _113.completion_tokens]), () => ( _optionalChain([usage, 'optionalAccess', _114 => _114.output_tokens]))), () => ( _optionalChain([meta, 'optionalAccess', _115 => _115.candidatesTokenCount]))), () => ( void 0));
2144
- const responseModel = _nullishCoalesce(_optionalChain([r, 'optionalAccess', _116 => _116.model]), () => ( _optionalChain([r, 'optionalAccess', _117 => _117.modelVersion])));
2324
+ const usage = _nullishCoalesce(_optionalChain([r, 'optionalAccess', _115 => _115.usage]), () => ( _optionalChain([r, 'optionalAccess', _116 => _116.message, 'optionalAccess', _117 => _117.usage])));
2325
+ const meta = _optionalChain([r, 'optionalAccess', _118 => _118.usageMetadata]);
2326
+ const details = _optionalChain([usage, 'optionalAccess', _119 => _119.prompt_tokens_details]);
2327
+ const cached = _nullishCoalesce(_nullishCoalesce(_optionalChain([usage, 'optionalAccess', _120 => _120.cache_read_input_tokens]), () => ( (typeof _optionalChain([details, 'optionalAccess', _121 => _121.cached_tokens]) === "number" ? details.cached_tokens : void 0))), () => ( _optionalChain([meta, 'optionalAccess', _122 => _122.cachedContentTokenCount])));
2328
+ const input = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([usage, 'optionalAccess', _123 => _123.prompt_tokens]), () => ( _optionalChain([usage, 'optionalAccess', _124 => _124.input_tokens]))), () => ( _optionalChain([meta, 'optionalAccess', _125 => _125.promptTokenCount]))), () => ( void 0));
2329
+ const output = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([usage, 'optionalAccess', _126 => _126.completion_tokens]), () => ( _optionalChain([usage, 'optionalAccess', _127 => _127.output_tokens]))), () => ( _optionalChain([meta, 'optionalAccess', _128 => _128.candidatesTokenCount]))), () => ( void 0));
2330
+ const responseModel = _nullishCoalesce(_optionalChain([r, 'optionalAccess', _129 => _129.model]), () => ( _optionalChain([r, 'optionalAccess', _130 => _130.modelVersion])));
2145
2331
  return {
2146
2332
  inputTokens: typeof input === "number" ? input : void 0,
2147
2333
  outputTokens: typeof output === "number" ? output : void 0,
@@ -2150,7 +2336,7 @@ function extractUsage(result) {
2150
2336
  };
2151
2337
  }
2152
2338
  function rollUp(model, usage) {
2153
- _chunk37W7YYXOcjs.recordOperationAiUsage.call(void 0, {
2339
+ _chunkYWTIKZSIcjs.recordOperationAiUsage.call(void 0, {
2154
2340
  model: _nullishCoalesce(usage.responseModel, () => ( model)),
2155
2341
  ...usage.inputTokens !== void 0 ? { inputTokens: usage.inputTokens } : {},
2156
2342
  ...usage.outputTokens !== void 0 ? { outputTokens: usage.outputTokens } : {},
@@ -2234,10 +2420,10 @@ function wrapStream(stream, span, model) {
2234
2420
  });
2235
2421
  }
2236
2422
  function instrumentLlmClient(client, options) {
2237
- const provider = (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _118 => _118.provider]), () => ( detectProvider(client)))).toLowerCase();
2423
+ const provider = (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _131 => _131.provider]), () => ( detectProvider(client)))).toLowerCase();
2238
2424
  const proxied = /* @__PURE__ */ new WeakMap();
2239
2425
  function resolveUserId() {
2240
- return typeof _optionalChain([options, 'optionalAccess', _119 => _119.userId]) === "function" ? options.userId() : _optionalChain([options, 'optionalAccess', _120 => _120.userId]);
2426
+ return typeof _optionalChain([options, 'optionalAccess', _132 => _132.userId]) === "function" ? options.userId() : _optionalChain([options, 'optionalAccess', _133 => _133.userId]);
2241
2427
  }
2242
2428
  function traceCall(fn, self, callPath, args) {
2243
2429
  const request = args[0];
@@ -2251,7 +2437,7 @@ function instrumentLlmClient(client, options) {
2251
2437
  "gen_ai.system": provider,
2252
2438
  "gen_ai.request.model": request.model,
2253
2439
  ...userId ? { "autter.user_id": userId } : {},
2254
- ...redactWithActive(_optionalChain([options, 'optionalAccess', _121 => _121.attributes]))
2440
+ ...redactWithActive(_optionalChain([options, 'optionalAccess', _134 => _134.attributes]))
2255
2441
  }
2256
2442
  });
2257
2443
  let result;
@@ -2375,9 +2561,9 @@ ${frames.join("\n")}`;
2375
2561
  function recordBoundaryError(error, req, rule) {
2376
2562
  try {
2377
2563
  const state = requestStateOf(req);
2378
- if (state) _chunk37W7YYXOcjs.noteOperationError.call(void 0, error, false, state);
2564
+ if (state) _chunkYWTIKZSIcjs.noteOperationError.call(void 0, error, false, state);
2379
2565
  captureAtBoundary(error, state, rule);
2380
- } catch (e32) {
2566
+ } catch (e34) {
2381
2567
  }
2382
2568
  }
2383
2569
  function autterErrorHandler(options = {}) {
@@ -2387,12 +2573,12 @@ function autterErrorHandler(options = {}) {
2387
2573
  };
2388
2574
  }
2389
2575
  function autterFastifyErrors(fastify, options, done) {
2390
- const rule = _optionalChain([options, 'optionalAccess', _122 => _122.capture]);
2576
+ const rule = _optionalChain([options, 'optionalAccess', _135 => _135.capture]);
2391
2577
  fastify.addHook("onError", ((request, _reply, error, next) => {
2392
- recordBoundaryError(error, _optionalChain([request, 'optionalAccess', _123 => _123.raw]), rule);
2578
+ recordBoundaryError(error, _optionalChain([request, 'optionalAccess', _136 => _136.raw]), rule);
2393
2579
  next();
2394
2580
  }));
2395
- _optionalChain([done, 'optionalCall', _124 => _124()]);
2581
+ _optionalChain([done, 'optionalCall', _137 => _137()]);
2396
2582
  }
2397
2583
  autterFastifyErrors[/* @__PURE__ */ Symbol.for("skip-override")] = true;
2398
2584
  autterFastifyErrors[/* @__PURE__ */ Symbol.for("fastify.display-name")] = "autter-runtime-errors";
@@ -2401,7 +2587,7 @@ function autterKoa(options = {}) {
2401
2587
  try {
2402
2588
  await next();
2403
2589
  } catch (error) {
2404
- recordBoundaryError(error, _optionalChain([ctx, 'optionalAccess', _125 => _125.req]), options.capture);
2590
+ recordBoundaryError(error, _optionalChain([ctx, 'optionalAccess', _138 => _138.req]), options.capture);
2405
2591
  throw error;
2406
2592
  }
2407
2593
  };
@@ -2412,7 +2598,7 @@ function autterKoa(options = {}) {
2412
2598
 
2413
2599
 
2414
2600
 
2415
- var L = _chunkMOZOUEMAcjs.sharedSlot.call(void 0, "logging", () => ({ active: null }));
2601
+ var L = _chunkBHYHORUDcjs.sharedSlot.call(void 0, "logging", () => ({ active: null }));
2416
2602
  function initAutterLogging(options) {
2417
2603
  if (L.active) return L.active;
2418
2604
  if (serverActive()) {
@@ -2421,37 +2607,37 @@ function initAutterLogging(options) {
2421
2607
  );
2422
2608
  return {
2423
2609
  captureException,
2424
- flush: _chunk37W7YYXOcjs.flushRuntimeLogs,
2610
+ flush: _chunkYWTIKZSIcjs.flushRuntimeLogs,
2425
2611
  shutdown: async () => {
2426
2612
  }
2427
2613
  };
2428
2614
  }
2429
- if (_chunkMOZOUEMAcjs.isDebugEnabled.call(void 0, ) || options.debug === true) _chunkMOZOUEMAcjs.setDebugMode.call(void 0, true);
2615
+ if (_chunkBHYHORUDcjs.isDebugEnabled.call(void 0, ) || options.debug === true) _chunkBHYHORUDcjs.setDebugMode.call(void 0, true);
2430
2616
  const endpoint = (_nullishCoalesce(options.endpoint, () => ( "https://otlp.autter.dev"))).replace(/\/$/, "");
2431
2617
  const environment = _nullishCoalesce(_nullishCoalesce(options.environment, () => ( process.env.NODE_ENV)), () => ( "production"));
2432
- const redact = _chunk37W7YYXOcjs.makeRedactor.call(void 0, _nullishCoalesce(options.redactAttributes, () => ( true)));
2618
+ const redact = _chunkYWTIKZSIcjs.makeRedactor.call(void 0, _nullishCoalesce(options.redactAttributes, () => ( true)));
2433
2619
  const mode = _nullishCoalesce(options.exceptions, () => ( "auto"));
2434
- _chunkMOZOUEMAcjs.debugLog.call(void 0, `initialising logger-only service=${options.service} endpoint=${endpoint}`);
2435
- const errorFilter = _chunk37W7YYXOcjs.createErrorFilter.call(void 0, { ignoreErrors: options.ignoreErrors, sampleRate: options.sampleRate });
2620
+ _chunkBHYHORUDcjs.debugLog.call(void 0, `initialising logger-only service=${options.service} endpoint=${endpoint}`);
2621
+ const errorFilter = _chunkYWTIKZSIcjs.createErrorFilter.call(void 0, { ignoreErrors: options.ignoreErrors, sampleRate: options.sampleRate });
2436
2622
  function captureException2(error, attributes) {
2437
- markCaptured(error);
2438
- const isErrValue = _chunk37W7YYXOcjs.isError.call(void 0, error);
2623
+ _chunkYWTIKZSIcjs.markCaptured.call(void 0, error);
2624
+ const isErrValue = _chunkYWTIKZSIcjs.isError.call(void 0, error);
2439
2625
  const reported = errorFilter({
2440
2626
  type: isErrValue ? String(_nullishCoalesce(error.name, () => ( ""))) : "Error",
2441
2627
  message: isErrValue ? String(_nullishCoalesce(error.message, () => ( ""))) : String(error),
2442
- crash: _optionalChain([attributes, 'optionalAccess', _126 => _126["autter.unhandled"]]) === true || _optionalChain([attributes, 'optionalAccess', _127 => _127["autter.unhandled_rejection"]]) === true
2628
+ crash: _optionalChain([attributes, 'optionalAccess', _139 => _139["autter.unhandled"]]) === true || _optionalChain([attributes, 'optionalAccess', _140 => _140["autter.unhandled_rejection"]]) === true
2443
2629
  });
2444
2630
  if (!reported) return;
2445
- const split = _chunk37W7YYXOcjs.splitFingerprint.call(void 0, attributes);
2446
- const fingerprint = _chunk37W7YYXOcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, redact.text);
2631
+ const split = _chunkYWTIKZSIcjs.splitFingerprint.call(void 0, attributes);
2632
+ const fingerprint = _chunkYWTIKZSIcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, redact.text);
2447
2633
  const redacted = redact(split.attributes);
2448
2634
  const span = _api.trace.getActiveSpan();
2449
- if (mode === "auto" && _optionalChain([span, 'optionalAccess', _128 => _128.isRecording, 'call', _129 => _129()])) {
2450
- _chunk37W7YYXOcjs.noteOperationError.call(void 0, error);
2451
- _chunk37W7YYXOcjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint });
2635
+ if (mode === "auto" && _optionalChain([span, 'optionalAccess', _141 => _141.isRecording, 'call', _142 => _142()])) {
2636
+ _chunkYWTIKZSIcjs.noteOperationError.call(void 0, error);
2637
+ _chunkYWTIKZSIcjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint });
2452
2638
  span.setAttributes({ "autter.severity": "error", ...redacted, ...structuredErrorAttributes(error) });
2453
- const declared = { ..._chunk37W7YYXOcjs.errorAttributes.call(void 0, error), ...fingerprint };
2454
- if (_chunk37W7YYXOcjs.isError.call(void 0, error)) {
2639
+ const declared = { ..._chunkYWTIKZSIcjs.errorAttributes.call(void 0, error), ...fingerprint };
2640
+ if (_chunkYWTIKZSIcjs.isError.call(void 0, error)) {
2455
2641
  span.addEvent("exception", {
2456
2642
  "exception.type": error.name,
2457
2643
  "exception.message": error.message,
@@ -2467,15 +2653,42 @@ function initAutterLogging(options) {
2467
2653
  }
2468
2654
  span.setStatus({
2469
2655
  code: _api.SpanStatusCode.ERROR,
2470
- message: _chunk37W7YYXOcjs.isError.call(void 0, error) ? error.message : String(error)
2656
+ message: _chunkYWTIKZSIcjs.isError.call(void 0, error) ? error.message : String(error)
2657
+ });
2658
+ return;
2659
+ }
2660
+ _chunkYWTIKZSIcjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint });
2661
+ _chunkYWTIKZSIcjs.captureExceptionAsLog.call(void 0, error, { ...redacted, ...fingerprint });
2662
+ }
2663
+ function captureHandled(error, attributes, severity) {
2664
+ _chunkYWTIKZSIcjs.markCaptured.call(void 0, error);
2665
+ const isErrValue = _chunkYWTIKZSIcjs.isError.call(void 0, error);
2666
+ if (!errorFilter({
2667
+ type: isErrValue ? String(_nullishCoalesce(error.name, () => ( ""))) : "Error",
2668
+ message: isErrValue ? String(_nullishCoalesce(error.message, () => ( ""))) : String(error),
2669
+ severity
2670
+ })) return;
2671
+ const split = _chunkYWTIKZSIcjs.splitFingerprint.call(void 0, attributes);
2672
+ const fingerprint = _chunkYWTIKZSIcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, redact.text);
2673
+ const redacted = redact(split.attributes);
2674
+ _chunkYWTIKZSIcjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint, "autter.severity": severity });
2675
+ const span = _api.trace.getActiveSpan();
2676
+ if (mode === "auto" && _optionalChain([span, 'optionalAccess', _143 => _143.isRecording, 'call', _144 => _144()])) {
2677
+ span.addEvent("exception", {
2678
+ ...redacted,
2679
+ "exception.type": isErrValue ? error.name : "Error",
2680
+ "exception.message": redact.text(isErrValue ? error.message : String(error)),
2681
+ ...isErrValue && error.stack ? { "exception.stacktrace": redact.text(error.stack) } : {},
2682
+ "autter.severity": severity,
2683
+ ..._chunkYWTIKZSIcjs.errorAttributes.call(void 0, error),
2684
+ ...fingerprint
2471
2685
  });
2472
2686
  return;
2473
2687
  }
2474
- _chunk37W7YYXOcjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint });
2475
- _chunk37W7YYXOcjs.captureExceptionAsLog.call(void 0, error, { ...redacted, ...fingerprint });
2688
+ _chunkYWTIKZSIcjs.captureExceptionAsLog.call(void 0, error, { ...redacted, ...fingerprint }, severity);
2476
2689
  }
2477
2690
  const captured = /* @__PURE__ */ new WeakSet();
2478
- _chunk37W7YYXOcjs.configureRuntimeLogger.call(void 0, {
2691
+ _chunkYWTIKZSIcjs.configureRuntimeLogger.call(void 0, {
2479
2692
  endpoint,
2480
2693
  apiKey: _nullishCoalesce(options.apiKey, () => ( "")),
2481
2694
  service: options.service,
@@ -2484,7 +2697,7 @@ function initAutterLogging(options) {
2484
2697
  ...options.logging ? { options: options.logging } : {},
2485
2698
  redact,
2486
2699
  reportOutcome: (name, message, attributes) => {
2487
- _chunk37W7YYXOcjs.runtimeLogger.error(message, {
2700
+ _chunkYWTIKZSIcjs.runtimeLogger.error(message, {
2488
2701
  ...attributes,
2489
2702
  "autter.outcome.name": name.slice(0, 200),
2490
2703
  "autter.outcome.message": message.slice(0, 1e3)
@@ -2498,7 +2711,8 @@ function initAutterLogging(options) {
2498
2711
  captureException2(error);
2499
2712
  }
2500
2713
  });
2501
- setLoggerOnlyCapture(captureException2);
2714
+ setLoggerOnlyCapture(captureException2, captureHandled);
2715
+ _chunkYWTIKZSIcjs.startLoggedErrorCapture.call(void 0, options.captureLoggedErrors);
2502
2716
  const onCrash = (error) => {
2503
2717
  if (recordedAsRejection(error)) return;
2504
2718
  captureException2(error, { "autter.unhandled": true });
@@ -2511,21 +2725,22 @@ function initAutterLogging(options) {
2511
2725
  (reason) => captureException2(reason, { "autter.unhandled_rejection": true })
2512
2726
  );
2513
2727
  }
2514
- _chunkMOZOUEMAcjs.registerFlushTarget.call(void 0, "logging", { forceFlush: () => _chunk37W7YYXOcjs.flushRuntimeLogs.call(void 0, ) });
2515
- let autoFlushHandle = options.autoFlush === false ? null : _chunkMOZOUEMAcjs.installAutterAutoFlush.call(void 0, );
2728
+ _chunkBHYHORUDcjs.registerFlushTarget.call(void 0, "logging", { forceFlush: () => _chunkYWTIKZSIcjs.flushRuntimeLogs.call(void 0, ) });
2729
+ let autoFlushHandle = options.autoFlush === false ? null : _chunkBHYHORUDcjs.installAutterAutoFlush.call(void 0, );
2516
2730
  const handle = {
2517
2731
  captureException: captureException2,
2518
- flush: _chunk37W7YYXOcjs.flushRuntimeLogs,
2732
+ flush: _chunkYWTIKZSIcjs.flushRuntimeLogs,
2519
2733
  shutdown: async () => {
2734
+ if (L.active === handle) _chunkYWTIKZSIcjs.stopLoggedErrorCapture.call(void 0, );
2520
2735
  process.off("uncaughtExceptionMonitor", onCrash);
2521
- _optionalChain([uninstallRejections, 'optionalCall', _130 => _130()]);
2736
+ _optionalChain([uninstallRejections, 'optionalCall', _145 => _145()]);
2522
2737
  uninstallRejections = null;
2523
2738
  setLoggerOnlyCapture(null);
2524
- _optionalChain([autoFlushHandle, 'optionalAccess', _131 => _131.dispose, 'call', _132 => _132()]);
2739
+ _optionalChain([autoFlushHandle, 'optionalAccess', _146 => _146.dispose, 'call', _147 => _147()]);
2525
2740
  autoFlushHandle = null;
2526
- _chunkMOZOUEMAcjs.unregisterFlushTargets.call(void 0, );
2741
+ _chunkBHYHORUDcjs.unregisterFlushTargets.call(void 0, );
2527
2742
  if (L.active === handle) L.active = null;
2528
- await _chunk37W7YYXOcjs.shutdownRuntimeLogger.call(void 0, );
2743
+ await _chunkYWTIKZSIcjs.shutdownRuntimeLogger.call(void 0, );
2529
2744
  }
2530
2745
  };
2531
2746
  L.active = handle;
@@ -2534,7 +2749,7 @@ function initAutterLogging(options) {
2534
2749
 
2535
2750
  // src/enrichers.ts
2536
2751
  function headerOf(req, name) {
2537
- const headers = _optionalChain([req, 'optionalAccess', _133 => _133.headers]);
2752
+ const headers = _optionalChain([req, 'optionalAccess', _148 => _148.headers]);
2538
2753
  if (!headers) return void 0;
2539
2754
  if (typeof headers.get === "function") {
2540
2755
  return _nullishCoalesce(headers.get(name), () => ( void 0));
@@ -2547,7 +2762,7 @@ function enrichUserAgent() {
2547
2762
  return (event, { req }) => {
2548
2763
  const ua = headerOf(req, "user-agent");
2549
2764
  if (!ua) return;
2550
- const info = _chunk37W7YYXOcjs.parseUserAgent.call(void 0, ua);
2765
+ const info = _chunkYWTIKZSIcjs.parseUserAgent.call(void 0, ua);
2551
2766
  if (info.browser) event.attributes["user_agent.browser"] = info.browser;
2552
2767
  if (info.os) event.attributes["user_agent.os"] = info.os;
2553
2768
  event.attributes["user_agent.device"] = info.device;
@@ -2559,7 +2774,7 @@ function enrichRequestSize() {
2559
2774
  const request = Number(headerOf(req, "content-length"));
2560
2775
  if (Number.isFinite(request) && request >= 0)
2561
2776
  event.attributes["http.request.body.size"] = request;
2562
- const raw = _optionalChain([res, 'optionalAccess', _134 => _134.getHeader, 'optionalCall', _135 => _135(
2777
+ const raw = _optionalChain([res, 'optionalAccess', _149 => _149.getHeader, 'optionalCall', _150 => _150(
2563
2778
  "content-length"
2564
2779
  )]);
2565
2780
  const response = Number(raw);
@@ -2577,7 +2792,7 @@ var COUNTRY_HEADERS = [
2577
2792
  function enrichEdgeGeo() {
2578
2793
  return (event, { req }) => {
2579
2794
  for (const name of COUNTRY_HEADERS) {
2580
- const value = _optionalChain([headerOf, 'call', _136 => _136(req, name), 'optionalAccess', _137 => _137.trim, 'call', _138 => _138(), 'access', _139 => _139.toUpperCase, 'call', _140 => _140()]);
2795
+ const value = _optionalChain([headerOf, 'call', _151 => _151(req, name), 'optionalAccess', _152 => _152.trim, 'call', _153 => _153(), 'access', _154 => _154.toUpperCase, 'call', _155 => _155()]);
2581
2796
  if (value && /^[A-Z]{2}$/.test(value) && value !== "XX" && value !== "T1") {
2582
2797
  event.attributes["geo.country.iso_code"] = value;
2583
2798
  return;
@@ -2611,9 +2826,9 @@ var COMMIT_VARS = [
2611
2826
  "SOURCE_VERSION"
2612
2827
  ];
2613
2828
  function enrichDeployment(env = process.env) {
2614
- const pick = (names) => names.map((name) => _optionalChain([env, 'access', _141 => _141[name], 'optionalAccess', _142 => _142.trim, 'call', _143 => _143()])).find((value) => value);
2615
- const region = _optionalChain([pick, 'call', _144 => _144(REGION_VARS), 'optionalAccess', _145 => _145.slice, 'call', _146 => _146(0, 64)]);
2616
- const commit = _optionalChain([pick, 'call', _147 => _147(COMMIT_VARS), 'optionalAccess', _148 => _148.slice, 'call', _149 => _149(0, 64)]);
2829
+ const pick = (names) => names.map((name) => _optionalChain([env, 'access', _156 => _156[name], 'optionalAccess', _157 => _157.trim, 'call', _158 => _158()])).find((value) => value);
2830
+ const region = _optionalChain([pick, 'call', _159 => _159(REGION_VARS), 'optionalAccess', _160 => _160.slice, 'call', _161 => _161(0, 64)]);
2831
+ const commit = _optionalChain([pick, 'call', _162 => _162(COMMIT_VARS), 'optionalAccess', _163 => _163.slice, 'call', _164 => _164(0, 64)]);
2617
2832
  return (event) => {
2618
2833
  if (region) event.attributes["deployment.region"] = region;
2619
2834
  if (commit) event.attributes["deployment.commit"] = commit;
@@ -2674,4 +2889,4 @@ function enrichDeployment(env = process.env) {
2674
2889
 
2675
2890
 
2676
2891
 
2677
- exports.CODE_PATTERN = _chunk37W7YYXOcjs.CODE_PATTERN; exports.COMPAT_MANIFEST = _chunkMOZOUEMAcjs.COMPAT_MANIFEST; exports.INGESTER_VERSION_HEADER = _chunkMOZOUEMAcjs.INGESTER_VERSION_HEADER; exports.RuntimeError = _chunk37W7YYXOcjs.RuntimeError; exports.SDK_IDENTITY = _chunkMOZOUEMAcjs.SDK_IDENTITY; exports.addBreadcrumb = _chunk37W7YYXOcjs.addBreadcrumb; exports.autterErrorHandler = autterErrorHandler; exports.autterErrorResponse = autterErrorResponse; exports.autterFastify = autterFastify; exports.autterFastifyErrors = autterFastifyErrors; exports.autterKoa = autterKoa; exports.autterRequests = autterRequests; exports.captureException = captureException; exports.captureMessage = captureMessage; exports.captureRequestError = captureRequestError; exports.consoleSink = _chunk37W7YYXOcjs.consoleSink; exports.createBrowserRelayFetchHandler = createBrowserRelayFetchHandler; exports.createBrowserRelayHandler = createBrowserRelayHandler; exports.createRuntimeLogger = _chunk37W7YYXOcjs.createRuntimeLogger; exports.defineRuntimeErrors = _chunk37W7YYXOcjs.defineRuntimeErrors; exports.emitLlmSelftestTrace = emitLlmSelftestTrace; exports.enrichDeployment = enrichDeployment; exports.enrichEdgeGeo = enrichEdgeGeo; exports.enrichRequestSize = enrichRequestSize; exports.enrichUserAgent = enrichUserAgent; exports.errorAttributes = _chunk37W7YYXOcjs.errorAttributes; exports.evaluateCompat = _chunkMOZOUEMAcjs.evaluateCompat; exports.fetchIngesterCompat = _chunkMOZOUEMAcjs.fetchIngesterCompat; exports.fileSink = _chunk37W7YYXOcjs.fileSink; exports.flushRuntimeLogs = _chunk37W7YYXOcjs.flushRuntimeLogs; exports.initAutterLogging = initAutterLogging; exports.initAutterServer = initAutterServer; exports.installAutterAutoFlush = _chunkMOZOUEMAcjs.installAutterAutoFlush; exports.instrumentLlmClient = instrumentLlmClient; exports.isRuntimeErrorLike = _chunk37W7YYXOcjs.isRuntimeErrorLike; exports.makeSafeCapture = makeSafeCapture; exports.otlpSink = _chunk37W7YYXOcjs.otlpSink; exports.redactAttributes = _chunk37W7YYXOcjs.redactAttributes; exports.redactText = _chunk37W7YYXOcjs.redactText; exports.reportOutcome = reportOutcome; exports.runDoctor = _chunk7H3FCV4Pcjs.runDoctor; exports.runInBackground = _chunk37W7YYXOcjs.runInBackground; exports.runtimeContext = _chunk37W7YYXOcjs.runtimeContext; exports.runtimeLogStats = _chunk37W7YYXOcjs.runtimeLogStats; exports.runtimeLogger = _chunk37W7YYXOcjs.runtimeLogger; exports.sanitizeBrowserPayload = sanitizeBrowserPayload; exports.startCaughtExceptionSampler = startCaughtExceptionSampler; exports.toClientError = _chunk37W7YYXOcjs.toClientError; exports.trackLlmCall = trackLlmCall; exports.unhandledRejectionsMode = unhandledRejectionsMode; exports.withLlmCall = withLlmCall; exports.withProcessSpan = withProcessSpan; exports.withRuntimeOperation = _chunk37W7YYXOcjs.withRuntimeOperation; exports.withRuntimeRequest = withRuntimeRequest;
2892
+ exports.CODE_PATTERN = _chunkYWTIKZSIcjs.CODE_PATTERN; exports.COMPAT_MANIFEST = _chunkBHYHORUDcjs.COMPAT_MANIFEST; exports.INGESTER_VERSION_HEADER = _chunkBHYHORUDcjs.INGESTER_VERSION_HEADER; exports.RuntimeError = _chunkYWTIKZSIcjs.RuntimeError; exports.SDK_IDENTITY = _chunkBHYHORUDcjs.SDK_IDENTITY; exports.addBreadcrumb = _chunkYWTIKZSIcjs.addBreadcrumb; exports.autterErrorHandler = autterErrorHandler; exports.autterErrorResponse = autterErrorResponse; exports.autterFastify = autterFastify; exports.autterFastifyErrors = autterFastifyErrors; exports.autterKoa = autterKoa; exports.autterRequests = autterRequests; exports.captureException = captureException; exports.captureMessage = captureMessage; exports.captureRequestError = captureRequestError; exports.consoleSink = _chunkYWTIKZSIcjs.consoleSink; exports.createBrowserRelayFetchHandler = createBrowserRelayFetchHandler; exports.createBrowserRelayHandler = createBrowserRelayHandler; exports.createRuntimeLogger = _chunkYWTIKZSIcjs.createRuntimeLogger; exports.defineRuntimeErrors = _chunkYWTIKZSIcjs.defineRuntimeErrors; exports.emitLlmSelftestTrace = emitLlmSelftestTrace; exports.enrichDeployment = enrichDeployment; exports.enrichEdgeGeo = enrichEdgeGeo; exports.enrichRequestSize = enrichRequestSize; exports.enrichUserAgent = enrichUserAgent; exports.errorAttributes = _chunkYWTIKZSIcjs.errorAttributes; exports.evaluateCompat = _chunkBHYHORUDcjs.evaluateCompat; exports.fetchIngesterCompat = _chunkBHYHORUDcjs.fetchIngesterCompat; exports.fileSink = _chunkYWTIKZSIcjs.fileSink; exports.flushRuntimeLogs = _chunkYWTIKZSIcjs.flushRuntimeLogs; exports.initAutterLogging = initAutterLogging; exports.initAutterServer = initAutterServer; exports.installAutterAutoFlush = _chunkBHYHORUDcjs.installAutterAutoFlush; exports.instrumentLlmClient = instrumentLlmClient; exports.isRuntimeErrorLike = _chunkYWTIKZSIcjs.isRuntimeErrorLike; exports.makeSafeCapture = makeSafeCapture; exports.otlpSink = _chunkYWTIKZSIcjs.otlpSink; exports.redactAttributes = _chunkYWTIKZSIcjs.redactAttributes; exports.redactText = _chunkYWTIKZSIcjs.redactText; exports.reportOutcome = reportOutcome; exports.runDoctor = _chunkAN45KLWDcjs.runDoctor; exports.runInBackground = _chunkYWTIKZSIcjs.runInBackground; exports.runtimeContext = _chunkYWTIKZSIcjs.runtimeContext; exports.runtimeLogStats = _chunkYWTIKZSIcjs.runtimeLogStats; exports.runtimeLogger = _chunkYWTIKZSIcjs.runtimeLogger; exports.sanitizeBrowserPayload = sanitizeBrowserPayload; exports.startCaughtExceptionSampler = startCaughtExceptionSampler; exports.toClientError = _chunkYWTIKZSIcjs.toClientError; exports.trackLlmCall = trackLlmCall; exports.unhandledRejectionsMode = unhandledRejectionsMode; exports.withLlmCall = withLlmCall; exports.withProcessSpan = withProcessSpan; exports.withRuntimeOperation = _chunkYWTIKZSIcjs.withRuntimeOperation; exports.withRuntimeRequest = withRuntimeRequest;