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