@autter/runtime-node 1.9.0 → 1.10.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
@@ -51,11 +51,11 @@
51
51
 
52
52
 
53
53
 
54
- var _chunkYWTIKZSIcjs = require('./chunk-YWTIKZSI.cjs');
54
+ var _chunkSTOXJZ7Zcjs = require('./chunk-STOXJZ7Z.cjs');
55
55
 
56
56
 
57
- var _chunkAN45KLWDcjs = require('./chunk-AN45KLWD.cjs');
58
57
 
58
+ var _chunkHBH64LWQcjs = require('./chunk-HBH64LWQ.cjs');
59
59
 
60
60
 
61
61
 
@@ -76,7 +76,13 @@ var _chunkAN45KLWDcjs = require('./chunk-AN45KLWD.cjs');
76
76
 
77
77
 
78
78
 
79
- var _chunkBHYHORUDcjs = require('./chunk-BHYHORUD.cjs');
79
+
80
+
81
+
82
+
83
+
84
+
85
+ var _chunkS6WJ5YLPcjs = require('./chunk-S6WJ5YLP.cjs');
80
86
 
81
87
  // src/relay.ts
82
88
  var IpWindow = (_class = class {
@@ -336,7 +342,7 @@ function relayContext(raw, redactor) {
336
342
  return Array.isArray(bounded) ? {} : { context: redactor(bounded) };
337
343
  }
338
344
  function relayBreadcrumbs(raw, redactor) {
339
- const breadcrumbs = _chunkYWTIKZSIcjs.sanitizeBreadcrumbs.call(void 0, raw, redactor);
345
+ const breadcrumbs = _chunkSTOXJZ7Zcjs.sanitizeBreadcrumbs.call(void 0, raw, redactor);
340
346
  return breadcrumbs ? { breadcrumbs } : {};
341
347
  }
342
348
  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}$/;
@@ -353,23 +359,58 @@ function relayDebugIds(raw, redactor) {
353
359
  return count ? { debugIds } : {};
354
360
  }
355
361
  function relayFingerprint(raw, redactor) {
356
- const values = _chunkYWTIKZSIcjs.fingerprintValues.call(void 0, raw, redactor.text);
362
+ const values = _chunkSTOXJZ7Zcjs.fingerprintValues.call(void 0, raw, redactor.text);
357
363
  return values ? { fingerprint: Array.isArray(raw) ? values : values[0] } : {};
358
364
  }
359
- var defaultRelayRedactor = _chunkYWTIKZSIcjs.makeRedactor.call(void 0, true);
365
+ var defaultRelayRedactor = _chunkSTOXJZ7Zcjs.makeRedactor.call(void 0, true);
360
366
  function sanitizeBrowserPayload(raw, redactor = defaultRelayRedactor) {
361
- if (typeof raw !== "object" || raw === null) return null;
367
+ const checked = checkBrowserPayload(raw, redactor);
368
+ return "payload" in checked ? checked.payload : null;
369
+ }
370
+ var MAX_RELAY_ISSUES = 5;
371
+ function describe(value) {
372
+ if (value === null) return "null";
373
+ if (Array.isArray(value)) return "an array";
374
+ if (typeof value === "string") return value ? `"${value.slice(0, 40)}"` : "an empty string";
375
+ return typeof value === "undefined" ? "missing" : `a ${typeof value}`;
376
+ }
377
+ function checkBrowserPayload(raw, redactor = defaultRelayRedactor) {
378
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
379
+ return { issues: [{ path: [], message: `expected a JSON object, got ${describe(raw)}` }] };
380
+ }
362
381
  const p = raw;
363
- if (p.version !== 1) return null;
364
- if (typeof p.service !== "string" || !p.service) return null;
365
- if (typeof p.environment !== "string" || !p.environment) return null;
366
- if (!Array.isArray(p.events) || p.events.length > MAX_EVENTS) return null;
382
+ const issues = [];
383
+ const issue = (path, message) => {
384
+ if (issues.length < MAX_RELAY_ISSUES) issues.push({ path, message });
385
+ };
386
+ if (p.version !== 1) issue(["version"], `expected 1, got ${describe(p.version)}`);
387
+ if (typeof p.service !== "string" || !p.service) issue(["service"], `expected a non-empty string, got ${describe(p.service)}`);
388
+ if (typeof p.environment !== "string" || !p.environment) {
389
+ issue(["environment"], `expected a non-empty string, got ${describe(p.environment)}`);
390
+ }
391
+ if (!Array.isArray(p.events)) issue(["events"], `expected an array, got ${describe(p.events)}`);
392
+ else if (p.events.length > MAX_EVENTS) issue(["events"], `at most ${MAX_EVENTS} events per batch, got ${p.events.length}`);
393
+ if (Array.isArray(p.events) && p.events.length <= MAX_EVENTS) {
394
+ p.events.forEach((rawEvent, index) => {
395
+ if (typeof rawEvent !== "object" || rawEvent === null) {
396
+ issue(["events", index], `expected an object, got ${describe(rawEvent)}`);
397
+ return;
398
+ }
399
+ const e = rawEvent;
400
+ if (typeof e.type !== "string" || !EVENT_TYPES.has(e.type)) {
401
+ issue(["events", index, "type"], `expected one of ${[...EVENT_TYPES].join(", ")}, got ${describe(e.type)}`);
402
+ }
403
+ if (typeof e.timestamp !== "string") {
404
+ issue(["events", index, "timestamp"], `expected an ISO 8601 string, got ${describe(e.timestamp)}`);
405
+ }
406
+ });
407
+ }
408
+ if (issues.length) return { issues };
409
+ const service = p.service;
410
+ const environment = p.environment;
367
411
  const events = [];
368
412
  for (const rawEvent of p.events) {
369
- if (typeof rawEvent !== "object" || rawEvent === null) return null;
370
413
  const e = rawEvent;
371
- if (typeof e.type !== "string" || !EVENT_TYPES.has(e.type)) return null;
372
- if (typeof e.timestamp !== "string") return null;
373
414
  events.push({
374
415
  type: e.type,
375
416
  timestamp: e.timestamp,
@@ -390,55 +431,99 @@ function sanitizeBrowserPayload(raw, redactor = defaultRelayRedactor) {
390
431
  ...typeof e.traceId === "string" && TRACE_ID.test(e.traceId) ? { traceId: e.traceId } : {}
391
432
  });
392
433
  }
393
- return {
434
+ return { payload: {
394
435
  version: 1,
395
436
  ...typeof p.sessionId === "string" ? { sessionId: p.sessionId.slice(0, 100) } : {},
396
- service: p.service.slice(0, 200),
397
- environment: p.environment.slice(0, 100),
437
+ service: service.slice(0, 200),
438
+ environment: environment.slice(0, 100),
398
439
  ...typeof p.release === "string" ? { release: p.release.slice(0, 200) } : {},
399
440
  // @autter/runtime-browser version, for the ingester's compat records.
400
441
  ...typeof p.sdk === "string" && /^\d{1,6}\.\d{1,6}\.\d{1,6}[0-9A-Za-z.+-]{0,20}$/.test(p.sdk) ? { sdk: p.sdk } : {},
401
442
  events
402
- };
443
+ } };
403
444
  }
404
- function forward(payload, opts) {
445
+ var NO_KEY_BODY = {
446
+ error: "relay has no ingest key",
447
+ fix: "set AUTTER_RUNTIME_KEY (a server key, autter_rt_\u2026) where the relay runs"
448
+ };
449
+ var FORWARD_ATTEMPTS = 3;
450
+ var FORWARD_MAX_WAIT_MS = 1e4;
451
+ function forward(payload, opts, apiKey) {
405
452
  const endpoint = (_nullishCoalesce(opts.endpoint, () => ( DEFAULT_ENDPOINT))).replace(/\/$/, "");
406
453
  const url = `${endpoint}/v1/browser`;
407
454
  const compat = opts.compatCheck !== false;
408
- if (compat) _chunkBHYHORUDcjs.ensureCompatConfigured.call(void 0, endpoint);
409
- void fetch(url, {
410
- method: "POST",
411
- headers: {
412
- "content-type": "application/json",
413
- authorization: `Bearer ${opts.apiKey}`
414
- },
415
- body: JSON.stringify(payload),
416
- signal: AbortSignal.timeout(1e4)
417
- }).then((response) => {
455
+ if (compat) _chunkS6WJ5YLPcjs.ensureCompatConfigured.call(void 0, endpoint);
456
+ const body = JSON.stringify(payload);
457
+ const attempt = async (n) => {
458
+ let response;
459
+ try {
460
+ response = await fetch(url, {
461
+ method: "POST",
462
+ headers: {
463
+ "content-type": "application/json",
464
+ ..._chunkS6WJ5YLPcjs.authHeaders.call(void 0, apiKey)
465
+ },
466
+ body,
467
+ signal: AbortSignal.timeout(1e4)
468
+ });
469
+ } catch (err) {
470
+ if (n >= FORWARD_ATTEMPTS) throw err;
471
+ await sleep(1e3 * 2 ** (n - 1));
472
+ return attempt(n + 1);
473
+ }
474
+ if ((response.status === 429 || response.status >= 500) && n < FORWARD_ATTEMPTS) {
475
+ const seconds = Number(response.headers.get("retry-after"));
476
+ await _optionalChain([response, 'access', _3 => _3.body, 'optionalAccess', _4 => _4.cancel, 'call', _5 => _5(), 'access', _6 => _6.catch, 'call', _7 => _7(() => {
477
+ })]);
478
+ await sleep(seconds > 0 ? Math.min(seconds * 1e3, FORWARD_MAX_WAIT_MS) : 1e3 * 2 ** (n - 1));
479
+ return attempt(n + 1);
480
+ }
481
+ if (!response.ok) {
482
+ _chunkS6WJ5YLPcjs.noteIngestRefusal.call(void 0, {
483
+ status: response.status,
484
+ route: "/v1/browser",
485
+ endpoint,
486
+ body: await response.clone().text().catch(() => ""),
487
+ via: "relay"
488
+ });
489
+ }
418
490
  if (!compat) return;
419
491
  const types = new Set(
420
492
  (_nullishCoalesce(payload.events, () => ( []))).map((e) => String(e.type))
421
493
  );
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);
494
+ _chunkS6WJ5YLPcjs.observeIngesterResponse.call(void 0, { status: response.status, headers: response.headers });
495
+ for (const feature of _chunkS6WJ5YLPcjs.featuresForBrowserEvents.call(void 0, types)) _chunkS6WJ5YLPcjs.noteCompatFeature.call(void 0, feature);
424
496
  if ((_nullishCoalesce(payload.events, () => ( []))).some((e) => e.traceId)) {
425
- _chunkBHYHORUDcjs.noteCompatFeature.call(void 0, "browser_trace_propagation");
497
+ _chunkS6WJ5YLPcjs.noteCompatFeature.call(void 0, "browser_trace_propagation");
426
498
  }
427
- _chunkBHYHORUDcjs.noteRelayRejection.call(void 0, types, response.status, response.headers);
428
- }).catch((err) => {
499
+ _chunkS6WJ5YLPcjs.noteRelayRejection.call(void 0, types, response.status, response.headers);
500
+ };
501
+ void attempt(1).catch((err) => {
429
502
  (_nullishCoalesce(opts.onError, () => ( ((e) => console.warn("autter relay forward failed:", e)))))(
430
503
  err
431
504
  );
432
505
  });
433
506
  }
507
+ function sleep(ms) {
508
+ return new Promise((resolve) => setTimeout(resolve, ms));
509
+ }
434
510
  function createBrowserRelayFetchHandler(opts) {
435
511
  const maxBody = _nullishCoalesce(opts.maxBodyBytes, () => ( DEFAULT_MAX_BODY));
436
- const redactor = opts.redact === void 0 || opts.redact === true ? defaultRelayRedactor : _chunkYWTIKZSIcjs.makeRedactor.call(void 0, opts.redact);
512
+ const redactor = opts.redact === void 0 || opts.redact === true ? defaultRelayRedactor : _chunkSTOXJZ7Zcjs.makeRedactor.call(void 0, opts.redact);
437
513
  const limiter = opts.perIpRateLimit === false ? null : new IpWindow(_nullishCoalesce(opts.perIpRateLimit, () => ( 120)));
514
+ const apiKey = _chunkS6WJ5YLPcjs.resolveIngestKey.call(void 0, opts.apiKey);
515
+ if (!apiKey) _chunkS6WJ5YLPcjs.warnMissingKey.call(void 0, "relay");
516
+ else _chunkS6WJ5YLPcjs.warnKeyKind.call(void 0, apiKey);
438
517
  return async (request) => {
439
518
  if (request.method !== "POST") {
440
519
  return new Response(null, { status: 405 });
441
520
  }
521
+ if (!apiKey) {
522
+ return new Response(JSON.stringify(NO_KEY_BODY), {
523
+ status: 500,
524
+ headers: { "content-type": "application/json" }
525
+ });
526
+ }
442
527
  if (limiter) {
443
528
  const ip = fetchClientKey(request, opts);
444
529
  if (!limiter.allow(ip)) {
@@ -468,19 +553,20 @@ function createBrowserRelayFetchHandler(opts) {
468
553
  status: 400
469
554
  });
470
555
  }
471
- const payload = sanitizeBrowserPayload(raw, redactor);
472
- if (!payload) {
473
- return new Response(JSON.stringify({ error: "invalid payload" }), {
474
- status: 400
556
+ const checked = checkBrowserPayload(raw, redactor);
557
+ if (!("payload" in checked)) {
558
+ return new Response(JSON.stringify({ error: "invalid payload", issues: checked.issues }), {
559
+ status: 400,
560
+ headers: { "content-type": "application/json" }
475
561
  });
476
562
  }
477
- forward(payload, opts);
563
+ forward(checked.payload, opts, apiKey);
478
564
  return new Response(null, { status: 202 });
479
565
  };
480
566
  }
481
567
  function createBrowserRelayHandler(opts) {
482
568
  const maxBody = _nullishCoalesce(opts.maxBodyBytes, () => ( DEFAULT_MAX_BODY));
483
- const redactor = opts.redact === void 0 || opts.redact === true ? defaultRelayRedactor : _chunkYWTIKZSIcjs.makeRedactor.call(void 0, opts.redact);
569
+ const redactor = opts.redact === void 0 || opts.redact === true ? defaultRelayRedactor : _chunkSTOXJZ7Zcjs.makeRedactor.call(void 0, opts.redact);
484
570
  const limiter = opts.perIpRateLimit === false ? null : new IpWindow(_nullishCoalesce(opts.perIpRateLimit, () => ( 120)));
485
571
  function respond(res, status, body) {
486
572
  res.statusCode = status;
@@ -491,13 +577,16 @@ function createBrowserRelayHandler(opts) {
491
577
  res.end();
492
578
  }
493
579
  }
580
+ const apiKey = _chunkS6WJ5YLPcjs.resolveIngestKey.call(void 0, opts.apiKey);
581
+ if (!apiKey) _chunkS6WJ5YLPcjs.warnMissingKey.call(void 0, "relay");
582
+ else _chunkS6WJ5YLPcjs.warnKeyKind.call(void 0, apiKey);
494
583
  function handleParsed(raw, res) {
495
- const payload = sanitizeBrowserPayload(raw, redactor);
496
- if (!payload) {
497
- respond(res, 400, { error: "invalid payload" });
584
+ const checked = checkBrowserPayload(raw, redactor);
585
+ if (!("payload" in checked)) {
586
+ respond(res, 400, { error: "invalid payload", issues: checked.issues });
498
587
  return;
499
588
  }
500
- forward(payload, opts);
589
+ forward(checked.payload, opts, apiKey);
501
590
  respond(res, 202);
502
591
  }
503
592
  return (req, res) => {
@@ -505,6 +594,10 @@ function createBrowserRelayHandler(opts) {
505
594
  respond(res, 405);
506
595
  return;
507
596
  }
597
+ if (!apiKey) {
598
+ respond(res, 500, NO_KEY_BODY);
599
+ return;
600
+ }
508
601
  if (limiter) {
509
602
  const ip = nodeClientKey(req, opts);
510
603
  if (!limiter.allow(ip)) {
@@ -635,7 +728,7 @@ function makeUrlQueryPolicy(keepQueryParams = []) {
635
728
  if (!name.includes("?") && !name.includes("#")) return name;
636
729
  return name.split(" ").map((token) => {
637
730
  if (!token.startsWith("/") && !SCHEME.test(token)) return token;
638
- return _nullishCoalesce(_optionalChain([splitUrl, 'call', _3 => _3(token), 'optionalAccess', _4 => _4.base]), () => ( token));
731
+ return _nullishCoalesce(_optionalChain([splitUrl, 'call', _8 => _8(token), 'optionalAccess', _9 => _9.base]), () => ( token));
639
732
  }).join(" ");
640
733
  };
641
734
  return {
@@ -770,7 +863,7 @@ var RedactingSpanExporter = class {
770
863
  return this.inner.shutdown();
771
864
  }
772
865
  forceFlush() {
773
- return _nullishCoalesce(_optionalChain([this, 'access', _5 => _5.inner, 'access', _6 => _6.forceFlush, 'optionalCall', _7 => _7()]), () => ( Promise.resolve()));
866
+ return _nullishCoalesce(_optionalChain([this, 'access', _10 => _10.inner, 'access', _11 => _11.forceFlush, 'optionalCall', _12 => _12()]), () => ( Promise.resolve()));
774
867
  }
775
868
  };
776
869
  var RedactingMetricExporter = class {
@@ -806,6 +899,73 @@ var RedactingMetricExporter = class {
806
899
  }
807
900
  };
808
901
 
902
+ // src/ingest-exporters.ts
903
+
904
+
905
+
906
+
907
+ function refusalOf(result) {
908
+ if (result.code === _core.ExportResultCode.SUCCESS) return null;
909
+ const error = result.error;
910
+ return typeof _optionalChain([error, 'optionalAccess', _13 => _13.code]) === "number" ? { status: error.code, body: error.data } : null;
911
+ }
912
+ var NO_KEY = {
913
+ code: _core.ExportResultCode.FAILED,
914
+ error: new Error("no Autter ingest key: not sent (set AUTTER_RUNTIME_KEY)")
915
+ };
916
+ function observe(endpoint, route, callback) {
917
+ return (result) => {
918
+ const refusal = refusalOf(result);
919
+ if (refusal) _chunkS6WJ5YLPcjs.noteIngestRefusal.call(void 0, { ...refusal, endpoint, route });
920
+ callback(result);
921
+ };
922
+ }
923
+ var IngestSpanExporter = class {
924
+ constructor(inner, target) {
925
+ this.inner = inner;
926
+ this.target = target;
927
+ }
928
+
929
+
930
+ export(spans, resultCallback) {
931
+ if (!this.target.hasKey) {
932
+ resultCallback(NO_KEY);
933
+ return;
934
+ }
935
+ this.inner.export(spans, observe(this.target.endpoint, "/v1/traces", resultCallback));
936
+ }
937
+ shutdown() {
938
+ return this.inner.shutdown();
939
+ }
940
+ forceFlush() {
941
+ return _nullishCoalesce(_optionalChain([this, 'access', _14 => _14.inner, 'access', _15 => _15.forceFlush, 'optionalCall', _16 => _16()]), () => ( Promise.resolve()));
942
+ }
943
+ };
944
+ var IngestMetricExporter = class {
945
+ constructor(inner, target) {
946
+ this.inner = inner;
947
+ this.target = target;
948
+ }
949
+
950
+
951
+ export(metrics2, resultCallback) {
952
+ if (!this.target.hasKey) {
953
+ resultCallback(NO_KEY);
954
+ return;
955
+ }
956
+ this.inner.export(metrics2, observe(this.target.endpoint, "/v1/metrics", resultCallback));
957
+ }
958
+ forceFlush() {
959
+ return this.inner.forceFlush();
960
+ }
961
+ shutdown() {
962
+ return this.inner.shutdown();
963
+ }
964
+ selectAggregationTemporality(instrumentType) {
965
+ return this.inner.selectAggregationTemporality ? this.inner.selectAggregationTemporality(instrumentType) : _sdkmetrics.AggregationTemporality.CUMULATIVE;
966
+ }
967
+ };
968
+
809
969
  // src/memory.ts
810
970
  var _perf_hooks = require('perf_hooks');
811
971
  var _v8 = require('v8');
@@ -827,7 +987,7 @@ function startMemoryMetrics() {
827
987
  [heapUsed, (result) => result.observe(process.memoryUsage().heapUsed)],
828
988
  [heapLimit, (result) => result.observe(_v8.getHeapStatistics.call(void 0, ).heap_size_limit)],
829
989
  [containerLimit, (result) => {
830
- const constrained = _nullishCoalesce(_optionalChain([process, 'access', _8 => _8.constrainedMemory, 'optionalCall', _9 => _9()]), () => ( 0));
990
+ const constrained = _nullishCoalesce(_optionalChain([process, 'access', _17 => _17.constrainedMemory, 'optionalCall', _18 => _18()]), () => ( 0));
831
991
  if (constrained > 0) result.observe(constrained);
832
992
  }],
833
993
  [afterGc, (result) => {
@@ -878,19 +1038,19 @@ function decide(rule, error, fallback) {
878
1038
  }
879
1039
  function expressRouteOf(req) {
880
1040
  const props = req;
881
- const path = _optionalChain([props, 'optionalAccess', _10 => _10.route, 'optionalAccess', _11 => _11.path]);
1041
+ const path = _optionalChain([props, 'optionalAccess', _19 => _19.route, 'optionalAccess', _20 => _20.path]);
882
1042
  if (typeof path !== "string" || path === "") return null;
883
- const base = typeof _optionalChain([props, 'optionalAccess', _12 => _12.baseUrl]) === "string" ? props.baseUrl : "";
1043
+ const base = typeof _optionalChain([props, 'optionalAccess', _21 => _21.baseUrl]) === "string" ? props.baseUrl : "";
884
1044
  const route = base + path;
885
1045
  return route.startsWith("/") ? route : null;
886
1046
  }
887
1047
  function defaultShouldCapture(error) {
888
- return error instanceof _chunkYWTIKZSIcjs.RuntimeError || _chunkYWTIKZSIcjs.errorCodeOf.call(void 0, error) !== void 0 || _chunkYWTIKZSIcjs.responseStatusOf.call(void 0, error) >= 500;
1048
+ return error instanceof _chunkSTOXJZ7Zcjs.RuntimeError || _chunkSTOXJZ7Zcjs.errorCodeOf.call(void 0, error) !== void 0 || _chunkSTOXJZ7Zcjs.responseStatusOf.call(void 0, error) >= 500;
889
1049
  }
890
1050
  function onRequestSpan(fn) {
891
1051
  const active = _api.context.active();
892
1052
  const metadata = _core.getRPCMetadata.call(void 0, active);
893
- const span = _optionalChain([metadata, 'optionalAccess', _13 => _13.type]) === _core.RPCType.HTTP ? metadata.span : void 0;
1053
+ const span = _optionalChain([metadata, 'optionalAccess', _22 => _22.type]) === _core.RPCType.HTTP ? metadata.span : void 0;
894
1054
  if (!span || !span.isRecording() || _api.trace.getSpan(active) === span) {
895
1055
  fn();
896
1056
  return;
@@ -905,29 +1065,50 @@ function captureAtBoundary(error, state, rule = void 0, attributes) {
905
1065
  wanted = false;
906
1066
  }
907
1067
  if (!wanted) return;
908
- if (_chunkYWTIKZSIcjs.isCaptured.call(void 0, error)) return;
909
- _chunkYWTIKZSIcjs.markCaptured.call(void 0, error);
1068
+ if (_chunkSTOXJZ7Zcjs.isCaptured.call(void 0, error)) return;
1069
+ _chunkSTOXJZ7Zcjs.markCaptured.call(void 0, error);
910
1070
  try {
911
1071
  const run = () => onRequestSpan(() => capturer(error, attributes));
912
- if (state && !state.sealed) _chunkYWTIKZSIcjs.local.run(state, run);
1072
+ if (state && !state.sealed) _chunkSTOXJZ7Zcjs.local.run(state, run);
913
1073
  else run();
914
1074
  } catch (e17) {
915
1075
  }
916
1076
  }
1077
+ function requestScopeAttributes() {
1078
+ try {
1079
+ const out = {};
1080
+ const state = _chunkSTOXJZ7Zcjs.local.getStore();
1081
+ const active = _api.context.active();
1082
+ const metadata = _core.getRPCMetadata.call(void 0, active);
1083
+ const http = _optionalChain([metadata, 'optionalAccess', _23 => _23.type]) === _core.RPCType.HTTP ? metadata : void 0;
1084
+ const spanAttributes = _optionalChain([http, 'optionalAccess', _24 => _24.span, 'optionalAccess', _25 => _25.attributes]);
1085
+ const req = _optionalChain([state, 'optionalAccess', _26 => _26.req]);
1086
+ const nodeRequest = !!req && typeof req === "object" && typeof req.url === "string" && req.url.startsWith("/");
1087
+ const requestId = _nullishCoalesce(_optionalChain([state, 'optionalAccess', _27 => _27.requestId]), () => ( _optionalChain([spanAttributes, 'optionalAccess', _28 => _28["autter.request.id"]])));
1088
+ if (typeof requestId === "string" && requestId) out["autter.request.id"] = requestId;
1089
+ const route = _nullishCoalesce(_nullishCoalesce(_optionalChain([http, 'optionalAccess', _29 => _29.route]), () => ( _optionalChain([spanAttributes, 'optionalAccess', _30 => _30["http.route"]]))), () => ( (nodeRequest ? _nullishCoalesce(expressRouteOf(req), () => ( _chunkSTOXJZ7Zcjs.normalizeRoutePath.call(void 0, pathOf(req)))) : void 0)));
1090
+ if (typeof route === "string" && route) out["http.route"] = route;
1091
+ const method = _nullishCoalesce(_nullishCoalesce((nodeRequest ? req.method : void 0), () => ( _optionalChain([spanAttributes, 'optionalAccess', _31 => _31["http.request.method"]]))), () => ( _optionalChain([spanAttributes, 'optionalAccess', _32 => _32["http.method"]])));
1092
+ if (typeof method === "string" && method) out["http.request.method"] = method.toUpperCase();
1093
+ return Object.keys(out).length > 0 ? out : void 0;
1094
+ } catch (e18) {
1095
+ return void 0;
1096
+ }
1097
+ }
917
1098
  function requestStateOf(req) {
918
1099
  if (!req || typeof req !== "object") return void 0;
919
1100
  return req[REQUEST_STATE];
920
1101
  }
921
1102
  function captureRequestError(error, attributes) {
922
- if (_chunkYWTIKZSIcjs.isCaptured.call(void 0, error)) {
1103
+ if (_chunkSTOXJZ7Zcjs.isCaptured.call(void 0, error)) {
923
1104
  if (!attributes) return;
924
1105
  try {
925
1106
  onRequestSpan(() => annotator(attributes));
926
- } catch (e18) {
1107
+ } catch (e19) {
927
1108
  }
928
1109
  return;
929
1110
  }
930
- captureAtBoundary(error, _chunkYWTIKZSIcjs.currentOperation.call(void 0, ), true, attributes);
1111
+ captureAtBoundary(error, _chunkSTOXJZ7Zcjs.currentOperation.call(void 0, ), true, attributes);
931
1112
  }
932
1113
  function bindEmitter(emitter, state) {
933
1114
  const target = emitter;
@@ -939,7 +1120,7 @@ function bindEmitter(emitter, state) {
939
1120
  let wrapped = wrappers.get(listener);
940
1121
  if (!wrapped) {
941
1122
  wrapped = function(...args) {
942
- return _chunkYWTIKZSIcjs.local.run(
1123
+ return _chunkSTOXJZ7Zcjs.local.run(
943
1124
  state,
944
1125
  () => listener.apply(this, args)
945
1126
  );
@@ -994,7 +1175,7 @@ function exposeOnCors(res, header) {
994
1175
  if (value && key && inline) inline[key] = value;
995
1176
  else if (value) res.setHeader("access-control-expose-headers", value);
996
1177
  }
997
- } catch (e19) {
1178
+ } catch (e20) {
998
1179
  }
999
1180
  return original.apply(this, args);
1000
1181
  };
@@ -1006,7 +1187,7 @@ function pathOf(req) {
1006
1187
  function finishRequest(state, input) {
1007
1188
  if (state.sealed) return;
1008
1189
  state.name = (_nullishCoalesce(input.name, () => ( `${input.method} ${input.route}`))).slice(0, 200);
1009
- state.outcome = _chunkYWTIKZSIcjs.requestOutcome.call(void 0, {
1190
+ state.outcome = _chunkSTOXJZ7Zcjs.requestOutcome.call(void 0, {
1010
1191
  ...state.explicitOutcome ? { explicit: state.outcome } : {},
1011
1192
  ...state.error !== void 0 ? { error: state.error } : {},
1012
1193
  ...state.errorThrown ? { thrown: true } : {},
@@ -1015,15 +1196,15 @@ function finishRequest(state, input) {
1015
1196
  ...state.degraded ? { degraded: true } : {}
1016
1197
  });
1017
1198
  const span = _api.trace.getActiveSpan();
1018
- if (_optionalChain([span, 'optionalAccess', _14 => _14.isRecording, 'call', _15 => _15()])) span.setAttribute("autter.operation.outcome", state.outcome);
1199
+ if (_optionalChain([span, 'optionalAccess', _33 => _33.isRecording, 'call', _34 => _34()])) span.setAttribute("autter.operation.outcome", state.outcome);
1019
1200
  if (input.span) {
1020
1201
  const remote = _api.trace.wrapSpanContext(input.span);
1021
1202
  _api.context.with(
1022
1203
  _api.trace.setSpan(_api.context.active(), remote),
1023
- () => _chunkYWTIKZSIcjs.reportExplicitFailure.call(void 0, state)
1204
+ () => _chunkSTOXJZ7Zcjs.reportExplicitFailure.call(void 0, state)
1024
1205
  );
1025
- } else _chunkYWTIKZSIcjs.reportExplicitFailure.call(void 0, state);
1026
- _chunkYWTIKZSIcjs.emitSummary.call(void 0, state, {
1206
+ } else _chunkSTOXJZ7Zcjs.reportExplicitFailure.call(void 0, state);
1207
+ _chunkSTOXJZ7Zcjs.emitSummary.call(void 0, state, {
1027
1208
  http: {
1028
1209
  "http.request.method": input.method,
1029
1210
  "http.route": input.route,
@@ -1034,14 +1215,14 @@ function finishRequest(state, input) {
1034
1215
  });
1035
1216
  }
1036
1217
  function beginNodeRequest(req, res, options, route) {
1037
- const header = (_nullishCoalesce(options.requestIdHeader, () => ( _chunkYWTIKZSIcjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
1038
- const requestId = _chunkYWTIKZSIcjs.resolveRequestId.call(void 0,
1218
+ const header = (_nullishCoalesce(options.requestIdHeader, () => ( _chunkSTOXJZ7Zcjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
1219
+ const requestId = _chunkSTOXJZ7Zcjs.resolveRequestId.call(void 0,
1039
1220
  options.trustRequestId === false ? void 0 : req.headers[header]
1040
1221
  );
1041
1222
  const method = (_nullishCoalesce(req.method, () => ( "GET"))).toUpperCase();
1042
1223
  const path = pathOf(req);
1043
- const state = _chunkYWTIKZSIcjs.createRequestState.call(void 0, {
1044
- name: `${method} ${_chunkYWTIKZSIcjs.normalizeRoutePath.call(void 0, path)}`,
1224
+ const state = _chunkSTOXJZ7Zcjs.createRequestState.call(void 0, {
1225
+ name: `${method} ${_chunkSTOXJZ7Zcjs.normalizeRoutePath.call(void 0, path)}`,
1045
1226
  requestId,
1046
1227
  req,
1047
1228
  res
@@ -1050,22 +1231,22 @@ function beginNodeRequest(req, res, options, route) {
1050
1231
  try {
1051
1232
  if (!res.headersSent) res.setHeader(header, requestId);
1052
1233
  exposeOnCors(res, header);
1053
- } catch (e20) {
1234
+ } catch (e21) {
1054
1235
  }
1055
1236
  const span = _api.trace.getActiveSpan();
1056
- if (_optionalChain([span, 'optionalAccess', _16 => _16.isRecording, 'call', _17 => _17()]))
1237
+ if (_optionalChain([span, 'optionalAccess', _35 => _35.isRecording, 'call', _36 => _36()]))
1057
1238
  span.setAttributes({
1058
1239
  "autter.request.id": requestId,
1059
1240
  "autter.operation.kind": "request"
1060
1241
  });
1061
- const spanContext = _optionalChain([span, 'optionalAccess', _18 => _18.spanContext, 'call', _19 => _19()]);
1242
+ const spanContext = _optionalChain([span, 'optionalAccess', _37 => _37.spanContext, 'call', _38 => _38()]);
1062
1243
  bindEmitter(req, state);
1063
1244
  bindEmitter(res, state);
1064
1245
  let finished = false;
1065
1246
  const done = () => {
1066
1247
  finishRequest(state, {
1067
1248
  method,
1068
- route: _nullishCoalesce(_nullishCoalesce(_optionalChain([route, 'optionalCall', _20 => _20()]), () => ( expressRouteOf(req))), () => ( _chunkYWTIKZSIcjs.normalizeRoutePath.call(void 0, path))),
1249
+ route: _nullishCoalesce(_nullishCoalesce(_optionalChain([route, 'optionalCall', _39 => _39()]), () => ( expressRouteOf(req))), () => ( _chunkSTOXJZ7Zcjs.normalizeRoutePath.call(void 0, path))),
1069
1250
  status: res.statusCode,
1070
1251
  aborted: !finished,
1071
1252
  ...spanContext ? { span: spanContext } : {}
@@ -1079,50 +1260,50 @@ function beginNodeRequest(req, res, options, route) {
1079
1260
  return state;
1080
1261
  }
1081
1262
  function autterRequests(options = {}) {
1082
- const ignored = _chunkYWTIKZSIcjs.compileIgnore.call(void 0, options.ignore);
1263
+ const ignored = _chunkSTOXJZ7Zcjs.compileIgnore.call(void 0, options.ignore);
1083
1264
  return function autterRequestsMiddleware(req, res, next) {
1084
1265
  if (req[REQUEST_STATE] || ignored(pathOf(req))) {
1085
1266
  next();
1086
1267
  return;
1087
1268
  }
1088
1269
  const state = beginNodeRequest(req, res, options);
1089
- _chunkYWTIKZSIcjs.local.run(state, () => next());
1270
+ _chunkSTOXJZ7Zcjs.local.run(state, () => next());
1090
1271
  };
1091
1272
  }
1092
1273
  function autterErrorResponse(options = {}) {
1093
1274
  return function autterErrorResponseMiddleware(error, req, res, next) {
1094
1275
  const state = req[REQUEST_STATE];
1095
- if (state) _chunkYWTIKZSIcjs.noteOperationError.call(void 0, error, true, state);
1276
+ if (state) _chunkSTOXJZ7Zcjs.noteOperationError.call(void 0, error, true, state);
1096
1277
  captureAtBoundary(error, state, options.capture);
1097
1278
  if (res.headersSent) {
1098
1279
  next(error);
1099
1280
  return;
1100
1281
  }
1101
- const header = (_nullishCoalesce(options.requestIdHeader, () => ( _chunkYWTIKZSIcjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
1102
- const inbound = _optionalChain([req, 'access', _21 => _21.headers, 'optionalAccess', _22 => _22[header]]);
1103
- const requestId = _nullishCoalesce(_optionalChain([state, 'optionalAccess', _23 => _23.requestId]), () => ( (typeof inbound === "string" ? inbound.slice(0, 128) : void 0)));
1104
- res.statusCode = _chunkYWTIKZSIcjs.responseStatusOf.call(void 0, error);
1282
+ const header = (_nullishCoalesce(options.requestIdHeader, () => ( _chunkSTOXJZ7Zcjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
1283
+ const inbound = _optionalChain([req, 'access', _40 => _40.headers, 'optionalAccess', _41 => _41[header]]);
1284
+ const requestId = _nullishCoalesce(_optionalChain([state, 'optionalAccess', _42 => _42.requestId]), () => ( (typeof inbound === "string" ? inbound.slice(0, 128) : void 0)));
1285
+ res.statusCode = _chunkSTOXJZ7Zcjs.responseStatusOf.call(void 0, error);
1105
1286
  res.setHeader("content-type", "application/json; charset=utf-8");
1106
- res.end(JSON.stringify(_chunkYWTIKZSIcjs.toClientError.call(void 0, error, requestId)));
1287
+ res.end(JSON.stringify(_chunkSTOXJZ7Zcjs.toClientError.call(void 0, error, requestId)));
1107
1288
  };
1108
1289
  }
1109
1290
  var RESOURCE = /* @__PURE__ */ Symbol.for("autter.runtime.resource");
1110
1291
  function autterFastify(fastify, options, done) {
1111
1292
  const opts = _nullishCoalesce(options, () => ( {}));
1112
- const header = (_nullishCoalesce(opts.requestIdHeader, () => ( _chunkYWTIKZSIcjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
1113
- const ignored = _chunkYWTIKZSIcjs.compileIgnore.call(void 0, opts.ignore);
1293
+ const header = (_nullishCoalesce(opts.requestIdHeader, () => ( _chunkSTOXJZ7Zcjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
1294
+ const ignored = _chunkSTOXJZ7Zcjs.compileIgnore.call(void 0, opts.ignore);
1114
1295
  const stateOf = (request) => request[REQUEST_STATE];
1115
1296
  fastify.addHook("onRequest", ((request, reply, next) => {
1116
1297
  if (ignored(request.url) || request.raw[REQUEST_STATE]) {
1117
1298
  next();
1118
1299
  return;
1119
1300
  }
1120
- const requestId = _chunkYWTIKZSIcjs.resolveRequestId.call(void 0,
1301
+ const requestId = _chunkSTOXJZ7Zcjs.resolveRequestId.call(void 0,
1121
1302
  opts.trustRequestId === false ? void 0 : request.headers[header]
1122
1303
  );
1123
1304
  const method = String(_nullishCoalesce(request.method, () => ( "GET"))).toUpperCase();
1124
- const state = _chunkYWTIKZSIcjs.createRequestState.call(void 0, {
1125
- name: `${method} ${_chunkYWTIKZSIcjs.normalizeRoutePath.call(void 0, request.url)}`,
1305
+ const state = _chunkSTOXJZ7Zcjs.createRequestState.call(void 0, {
1306
+ name: `${method} ${_chunkSTOXJZ7Zcjs.normalizeRoutePath.call(void 0, request.url)}`,
1126
1307
  requestId,
1127
1308
  req: request.raw,
1128
1309
  res: reply.raw
@@ -1131,18 +1312,18 @@ function autterFastify(fastify, options, done) {
1131
1312
  request.raw[REQUEST_STATE] = state;
1132
1313
  reply.header(header, requestId);
1133
1314
  const span = _api.trace.getActiveSpan();
1134
- if (_optionalChain([span, 'optionalAccess', _24 => _24.isRecording, 'call', _25 => _25()]))
1315
+ if (_optionalChain([span, 'optionalAccess', _43 => _43.isRecording, 'call', _44 => _44()]))
1135
1316
  span.setAttributes({
1136
1317
  "autter.request.id": requestId,
1137
1318
  "autter.operation.kind": "request"
1138
1319
  });
1139
- const spanContext = _optionalChain([span, 'optionalAccess', _26 => _26.spanContext, 'call', _27 => _27()]);
1320
+ const spanContext = _optionalChain([span, 'optionalAccess', _45 => _45.spanContext, 'call', _46 => _46()]);
1140
1321
  bindEmitter(request.raw, state);
1141
1322
  bindEmitter(reply.raw, state);
1142
1323
  let finished = false;
1143
1324
  const finish = (aborted) => finishRequest(state, {
1144
1325
  method,
1145
- route: _nullishCoalesce(_nullishCoalesce(_optionalChain([request, 'access', _28 => _28.routeOptions, 'optionalAccess', _29 => _29.url]), () => ( request.routerPath)), () => ( _chunkYWTIKZSIcjs.normalizeRoutePath.call(void 0, request.url))),
1326
+ route: _nullishCoalesce(_nullishCoalesce(_optionalChain([request, 'access', _47 => _47.routeOptions, 'optionalAccess', _48 => _48.url]), () => ( request.routerPath)), () => ( _chunkSTOXJZ7Zcjs.normalizeRoutePath.call(void 0, request.url))),
1146
1327
  status: reply.raw.statusCode || reply.statusCode,
1147
1328
  aborted,
1148
1329
  ...spanContext ? { span: spanContext } : {}
@@ -1152,7 +1333,7 @@ function autterFastify(fastify, options, done) {
1152
1333
  finish(false);
1153
1334
  });
1154
1335
  reply.raw.once("close", () => finish(!finished));
1155
- _chunkYWTIKZSIcjs.local.run(state, () => {
1336
+ _chunkSTOXJZ7Zcjs.local.run(state, () => {
1156
1337
  request[RESOURCE] = new (0, _async_hooks.AsyncResource)("autter-request");
1157
1338
  next();
1158
1339
  });
@@ -1168,13 +1349,13 @@ function autterFastify(fastify, options, done) {
1168
1349
  const value = exposeHeaderValue(reply.getHeader("access-control-expose-headers"), header);
1169
1350
  if (value) reply.header("access-control-expose-headers", value);
1170
1351
  }
1171
- } catch (e21) {
1352
+ } catch (e22) {
1172
1353
  }
1173
1354
  next(null, payload);
1174
1355
  }));
1175
1356
  fastify.addHook("onError", ((request, _reply, error, next) => {
1176
1357
  const state = stateOf(request);
1177
- if (state) _chunkYWTIKZSIcjs.noteOperationError.call(void 0, error, true, state);
1358
+ if (state) _chunkSTOXJZ7Zcjs.noteOperationError.call(void 0, error, true, state);
1178
1359
  captureAtBoundary(error, state);
1179
1360
  next();
1180
1361
  }));
@@ -1196,54 +1377,54 @@ function withHeaders(response, header, requestId) {
1196
1377
  };
1197
1378
  try {
1198
1379
  return apply(response);
1199
- } catch (e22) {
1380
+ } catch (e23) {
1200
1381
  try {
1201
1382
  return apply(new Response(response.body, response));
1202
- } catch (e23) {
1383
+ } catch (e24) {
1203
1384
  return response;
1204
1385
  }
1205
1386
  }
1206
1387
  }
1207
1388
  function withRuntimeRequest(handler, options = {}) {
1208
- const header = (_nullishCoalesce(options.requestIdHeader, () => ( _chunkYWTIKZSIcjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
1209
- const ignored = _chunkYWTIKZSIcjs.compileIgnore.call(void 0, options.ignore);
1389
+ const header = (_nullishCoalesce(options.requestIdHeader, () => ( _chunkSTOXJZ7Zcjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
1390
+ const ignored = _chunkSTOXJZ7Zcjs.compileIgnore.call(void 0, options.ignore);
1210
1391
  return async (request, ...rest) => {
1211
1392
  let pathname = "/";
1212
1393
  try {
1213
1394
  pathname = new URL(request.url, "http://localhost").pathname;
1214
- } catch (e24) {
1395
+ } catch (e25) {
1215
1396
  }
1216
1397
  if (ignored(pathname)) return handler(request, ...rest);
1217
- const requestId = _chunkYWTIKZSIcjs.resolveRequestId.call(void 0,
1398
+ const requestId = _chunkSTOXJZ7Zcjs.resolveRequestId.call(void 0,
1218
1399
  options.trustRequestId === false ? void 0 : request.headers.get(header)
1219
1400
  );
1220
1401
  const method = String(_nullishCoalesce(request.method, () => ( "GET"))).toUpperCase();
1221
- const route = _nullishCoalesce(options.route, () => ( _chunkYWTIKZSIcjs.normalizeRoutePath.call(void 0, pathname)));
1222
- const state = _chunkYWTIKZSIcjs.createRequestState.call(void 0, {
1402
+ const route = _nullishCoalesce(options.route, () => ( _chunkSTOXJZ7Zcjs.normalizeRoutePath.call(void 0, pathname)));
1403
+ const state = _chunkSTOXJZ7Zcjs.createRequestState.call(void 0, {
1223
1404
  name: `${method} ${_nullishCoalesce(options.name, () => ( route))}`,
1224
1405
  requestId,
1225
1406
  req: request
1226
1407
  });
1227
1408
  const span = _api.trace.getActiveSpan();
1228
- if (_optionalChain([span, 'optionalAccess', _30 => _30.isRecording, 'call', _31 => _31()]))
1409
+ if (_optionalChain([span, 'optionalAccess', _49 => _49.isRecording, 'call', _50 => _50()]))
1229
1410
  span.setAttributes({
1230
1411
  "autter.request.id": requestId,
1231
1412
  "autter.operation.kind": "request"
1232
1413
  });
1233
- const spanContext = _optionalChain([span, 'optionalAccess', _32 => _32.spanContext, 'call', _33 => _33()]);
1414
+ const spanContext = _optionalChain([span, 'optionalAccess', _51 => _51.spanContext, 'call', _52 => _52()]);
1234
1415
  let status = 500;
1235
1416
  try {
1236
- const response = await _chunkYWTIKZSIcjs.local.run(state, async () => {
1417
+ const response = await _chunkSTOXJZ7Zcjs.local.run(state, async () => {
1237
1418
  try {
1238
1419
  return await handler(request, ...rest);
1239
1420
  } catch (error) {
1240
1421
  if (decide(options.capture, error, true)) {
1241
- _chunkYWTIKZSIcjs.noteOperationError.call(void 0, error, true, state);
1422
+ _chunkSTOXJZ7Zcjs.noteOperationError.call(void 0, error, true, state);
1242
1423
  captureAtBoundary(error, state, true);
1243
1424
  }
1244
1425
  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),
1426
+ return new Response(JSON.stringify(_chunkSTOXJZ7Zcjs.toClientError.call(void 0, error, requestId)), {
1427
+ status: _chunkSTOXJZ7Zcjs.responseStatusOf.call(void 0, error),
1247
1428
  headers: { "content-type": "application/json; charset=utf-8" }
1248
1429
  });
1249
1430
  }
@@ -1251,7 +1432,7 @@ function withRuntimeRequest(handler, options = {}) {
1251
1432
  status = response.status;
1252
1433
  return withHeaders(response, header, requestId);
1253
1434
  } finally {
1254
- const aborted = _optionalChain([request, 'access', _34 => _34.signal, 'optionalAccess', _35 => _35.aborted]) === true;
1435
+ const aborted = _optionalChain([request, 'access', _53 => _53.signal, 'optionalAccess', _54 => _54.aborted]) === true;
1255
1436
  finishRequest(state, {
1256
1437
  method,
1257
1438
  route,
@@ -1262,9 +1443,9 @@ function withRuntimeRequest(handler, options = {}) {
1262
1443
  });
1263
1444
  if (options.waitUntil) {
1264
1445
  try {
1265
- options.waitUntil(_chunkYWTIKZSIcjs.flushRuntimeLogs.call(void 0, ).catch(() => {
1446
+ options.waitUntil(_chunkSTOXJZ7Zcjs.flushRuntimeLogs.call(void 0, ).catch(() => {
1266
1447
  }));
1267
- } catch (e25) {
1448
+ } catch (e26) {
1268
1449
  }
1269
1450
  }
1270
1451
  }
@@ -1274,7 +1455,7 @@ function startHookRequest(res) {
1274
1455
  const req = res.req;
1275
1456
  if (!req || req[REQUEST_STATE]) return;
1276
1457
  const state = beginNodeRequest(req, res, {});
1277
- _chunkYWTIKZSIcjs.local.enterWith(state);
1458
+ _chunkSTOXJZ7Zcjs.local.enterWith(state);
1278
1459
  }
1279
1460
 
1280
1461
  // src/unhandled-rejections.ts
@@ -1300,7 +1481,7 @@ var recorded = /* @__PURE__ */ new WeakSet();
1300
1481
  function markRecorded(reason) {
1301
1482
  if (!reason || typeof reason !== "object") return;
1302
1483
  recorded.add(reason);
1303
- _optionalChain([setImmediate, 'call', _36 => _36(() => recorded.delete(reason)), 'access', _37 => _37.unref, 'optionalCall', _38 => _38()]);
1484
+ _optionalChain([setImmediate, 'call', _55 => _55(() => recorded.delete(reason)), 'access', _56 => _56.unref, 'optionalCall', _57 => _57()]);
1304
1485
  }
1305
1486
  function recordedAsRejection(error) {
1306
1487
  return !!error && typeof error === "object" && recorded.has(error);
@@ -1326,7 +1507,7 @@ function unhandledRejectionsMode(execArgv = process.execArgv, nodeOptions = proc
1326
1507
  function isErrorLike(value) {
1327
1508
  try {
1328
1509
  return typeof value === "object" && value !== null && Object.prototype.hasOwnProperty.call(value, "stack");
1329
- } catch (e26) {
1510
+ } catch (e27) {
1330
1511
  return false;
1331
1512
  }
1332
1513
  }
@@ -1334,16 +1515,16 @@ function describeReason(reason) {
1334
1515
  if (typeof reason !== "object" && typeof reason !== "function" || reason === null) {
1335
1516
  try {
1336
1517
  return String(reason);
1337
- } catch (e27) {
1518
+ } catch (e28) {
1338
1519
  return typeof reason;
1339
1520
  }
1340
1521
  }
1341
1522
  try {
1342
1523
  const proto = Object.getPrototypeOf(reason);
1343
- const ctor = _optionalChain([proto, 'optionalAccess', _39 => _39.constructor]);
1524
+ const ctor = _optionalChain([proto, 'optionalAccess', _58 => _58.constructor]);
1344
1525
  const name = typeof ctor === "function" ? ctor.name : "";
1345
1526
  return name ? `#<${name}>` : "[object Object]";
1346
- } catch (e28) {
1527
+ } catch (e29) {
1347
1528
  return "[object Object]";
1348
1529
  }
1349
1530
  }
@@ -1354,7 +1535,7 @@ function toUncaught(reason, from) {
1354
1535
  );
1355
1536
  error.name = "UnhandledPromiseRejection";
1356
1537
  error.code = "ERR_UNHANDLED_REJECTION";
1357
- _optionalChain([Error, 'access', _40 => _40.captureStackTrace, 'optionalCall', _41 => _41(error, from)]);
1538
+ _optionalChain([Error, 'access', _59 => _59.captureStackTrace, 'optionalCall', _60 => _60(error, from)]);
1358
1539
  return error;
1359
1540
  }
1360
1541
  var warningId = 0;
@@ -1366,7 +1547,7 @@ function emitNodeWarning(reason) {
1366
1547
  `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})`,
1367
1548
  "UnhandledPromiseRejectionWarning"
1368
1549
  );
1369
- } catch (e29) {
1550
+ } catch (e30) {
1370
1551
  }
1371
1552
  }
1372
1553
  function installUnhandledRejectionCapture(capture, mode = unhandledRejectionsMode()) {
@@ -1393,7 +1574,7 @@ function installUnhandledRejectionCapture(capture, mode = unhandledRejectionsMod
1393
1574
  }
1394
1575
  markRecorded(reason);
1395
1576
  capture(reason);
1396
- } catch (e30) {
1577
+ } catch (e31) {
1397
1578
  }
1398
1579
  };
1399
1580
  listener[LISTENER_MARK] = true;
@@ -1403,14 +1584,181 @@ function installUnhandledRejectionCapture(capture, mode = unhandledRejectionsMod
1403
1584
  };
1404
1585
  }
1405
1586
 
1587
+ // src/express-errors.ts
1588
+
1589
+
1590
+
1591
+ var _requireinthemiddle = require('require-in-the-middle');
1592
+ var PATCHED = /* @__PURE__ */ Symbol.for("autter.runtime.express.layer");
1593
+ var WRAPPED = /* @__PURE__ */ Symbol.for("autter.runtime.express.next");
1594
+ var ERRORS = /* @__PURE__ */ Symbol.for("autter.runtime.express.errors");
1595
+ var MAX_ERRORS = 8;
1596
+ function noteExpressError(req, error) {
1597
+ if (error === void 0 || error === null || error === false) return;
1598
+ if (error === "route" || error === "router") return;
1599
+ if (!req || typeof req !== "object") return;
1600
+ try {
1601
+ const target = req;
1602
+ let list = target[ERRORS];
1603
+ if (!list) {
1604
+ list = [];
1605
+ target[ERRORS] = list;
1606
+ }
1607
+ if (list.length < MAX_ERRORS && !list.includes(error)) list.push(error);
1608
+ } catch (e32) {
1609
+ }
1610
+ }
1611
+ function wrapNext(req, next) {
1612
+ if (typeof next !== "function") return next;
1613
+ const fn = next;
1614
+ const existing = fn[WRAPPED];
1615
+ if (existing) return existing;
1616
+ const wrapped = function autterExpressNext(...args) {
1617
+ if (args.length > 0) noteExpressError(req, args[0]);
1618
+ return fn.apply(this, args);
1619
+ };
1620
+ try {
1621
+ fn[WRAPPED] = wrapped;
1622
+ } catch (e33) {
1623
+ }
1624
+ return wrapped;
1625
+ }
1626
+ function patchLayerPrototype(proto) {
1627
+ if (!proto || typeof proto !== "object") return false;
1628
+ const target = proto;
1629
+ if (target[PATCHED]) return true;
1630
+ const requestName = typeof target.handleRequest === "function" ? "handleRequest" : typeof target.handle_request === "function" ? "handle_request" : null;
1631
+ const errorName = typeof target.handleError === "function" ? "handleError" : typeof target.handle_error === "function" ? "handle_error" : null;
1632
+ if (!requestName || !errorName) return false;
1633
+ const handleRequest = target[requestName];
1634
+ const handleError = target[errorName];
1635
+ target[requestName] = function autterHandleRequest(req, res, next) {
1636
+ let wrapped = next;
1637
+ try {
1638
+ wrapped = wrapNext(req, next);
1639
+ } catch (e34) {
1640
+ wrapped = next;
1641
+ }
1642
+ return handleRequest.call(this, req, res, wrapped);
1643
+ };
1644
+ target[errorName] = function autterHandleError(error, req, res, next) {
1645
+ let wrapped = next;
1646
+ try {
1647
+ noteExpressError(req, error);
1648
+ wrapped = wrapNext(req, next);
1649
+ } catch (e35) {
1650
+ wrapped = next;
1651
+ }
1652
+ return handleError.call(this, error, req, res, wrapped);
1653
+ };
1654
+ try {
1655
+ Object.defineProperty(target, PATCHED, { value: true });
1656
+ } catch (e36) {
1657
+ target[PATCHED] = true;
1658
+ }
1659
+ return true;
1660
+ }
1661
+ var LAYER_FILES = ["express/lib/router/layer.js", "router/lib/layer.js"];
1662
+ function patchLayerModule(exports) {
1663
+ try {
1664
+ const Layer = exports;
1665
+ if (typeof Layer === "function" && patchLayerPrototype(Layer.prototype))
1666
+ _chunkS6WJ5YLPcjs.debugLog.call(void 0, "express: error capture installed");
1667
+ } catch (e37) {
1668
+ }
1669
+ }
1670
+ function scanModuleCache() {
1671
+ try {
1672
+ const cache = _module.createRequire.call(void 0, _path.join.call(void 0, process.cwd(), "autter-runtime-express.cjs")).cache;
1673
+ for (const [key, entry] of Object.entries(cache)) {
1674
+ const path = key.replace(/\\/g, "/");
1675
+ if (LAYER_FILES.some((file) => path.endsWith(`/node_modules/${file}`)))
1676
+ patchLayerModule(_optionalChain([entry, 'optionalAccess', _61 => _61.exports]));
1677
+ }
1678
+ } catch (e38) {
1679
+ }
1680
+ }
1681
+ var installed = false;
1682
+ function installExpressErrorCapture() {
1683
+ if (installed) return;
1684
+ installed = true;
1685
+ scanModuleCache();
1686
+ try {
1687
+ new (0, _requireinthemiddle.Hook)(["express", "router"], { internals: true }, (exports, name) => {
1688
+ const file = name.replace(/\\/g, "/");
1689
+ if (LAYER_FILES.includes(file)) patchLayerModule(exports);
1690
+ return exports;
1691
+ });
1692
+ } catch (e39) {
1693
+ }
1694
+ }
1695
+ function patchFromRequest(req) {
1696
+ try {
1697
+ const app = _optionalChain([req, 'optionalAccess', _62 => _62.app]);
1698
+ if (!app || typeof app !== "function" && typeof app !== "object") return;
1699
+ const router = _nullishCoalesce(app._router, () => ( app.router));
1700
+ const layer = _optionalChain([router, 'optionalAccess', _63 => _63.stack, 'optionalAccess', _64 => _64[0]]);
1701
+ if (layer && typeof layer === "object" && patchLayerPrototype(Object.getPrototypeOf(layer)))
1702
+ _chunkS6WJ5YLPcjs.debugLog.call(void 0, "express: error capture installed (from a request)");
1703
+ } catch (e40) {
1704
+ }
1705
+ }
1706
+ function declaredStatus(error) {
1707
+ if (!error || typeof error !== "object") return void 0;
1708
+ try {
1709
+ const value = _nullishCoalesce(error.status, () => ( error.statusCode));
1710
+ const status = typeof value === "string" ? Number(value) : value;
1711
+ return typeof status === "number" && Number.isInteger(status) && status >= 400 && status < 600 ? status : void 0;
1712
+ } catch (e41) {
1713
+ return void 0;
1714
+ }
1715
+ }
1716
+ function watchExpressResponse(span, res, enabled) {
1717
+ const req = res.req;
1718
+ if (!req) return;
1719
+ const ctx = _api.context.active();
1720
+ let done = false;
1721
+ const settle = (finished) => {
1722
+ if (done) return;
1723
+ done = true;
1724
+ try {
1725
+ const errors = req[ERRORS];
1726
+ if (!_optionalChain([errors, 'optionalAccess', _65 => _65.length])) {
1727
+ patchFromRequest(req);
1728
+ return;
1729
+ }
1730
+ req[ERRORS] = void 0;
1731
+ if (!enabled()) return;
1732
+ if (finished && !(res.statusCode >= 500)) return;
1733
+ if (errors.some((error2) => _chunkSTOXJZ7Zcjs.isCaptured.call(void 0, error2))) return;
1734
+ const error = errors.find((candidate) => {
1735
+ const status = declaredStatus(candidate);
1736
+ return status === void 0 || status >= 500;
1737
+ });
1738
+ if (error === void 0) return;
1739
+ const state = requestStateOf(req);
1740
+ if (state && !state.sealed) _chunkSTOXJZ7Zcjs.noteOperationError.call(void 0, error, false, state);
1741
+ const run = () => captureAtBoundary(error, state, true);
1742
+ if (span.isRecording()) _api.context.with(_api.trace.setSpan(ctx, span), run);
1743
+ else _api.context.with(ctx, run);
1744
+ } catch (e42) {
1745
+ }
1746
+ };
1747
+ try {
1748
+ res.prependListener("finish", () => settle(true));
1749
+ res.prependListener("close", () => settle(false));
1750
+ } catch (e43) {
1751
+ }
1752
+ }
1753
+
1406
1754
  // src/route-label.ts
1407
1755
 
1408
1756
  var ours = /* @__PURE__ */ new WeakMap();
1409
1757
  var RAW_PATH_SPAN_TYPES = /* @__PURE__ */ new Set(["BaseServer.renderToResponse"]);
1410
1758
  function noteFrameworkRoute(parent, attributes) {
1411
- const route = _optionalChain([attributes, 'optionalAccess', _42 => _42["next.route"]]);
1759
+ const route = _optionalChain([attributes, 'optionalAccess', _66 => _66["next.route"]]);
1412
1760
  if (typeof route !== "string" || !route.startsWith("/")) return;
1413
- if (RAW_PATH_SPAN_TYPES.has(String(_nullishCoalesce(_optionalChain([attributes, 'optionalAccess', _43 => _43["next.span_type"]]), () => ( ""))))) return;
1761
+ if (RAW_PATH_SPAN_TYPES.has(String(_nullishCoalesce(_optionalChain([attributes, 'optionalAccess', _67 => _67["next.span_type"]]), () => ( ""))))) return;
1414
1762
  const rpc = _core.getRPCMetadata.call(void 0, parent);
1415
1763
  if (!rpc || rpc.type !== _core.RPCType.HTTP) return;
1416
1764
  const mine = ours.get(rpc);
@@ -1428,7 +1776,7 @@ var RouteLabelSampler = class {
1428
1776
  shouldSample(ctx, traceId, spanName, spanKind, attributes, links) {
1429
1777
  try {
1430
1778
  noteFrameworkRoute(ctx, attributes);
1431
- } catch (e31) {
1779
+ } catch (e44) {
1432
1780
  }
1433
1781
  return this.delegate.shouldSample(ctx, traceId, spanName, spanKind, attributes, links);
1434
1782
  }
@@ -1438,10 +1786,10 @@ var RouteLabelSampler = class {
1438
1786
  };
1439
1787
 
1440
1788
  // src/server.ts
1441
- var S = _chunkBHYHORUDcjs.sharedSlot.call(void 0, "server", () => ({
1789
+ var S = _chunkS6WJ5YLPcjs.sharedSlot.call(void 0, "server", () => ({
1442
1790
  active: null,
1443
1791
  alwaysOnProvider: null,
1444
- redactor: _chunkYWTIKZSIcjs.makeRedactor.call(void 0, true),
1792
+ redactor: _chunkSTOXJZ7Zcjs.makeRedactor.call(void 0, true),
1445
1793
  loggerOnlyCapture: null,
1446
1794
  handled: null,
1447
1795
  loggerOnlyHandled: null,
@@ -1543,7 +1891,7 @@ var ErrorTraceRetentionProcessor = (_class2 = class {
1543
1891
  this.retainErrors = retainErrors;
1544
1892
  this.slowThresholdMs = slowThresholdMs;
1545
1893
  this.sweeper = setInterval(() => this.sweep(), RETENTION_SWEEP_INTERVAL_MS);
1546
- _optionalChain([this, 'access', _44 => _44.sweeper, 'access', _45 => _45.unref, 'optionalCall', _46 => _46()]);
1894
+ _optionalChain([this, 'access', _68 => _68.sweeper, 'access', _69 => _69.unref, 'optionalCall', _70 => _70()]);
1547
1895
  }
1548
1896
 
1549
1897
 
@@ -1574,7 +1922,7 @@ var ErrorTraceRetentionProcessor = (_class2 = class {
1574
1922
  }
1575
1923
  /** Promote the active trace, if any — called on captured errors. */
1576
1924
  retainActiveTrace() {
1577
- const active = _optionalChain([_api.trace, 'access', _47 => _47.getActiveSpan, 'call', _48 => _48(), 'optionalAccess', _49 => _49.spanContext, 'call', _50 => _50()]);
1925
+ const active = _optionalChain([_api.trace, 'access', _71 => _71.getActiveSpan, 'call', _72 => _72(), 'optionalAccess', _73 => _73.spanContext, 'call', _74 => _74()]);
1578
1926
  if (!active || (active.traceFlags & _api.TraceFlags.SAMPLED) !== 0) return;
1579
1927
  const entry = this.entryFor(active.traceId);
1580
1928
  if (entry.retained) return;
@@ -1695,15 +2043,15 @@ async function runLlmSpan(tracer, info, fn) {
1695
2043
  return result;
1696
2044
  } catch (err) {
1697
2045
  recordError(span, err);
1698
- if (_chunkYWTIKZSIcjs.isError.call(void 0, err)) span.setAttribute("error.type", err.name);
2046
+ if (_chunkSTOXJZ7Zcjs.isError.call(void 0, err)) span.setAttribute("error.type", err.name);
1699
2047
  throw err;
1700
2048
  } finally {
1701
2049
  span.end();
1702
- _chunkYWTIKZSIcjs.recordOperationAiUsage.call(void 0, { ...usage, model: _nullishCoalesce(responseModel, () => ( info.model)) });
2050
+ _chunkSTOXJZ7Zcjs.recordOperationAiUsage.call(void 0, { ...usage, model: _nullishCoalesce(responseModel, () => ( info.model)) });
1703
2051
  }
1704
2052
  }
1705
2053
  function recordLlmCall(tracer, call) {
1706
- _chunkYWTIKZSIcjs.recordOperationAiUsage.call(void 0, { ...call, model: call.model });
2054
+ _chunkSTOXJZ7Zcjs.recordOperationAiUsage.call(void 0, { ...call, model: call.model });
1707
2055
  const durationMs = Math.max(0, _nullishCoalesce(call.durationMs, () => ( 0)));
1708
2056
  const endTime = /* @__PURE__ */ new Date();
1709
2057
  const startTime = new Date(endTime.getTime() - durationMs);
@@ -1717,7 +2065,7 @@ function recordLlmCall(tracer, call) {
1717
2065
  );
1718
2066
  if (call.error !== void 0 && call.error !== null) {
1719
2067
  recordError(span, call.error);
1720
- if (_chunkYWTIKZSIcjs.isError.call(void 0, call.error)) {
2068
+ if (_chunkSTOXJZ7Zcjs.isError.call(void 0, call.error)) {
1721
2069
  span.setAttribute("error.type", call.error.name);
1722
2070
  }
1723
2071
  } else {
@@ -1728,7 +2076,7 @@ function recordLlmCall(tracer, call) {
1728
2076
  async function runWithSpan(tracer, name, fn, attributes, links) {
1729
2077
  const span = tracer.startSpan(name, {
1730
2078
  attributes,
1731
- ..._optionalChain([links, 'optionalAccess', _51 => _51.length]) ? { links } : {}
2079
+ ..._optionalChain([links, 'optionalAccess', _75 => _75.length]) ? { links } : {}
1732
2080
  });
1733
2081
  try {
1734
2082
  const result = await _api.context.with(
@@ -1745,14 +2093,14 @@ async function runWithSpan(tracer, name, fn, attributes, links) {
1745
2093
  }
1746
2094
  }
1747
2095
  function recordError(span, err) {
1748
- const isErr = _chunkYWTIKZSIcjs.isError.call(void 0, err);
2096
+ const isErr = _chunkSTOXJZ7Zcjs.isError.call(void 0, err);
1749
2097
  const message = S.redactor.text(isErr ? err.message : String(err));
1750
2098
  if (isErr) {
1751
2099
  span.addEvent("exception", {
1752
2100
  "exception.type": err.name,
1753
2101
  "exception.message": message,
1754
2102
  ...err.stack ? { "exception.stacktrace": S.redactor.text(err.stack) } : {},
1755
- ..._chunkYWTIKZSIcjs.breadcrumbEventAttributes.call(void 0, S.redactor.text, err)
2103
+ ..._chunkSTOXJZ7Zcjs.breadcrumbEventAttributes.call(void 0, S.redactor.text, err)
1756
2104
  });
1757
2105
  }
1758
2106
  span.setStatus({ code: _api.SpanStatusCode.ERROR, message });
@@ -1765,14 +2113,14 @@ function patchLoadedHttpModules() {
1765
2113
  const load = _module.createRequire.call(void 0, _path.join.call(void 0, process.cwd(), "autter-runtime-http.cjs"));
1766
2114
  load("http");
1767
2115
  load("https");
1768
- } catch (e32) {
2116
+ } catch (e45) {
1769
2117
  }
1770
2118
  }
1771
2119
  var METRIC_ROUTE_ATTR = "autter.metric_has_route";
1772
2120
  function captureRequestRoute(span, response) {
1773
2121
  if (!(response instanceof _http.ServerResponse)) return;
1774
2122
  const rpcMetadata = _core.getRPCMetadata.call(void 0, _api.context.active());
1775
- if (_optionalChain([rpcMetadata, 'optionalAccess', _52 => _52.type]) !== _core.RPCType.HTTP) return;
2123
+ if (_optionalChain([rpcMetadata, 'optionalAccess', _76 => _76.type]) !== _core.RPCType.HTTP) return;
1776
2124
  let failed = false;
1777
2125
  response.on(_events.errorMonitor, () => {
1778
2126
  failed = true;
@@ -1787,17 +2135,18 @@ function captureRequestRoute(span, response) {
1787
2135
  setRoute();
1788
2136
  if (rpcMetadata.route && !failed) span.setAttribute(METRIC_ROUTE_ATTR, true);
1789
2137
  });
2138
+ if (S.expressErrors) watchExpressResponse(span, response, () => S.expressErrors === true);
1790
2139
  if (S.hookRequests) startHookRequest(response);
1791
2140
  }
1792
2141
  function structuredErrorAttributes(error) {
1793
- const attrs = { ..._chunkYWTIKZSIcjs.errorAttributes.call(void 0, error, { causes: false }) };
1794
- const internal = _chunkYWTIKZSIcjs.errorInternal.call(void 0, error);
2142
+ const attrs = { ..._chunkSTOXJZ7Zcjs.errorAttributes.call(void 0, error, { causes: false }) };
2143
+ const internal = _chunkSTOXJZ7Zcjs.errorInternal.call(void 0, error);
1795
2144
  if (internal) {
1796
2145
  try {
1797
2146
  attrs["autter.error.internal"] = JSON.stringify(
1798
2147
  S.redactor(internal)
1799
2148
  ).slice(0, 4e3);
1800
- } catch (e33) {
2149
+ } catch (e46) {
1801
2150
  }
1802
2151
  }
1803
2152
  return attrs;
@@ -1808,22 +2157,26 @@ function initAutterServer(options) {
1808
2157
  /\/$/,
1809
2158
  ""
1810
2159
  );
1811
- const headers = { authorization: `Bearer ${options.apiKey}` };
1812
- const redactor = _chunkYWTIKZSIcjs.makeRedactor.call(void 0, _nullishCoalesce(options.redactAttributes, () => ( true)));
2160
+ const apiKey = _chunkS6WJ5YLPcjs.resolveIngestKey.call(void 0, options.apiKey);
2161
+ const headers = _chunkS6WJ5YLPcjs.authHeaders.call(void 0, apiKey);
2162
+ const ingestTarget = { endpoint, hasKey: apiKey !== null };
2163
+ const redactor = _chunkSTOXJZ7Zcjs.makeRedactor.call(void 0, _nullishCoalesce(options.redactAttributes, () => ( true)));
1813
2164
  const queryPolicy = makeUrlQueryPolicy(options.keepQueryParams);
1814
- const traceExporter = () => new (0, _chunkBHYHORUDcjs.CountingExporter)(
2165
+ const traceExporter = () => new (0, _chunkS6WJ5YLPcjs.CountingExporter)(
1815
2166
  new RedactingSpanExporter(
1816
- new (0, _exportertraceotlphttp.OTLPTraceExporter)({ url: `${endpoint}/v1/traces`, headers }),
2167
+ new IngestSpanExporter(new (0, _exportertraceotlphttp.OTLPTraceExporter)({ url: `${endpoint}/v1/traces`, headers }), ingestTarget),
1817
2168
  () => redactor,
1818
2169
  queryPolicy
1819
2170
  )
1820
2171
  );
1821
2172
  const environment = _nullishCoalesce(_nullishCoalesce(options.environment, () => ( process.env.NODE_ENV)), () => ( "production"));
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}`);
2173
+ if (_chunkS6WJ5YLPcjs.isDebugEnabled.call(void 0, ) || options.debug === true) _chunkS6WJ5YLPcjs.setDebugMode.call(void 0, true);
2174
+ _chunkS6WJ5YLPcjs.debugLog.call(void 0, `initialising service=${options.service} endpoint=${endpoint}`);
2175
+ if (apiKey === null) _chunkS6WJ5YLPcjs.warnMissingKey.call(void 0, "server", options.service);
2176
+ else _chunkS6WJ5YLPcjs.warnKeyKind.call(void 0, apiKey);
1824
2177
  S.redactor = redactor;
1825
- const distro = _nullishCoalesce(options.distro, () => ( _chunkBHYHORUDcjs.SDK_IDENTITY));
1826
- _chunkBHYHORUDcjs.configureCompatCheck.call(void 0, { endpoint, enabled: options.compatCheck !== false, sdk: distro });
2178
+ const distro = _nullishCoalesce(options.distro, () => ( _chunkS6WJ5YLPcjs.SDK_IDENTITY));
2179
+ _chunkS6WJ5YLPcjs.configureCompatCheck.call(void 0, { endpoint, enabled: options.compatCheck !== false, sdk: distro });
1827
2180
  const resource = new (0, _resources.Resource)({
1828
2181
  [_semanticconventions.ATTR_SERVICE_NAME]: options.service,
1829
2182
  "service.instance.id": (options.instanceId || process.env.AUTTER_RUNTIME_INSTANCE_ID || _crypto.randomUUID.call(void 0, )).slice(0, 128),
@@ -1844,7 +2197,7 @@ function initAutterServer(options) {
1844
2197
  // its span-fed per-route counts.
1845
2198
  "autter.metrics_routes": true
1846
2199
  });
1847
- const errorFilter = _chunkYWTIKZSIcjs.createErrorFilter.call(void 0, { ignoreErrors: options.ignoreErrors, sampleRate: options.sampleRate });
2200
+ const errorFilter = _chunkSTOXJZ7Zcjs.createErrorFilter.call(void 0, { ignoreErrors: options.ignoreErrors, sampleRate: options.sampleRate });
1848
2201
  const rootSampler = new (0, _sdktracebase.TraceIdRatioBasedSampler)(_nullishCoalesce(options.traceSampleRate, () => ( 0.01)));
1849
2202
  const headSampler = new (0, _sdktracebase.ParentBasedSampler)({
1850
2203
  root: rootSampler,
@@ -1869,7 +2222,7 @@ function initAutterServer(options) {
1869
2222
  const mainSpanProcessor = new (0, _sdktracebase.BatchSpanProcessor)(traceExporter());
1870
2223
  const metricReader = new (0, _sdkmetrics.PeriodicExportingMetricReader)({
1871
2224
  exporter: new RedactingMetricExporter(
1872
- new (0, _exportermetricsotlphttp.OTLPMetricExporter)({
2225
+ new IngestMetricExporter(new (0, _exportermetricsotlphttp.OTLPMetricExporter)({
1873
2226
  url: `${endpoint}/v1/metrics`,
1874
2227
  headers,
1875
2228
  // Deltas, not lifetime totals: the ingester SUMs data points
@@ -1877,7 +2230,7 @@ function initAutterServer(options) {
1877
2230
  // temporality would re-count every past request on each
1878
2231
  // 60 s export.
1879
2232
  temporalityPreference: _exportermetricsotlphttp.AggregationTemporalityPreference.DELTA
1880
- }),
2233
+ }), ingestTarget),
1881
2234
  () => redactor
1882
2235
  ),
1883
2236
  exportIntervalMillis: _nullishCoalesce(options.metricIntervalMs, () => ( 6e4))
@@ -1906,9 +2259,9 @@ function initAutterServer(options) {
1906
2259
  sdk.start();
1907
2260
  patchLoadedHttpModules();
1908
2261
  const stopMemoryMetrics = options.memoryMetrics === false ? null : startMemoryMetrics();
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");
2262
+ _chunkS6WJ5YLPcjs.noteCompatFeature.call(void 0, "endpoint_latency");
2263
+ if (stopMemoryMetrics) _chunkS6WJ5YLPcjs.noteCompatFeature.call(void 0, "memory_metrics");
2264
+ if (options.llmTracing !== false) _chunkS6WJ5YLPcjs.noteCompatFeature.call(void 0, "llm_calls");
1912
2265
  const alwaysOnProvider = new (0, _sdktracebase.BasicTracerProvider)({
1913
2266
  resource,
1914
2267
  sampler: new (0, _sdktracebase.AlwaysOnSampler)(),
@@ -1920,44 +2273,47 @@ function initAutterServer(options) {
1920
2273
  const processTracer = alwaysOnProvider.getTracer("autter-processes");
1921
2274
  const llmTracer = alwaysOnProvider.getTracer("autter-llm");
1922
2275
  function captureException2(error, attributes) {
1923
- const isErrValue = _chunkYWTIKZSIcjs.isError.call(void 0, error);
2276
+ const isErrValue = _chunkSTOXJZ7Zcjs.isError.call(void 0, error);
1924
2277
  const reported = errorFilter({
1925
2278
  type: isErrValue ? String(_nullishCoalesce(error.name, () => ( ""))) : "Error",
1926
2279
  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
2280
+ crash: _optionalChain([attributes, 'optionalAccess', _77 => _77["autter.unhandled"]]) === true || _optionalChain([attributes, 'optionalAccess', _78 => _78["autter.unhandled_rejection"]]) === true
1928
2281
  });
1929
2282
  if (!reported) {
1930
- _chunkYWTIKZSIcjs.markCaptured.call(void 0, error);
2283
+ _chunkSTOXJZ7Zcjs.markCaptured.call(void 0, error);
1931
2284
  return;
1932
2285
  }
1933
- _optionalChain([errorTraceBuffer, 'optionalAccess', _55 => _55.retainActiveTrace, 'call', _56 => _56()]);
1934
- _chunkBHYHORUDcjs.telemetryStats.markCaptured();
1935
- const isErr = _chunkYWTIKZSIcjs.isError.call(void 0, error);
2286
+ _optionalChain([errorTraceBuffer, 'optionalAccess', _79 => _79.retainActiveTrace, 'call', _80 => _80()]);
2287
+ _chunkS6WJ5YLPcjs.telemetryStats.markCaptured();
2288
+ const isErr = _chunkSTOXJZ7Zcjs.isError.call(void 0, error);
1936
2289
  const message = redactor.text(isErr ? error.message : String(error));
1937
2290
  const stackText = isErr && error.stack ? redactor.text(error.stack) : "";
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");
2291
+ const split = _chunkSTOXJZ7Zcjs.splitFingerprint.call(void 0, attributes);
2292
+ const fingerprint = _chunkSTOXJZ7Zcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, redactor.text);
2293
+ if (fingerprint["autter.fingerprint"]) _chunkS6WJ5YLPcjs.noteCompatFeature.call(void 0, "fingerprint_override");
1941
2294
  const redacted = redactor(split.attributes);
2295
+ const crash = _optionalChain([attributes, 'optionalAccess', _81 => _81["autter.unhandled"]]) === true;
1942
2296
  const activeSpan = _api.trace.getActiveSpan();
1943
- const reuseActive = _optionalChain([activeSpan, 'optionalAccess', _57 => _57.isRecording, 'call', _58 => _58()]) === true;
2297
+ const reuseActive = !crash && _optionalChain([activeSpan, 'optionalAccess', _82 => _82.isRecording, 'call', _83 => _83()]) === true;
1944
2298
  const span = reuseActive ? activeSpan : errorTracer.startSpan(isErr ? error.name : "Error");
2299
+ const scope = reuseActive ? void 0 : requestScopeAttributes();
1945
2300
  const structured = structuredErrorAttributes(error);
1946
- const causes = _chunkYWTIKZSIcjs.errorAttributes.call(void 0, error);
2301
+ const causes = _chunkSTOXJZ7Zcjs.errorAttributes.call(void 0, error);
1947
2302
  const declared = {
1948
2303
  ...Object.fromEntries(Object.entries(causes).filter(([key]) => key !== "autter.error.internal")),
1949
2304
  ...fingerprint
1950
2305
  };
1951
- const requestId = _optionalChain([_chunkYWTIKZSIcjs.currentOperation.call(void 0, ), 'optionalAccess', _59 => _59.requestId]);
2306
+ const requestId = _optionalChain([_chunkSTOXJZ7Zcjs.currentOperation.call(void 0, ), 'optionalAccess', _84 => _84.requestId]);
1952
2307
  span.setAttributes({
2308
+ ...scope,
1953
2309
  "autter.severity": "error",
1954
2310
  ...redacted,
1955
2311
  ...structured,
1956
2312
  ...requestId ? { "autter.request.id": requestId } : {}
1957
2313
  });
1958
- _chunkYWTIKZSIcjs.markCaptured.call(void 0, error);
1959
- _chunkYWTIKZSIcjs.noteOperationError.call(void 0, error);
1960
- _chunkYWTIKZSIcjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint });
2314
+ _chunkSTOXJZ7Zcjs.markCaptured.call(void 0, error);
2315
+ _chunkSTOXJZ7Zcjs.noteOperationError.call(void 0, error);
2316
+ _chunkSTOXJZ7Zcjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint });
1961
2317
  if (isErr && stackText) {
1962
2318
  span.addEvent("exception", {
1963
2319
  "exception.type": error.name,
@@ -1965,17 +2321,17 @@ function initAutterServer(options) {
1965
2321
  "exception.stacktrace": stackText,
1966
2322
  ...redacted["autter.handled"] === true ? { "autter.handled": true, "autter.sampled": redacted["autter.sampled"] === true } : {},
1967
2323
  ...declared,
1968
- ..._chunkYWTIKZSIcjs.breadcrumbEventAttributes.call(void 0, redactor.text, error)
2324
+ ..._chunkSTOXJZ7Zcjs.breadcrumbEventAttributes.call(void 0, redactor.text, error)
1969
2325
  });
1970
2326
  } else {
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")]);
2327
+ const stack = _optionalChain([new Error(), 'access', _85 => _85.stack, 'optionalAccess', _86 => _86.split, 'call', _87 => _87("\n"), 'access', _88 => _88.filter, 'call', _89 => _89((line, i) => i === 0 || !line.includes("captureException")), 'access', _90 => _90.join, 'call', _91 => _91("\n")]);
1972
2328
  span.addEvent("exception", {
1973
2329
  "exception.type": isErr ? error.name : "Error",
1974
2330
  "exception.message": message,
1975
2331
  ...stack ? { "exception.stacktrace": redactor.text(stack) } : {},
1976
2332
  ...redacted["autter.handled"] === true ? { "autter.handled": true, "autter.sampled": redacted["autter.sampled"] === true } : {},
1977
2333
  ...declared,
1978
- ..._chunkYWTIKZSIcjs.breadcrumbEventAttributes.call(void 0, redactor.text, error)
2334
+ ..._chunkSTOXJZ7Zcjs.breadcrumbEventAttributes.call(void 0, redactor.text, error)
1979
2335
  });
1980
2336
  }
1981
2337
  span.setStatus({ code: _api.SpanStatusCode.ERROR, message });
@@ -1984,10 +2340,10 @@ function initAutterServer(options) {
1984
2340
  function captureMessage2(message, severity = "warning", attributes) {
1985
2341
  if (!errorFilter({ type: "Message", message: String(message), severity })) return;
1986
2342
  if (severity === "error" || severity === "fatal") {
1987
- _optionalChain([errorTraceBuffer, 'optionalAccess', _67 => _67.retainActiveTrace, 'call', _68 => _68()]);
2343
+ _optionalChain([errorTraceBuffer, 'optionalAccess', _92 => _92.retainActiveTrace, 'call', _93 => _93()]);
1988
2344
  }
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")]);
2345
+ _chunkS6WJ5YLPcjs.telemetryStats.markCaptured();
2346
+ const stack = _optionalChain([new Error(), 'access', _94 => _94.stack, 'optionalAccess', _95 => _95.split, 'call', _96 => _96("\n"), 'access', _97 => _97.filter, 'call', _98 => _98((line, i) => i === 0 || !line.includes("captureMessage")), 'access', _99 => _99.join, 'call', _100 => _100("\n")]);
1991
2347
  const safeMessage = redactor.text(message);
1992
2348
  const span = errorTracer.startSpan("Message", {
1993
2349
  attributes: { "autter.severity": severity, ...redactor(attributes) }
@@ -1997,17 +2353,17 @@ function initAutterServer(options) {
1997
2353
  "exception.message": safeMessage,
1998
2354
  ...stack ? { "exception.stacktrace": redactor.text(stack) } : {},
1999
2355
  "autter.severity": severity,
2000
- ..._chunkYWTIKZSIcjs.breadcrumbEventAttributes.call(void 0, redactor.text)
2356
+ ..._chunkSTOXJZ7Zcjs.breadcrumbEventAttributes.call(void 0, redactor.text)
2001
2357
  });
2002
2358
  span.setStatus({ code: _api.SpanStatusCode.ERROR, message: safeMessage });
2003
2359
  span.end();
2004
2360
  }
2005
2361
  function reportOutcome2(name, message, attributes) {
2006
2362
  if (!errorFilter({ type: "OutcomeFailure", message: `${name}: ${message}` })) return;
2007
- _optionalChain([errorTraceBuffer, 'optionalAccess', _76 => _76.retainActiveTrace, 'call', _77 => _77()]);
2008
- _chunkBHYHORUDcjs.telemetryStats.markCaptured();
2363
+ _optionalChain([errorTraceBuffer, 'optionalAccess', _101 => _101.retainActiveTrace, 'call', _102 => _102()]);
2364
+ _chunkS6WJ5YLPcjs.telemetryStats.markCaptured();
2009
2365
  const activeSpan = _api.trace.getActiveSpan();
2010
- const reuseActive = _optionalChain([activeSpan, 'optionalAccess', _78 => _78.isRecording, 'call', _79 => _79()]) === true;
2366
+ const reuseActive = _optionalChain([activeSpan, 'optionalAccess', _103 => _103.isRecording, 'call', _104 => _104()]) === true;
2011
2367
  const span = reuseActive ? activeSpan : errorTracer.startSpan("OutcomeFailure");
2012
2368
  const safeOutcome = redactor({ "autter.outcome.name": name.slice(0, 200), "autter.outcome.message": message.slice(0, 1e3) });
2013
2369
  const safeName = String(_nullishCoalesce(safeOutcome["autter.outcome.name"], () => ( "operation")));
@@ -2022,39 +2378,39 @@ function initAutterServer(options) {
2022
2378
  if (!reuseActive) span.end();
2023
2379
  }
2024
2380
  function captureHandled(error, attributes, severity) {
2025
- const isErr = _chunkYWTIKZSIcjs.isError.call(void 0, error);
2381
+ const isErr = _chunkSTOXJZ7Zcjs.isError.call(void 0, error);
2026
2382
  if (!errorFilter({
2027
2383
  type: isErr ? String(_nullishCoalesce(error.name, () => ( ""))) : "Error",
2028
2384
  message: isErr ? String(_nullishCoalesce(error.message, () => ( ""))) : String(error),
2029
2385
  severity
2030
2386
  })) return;
2031
- if (severity === "error") _optionalChain([errorTraceBuffer, 'optionalAccess', _80 => _80.retainActiveTrace, 'call', _81 => _81()]);
2032
- _chunkBHYHORUDcjs.telemetryStats.markCaptured();
2387
+ if (severity === "error") _optionalChain([errorTraceBuffer, 'optionalAccess', _105 => _105.retainActiveTrace, 'call', _106 => _106()]);
2388
+ _chunkS6WJ5YLPcjs.telemetryStats.markCaptured();
2033
2389
  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);
2390
+ const stack = isErr && error.stack ? error.stack : _optionalChain([new Error(), 'access', _107 => _107.stack, 'optionalAccess', _108 => _108.split, 'call', _109 => _109("\n"), 'access', _110 => _110.filter, 'call', _111 => _111((line, i) => i === 0 || !/captureHandled|report(?:Degraded|LoggedError)/.test(line)), 'access', _112 => _112.join, 'call', _113 => _113("\n")]);
2391
+ const split = _chunkSTOXJZ7Zcjs.splitFingerprint.call(void 0, attributes);
2392
+ const fingerprint = _chunkSTOXJZ7Zcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, redactor.text);
2037
2393
  const redacted = redactor(split.attributes);
2038
2394
  const activeSpan = _api.trace.getActiveSpan();
2039
- const reuseActive = _optionalChain([activeSpan, 'optionalAccess', _89 => _89.isRecording, 'call', _90 => _90()]) === true;
2395
+ const reuseActive = _optionalChain([activeSpan, 'optionalAccess', _114 => _114.isRecording, 'call', _115 => _115()]) === true;
2040
2396
  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 });
2397
+ _chunkSTOXJZ7Zcjs.markCaptured.call(void 0, error);
2398
+ _chunkSTOXJZ7Zcjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint, "autter.severity": severity });
2043
2399
  span.addEvent("exception", {
2044
2400
  ...redacted,
2045
2401
  "exception.type": isErr ? error.name : "Error",
2046
2402
  "exception.message": message,
2047
2403
  ...stack ? { "exception.stacktrace": redactor.text(stack) } : {},
2048
2404
  "autter.severity": severity,
2049
- ..._chunkYWTIKZSIcjs.errorAttributes.call(void 0, error),
2405
+ ..._chunkSTOXJZ7Zcjs.errorAttributes.call(void 0, error),
2050
2406
  ...fingerprint,
2051
- ..._chunkYWTIKZSIcjs.breadcrumbEventAttributes.call(void 0, redactor.text, error)
2407
+ ..._chunkSTOXJZ7Zcjs.breadcrumbEventAttributes.call(void 0, redactor.text, error)
2052
2408
  });
2053
2409
  if (!reuseActive) span.end();
2054
2410
  }
2055
- _chunkYWTIKZSIcjs.configureRuntimeLogger.call(void 0, {
2411
+ _chunkSTOXJZ7Zcjs.configureRuntimeLogger.call(void 0, {
2056
2412
  endpoint,
2057
- apiKey: options.apiKey,
2413
+ apiKey: _nullishCoalesce(apiKey, () => ( "")),
2058
2414
  service: options.service,
2059
2415
  environment,
2060
2416
  distro,
@@ -2064,9 +2420,11 @@ function initAutterServer(options) {
2064
2420
  run: (name, fn, attributes, links) => runWithSpan(processTracer, name, fn, redactor(attributes), links),
2065
2421
  reportOutcome: reportOutcome2
2066
2422
  });
2067
- S.hookRequests = _optionalChain([options, 'access', _91 => _91.logging, 'optionalAccess', _92 => _92.requests]) === true;
2423
+ S.hookRequests = _optionalChain([options, 'access', _116 => _116.logging, 'optionalAccess', _117 => _117.requests]) === true;
2424
+ S.expressErrors = options.captureExpressErrors !== false;
2425
+ if (S.expressErrors) installExpressErrorCapture();
2068
2426
  S.handled = captureHandled;
2069
- _chunkYWTIKZSIcjs.startLoggedErrorCapture.call(void 0, options.captureLoggedErrors);
2427
+ _chunkSTOXJZ7Zcjs.startLoggedErrorCapture.call(void 0, options.captureLoggedErrors);
2070
2428
  let onCrash = null;
2071
2429
  let uninstallRejections = null;
2072
2430
  if (options.captureGlobalErrors !== false) {
@@ -2086,7 +2444,7 @@ function initAutterServer(options) {
2086
2444
  const flushTarget = {
2087
2445
  forceFlush: async () => {
2088
2446
  const results = await Promise.allSettled([
2089
- _chunkYWTIKZSIcjs.flushRuntimeLogs.call(void 0, ),
2447
+ _chunkSTOXJZ7Zcjs.flushRuntimeLogs.call(void 0, ),
2090
2448
  Promise.resolve().then(() => alwaysOnProvider.forceFlush()),
2091
2449
  Promise.resolve().then(() => mainSpanProcessor.forceFlush()),
2092
2450
  ...errorTraceBuffer ? [Promise.resolve().then(() => errorTraceBuffer.forceFlush())] : [],
@@ -2100,10 +2458,10 @@ function initAutterServer(options) {
2100
2458
  }
2101
2459
  }
2102
2460
  };
2103
- _chunkBHYHORUDcjs.registerFlushTarget.call(void 0, "active-server", flushTarget);
2461
+ _chunkS6WJ5YLPcjs.registerFlushTarget.call(void 0, "active-server", flushTarget);
2104
2462
  let autoFlushHandle = null;
2105
2463
  if (options.autoFlush !== false) {
2106
- autoFlushHandle = _chunkBHYHORUDcjs.installAutterAutoFlush.call(void 0, );
2464
+ autoFlushHandle = _chunkS6WJ5YLPcjs.installAutterAutoFlush.call(void 0, );
2107
2465
  }
2108
2466
  const server = {
2109
2467
  captureException: captureException2,
@@ -2113,24 +2471,25 @@ function initAutterServer(options) {
2113
2471
  withLlmCall: (info, fn) => runLlmSpan(llmTracer, info, fn),
2114
2472
  trackLlmCall: (call) => recordLlmCall(llmTracer, call),
2115
2473
  shutdown: async () => {
2116
- if (S.active === server) _chunkYWTIKZSIcjs.stopLoggedErrorCapture.call(void 0, );
2117
- const logShutdown = await Promise.allSettled([_chunkYWTIKZSIcjs.shutdownRuntimeLogger.call(void 0, )]);
2474
+ if (S.active === server) _chunkSTOXJZ7Zcjs.stopLoggedErrorCapture.call(void 0, );
2475
+ const logShutdown = await Promise.allSettled([_chunkSTOXJZ7Zcjs.shutdownRuntimeLogger.call(void 0, )]);
2118
2476
  if (onCrash) process.off("uncaughtExceptionMonitor", onCrash);
2119
- _optionalChain([uninstallRejections, 'optionalCall', _93 => _93()]);
2120
- _optionalChain([stopMemoryMetrics, 'optionalCall', _94 => _94()]);
2477
+ _optionalChain([uninstallRejections, 'optionalCall', _118 => _118()]);
2478
+ _optionalChain([stopMemoryMetrics, 'optionalCall', _119 => _119()]);
2121
2479
  if (S.active === server) {
2122
2480
  S.active = null;
2123
2481
  S.alwaysOnProvider = null;
2124
2482
  S.handled = null;
2125
2483
  S.hookRequests = false;
2126
- S.redactor = _chunkYWTIKZSIcjs.makeRedactor.call(void 0, true);
2484
+ S.expressErrors = false;
2485
+ S.redactor = _chunkSTOXJZ7Zcjs.makeRedactor.call(void 0, true);
2127
2486
  }
2128
- _optionalChain([autoFlushHandle, 'optionalAccess', _95 => _95.dispose, 'call', _96 => _96()]);
2487
+ _optionalChain([autoFlushHandle, 'optionalAccess', _120 => _120.dispose, 'call', _121 => _121()]);
2129
2488
  autoFlushHandle = null;
2130
- _chunkBHYHORUDcjs.unregisterFlushTargets.call(void 0, );
2131
- _chunkBHYHORUDcjs.telemetryStats.markAllFlushed();
2489
+ _chunkS6WJ5YLPcjs.unregisterFlushTargets.call(void 0, );
2490
+ _chunkS6WJ5YLPcjs.telemetryStats.markAllFlushed();
2132
2491
  await Promise.allSettled([alwaysOnProvider.shutdown(), sdk.shutdown()]);
2133
- if (_optionalChain([logShutdown, 'access', _97 => _97[0], 'optionalAccess', _98 => _98.status]) === "rejected") throw logShutdown[0].reason;
2492
+ if (_optionalChain([logShutdown, 'access', _122 => _122[0], 'optionalAccess', _123 => _123.status]) === "rejected") throw logShutdown[0].reason;
2134
2493
  }
2135
2494
  };
2136
2495
  S.active = server;
@@ -2146,12 +2505,12 @@ function captureException(error, attributes) {
2146
2505
  S.loggerOnlyCapture(error, attributes);
2147
2506
  return;
2148
2507
  }
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", {
2508
+ _chunkSTOXJZ7Zcjs.markCaptured.call(void 0, error);
2509
+ _chunkSTOXJZ7Zcjs.noteOperationError.call(void 0, error);
2510
+ const split = _chunkSTOXJZ7Zcjs.splitFingerprint.call(void 0, attributes);
2511
+ const fingerprint = _chunkSTOXJZ7Zcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, S.redactor.text);
2512
+ _chunkSTOXJZ7Zcjs.notifyException.call(void 0, error, { ...split.attributes, ...fingerprint });
2513
+ const span = _api.trace.getTracer("autter-errors").startSpan(_chunkSTOXJZ7Zcjs.isError.call(void 0, error) ? error.name : "Error", {
2155
2514
  attributes: { ...S.redactor(split.attributes), ...fingerprint }
2156
2515
  });
2157
2516
  recordError(span, error);
@@ -2163,25 +2522,25 @@ function setLoggerOnlyCapture(fn, handled = null) {
2163
2522
  }
2164
2523
  function captureHandledError(error, attributes, severity) {
2165
2524
  if (S.active) {
2166
- _optionalChain([S, 'access', _99 => _99.handled, 'optionalCall', _100 => _100(error, attributes, severity)]);
2525
+ _optionalChain([S, 'access', _124 => _124.handled, 'optionalCall', _125 => _125(error, attributes, severity)]);
2167
2526
  return;
2168
2527
  }
2169
2528
  if (S.loggerOnlyHandled) {
2170
2529
  S.loggerOnlyHandled(error, attributes, severity);
2171
2530
  return;
2172
2531
  }
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");
2532
+ _chunkSTOXJZ7Zcjs.markCaptured.call(void 0, error);
2533
+ const split = _chunkSTOXJZ7Zcjs.splitFingerprint.call(void 0, attributes);
2534
+ _chunkSTOXJZ7Zcjs.notifyException.call(void 0, error, { ...split.attributes, "autter.severity": severity });
2535
+ const span = _api.trace.getTracer("autter-errors").startSpan(_chunkSTOXJZ7Zcjs.isError.call(void 0, error) ? error.name : "Error");
2177
2536
  span.addEvent("exception", {
2178
2537
  ...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) } : {},
2538
+ "exception.type": _chunkSTOXJZ7Zcjs.isError.call(void 0, error) ? error.name : "Error",
2539
+ "exception.message": S.redactor.text(_chunkSTOXJZ7Zcjs.isError.call(void 0, error) ? error.message : String(error)),
2540
+ ..._chunkSTOXJZ7Zcjs.isError.call(void 0, error) && error.stack ? { "exception.stacktrace": S.redactor.text(error.stack) } : {},
2182
2541
  "autter.severity": severity,
2183
- ..._chunkYWTIKZSIcjs.errorAttributes.call(void 0, error),
2184
- ..._chunkYWTIKZSIcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, S.redactor.text)
2542
+ ..._chunkSTOXJZ7Zcjs.errorAttributes.call(void 0, error),
2543
+ ..._chunkSTOXJZ7Zcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, S.redactor.text)
2185
2544
  });
2186
2545
  span.end();
2187
2546
  }
@@ -2189,10 +2548,10 @@ function serverActive() {
2189
2548
  return S.active !== null;
2190
2549
  }
2191
2550
  setRequestExceptionCapturer((error, attributes) => captureException(error, attributes));
2192
- _chunkYWTIKZSIcjs.setHandledCapture.call(void 0, captureHandledError);
2551
+ _chunkSTOXJZ7Zcjs.setHandledCapture.call(void 0, captureHandledError);
2193
2552
  setRequestSpanAnnotator((attributes) => {
2194
2553
  const span = _api.trace.getActiveSpan();
2195
- if (_optionalChain([span, 'optionalAccess', _101 => _101.isRecording, 'call', _102 => _102()])) span.setAttributes(S.redactor(_chunkYWTIKZSIcjs.splitFingerprint.call(void 0, attributes).attributes));
2554
+ if (_optionalChain([span, 'optionalAccess', _126 => _126.isRecording, 'call', _127 => _127()])) span.setAttributes(S.redactor(_chunkSTOXJZ7Zcjs.splitFingerprint.call(void 0, attributes).attributes));
2196
2555
  });
2197
2556
  function withProcessSpan(name, fn, attributes) {
2198
2557
  if (S.active) return S.active.withProcessSpan(name, fn, attributes);
@@ -2227,7 +2586,7 @@ function captureMessage(message, severity = "warning", attributes) {
2227
2586
  "exception.type": "Message",
2228
2587
  "exception.message": safeMessage,
2229
2588
  "autter.severity": severity,
2230
- ..._chunkYWTIKZSIcjs.breadcrumbEventAttributes.call(void 0, S.redactor.text)
2589
+ ..._chunkSTOXJZ7Zcjs.breadcrumbEventAttributes.call(void 0, S.redactor.text)
2231
2590
  });
2232
2591
  span.setStatus({ code: _api.SpanStatusCode.ERROR, message: safeMessage });
2233
2592
  span.end();
@@ -2235,11 +2594,11 @@ function captureMessage(message, severity = "warning", attributes) {
2235
2594
  function reportOutcome(name, message, attributes) {
2236
2595
  if (S.active) return S.active.reportOutcome(name, message, attributes);
2237
2596
  const span = _api.trace.getTracer("autter-outcomes").startSpan("OutcomeFailure");
2238
- const safeOutcome = _chunkYWTIKZSIcjs.redactAttributes.call(void 0, { "autter.outcome.name": name.slice(0, 200), "autter.outcome.message": message.slice(0, 1e3) });
2597
+ const safeOutcome = _chunkSTOXJZ7Zcjs.redactAttributes.call(void 0, { "autter.outcome.name": name.slice(0, 200), "autter.outcome.message": message.slice(0, 1e3) });
2239
2598
  const safeName = String(_nullishCoalesce(safeOutcome["autter.outcome.name"], () => ( "operation")));
2240
2599
  const safeMessage = String(_nullishCoalesce(safeOutcome["autter.outcome.message"], () => ( "failed")));
2241
2600
  span.addEvent("autter.outcome", {
2242
- ..._chunkYWTIKZSIcjs.redactAttributes.call(void 0, attributes),
2601
+ ..._chunkSTOXJZ7Zcjs.redactAttributes.call(void 0, attributes),
2243
2602
  "autter.outcome.status": "error",
2244
2603
  "autter.outcome.name": safeName,
2245
2604
  "autter.outcome.message": safeMessage
@@ -2248,7 +2607,7 @@ function reportOutcome(name, message, attributes) {
2248
2607
  span.end();
2249
2608
  }
2250
2609
  function makeSafeCapture(options) {
2251
- const clean = (attributes) => attributes ? { ..._chunkYWTIKZSIcjs.redactAttributes.call(void 0, attributes, options) } : void 0;
2610
+ const clean = (attributes) => attributes ? { ..._chunkSTOXJZ7Zcjs.redactAttributes.call(void 0, attributes, options) } : void 0;
2252
2611
  return {
2253
2612
  captureException: (error, attributes) => captureException(error, clean(attributes)),
2254
2613
  captureMessage: (message, severity, attributes) => captureMessage(message, _nullishCoalesce(severity, () => ( "warning")), clean(attributes))
@@ -2275,7 +2634,7 @@ async function emitLlmSelftestTrace() {
2275
2634
  attributes: { "autter.selftest": true }
2276
2635
  },
2277
2636
  (llm) => {
2278
- traceId = _nullishCoalesce(_optionalChain([_api.trace, 'access', _103 => _103.getActiveSpan, 'call', _104 => _104(), 'optionalAccess', _105 => _105.spanContext, 'call', _106 => _106(), 'access', _107 => _107.traceId]), () => ( ""));
2637
+ traceId = _nullishCoalesce(_optionalChain([_api.trace, 'access', _128 => _128.getActiveSpan, 'call', _129 => _129(), 'optionalAccess', _130 => _130.spanContext, 'call', _131 => _131(), 'access', _132 => _132.traceId]), () => ( ""));
2279
2638
  llm.setUsage({ inputTokens: 1, outputTokens: 1 });
2280
2639
  llm.setCost(0);
2281
2640
  }
@@ -2303,7 +2662,7 @@ var CALL_METHODS = /* @__PURE__ */ new Set([
2303
2662
  // openai beta structured outputs
2304
2663
  ]);
2305
2664
  function detectProvider(client) {
2306
- const name = _nullishCoalesce(_optionalChain([client, 'access', _108 => _108.constructor, 'optionalAccess', _109 => _109.name, 'optionalAccess', _110 => _110.toLowerCase, 'call', _111 => _111()]), () => ( ""));
2665
+ const name = _nullishCoalesce(_optionalChain([client, 'access', _133 => _133.constructor, 'optionalAccess', _134 => _134.name, 'optionalAccess', _135 => _135.toLowerCase, 'call', _136 => _136()]), () => ( ""));
2307
2666
  for (const known of ["openai", "anthropic", "mistral", "groq", "cohere"]) {
2308
2667
  if (name.includes(known)) return known;
2309
2668
  }
@@ -2311,7 +2670,7 @@ function detectProvider(client) {
2311
2670
  const baseUrl = String(
2312
2671
  _nullishCoalesce(_nullishCoalesce(client.baseURL, () => ( client.baseUrl)), () => ( ""))
2313
2672
  );
2314
- const host = _nullishCoalesce(_optionalChain([baseUrl, 'access', _112 => _112.match, 'call', _113 => _113(/https?:\/\/([^/]+)/), 'optionalAccess', _114 => _114[1]]), () => ( ""));
2673
+ const host = _nullishCoalesce(_optionalChain([baseUrl, 'access', _137 => _137.match, 'call', _138 => _138(/https?:\/\/([^/]+)/), 'optionalAccess', _139 => _139[1]]), () => ( ""));
2315
2674
  if (host.includes("openai")) return "openai";
2316
2675
  if (host.includes("anthropic")) return "anthropic";
2317
2676
  if (host.includes("googleapis")) return "google";
@@ -2321,13 +2680,13 @@ function detectProvider(client) {
2321
2680
  }
2322
2681
  function extractUsage(result) {
2323
2682
  const r = result;
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])));
2683
+ const usage = _nullishCoalesce(_optionalChain([r, 'optionalAccess', _140 => _140.usage]), () => ( _optionalChain([r, 'optionalAccess', _141 => _141.message, 'optionalAccess', _142 => _142.usage])));
2684
+ const meta = _optionalChain([r, 'optionalAccess', _143 => _143.usageMetadata]);
2685
+ const details = _optionalChain([usage, 'optionalAccess', _144 => _144.prompt_tokens_details]);
2686
+ const cached = _nullishCoalesce(_nullishCoalesce(_optionalChain([usage, 'optionalAccess', _145 => _145.cache_read_input_tokens]), () => ( (typeof _optionalChain([details, 'optionalAccess', _146 => _146.cached_tokens]) === "number" ? details.cached_tokens : void 0))), () => ( _optionalChain([meta, 'optionalAccess', _147 => _147.cachedContentTokenCount])));
2687
+ const input = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([usage, 'optionalAccess', _148 => _148.prompt_tokens]), () => ( _optionalChain([usage, 'optionalAccess', _149 => _149.input_tokens]))), () => ( _optionalChain([meta, 'optionalAccess', _150 => _150.promptTokenCount]))), () => ( void 0));
2688
+ const output = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([usage, 'optionalAccess', _151 => _151.completion_tokens]), () => ( _optionalChain([usage, 'optionalAccess', _152 => _152.output_tokens]))), () => ( _optionalChain([meta, 'optionalAccess', _153 => _153.candidatesTokenCount]))), () => ( void 0));
2689
+ const responseModel = _nullishCoalesce(_optionalChain([r, 'optionalAccess', _154 => _154.model]), () => ( _optionalChain([r, 'optionalAccess', _155 => _155.modelVersion])));
2331
2690
  return {
2332
2691
  inputTokens: typeof input === "number" ? input : void 0,
2333
2692
  outputTokens: typeof output === "number" ? output : void 0,
@@ -2336,7 +2695,7 @@ function extractUsage(result) {
2336
2695
  };
2337
2696
  }
2338
2697
  function rollUp(model, usage) {
2339
- _chunkYWTIKZSIcjs.recordOperationAiUsage.call(void 0, {
2698
+ _chunkSTOXJZ7Zcjs.recordOperationAiUsage.call(void 0, {
2340
2699
  model: _nullishCoalesce(usage.responseModel, () => ( model)),
2341
2700
  ...usage.inputTokens !== void 0 ? { inputTokens: usage.inputTokens } : {},
2342
2701
  ...usage.outputTokens !== void 0 ? { outputTokens: usage.outputTokens } : {},
@@ -2420,10 +2779,10 @@ function wrapStream(stream, span, model) {
2420
2779
  });
2421
2780
  }
2422
2781
  function instrumentLlmClient(client, options) {
2423
- const provider = (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _131 => _131.provider]), () => ( detectProvider(client)))).toLowerCase();
2782
+ const provider = (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _156 => _156.provider]), () => ( detectProvider(client)))).toLowerCase();
2424
2783
  const proxied = /* @__PURE__ */ new WeakMap();
2425
2784
  function resolveUserId() {
2426
- return typeof _optionalChain([options, 'optionalAccess', _132 => _132.userId]) === "function" ? options.userId() : _optionalChain([options, 'optionalAccess', _133 => _133.userId]);
2785
+ return typeof _optionalChain([options, 'optionalAccess', _157 => _157.userId]) === "function" ? options.userId() : _optionalChain([options, 'optionalAccess', _158 => _158.userId]);
2427
2786
  }
2428
2787
  function traceCall(fn, self, callPath, args) {
2429
2788
  const request = args[0];
@@ -2437,7 +2796,7 @@ function instrumentLlmClient(client, options) {
2437
2796
  "gen_ai.system": provider,
2438
2797
  "gen_ai.request.model": request.model,
2439
2798
  ...userId ? { "autter.user_id": userId } : {},
2440
- ...redactWithActive(_optionalChain([options, 'optionalAccess', _134 => _134.attributes]))
2799
+ ...redactWithActive(_optionalChain([options, 'optionalAccess', _159 => _159.attributes]))
2441
2800
  }
2442
2801
  });
2443
2802
  let result;
@@ -2561,9 +2920,9 @@ ${frames.join("\n")}`;
2561
2920
  function recordBoundaryError(error, req, rule) {
2562
2921
  try {
2563
2922
  const state = requestStateOf(req);
2564
- if (state) _chunkYWTIKZSIcjs.noteOperationError.call(void 0, error, false, state);
2923
+ if (state) _chunkSTOXJZ7Zcjs.noteOperationError.call(void 0, error, false, state);
2565
2924
  captureAtBoundary(error, state, rule);
2566
- } catch (e34) {
2925
+ } catch (e47) {
2567
2926
  }
2568
2927
  }
2569
2928
  function autterErrorHandler(options = {}) {
@@ -2573,12 +2932,12 @@ function autterErrorHandler(options = {}) {
2573
2932
  };
2574
2933
  }
2575
2934
  function autterFastifyErrors(fastify, options, done) {
2576
- const rule = _optionalChain([options, 'optionalAccess', _135 => _135.capture]);
2935
+ const rule = _optionalChain([options, 'optionalAccess', _160 => _160.capture]);
2577
2936
  fastify.addHook("onError", ((request, _reply, error, next) => {
2578
- recordBoundaryError(error, _optionalChain([request, 'optionalAccess', _136 => _136.raw]), rule);
2937
+ recordBoundaryError(error, _optionalChain([request, 'optionalAccess', _161 => _161.raw]), rule);
2579
2938
  next();
2580
2939
  }));
2581
- _optionalChain([done, 'optionalCall', _137 => _137()]);
2940
+ _optionalChain([done, 'optionalCall', _162 => _162()]);
2582
2941
  }
2583
2942
  autterFastifyErrors[/* @__PURE__ */ Symbol.for("skip-override")] = true;
2584
2943
  autterFastifyErrors[/* @__PURE__ */ Symbol.for("fastify.display-name")] = "autter-runtime-errors";
@@ -2587,7 +2946,7 @@ function autterKoa(options = {}) {
2587
2946
  try {
2588
2947
  await next();
2589
2948
  } catch (error) {
2590
- recordBoundaryError(error, _optionalChain([ctx, 'optionalAccess', _138 => _138.req]), options.capture);
2949
+ recordBoundaryError(error, _optionalChain([ctx, 'optionalAccess', _163 => _163.req]), options.capture);
2591
2950
  throw error;
2592
2951
  }
2593
2952
  };
@@ -2598,7 +2957,7 @@ function autterKoa(options = {}) {
2598
2957
 
2599
2958
 
2600
2959
 
2601
- var L = _chunkBHYHORUDcjs.sharedSlot.call(void 0, "logging", () => ({ active: null }));
2960
+ var L = _chunkS6WJ5YLPcjs.sharedSlot.call(void 0, "logging", () => ({ active: null }));
2602
2961
  function initAutterLogging(options) {
2603
2962
  if (L.active) return L.active;
2604
2963
  if (serverActive()) {
@@ -2607,37 +2966,37 @@ function initAutterLogging(options) {
2607
2966
  );
2608
2967
  return {
2609
2968
  captureException,
2610
- flush: _chunkYWTIKZSIcjs.flushRuntimeLogs,
2969
+ flush: _chunkSTOXJZ7Zcjs.flushRuntimeLogs,
2611
2970
  shutdown: async () => {
2612
2971
  }
2613
2972
  };
2614
2973
  }
2615
- if (_chunkBHYHORUDcjs.isDebugEnabled.call(void 0, ) || options.debug === true) _chunkBHYHORUDcjs.setDebugMode.call(void 0, true);
2974
+ if (_chunkS6WJ5YLPcjs.isDebugEnabled.call(void 0, ) || options.debug === true) _chunkS6WJ5YLPcjs.setDebugMode.call(void 0, true);
2616
2975
  const endpoint = (_nullishCoalesce(options.endpoint, () => ( "https://otlp.autter.dev"))).replace(/\/$/, "");
2617
2976
  const environment = _nullishCoalesce(_nullishCoalesce(options.environment, () => ( process.env.NODE_ENV)), () => ( "production"));
2618
- const redact = _chunkYWTIKZSIcjs.makeRedactor.call(void 0, _nullishCoalesce(options.redactAttributes, () => ( true)));
2977
+ const redact = _chunkSTOXJZ7Zcjs.makeRedactor.call(void 0, _nullishCoalesce(options.redactAttributes, () => ( true)));
2619
2978
  const mode = _nullishCoalesce(options.exceptions, () => ( "auto"));
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 });
2979
+ _chunkS6WJ5YLPcjs.debugLog.call(void 0, `initialising logger-only service=${options.service} endpoint=${endpoint}`);
2980
+ const errorFilter = _chunkSTOXJZ7Zcjs.createErrorFilter.call(void 0, { ignoreErrors: options.ignoreErrors, sampleRate: options.sampleRate });
2622
2981
  function captureException2(error, attributes) {
2623
- _chunkYWTIKZSIcjs.markCaptured.call(void 0, error);
2624
- const isErrValue = _chunkYWTIKZSIcjs.isError.call(void 0, error);
2982
+ _chunkSTOXJZ7Zcjs.markCaptured.call(void 0, error);
2983
+ const isErrValue = _chunkSTOXJZ7Zcjs.isError.call(void 0, error);
2625
2984
  const reported = errorFilter({
2626
2985
  type: isErrValue ? String(_nullishCoalesce(error.name, () => ( ""))) : "Error",
2627
2986
  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
2987
+ crash: _optionalChain([attributes, 'optionalAccess', _164 => _164["autter.unhandled"]]) === true || _optionalChain([attributes, 'optionalAccess', _165 => _165["autter.unhandled_rejection"]]) === true
2629
2988
  });
2630
2989
  if (!reported) return;
2631
- const split = _chunkYWTIKZSIcjs.splitFingerprint.call(void 0, attributes);
2632
- const fingerprint = _chunkYWTIKZSIcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, redact.text);
2990
+ const split = _chunkSTOXJZ7Zcjs.splitFingerprint.call(void 0, attributes);
2991
+ const fingerprint = _chunkSTOXJZ7Zcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, redact.text);
2633
2992
  const redacted = redact(split.attributes);
2634
2993
  const span = _api.trace.getActiveSpan();
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 });
2994
+ if (mode === "auto" && _optionalChain([span, 'optionalAccess', _166 => _166.isRecording, 'call', _167 => _167()])) {
2995
+ _chunkSTOXJZ7Zcjs.noteOperationError.call(void 0, error);
2996
+ _chunkSTOXJZ7Zcjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint });
2638
2997
  span.setAttributes({ "autter.severity": "error", ...redacted, ...structuredErrorAttributes(error) });
2639
- const declared = { ..._chunkYWTIKZSIcjs.errorAttributes.call(void 0, error), ...fingerprint };
2640
- if (_chunkYWTIKZSIcjs.isError.call(void 0, error)) {
2998
+ const declared = { ..._chunkSTOXJZ7Zcjs.errorAttributes.call(void 0, error), ...fingerprint };
2999
+ if (_chunkSTOXJZ7Zcjs.isError.call(void 0, error)) {
2641
3000
  span.addEvent("exception", {
2642
3001
  "exception.type": error.name,
2643
3002
  "exception.message": error.message,
@@ -2653,51 +3012,53 @@ function initAutterLogging(options) {
2653
3012
  }
2654
3013
  span.setStatus({
2655
3014
  code: _api.SpanStatusCode.ERROR,
2656
- message: _chunkYWTIKZSIcjs.isError.call(void 0, error) ? error.message : String(error)
3015
+ message: _chunkSTOXJZ7Zcjs.isError.call(void 0, error) ? error.message : String(error)
2657
3016
  });
2658
3017
  return;
2659
3018
  }
2660
- _chunkYWTIKZSIcjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint });
2661
- _chunkYWTIKZSIcjs.captureExceptionAsLog.call(void 0, error, { ...redacted, ...fingerprint });
3019
+ _chunkSTOXJZ7Zcjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint });
3020
+ _chunkSTOXJZ7Zcjs.captureExceptionAsLog.call(void 0, error, { ...redacted, ...fingerprint });
2662
3021
  }
2663
3022
  function captureHandled(error, attributes, severity) {
2664
- _chunkYWTIKZSIcjs.markCaptured.call(void 0, error);
2665
- const isErrValue = _chunkYWTIKZSIcjs.isError.call(void 0, error);
3023
+ _chunkSTOXJZ7Zcjs.markCaptured.call(void 0, error);
3024
+ const isErrValue = _chunkSTOXJZ7Zcjs.isError.call(void 0, error);
2666
3025
  if (!errorFilter({
2667
3026
  type: isErrValue ? String(_nullishCoalesce(error.name, () => ( ""))) : "Error",
2668
3027
  message: isErrValue ? String(_nullishCoalesce(error.message, () => ( ""))) : String(error),
2669
3028
  severity
2670
3029
  })) return;
2671
- const split = _chunkYWTIKZSIcjs.splitFingerprint.call(void 0, attributes);
2672
- const fingerprint = _chunkYWTIKZSIcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, redact.text);
3030
+ const split = _chunkSTOXJZ7Zcjs.splitFingerprint.call(void 0, attributes);
3031
+ const fingerprint = _chunkSTOXJZ7Zcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, redact.text);
2673
3032
  const redacted = redact(split.attributes);
2674
- _chunkYWTIKZSIcjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint, "autter.severity": severity });
3033
+ _chunkSTOXJZ7Zcjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint, "autter.severity": severity });
2675
3034
  const span = _api.trace.getActiveSpan();
2676
- if (mode === "auto" && _optionalChain([span, 'optionalAccess', _143 => _143.isRecording, 'call', _144 => _144()])) {
3035
+ if (mode === "auto" && _optionalChain([span, 'optionalAccess', _168 => _168.isRecording, 'call', _169 => _169()])) {
2677
3036
  span.addEvent("exception", {
2678
3037
  ...redacted,
2679
3038
  "exception.type": isErrValue ? error.name : "Error",
2680
3039
  "exception.message": redact.text(isErrValue ? error.message : String(error)),
2681
3040
  ...isErrValue && error.stack ? { "exception.stacktrace": redact.text(error.stack) } : {},
2682
3041
  "autter.severity": severity,
2683
- ..._chunkYWTIKZSIcjs.errorAttributes.call(void 0, error),
3042
+ ..._chunkSTOXJZ7Zcjs.errorAttributes.call(void 0, error),
2684
3043
  ...fingerprint
2685
3044
  });
2686
3045
  return;
2687
3046
  }
2688
- _chunkYWTIKZSIcjs.captureExceptionAsLog.call(void 0, error, { ...redacted, ...fingerprint }, severity);
3047
+ _chunkSTOXJZ7Zcjs.captureExceptionAsLog.call(void 0, error, { ...redacted, ...fingerprint }, severity);
2689
3048
  }
2690
3049
  const captured = /* @__PURE__ */ new WeakSet();
2691
- _chunkYWTIKZSIcjs.configureRuntimeLogger.call(void 0, {
3050
+ _chunkSTOXJZ7Zcjs.configureRuntimeLogger.call(void 0, {
2692
3051
  endpoint,
2693
- apiKey: _nullishCoalesce(options.apiKey, () => ( "")),
3052
+ // Normalised ("undefined"/empty is no key), no env fallback: without
3053
+ // an apiKey this mode logs locally only, by design.
3054
+ apiKey: _nullishCoalesce(_chunkS6WJ5YLPcjs.resolveIngestKey.call(void 0, options.apiKey, {}), () => ( "")),
2694
3055
  service: options.service,
2695
3056
  environment,
2696
3057
  ...options.release ? { release: options.release } : {},
2697
3058
  ...options.logging ? { options: options.logging } : {},
2698
3059
  redact,
2699
3060
  reportOutcome: (name, message, attributes) => {
2700
- _chunkYWTIKZSIcjs.runtimeLogger.error(message, {
3061
+ _chunkSTOXJZ7Zcjs.runtimeLogger.error(message, {
2701
3062
  ...attributes,
2702
3063
  "autter.outcome.name": name.slice(0, 200),
2703
3064
  "autter.outcome.message": message.slice(0, 1e3)
@@ -2712,7 +3073,7 @@ function initAutterLogging(options) {
2712
3073
  }
2713
3074
  });
2714
3075
  setLoggerOnlyCapture(captureException2, captureHandled);
2715
- _chunkYWTIKZSIcjs.startLoggedErrorCapture.call(void 0, options.captureLoggedErrors);
3076
+ _chunkSTOXJZ7Zcjs.startLoggedErrorCapture.call(void 0, options.captureLoggedErrors);
2716
3077
  const onCrash = (error) => {
2717
3078
  if (recordedAsRejection(error)) return;
2718
3079
  captureException2(error, { "autter.unhandled": true });
@@ -2725,22 +3086,22 @@ function initAutterLogging(options) {
2725
3086
  (reason) => captureException2(reason, { "autter.unhandled_rejection": true })
2726
3087
  );
2727
3088
  }
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, );
3089
+ _chunkS6WJ5YLPcjs.registerFlushTarget.call(void 0, "logging", { forceFlush: () => _chunkSTOXJZ7Zcjs.flushRuntimeLogs.call(void 0, ) });
3090
+ let autoFlushHandle = options.autoFlush === false ? null : _chunkS6WJ5YLPcjs.installAutterAutoFlush.call(void 0, );
2730
3091
  const handle = {
2731
3092
  captureException: captureException2,
2732
- flush: _chunkYWTIKZSIcjs.flushRuntimeLogs,
3093
+ flush: _chunkSTOXJZ7Zcjs.flushRuntimeLogs,
2733
3094
  shutdown: async () => {
2734
- if (L.active === handle) _chunkYWTIKZSIcjs.stopLoggedErrorCapture.call(void 0, );
3095
+ if (L.active === handle) _chunkSTOXJZ7Zcjs.stopLoggedErrorCapture.call(void 0, );
2735
3096
  process.off("uncaughtExceptionMonitor", onCrash);
2736
- _optionalChain([uninstallRejections, 'optionalCall', _145 => _145()]);
3097
+ _optionalChain([uninstallRejections, 'optionalCall', _170 => _170()]);
2737
3098
  uninstallRejections = null;
2738
3099
  setLoggerOnlyCapture(null);
2739
- _optionalChain([autoFlushHandle, 'optionalAccess', _146 => _146.dispose, 'call', _147 => _147()]);
3100
+ _optionalChain([autoFlushHandle, 'optionalAccess', _171 => _171.dispose, 'call', _172 => _172()]);
2740
3101
  autoFlushHandle = null;
2741
- _chunkBHYHORUDcjs.unregisterFlushTargets.call(void 0, );
3102
+ _chunkS6WJ5YLPcjs.unregisterFlushTargets.call(void 0, );
2742
3103
  if (L.active === handle) L.active = null;
2743
- await _chunkYWTIKZSIcjs.shutdownRuntimeLogger.call(void 0, );
3104
+ await _chunkSTOXJZ7Zcjs.shutdownRuntimeLogger.call(void 0, );
2744
3105
  }
2745
3106
  };
2746
3107
  L.active = handle;
@@ -2749,7 +3110,7 @@ function initAutterLogging(options) {
2749
3110
 
2750
3111
  // src/enrichers.ts
2751
3112
  function headerOf(req, name) {
2752
- const headers = _optionalChain([req, 'optionalAccess', _148 => _148.headers]);
3113
+ const headers = _optionalChain([req, 'optionalAccess', _173 => _173.headers]);
2753
3114
  if (!headers) return void 0;
2754
3115
  if (typeof headers.get === "function") {
2755
3116
  return _nullishCoalesce(headers.get(name), () => ( void 0));
@@ -2762,7 +3123,7 @@ function enrichUserAgent() {
2762
3123
  return (event, { req }) => {
2763
3124
  const ua = headerOf(req, "user-agent");
2764
3125
  if (!ua) return;
2765
- const info = _chunkYWTIKZSIcjs.parseUserAgent.call(void 0, ua);
3126
+ const info = _chunkSTOXJZ7Zcjs.parseUserAgent.call(void 0, ua);
2766
3127
  if (info.browser) event.attributes["user_agent.browser"] = info.browser;
2767
3128
  if (info.os) event.attributes["user_agent.os"] = info.os;
2768
3129
  event.attributes["user_agent.device"] = info.device;
@@ -2774,7 +3135,7 @@ function enrichRequestSize() {
2774
3135
  const request = Number(headerOf(req, "content-length"));
2775
3136
  if (Number.isFinite(request) && request >= 0)
2776
3137
  event.attributes["http.request.body.size"] = request;
2777
- const raw = _optionalChain([res, 'optionalAccess', _149 => _149.getHeader, 'optionalCall', _150 => _150(
3138
+ const raw = _optionalChain([res, 'optionalAccess', _174 => _174.getHeader, 'optionalCall', _175 => _175(
2778
3139
  "content-length"
2779
3140
  )]);
2780
3141
  const response = Number(raw);
@@ -2792,7 +3153,7 @@ var COUNTRY_HEADERS = [
2792
3153
  function enrichEdgeGeo() {
2793
3154
  return (event, { req }) => {
2794
3155
  for (const name of COUNTRY_HEADERS) {
2795
- const value = _optionalChain([headerOf, 'call', _151 => _151(req, name), 'optionalAccess', _152 => _152.trim, 'call', _153 => _153(), 'access', _154 => _154.toUpperCase, 'call', _155 => _155()]);
3156
+ const value = _optionalChain([headerOf, 'call', _176 => _176(req, name), 'optionalAccess', _177 => _177.trim, 'call', _178 => _178(), 'access', _179 => _179.toUpperCase, 'call', _180 => _180()]);
2796
3157
  if (value && /^[A-Z]{2}$/.test(value) && value !== "XX" && value !== "T1") {
2797
3158
  event.attributes["geo.country.iso_code"] = value;
2798
3159
  return;
@@ -2826,9 +3187,9 @@ var COMMIT_VARS = [
2826
3187
  "SOURCE_VERSION"
2827
3188
  ];
2828
3189
  function enrichDeployment(env = process.env) {
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)]);
3190
+ const pick = (names) => names.map((name) => _optionalChain([env, 'access', _181 => _181[name], 'optionalAccess', _182 => _182.trim, 'call', _183 => _183()])).find((value) => value);
3191
+ const region = _optionalChain([pick, 'call', _184 => _184(REGION_VARS), 'optionalAccess', _185 => _185.slice, 'call', _186 => _186(0, 64)]);
3192
+ const commit = _optionalChain([pick, 'call', _187 => _187(COMMIT_VARS), 'optionalAccess', _188 => _188.slice, 'call', _189 => _189(0, 64)]);
2832
3193
  return (event) => {
2833
3194
  if (region) event.attributes["deployment.region"] = region;
2834
3195
  if (commit) event.attributes["deployment.commit"] = commit;
@@ -2889,4 +3250,6 @@ function enrichDeployment(env = process.env) {
2889
3250
 
2890
3251
 
2891
3252
 
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;
3253
+
3254
+
3255
+ exports.CODE_PATTERN = _chunkSTOXJZ7Zcjs.CODE_PATTERN; exports.COMPAT_MANIFEST = _chunkS6WJ5YLPcjs.COMPAT_MANIFEST; exports.INGESTER_VERSION_HEADER = _chunkS6WJ5YLPcjs.INGESTER_VERSION_HEADER; exports.RuntimeError = _chunkSTOXJZ7Zcjs.RuntimeError; exports.SDK_IDENTITY = _chunkS6WJ5YLPcjs.SDK_IDENTITY; exports.addBreadcrumb = _chunkSTOXJZ7Zcjs.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.checkBrowserPayload = checkBrowserPayload; exports.consoleSink = _chunkSTOXJZ7Zcjs.consoleSink; exports.createBrowserRelayFetchHandler = createBrowserRelayFetchHandler; exports.createBrowserRelayHandler = createBrowserRelayHandler; exports.createRuntimeLogger = _chunkSTOXJZ7Zcjs.createRuntimeLogger; exports.defineRuntimeErrors = _chunkSTOXJZ7Zcjs.defineRuntimeErrors; exports.emitLlmSelftestTrace = emitLlmSelftestTrace; exports.enrichDeployment = enrichDeployment; exports.enrichEdgeGeo = enrichEdgeGeo; exports.enrichRequestSize = enrichRequestSize; exports.enrichUserAgent = enrichUserAgent; exports.errorAttributes = _chunkSTOXJZ7Zcjs.errorAttributes; exports.evaluateCompat = _chunkS6WJ5YLPcjs.evaluateCompat; exports.fetchIngesterCompat = _chunkS6WJ5YLPcjs.fetchIngesterCompat; exports.fileSink = _chunkSTOXJZ7Zcjs.fileSink; exports.flushRuntimeLogs = _chunkSTOXJZ7Zcjs.flushRuntimeLogs; exports.initAutterLogging = initAutterLogging; exports.initAutterServer = initAutterServer; exports.installAutterAutoFlush = _chunkS6WJ5YLPcjs.installAutterAutoFlush; exports.instrumentLlmClient = instrumentLlmClient; exports.isRuntimeErrorLike = _chunkSTOXJZ7Zcjs.isRuntimeErrorLike; exports.makeSafeCapture = makeSafeCapture; exports.otlpSink = _chunkSTOXJZ7Zcjs.otlpSink; exports.redactAttributes = _chunkSTOXJZ7Zcjs.redactAttributes; exports.redactText = _chunkSTOXJZ7Zcjs.redactText; exports.reportOutcome = reportOutcome; exports.runDoctor = _chunkHBH64LWQcjs.runDoctor; exports.runInBackground = _chunkSTOXJZ7Zcjs.runInBackground; exports.runVerify = _chunkHBH64LWQcjs.runVerify; exports.runtimeContext = _chunkSTOXJZ7Zcjs.runtimeContext; exports.runtimeLogStats = _chunkSTOXJZ7Zcjs.runtimeLogStats; exports.runtimeLogger = _chunkSTOXJZ7Zcjs.runtimeLogger; exports.sanitizeBrowserPayload = sanitizeBrowserPayload; exports.startCaughtExceptionSampler = startCaughtExceptionSampler; exports.toClientError = _chunkSTOXJZ7Zcjs.toClientError; exports.trackLlmCall = trackLlmCall; exports.unhandledRejectionsMode = unhandledRejectionsMode; exports.withLlmCall = withLlmCall; exports.withProcessSpan = withProcessSpan; exports.withRuntimeOperation = _chunkSTOXJZ7Zcjs.withRuntimeOperation; exports.withRuntimeRequest = withRuntimeRequest;