@autter/runtime-node 1.6.1 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -45,10 +45,10 @@
45
45
 
46
46
 
47
47
 
48
- var _chunkUXTIMS3Gcjs = require('./chunk-UXTIMS3G.cjs');
48
+ var _chunkRV4MJNM2cjs = require('./chunk-RV4MJNM2.cjs');
49
49
 
50
50
 
51
- var _chunk7OTD2YPTcjs = require('./chunk-7OTD2YPT.cjs');
51
+ var _chunkHKVFURYTcjs = require('./chunk-HKVFURYT.cjs');
52
52
 
53
53
 
54
54
 
@@ -70,7 +70,7 @@ var _chunk7OTD2YPTcjs = require('./chunk-7OTD2YPT.cjs');
70
70
 
71
71
 
72
72
 
73
- var _chunk4MVWIRBIcjs = require('./chunk-4MVWIRBI.cjs');
73
+ var _chunkGYTQLITWcjs = require('./chunk-GYTQLITW.cjs');
74
74
 
75
75
  // src/relay.ts
76
76
  var IpWindow = (_class = class {
@@ -224,7 +224,7 @@ function relayContext(raw, redactor) {
224
224
  return Array.isArray(bounded) ? {} : { context: redactor(bounded) };
225
225
  }
226
226
  function relayBreadcrumbs(raw, redactor) {
227
- const breadcrumbs = _chunkUXTIMS3Gcjs.sanitizeBreadcrumbs.call(void 0, raw, redactor);
227
+ const breadcrumbs = _chunkRV4MJNM2cjs.sanitizeBreadcrumbs.call(void 0, raw, redactor);
228
228
  return breadcrumbs ? { breadcrumbs } : {};
229
229
  }
230
230
  var DEBUG_ID_RE = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
@@ -241,10 +241,10 @@ function relayDebugIds(raw, redactor) {
241
241
  return count ? { debugIds } : {};
242
242
  }
243
243
  function relayFingerprint(raw, redactor) {
244
- const values = _chunkUXTIMS3Gcjs.fingerprintValues.call(void 0, raw, redactor.text);
244
+ const values = _chunkRV4MJNM2cjs.fingerprintValues.call(void 0, raw, redactor.text);
245
245
  return values ? { fingerprint: Array.isArray(raw) ? values : values[0] } : {};
246
246
  }
247
- var defaultRelayRedactor = _chunkUXTIMS3Gcjs.makeRedactor.call(void 0, true);
247
+ var defaultRelayRedactor = _chunkRV4MJNM2cjs.makeRedactor.call(void 0, true);
248
248
  function sanitizeBrowserPayload(raw, redactor = defaultRelayRedactor) {
249
249
  if (typeof raw !== "object" || raw === null) return null;
250
250
  const p = raw;
@@ -293,7 +293,7 @@ function forward(payload, opts) {
293
293
  const endpoint = (_nullishCoalesce(opts.endpoint, () => ( DEFAULT_ENDPOINT))).replace(/\/$/, "");
294
294
  const url = `${endpoint}/v1/browser`;
295
295
  const compat = opts.compatCheck !== false;
296
- if (compat) _chunk4MVWIRBIcjs.ensureCompatConfigured.call(void 0, endpoint);
296
+ if (compat) _chunkGYTQLITWcjs.ensureCompatConfigured.call(void 0, endpoint);
297
297
  void fetch(url, {
298
298
  method: "POST",
299
299
  headers: {
@@ -307,12 +307,12 @@ function forward(payload, opts) {
307
307
  const types = new Set(
308
308
  (_nullishCoalesce(payload.events, () => ( []))).map((e) => String(e.type))
309
309
  );
310
- _chunk4MVWIRBIcjs.observeIngesterResponse.call(void 0, { status: response.status, headers: response.headers });
311
- for (const feature of _chunk4MVWIRBIcjs.featuresForBrowserEvents.call(void 0, types)) _chunk4MVWIRBIcjs.noteCompatFeature.call(void 0, feature);
310
+ _chunkGYTQLITWcjs.observeIngesterResponse.call(void 0, { status: response.status, headers: response.headers });
311
+ for (const feature of _chunkGYTQLITWcjs.featuresForBrowserEvents.call(void 0, types)) _chunkGYTQLITWcjs.noteCompatFeature.call(void 0, feature);
312
312
  if ((_nullishCoalesce(payload.events, () => ( []))).some((e) => e.traceId)) {
313
- _chunk4MVWIRBIcjs.noteCompatFeature.call(void 0, "browser_trace_propagation");
313
+ _chunkGYTQLITWcjs.noteCompatFeature.call(void 0, "browser_trace_propagation");
314
314
  }
315
- _chunk4MVWIRBIcjs.noteRelayRejection.call(void 0, types, response.status, response.headers);
315
+ _chunkGYTQLITWcjs.noteRelayRejection.call(void 0, types, response.status, response.headers);
316
316
  }).catch((err) => {
317
317
  (_nullishCoalesce(opts.onError, () => ( ((e) => console.warn("autter relay forward failed:", e)))))(
318
318
  err
@@ -321,7 +321,7 @@ function forward(payload, opts) {
321
321
  }
322
322
  function createBrowserRelayFetchHandler(opts) {
323
323
  const maxBody = _nullishCoalesce(opts.maxBodyBytes, () => ( DEFAULT_MAX_BODY));
324
- const redactor = opts.redact === void 0 || opts.redact === true ? defaultRelayRedactor : _chunkUXTIMS3Gcjs.makeRedactor.call(void 0, opts.redact);
324
+ const redactor = opts.redact === void 0 || opts.redact === true ? defaultRelayRedactor : _chunkRV4MJNM2cjs.makeRedactor.call(void 0, opts.redact);
325
325
  const limiter = opts.perIpRateLimit === false ? null : new IpWindow(_nullishCoalesce(opts.perIpRateLimit, () => ( 120)));
326
326
  return async (request) => {
327
327
  if (request.method !== "POST") {
@@ -368,7 +368,7 @@ function createBrowserRelayFetchHandler(opts) {
368
368
  }
369
369
  function createBrowserRelayHandler(opts) {
370
370
  const maxBody = _nullishCoalesce(opts.maxBodyBytes, () => ( DEFAULT_MAX_BODY));
371
- const redactor = opts.redact === void 0 || opts.redact === true ? defaultRelayRedactor : _chunkUXTIMS3Gcjs.makeRedactor.call(void 0, opts.redact);
371
+ const redactor = opts.redact === void 0 || opts.redact === true ? defaultRelayRedactor : _chunkRV4MJNM2cjs.makeRedactor.call(void 0, opts.redact);
372
372
  const limiter = opts.perIpRateLimit === false ? null : new IpWindow(_nullishCoalesce(opts.perIpRateLimit, () => ( 120)));
373
373
  function respond(res, status, body) {
374
374
  res.statusCode = status;
@@ -441,6 +441,9 @@ function createBrowserRelayHandler(opts) {
441
441
  }
442
442
 
443
443
  // src/server.ts
444
+ var _events = require('events');
445
+ var _module = require('module');
446
+ var _path = require('path');
444
447
  var _http = require('http');
445
448
  var _crypto = require('crypto');
446
449
 
@@ -742,7 +745,7 @@ var _async_hooks = require('async_hooks');
742
745
 
743
746
  var REQUEST_STATE = /* @__PURE__ */ Symbol.for("autter.runtime.request");
744
747
  var BOUND = /* @__PURE__ */ Symbol.for("autter.runtime.bound");
745
- var CAPTURED = _chunk4MVWIRBIcjs.sharedSlot.call(void 0, "requests", () => ({ captured: /* @__PURE__ */ new WeakSet() })).captured;
748
+ var CAPTURED = _chunkGYTQLITWcjs.sharedSlot.call(void 0, "requests", () => ({ captured: /* @__PURE__ */ new WeakSet() })).captured;
746
749
  var capturer = () => {
747
750
  };
748
751
  function setRequestExceptionCapturer(fn) {
@@ -765,7 +768,7 @@ function expressRouteOf(req) {
765
768
  return route.startsWith("/") ? route : null;
766
769
  }
767
770
  function defaultShouldCapture(error) {
768
- return error instanceof _chunkUXTIMS3Gcjs.RuntimeError || _chunkUXTIMS3Gcjs.errorCodeOf.call(void 0, error) !== void 0 || _chunkUXTIMS3Gcjs.responseStatusOf.call(void 0, error) >= 500;
771
+ return error instanceof _chunkRV4MJNM2cjs.RuntimeError || _chunkRV4MJNM2cjs.errorCodeOf.call(void 0, error) !== void 0 || _chunkRV4MJNM2cjs.responseStatusOf.call(void 0, error) >= 500;
769
772
  }
770
773
  function onRequestSpan(fn) {
771
774
  const active = _api.context.active();
@@ -789,7 +792,7 @@ function captureAtBoundary(error, state, rule = void 0, attributes) {
789
792
  markCaptured(error);
790
793
  try {
791
794
  const run = () => onRequestSpan(() => capturer(error, attributes));
792
- if (state && !state.sealed) _chunkUXTIMS3Gcjs.local.run(state, run);
795
+ if (state && !state.sealed) _chunkRV4MJNM2cjs.local.run(state, run);
793
796
  else run();
794
797
  } catch (e15) {
795
798
  }
@@ -807,7 +810,7 @@ function captureRequestError(error, attributes) {
807
810
  }
808
811
  return;
809
812
  }
810
- captureAtBoundary(error, _chunkUXTIMS3Gcjs.currentOperation.call(void 0, ), true, attributes);
813
+ captureAtBoundary(error, _chunkRV4MJNM2cjs.currentOperation.call(void 0, ), true, attributes);
811
814
  }
812
815
  function bindEmitter(emitter, state) {
813
816
  const target = emitter;
@@ -819,7 +822,7 @@ function bindEmitter(emitter, state) {
819
822
  let wrapped = wrappers.get(listener);
820
823
  if (!wrapped) {
821
824
  wrapped = function(...args) {
822
- return _chunkUXTIMS3Gcjs.local.run(
825
+ return _chunkRV4MJNM2cjs.local.run(
823
826
  state,
824
827
  () => listener.apply(this, args)
825
828
  );
@@ -886,7 +889,7 @@ function pathOf(req) {
886
889
  function finishRequest(state, input) {
887
890
  if (state.sealed) return;
888
891
  state.name = (_nullishCoalesce(input.name, () => ( `${input.method} ${input.route}`))).slice(0, 200);
889
- state.outcome = _chunkUXTIMS3Gcjs.requestOutcome.call(void 0, {
892
+ state.outcome = _chunkRV4MJNM2cjs.requestOutcome.call(void 0, {
890
893
  ...state.explicitOutcome ? { explicit: state.outcome } : {},
891
894
  ...state.error !== void 0 ? { error: state.error } : {},
892
895
  ...state.errorThrown ? { thrown: true } : {},
@@ -899,10 +902,10 @@ function finishRequest(state, input) {
899
902
  const remote = _api.trace.wrapSpanContext(input.span);
900
903
  _api.context.with(
901
904
  _api.trace.setSpan(_api.context.active(), remote),
902
- () => _chunkUXTIMS3Gcjs.reportExplicitFailure.call(void 0, state)
905
+ () => _chunkRV4MJNM2cjs.reportExplicitFailure.call(void 0, state)
903
906
  );
904
- } else _chunkUXTIMS3Gcjs.reportExplicitFailure.call(void 0, state);
905
- _chunkUXTIMS3Gcjs.emitSummary.call(void 0, state, {
907
+ } else _chunkRV4MJNM2cjs.reportExplicitFailure.call(void 0, state);
908
+ _chunkRV4MJNM2cjs.emitSummary.call(void 0, state, {
906
909
  http: {
907
910
  "http.request.method": input.method,
908
911
  "http.route": input.route,
@@ -913,14 +916,14 @@ function finishRequest(state, input) {
913
916
  });
914
917
  }
915
918
  function beginNodeRequest(req, res, options, route) {
916
- const header = (_nullishCoalesce(options.requestIdHeader, () => ( _chunkUXTIMS3Gcjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
917
- const requestId = _chunkUXTIMS3Gcjs.resolveRequestId.call(void 0,
919
+ const header = (_nullishCoalesce(options.requestIdHeader, () => ( _chunkRV4MJNM2cjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
920
+ const requestId = _chunkRV4MJNM2cjs.resolveRequestId.call(void 0,
918
921
  options.trustRequestId === false ? void 0 : req.headers[header]
919
922
  );
920
923
  const method = (_nullishCoalesce(req.method, () => ( "GET"))).toUpperCase();
921
924
  const path = pathOf(req);
922
- const state = _chunkUXTIMS3Gcjs.createRequestState.call(void 0, {
923
- name: `${method} ${_chunkUXTIMS3Gcjs.normalizeRoutePath.call(void 0, path)}`,
925
+ const state = _chunkRV4MJNM2cjs.createRequestState.call(void 0, {
926
+ name: `${method} ${_chunkRV4MJNM2cjs.normalizeRoutePath.call(void 0, path)}`,
924
927
  requestId,
925
928
  req,
926
929
  res
@@ -944,7 +947,7 @@ function beginNodeRequest(req, res, options, route) {
944
947
  const done = () => {
945
948
  finishRequest(state, {
946
949
  method,
947
- route: _nullishCoalesce(_nullishCoalesce(_optionalChain([route, 'optionalCall', _20 => _20()]), () => ( expressRouteOf(req))), () => ( _chunkUXTIMS3Gcjs.normalizeRoutePath.call(void 0, path))),
950
+ route: _nullishCoalesce(_nullishCoalesce(_optionalChain([route, 'optionalCall', _20 => _20()]), () => ( expressRouteOf(req))), () => ( _chunkRV4MJNM2cjs.normalizeRoutePath.call(void 0, path))),
948
951
  status: res.statusCode,
949
952
  aborted: !finished,
950
953
  ...spanContext ? { span: spanContext } : {}
@@ -958,50 +961,50 @@ function beginNodeRequest(req, res, options, route) {
958
961
  return state;
959
962
  }
960
963
  function autterRequests(options = {}) {
961
- const ignored = _chunkUXTIMS3Gcjs.compileIgnore.call(void 0, options.ignore);
964
+ const ignored = _chunkRV4MJNM2cjs.compileIgnore.call(void 0, options.ignore);
962
965
  return function autterRequestsMiddleware(req, res, next) {
963
966
  if (req[REQUEST_STATE] || ignored(pathOf(req))) {
964
967
  next();
965
968
  return;
966
969
  }
967
970
  const state = beginNodeRequest(req, res, options);
968
- _chunkUXTIMS3Gcjs.local.run(state, () => next());
971
+ _chunkRV4MJNM2cjs.local.run(state, () => next());
969
972
  };
970
973
  }
971
974
  function autterErrorResponse(options = {}) {
972
975
  return function autterErrorResponseMiddleware(error, req, res, next) {
973
976
  const state = req[REQUEST_STATE];
974
- if (state) _chunkUXTIMS3Gcjs.noteOperationError.call(void 0, error, true, state);
977
+ if (state) _chunkRV4MJNM2cjs.noteOperationError.call(void 0, error, true, state);
975
978
  captureAtBoundary(error, state, options.capture);
976
979
  if (res.headersSent) {
977
980
  next(error);
978
981
  return;
979
982
  }
980
- const header = (_nullishCoalesce(options.requestIdHeader, () => ( _chunkUXTIMS3Gcjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
983
+ const header = (_nullishCoalesce(options.requestIdHeader, () => ( _chunkRV4MJNM2cjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
981
984
  const inbound = _optionalChain([req, 'access', _21 => _21.headers, 'optionalAccess', _22 => _22[header]]);
982
985
  const requestId = _nullishCoalesce(_optionalChain([state, 'optionalAccess', _23 => _23.requestId]), () => ( (typeof inbound === "string" ? inbound.slice(0, 128) : void 0)));
983
- res.statusCode = _chunkUXTIMS3Gcjs.responseStatusOf.call(void 0, error);
986
+ res.statusCode = _chunkRV4MJNM2cjs.responseStatusOf.call(void 0, error);
984
987
  res.setHeader("content-type", "application/json; charset=utf-8");
985
- res.end(JSON.stringify(_chunkUXTIMS3Gcjs.toClientError.call(void 0, error, requestId)));
988
+ res.end(JSON.stringify(_chunkRV4MJNM2cjs.toClientError.call(void 0, error, requestId)));
986
989
  };
987
990
  }
988
991
  var RESOURCE = /* @__PURE__ */ Symbol.for("autter.runtime.resource");
989
992
  function autterFastify(fastify, options, done) {
990
993
  const opts = _nullishCoalesce(options, () => ( {}));
991
- const header = (_nullishCoalesce(opts.requestIdHeader, () => ( _chunkUXTIMS3Gcjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
992
- const ignored = _chunkUXTIMS3Gcjs.compileIgnore.call(void 0, opts.ignore);
994
+ const header = (_nullishCoalesce(opts.requestIdHeader, () => ( _chunkRV4MJNM2cjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
995
+ const ignored = _chunkRV4MJNM2cjs.compileIgnore.call(void 0, opts.ignore);
993
996
  const stateOf = (request) => request[REQUEST_STATE];
994
997
  fastify.addHook("onRequest", ((request, reply, next) => {
995
998
  if (ignored(request.url) || request.raw[REQUEST_STATE]) {
996
999
  next();
997
1000
  return;
998
1001
  }
999
- const requestId = _chunkUXTIMS3Gcjs.resolveRequestId.call(void 0,
1002
+ const requestId = _chunkRV4MJNM2cjs.resolveRequestId.call(void 0,
1000
1003
  opts.trustRequestId === false ? void 0 : request.headers[header]
1001
1004
  );
1002
1005
  const method = String(_nullishCoalesce(request.method, () => ( "GET"))).toUpperCase();
1003
- const state = _chunkUXTIMS3Gcjs.createRequestState.call(void 0, {
1004
- name: `${method} ${_chunkUXTIMS3Gcjs.normalizeRoutePath.call(void 0, request.url)}`,
1006
+ const state = _chunkRV4MJNM2cjs.createRequestState.call(void 0, {
1007
+ name: `${method} ${_chunkRV4MJNM2cjs.normalizeRoutePath.call(void 0, request.url)}`,
1005
1008
  requestId,
1006
1009
  req: request.raw,
1007
1010
  res: reply.raw
@@ -1021,7 +1024,7 @@ function autterFastify(fastify, options, done) {
1021
1024
  let finished = false;
1022
1025
  const finish = (aborted) => finishRequest(state, {
1023
1026
  method,
1024
- route: _nullishCoalesce(_nullishCoalesce(_optionalChain([request, 'access', _28 => _28.routeOptions, 'optionalAccess', _29 => _29.url]), () => ( request.routerPath)), () => ( _chunkUXTIMS3Gcjs.normalizeRoutePath.call(void 0, request.url))),
1027
+ route: _nullishCoalesce(_nullishCoalesce(_optionalChain([request, 'access', _28 => _28.routeOptions, 'optionalAccess', _29 => _29.url]), () => ( request.routerPath)), () => ( _chunkRV4MJNM2cjs.normalizeRoutePath.call(void 0, request.url))),
1025
1028
  status: reply.raw.statusCode || reply.statusCode,
1026
1029
  aborted,
1027
1030
  ...spanContext ? { span: spanContext } : {}
@@ -1031,7 +1034,7 @@ function autterFastify(fastify, options, done) {
1031
1034
  finish(false);
1032
1035
  });
1033
1036
  reply.raw.once("close", () => finish(!finished));
1034
- _chunkUXTIMS3Gcjs.local.run(state, () => {
1037
+ _chunkRV4MJNM2cjs.local.run(state, () => {
1035
1038
  request[RESOURCE] = new (0, _async_hooks.AsyncResource)("autter-request");
1036
1039
  next();
1037
1040
  });
@@ -1053,7 +1056,7 @@ function autterFastify(fastify, options, done) {
1053
1056
  }));
1054
1057
  fastify.addHook("onError", ((request, _reply, error, next) => {
1055
1058
  const state = stateOf(request);
1056
- if (state) _chunkUXTIMS3Gcjs.noteOperationError.call(void 0, error, true, state);
1059
+ if (state) _chunkRV4MJNM2cjs.noteOperationError.call(void 0, error, true, state);
1057
1060
  captureAtBoundary(error, state);
1058
1061
  next();
1059
1062
  }));
@@ -1084,8 +1087,8 @@ function withHeaders(response, header, requestId) {
1084
1087
  }
1085
1088
  }
1086
1089
  function withRuntimeRequest(handler, options = {}) {
1087
- const header = (_nullishCoalesce(options.requestIdHeader, () => ( _chunkUXTIMS3Gcjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
1088
- const ignored = _chunkUXTIMS3Gcjs.compileIgnore.call(void 0, options.ignore);
1090
+ const header = (_nullishCoalesce(options.requestIdHeader, () => ( _chunkRV4MJNM2cjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
1091
+ const ignored = _chunkRV4MJNM2cjs.compileIgnore.call(void 0, options.ignore);
1089
1092
  return async (request, ...rest) => {
1090
1093
  let pathname = "/";
1091
1094
  try {
@@ -1093,12 +1096,12 @@ function withRuntimeRequest(handler, options = {}) {
1093
1096
  } catch (e22) {
1094
1097
  }
1095
1098
  if (ignored(pathname)) return handler(request, ...rest);
1096
- const requestId = _chunkUXTIMS3Gcjs.resolveRequestId.call(void 0,
1099
+ const requestId = _chunkRV4MJNM2cjs.resolveRequestId.call(void 0,
1097
1100
  options.trustRequestId === false ? void 0 : request.headers.get(header)
1098
1101
  );
1099
1102
  const method = String(_nullishCoalesce(request.method, () => ( "GET"))).toUpperCase();
1100
- const route = _nullishCoalesce(options.route, () => ( _chunkUXTIMS3Gcjs.normalizeRoutePath.call(void 0, pathname)));
1101
- const state = _chunkUXTIMS3Gcjs.createRequestState.call(void 0, {
1103
+ const route = _nullishCoalesce(options.route, () => ( _chunkRV4MJNM2cjs.normalizeRoutePath.call(void 0, pathname)));
1104
+ const state = _chunkRV4MJNM2cjs.createRequestState.call(void 0, {
1102
1105
  name: `${method} ${_nullishCoalesce(options.name, () => ( route))}`,
1103
1106
  requestId,
1104
1107
  req: request
@@ -1112,11 +1115,11 @@ function withRuntimeRequest(handler, options = {}) {
1112
1115
  const spanContext = _optionalChain([span, 'optionalAccess', _32 => _32.spanContext, 'call', _33 => _33()]);
1113
1116
  let status = 500;
1114
1117
  try {
1115
- const response = await _chunkUXTIMS3Gcjs.local.run(state, async () => {
1118
+ const response = await _chunkRV4MJNM2cjs.local.run(state, async () => {
1116
1119
  try {
1117
1120
  return await handler(request, ...rest);
1118
1121
  } catch (error) {
1119
- _chunkUXTIMS3Gcjs.noteOperationError.call(void 0, error, true, state);
1122
+ _chunkRV4MJNM2cjs.noteOperationError.call(void 0, error, true, state);
1120
1123
  captureAtBoundary(error, state, true);
1121
1124
  throw error;
1122
1125
  }
@@ -1135,7 +1138,7 @@ function withRuntimeRequest(handler, options = {}) {
1135
1138
  });
1136
1139
  if (options.waitUntil) {
1137
1140
  try {
1138
- options.waitUntil(_chunkUXTIMS3Gcjs.flushRuntimeLogs.call(void 0, ).catch(() => {
1141
+ options.waitUntil(_chunkRV4MJNM2cjs.flushRuntimeLogs.call(void 0, ).catch(() => {
1139
1142
  }));
1140
1143
  } catch (e23) {
1141
1144
  }
@@ -1147,7 +1150,7 @@ function startHookRequest(res) {
1147
1150
  const req = res.req;
1148
1151
  if (!req || req[REQUEST_STATE]) return;
1149
1152
  const state = beginNodeRequest(req, res, {});
1150
- _chunkUXTIMS3Gcjs.local.enterWith(state);
1153
+ _chunkRV4MJNM2cjs.local.enterWith(state);
1151
1154
  }
1152
1155
 
1153
1156
  // src/unhandled-rejections.ts
@@ -1276,11 +1279,45 @@ function installUnhandledRejectionCapture(capture, mode = unhandledRejectionsMod
1276
1279
  };
1277
1280
  }
1278
1281
 
1282
+ // src/route-label.ts
1283
+
1284
+ var ours = /* @__PURE__ */ new WeakMap();
1285
+ var RAW_PATH_SPAN_TYPES = /* @__PURE__ */ new Set(["BaseServer.renderToResponse"]);
1286
+ function noteFrameworkRoute(parent, attributes) {
1287
+ const route = _optionalChain([attributes, 'optionalAccess', _42 => _42["next.route"]]);
1288
+ if (typeof route !== "string" || !route.startsWith("/")) return;
1289
+ if (RAW_PATH_SPAN_TYPES.has(String(_nullishCoalesce(_optionalChain([attributes, 'optionalAccess', _43 => _43["next.span_type"]]), () => ( ""))))) return;
1290
+ const rpc = _core.getRPCMetadata.call(void 0, parent);
1291
+ if (!rpc || rpc.type !== _core.RPCType.HTTP) return;
1292
+ const mine = ours.get(rpc);
1293
+ if (rpc.route !== void 0 && rpc.route !== mine) return;
1294
+ if (mine !== void 0 && mine.includes("[") && !route.includes("[")) return;
1295
+ if (mine !== void 0 && (route === `${mine}/route` || route === `${mine}/page`)) return;
1296
+ rpc.route = route;
1297
+ ours.set(rpc, route);
1298
+ }
1299
+ var RouteLabelSampler = class {
1300
+ constructor(delegate) {
1301
+ this.delegate = delegate;
1302
+ }
1303
+
1304
+ shouldSample(ctx, traceId, spanName, spanKind, attributes, links) {
1305
+ try {
1306
+ noteFrameworkRoute(ctx, attributes);
1307
+ } catch (e29) {
1308
+ }
1309
+ return this.delegate.shouldSample(ctx, traceId, spanName, spanKind, attributes, links);
1310
+ }
1311
+ toString() {
1312
+ return `RouteLabel(${this.delegate.toString()})`;
1313
+ }
1314
+ };
1315
+
1279
1316
  // src/server.ts
1280
- var S = _chunk4MVWIRBIcjs.sharedSlot.call(void 0, "server", () => ({
1317
+ var S = _chunkGYTQLITWcjs.sharedSlot.call(void 0, "server", () => ({
1281
1318
  active: null,
1282
1319
  alwaysOnProvider: null,
1283
- redactor: _chunkUXTIMS3Gcjs.makeRedactor.call(void 0, true),
1320
+ redactor: _chunkRV4MJNM2cjs.makeRedactor.call(void 0, true),
1284
1321
  loggerOnlyCapture: null,
1285
1322
  hookRequests: false
1286
1323
  }));
@@ -1380,7 +1417,7 @@ var ErrorTraceRetentionProcessor = (_class2 = class {
1380
1417
  this.retainErrors = retainErrors;
1381
1418
  this.slowThresholdMs = slowThresholdMs;
1382
1419
  this.sweeper = setInterval(() => this.sweep(), RETENTION_SWEEP_INTERVAL_MS);
1383
- _optionalChain([this, 'access', _42 => _42.sweeper, 'access', _43 => _43.unref, 'optionalCall', _44 => _44()]);
1420
+ _optionalChain([this, 'access', _44 => _44.sweeper, 'access', _45 => _45.unref, 'optionalCall', _46 => _46()]);
1384
1421
  }
1385
1422
 
1386
1423
 
@@ -1411,7 +1448,7 @@ var ErrorTraceRetentionProcessor = (_class2 = class {
1411
1448
  }
1412
1449
  /** Promote the active trace, if any — called on captured errors. */
1413
1450
  retainActiveTrace() {
1414
- const active = _optionalChain([_api.trace, 'access', _45 => _45.getActiveSpan, 'call', _46 => _46(), 'optionalAccess', _47 => _47.spanContext, 'call', _48 => _48()]);
1451
+ const active = _optionalChain([_api.trace, 'access', _47 => _47.getActiveSpan, 'call', _48 => _48(), 'optionalAccess', _49 => _49.spanContext, 'call', _50 => _50()]);
1415
1452
  if (!active || (active.traceFlags & _api.TraceFlags.SAMPLED) !== 0) return;
1416
1453
  const entry = this.entryFor(active.traceId);
1417
1454
  if (entry.retained) return;
@@ -1532,15 +1569,15 @@ async function runLlmSpan(tracer, info, fn) {
1532
1569
  return result;
1533
1570
  } catch (err) {
1534
1571
  recordError(span, err);
1535
- if (_chunkUXTIMS3Gcjs.isError.call(void 0, err)) span.setAttribute("error.type", err.name);
1572
+ if (_chunkRV4MJNM2cjs.isError.call(void 0, err)) span.setAttribute("error.type", err.name);
1536
1573
  throw err;
1537
1574
  } finally {
1538
1575
  span.end();
1539
- _chunkUXTIMS3Gcjs.recordOperationAiUsage.call(void 0, { ...usage, model: _nullishCoalesce(responseModel, () => ( info.model)) });
1576
+ _chunkRV4MJNM2cjs.recordOperationAiUsage.call(void 0, { ...usage, model: _nullishCoalesce(responseModel, () => ( info.model)) });
1540
1577
  }
1541
1578
  }
1542
1579
  function recordLlmCall(tracer, call) {
1543
- _chunkUXTIMS3Gcjs.recordOperationAiUsage.call(void 0, { ...call, model: call.model });
1580
+ _chunkRV4MJNM2cjs.recordOperationAiUsage.call(void 0, { ...call, model: call.model });
1544
1581
  const durationMs = Math.max(0, _nullishCoalesce(call.durationMs, () => ( 0)));
1545
1582
  const endTime = /* @__PURE__ */ new Date();
1546
1583
  const startTime = new Date(endTime.getTime() - durationMs);
@@ -1554,7 +1591,7 @@ function recordLlmCall(tracer, call) {
1554
1591
  );
1555
1592
  if (call.error !== void 0 && call.error !== null) {
1556
1593
  recordError(span, call.error);
1557
- if (_chunkUXTIMS3Gcjs.isError.call(void 0, call.error)) {
1594
+ if (_chunkRV4MJNM2cjs.isError.call(void 0, call.error)) {
1558
1595
  span.setAttribute("error.type", call.error.name);
1559
1596
  }
1560
1597
  } else {
@@ -1565,7 +1602,7 @@ function recordLlmCall(tracer, call) {
1565
1602
  async function runWithSpan(tracer, name, fn, attributes, links) {
1566
1603
  const span = tracer.startSpan(name, {
1567
1604
  attributes,
1568
- ..._optionalChain([links, 'optionalAccess', _49 => _49.length]) ? { links } : {}
1605
+ ..._optionalChain([links, 'optionalAccess', _51 => _51.length]) ? { links } : {}
1569
1606
  });
1570
1607
  try {
1571
1608
  const result = await _api.context.with(
@@ -1582,14 +1619,14 @@ async function runWithSpan(tracer, name, fn, attributes, links) {
1582
1619
  }
1583
1620
  }
1584
1621
  function recordError(span, err) {
1585
- const isErr = _chunkUXTIMS3Gcjs.isError.call(void 0, err);
1622
+ const isErr = _chunkRV4MJNM2cjs.isError.call(void 0, err);
1586
1623
  const message = S.redactor.text(isErr ? err.message : String(err));
1587
1624
  if (isErr) {
1588
1625
  span.addEvent("exception", {
1589
1626
  "exception.type": err.name,
1590
1627
  "exception.message": message,
1591
1628
  ...err.stack ? { "exception.stacktrace": S.redactor.text(err.stack) } : {},
1592
- ..._chunkUXTIMS3Gcjs.breadcrumbEventAttributes.call(void 0, S.redactor.text, err)
1629
+ ..._chunkRV4MJNM2cjs.breadcrumbEventAttributes.call(void 0, S.redactor.text, err)
1593
1630
  });
1594
1631
  }
1595
1632
  span.setStatus({ code: _api.SpanStatusCode.ERROR, message });
@@ -1597,28 +1634,44 @@ function recordError(span, err) {
1597
1634
  function redactWithActive(attributes) {
1598
1635
  return S.redactor(attributes);
1599
1636
  }
1600
- function captureExpressRoute(_span, response) {
1637
+ function patchLoadedHttpModules() {
1638
+ try {
1639
+ const load = _module.createRequire.call(void 0, _path.join.call(void 0, process.cwd(), "autter-runtime-http.cjs"));
1640
+ load("http");
1641
+ load("https");
1642
+ } catch (e30) {
1643
+ }
1644
+ }
1645
+ var METRIC_ROUTE_ATTR = "autter.metric_has_route";
1646
+ function captureRequestRoute(span, response) {
1601
1647
  if (!(response instanceof _http.ServerResponse)) return;
1602
1648
  const rpcMetadata = _core.getRPCMetadata.call(void 0, _api.context.active());
1603
- if (_optionalChain([rpcMetadata, 'optionalAccess', _50 => _50.type]) !== _core.RPCType.HTTP) return;
1649
+ if (_optionalChain([rpcMetadata, 'optionalAccess', _52 => _52.type]) !== _core.RPCType.HTTP) return;
1650
+ let failed = false;
1651
+ response.on(_events.errorMonitor, () => {
1652
+ failed = true;
1653
+ });
1604
1654
  const setRoute = () => {
1605
1655
  if (rpcMetadata.route) return;
1606
1656
  const route = expressRouteOf(response.req);
1607
1657
  if (route) rpcMetadata.route = route;
1608
1658
  };
1609
1659
  response.prependListener("finish", setRoute);
1610
- response.prependListener("close", setRoute);
1660
+ response.prependListener("close", () => {
1661
+ setRoute();
1662
+ if (rpcMetadata.route && !failed) span.setAttribute(METRIC_ROUTE_ATTR, true);
1663
+ });
1611
1664
  if (S.hookRequests) startHookRequest(response);
1612
1665
  }
1613
1666
  function structuredErrorAttributes(error) {
1614
- const attrs = { ..._chunkUXTIMS3Gcjs.errorAttributes.call(void 0, error, { causes: false }) };
1615
- const internal = _chunkUXTIMS3Gcjs.errorInternal.call(void 0, error);
1667
+ const attrs = { ..._chunkRV4MJNM2cjs.errorAttributes.call(void 0, error, { causes: false }) };
1668
+ const internal = _chunkRV4MJNM2cjs.errorInternal.call(void 0, error);
1616
1669
  if (internal) {
1617
1670
  try {
1618
1671
  attrs["autter.error.internal"] = JSON.stringify(
1619
1672
  S.redactor(internal)
1620
1673
  ).slice(0, 4e3);
1621
- } catch (e29) {
1674
+ } catch (e31) {
1622
1675
  }
1623
1676
  }
1624
1677
  return attrs;
@@ -1630,9 +1683,9 @@ function initAutterServer(options) {
1630
1683
  ""
1631
1684
  );
1632
1685
  const headers = { authorization: `Bearer ${options.apiKey}` };
1633
- const redactor = _chunkUXTIMS3Gcjs.makeRedactor.call(void 0, _nullishCoalesce(options.redactAttributes, () => ( true)));
1686
+ const redactor = _chunkRV4MJNM2cjs.makeRedactor.call(void 0, _nullishCoalesce(options.redactAttributes, () => ( true)));
1634
1687
  const queryPolicy = makeUrlQueryPolicy(options.keepQueryParams);
1635
- const traceExporter = () => new (0, _chunk4MVWIRBIcjs.CountingExporter)(
1688
+ const traceExporter = () => new (0, _chunkGYTQLITWcjs.CountingExporter)(
1636
1689
  new RedactingSpanExporter(
1637
1690
  new (0, _exportertraceotlphttp.OTLPTraceExporter)({ url: `${endpoint}/v1/traces`, headers }),
1638
1691
  () => redactor,
@@ -1640,11 +1693,11 @@ function initAutterServer(options) {
1640
1693
  )
1641
1694
  );
1642
1695
  const environment = _nullishCoalesce(_nullishCoalesce(options.environment, () => ( process.env.NODE_ENV)), () => ( "production"));
1643
- if (_chunk4MVWIRBIcjs.isDebugEnabled.call(void 0, ) || options.debug === true) _chunk4MVWIRBIcjs.setDebugMode.call(void 0, true);
1644
- _chunk4MVWIRBIcjs.debugLog.call(void 0, `initialising service=${options.service} endpoint=${endpoint}`);
1696
+ if (_chunkGYTQLITWcjs.isDebugEnabled.call(void 0, ) || options.debug === true) _chunkGYTQLITWcjs.setDebugMode.call(void 0, true);
1697
+ _chunkGYTQLITWcjs.debugLog.call(void 0, `initialising service=${options.service} endpoint=${endpoint}`);
1645
1698
  S.redactor = redactor;
1646
- const distro = _nullishCoalesce(options.distro, () => ( _chunk4MVWIRBIcjs.SDK_IDENTITY));
1647
- _chunk4MVWIRBIcjs.configureCompatCheck.call(void 0, { endpoint, enabled: options.compatCheck !== false, sdk: distro });
1699
+ const distro = _nullishCoalesce(options.distro, () => ( _chunkGYTQLITWcjs.SDK_IDENTITY));
1700
+ _chunkGYTQLITWcjs.configureCompatCheck.call(void 0, { endpoint, enabled: options.compatCheck !== false, sdk: distro });
1648
1701
  const resource = new (0, _resources.Resource)({
1649
1702
  [_semanticconventions.ATTR_SERVICE_NAME]: options.service,
1650
1703
  "service.instance.id": (options.instanceId || process.env.AUTTER_RUNTIME_INSTANCE_ID || _crypto.randomUUID.call(void 0, )).slice(0, 128),
@@ -1656,8 +1709,14 @@ function initAutterServer(options) {
1656
1709
  "telemetry.distro.version": distro.version,
1657
1710
  // Tells the ingester request metrics arrive on the metrics pipe, so
1658
1711
  // it must not also fold our server spans into usage rollups (that
1659
- // would double-count every sampled request).
1660
- "autter.metrics_wired": true
1712
+ // would double-count every sampled request)...
1713
+ "autter.metrics_wired": true,
1714
+ // ...for the requests whose metric carries their route: those
1715
+ // request spans say so (`autter.metric_has_route`, see
1716
+ // captureRequestRoute). Ingesters honour metrics_wired only with
1717
+ // this, so an older SDK, whose Next.js metrics have no route, keeps
1718
+ // its span-fed per-route counts.
1719
+ "autter.metrics_routes": true
1661
1720
  });
1662
1721
  const rootSampler = new (0, _sdktracebase.TraceIdRatioBasedSampler)(_nullishCoalesce(options.traceSampleRate, () => ( 0.01)));
1663
1722
  const headSampler = new (0, _sdktracebase.ParentBasedSampler)({
@@ -1674,6 +1733,7 @@ function initAutterServer(options) {
1674
1733
  const retainTraces = retainOnError || slowThresholdMs > 0;
1675
1734
  let sampler = retainTraces ? new RecordUnsampledSampler(headSampler) : headSampler;
1676
1735
  if (options.llmTracing !== false) sampler = new LlmAwareSampler(sampler);
1736
+ sampler = new RouteLabelSampler(sampler);
1677
1737
  const errorTraceBuffer = retainTraces ? new ErrorTraceRetentionProcessor(
1678
1738
  new (0, _sdktracebase.BatchSpanProcessor)(traceExporter(), { scheduledDelayMillis: 2e3 }),
1679
1739
  retainOnError,
@@ -1712,15 +1772,16 @@ function initAutterServer(options) {
1712
1772
  ) })
1713
1773
  ],
1714
1774
  instrumentations: [
1715
- new (0, _instrumentationhttp.HttpInstrumentation)({ responseHook: captureExpressRoute }),
1775
+ new (0, _instrumentationhttp.HttpInstrumentation)({ responseHook: captureRequestRoute }),
1716
1776
  ..._nullishCoalesce(options.instrumentations, () => ( []))
1717
1777
  ]
1718
1778
  });
1719
1779
  sdk.start();
1780
+ patchLoadedHttpModules();
1720
1781
  const stopMemoryMetrics = options.memoryMetrics === false ? null : startMemoryMetrics();
1721
- _chunk4MVWIRBIcjs.noteCompatFeature.call(void 0, "endpoint_latency");
1722
- if (stopMemoryMetrics) _chunk4MVWIRBIcjs.noteCompatFeature.call(void 0, "memory_metrics");
1723
- if (options.llmTracing !== false) _chunk4MVWIRBIcjs.noteCompatFeature.call(void 0, "llm_calls");
1782
+ _chunkGYTQLITWcjs.noteCompatFeature.call(void 0, "endpoint_latency");
1783
+ if (stopMemoryMetrics) _chunkGYTQLITWcjs.noteCompatFeature.call(void 0, "memory_metrics");
1784
+ if (options.llmTracing !== false) _chunkGYTQLITWcjs.noteCompatFeature.call(void 0, "llm_calls");
1724
1785
  const alwaysOnProvider = new (0, _sdktracebase.BasicTracerProvider)({
1725
1786
  resource,
1726
1787
  sampler: new (0, _sdktracebase.AlwaysOnSampler)(),
@@ -1732,25 +1793,25 @@ function initAutterServer(options) {
1732
1793
  const processTracer = alwaysOnProvider.getTracer("autter-processes");
1733
1794
  const llmTracer = alwaysOnProvider.getTracer("autter-llm");
1734
1795
  function captureException2(error, attributes) {
1735
- _optionalChain([errorTraceBuffer, 'optionalAccess', _51 => _51.retainActiveTrace, 'call', _52 => _52()]);
1736
- _chunk4MVWIRBIcjs.telemetryStats.markCaptured();
1737
- const isErr = _chunkUXTIMS3Gcjs.isError.call(void 0, error);
1796
+ _optionalChain([errorTraceBuffer, 'optionalAccess', _53 => _53.retainActiveTrace, 'call', _54 => _54()]);
1797
+ _chunkGYTQLITWcjs.telemetryStats.markCaptured();
1798
+ const isErr = _chunkRV4MJNM2cjs.isError.call(void 0, error);
1738
1799
  const message = redactor.text(isErr ? error.message : String(error));
1739
1800
  const stackText = isErr && error.stack ? redactor.text(error.stack) : "";
1740
- const split = _chunkUXTIMS3Gcjs.splitFingerprint.call(void 0, attributes);
1741
- const fingerprint = _chunkUXTIMS3Gcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, redactor.text);
1742
- if (fingerprint["autter.fingerprint"]) _chunk4MVWIRBIcjs.noteCompatFeature.call(void 0, "fingerprint_override");
1801
+ const split = _chunkRV4MJNM2cjs.splitFingerprint.call(void 0, attributes);
1802
+ const fingerprint = _chunkRV4MJNM2cjs.fingerprintEventAttributes.call(void 0, split.fingerprint, redactor.text);
1803
+ if (fingerprint["autter.fingerprint"]) _chunkGYTQLITWcjs.noteCompatFeature.call(void 0, "fingerprint_override");
1743
1804
  const redacted = redactor(split.attributes);
1744
1805
  const activeSpan = _api.trace.getActiveSpan();
1745
- const reuseActive = _optionalChain([activeSpan, 'optionalAccess', _53 => _53.isRecording, 'call', _54 => _54()]) === true;
1806
+ const reuseActive = _optionalChain([activeSpan, 'optionalAccess', _55 => _55.isRecording, 'call', _56 => _56()]) === true;
1746
1807
  const span = reuseActive ? activeSpan : errorTracer.startSpan(isErr ? error.name : "Error");
1747
1808
  const structured = structuredErrorAttributes(error);
1748
- const causes = _chunkUXTIMS3Gcjs.errorAttributes.call(void 0, error);
1809
+ const causes = _chunkRV4MJNM2cjs.errorAttributes.call(void 0, error);
1749
1810
  const declared = {
1750
1811
  ...Object.fromEntries(Object.entries(causes).filter(([key]) => key !== "autter.error.internal")),
1751
1812
  ...fingerprint
1752
1813
  };
1753
- const requestId = _optionalChain([_chunkUXTIMS3Gcjs.currentOperation.call(void 0, ), 'optionalAccess', _55 => _55.requestId]);
1814
+ const requestId = _optionalChain([_chunkRV4MJNM2cjs.currentOperation.call(void 0, ), 'optionalAccess', _57 => _57.requestId]);
1754
1815
  span.setAttributes({
1755
1816
  "autter.severity": "error",
1756
1817
  ...redacted,
@@ -1758,8 +1819,8 @@ function initAutterServer(options) {
1758
1819
  ...requestId ? { "autter.request.id": requestId } : {}
1759
1820
  });
1760
1821
  markCaptured(error);
1761
- _chunkUXTIMS3Gcjs.noteOperationError.call(void 0, error);
1762
- _chunkUXTIMS3Gcjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint });
1822
+ _chunkRV4MJNM2cjs.noteOperationError.call(void 0, error);
1823
+ _chunkRV4MJNM2cjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint });
1763
1824
  if (isErr && stackText) {
1764
1825
  span.addEvent("exception", {
1765
1826
  "exception.type": error.name,
@@ -1767,17 +1828,17 @@ function initAutterServer(options) {
1767
1828
  "exception.stacktrace": stackText,
1768
1829
  ...redacted["autter.handled"] === true ? { "autter.handled": true, "autter.sampled": redacted["autter.sampled"] === true } : {},
1769
1830
  ...declared,
1770
- ..._chunkUXTIMS3Gcjs.breadcrumbEventAttributes.call(void 0, redactor.text, error)
1831
+ ..._chunkRV4MJNM2cjs.breadcrumbEventAttributes.call(void 0, redactor.text, error)
1771
1832
  });
1772
1833
  } else {
1773
- const stack = _optionalChain([new Error(), 'access', _56 => _56.stack, 'optionalAccess', _57 => _57.split, 'call', _58 => _58("\n"), 'access', _59 => _59.filter, 'call', _60 => _60((line, i) => i === 0 || !line.includes("captureException")), 'access', _61 => _61.join, 'call', _62 => _62("\n")]);
1834
+ const stack = _optionalChain([new Error(), 'access', _58 => _58.stack, 'optionalAccess', _59 => _59.split, 'call', _60 => _60("\n"), 'access', _61 => _61.filter, 'call', _62 => _62((line, i) => i === 0 || !line.includes("captureException")), 'access', _63 => _63.join, 'call', _64 => _64("\n")]);
1774
1835
  span.addEvent("exception", {
1775
1836
  "exception.type": isErr ? error.name : "Error",
1776
1837
  "exception.message": message,
1777
1838
  ...stack ? { "exception.stacktrace": redactor.text(stack) } : {},
1778
1839
  ...redacted["autter.handled"] === true ? { "autter.handled": true, "autter.sampled": redacted["autter.sampled"] === true } : {},
1779
1840
  ...declared,
1780
- ..._chunkUXTIMS3Gcjs.breadcrumbEventAttributes.call(void 0, redactor.text, error)
1841
+ ..._chunkRV4MJNM2cjs.breadcrumbEventAttributes.call(void 0, redactor.text, error)
1781
1842
  });
1782
1843
  }
1783
1844
  span.setStatus({ code: _api.SpanStatusCode.ERROR, message });
@@ -1785,10 +1846,10 @@ function initAutterServer(options) {
1785
1846
  }
1786
1847
  function captureMessage2(message, severity = "warning", attributes) {
1787
1848
  if (severity === "error" || severity === "fatal") {
1788
- _optionalChain([errorTraceBuffer, 'optionalAccess', _63 => _63.retainActiveTrace, 'call', _64 => _64()]);
1849
+ _optionalChain([errorTraceBuffer, 'optionalAccess', _65 => _65.retainActiveTrace, 'call', _66 => _66()]);
1789
1850
  }
1790
- _chunk4MVWIRBIcjs.telemetryStats.markCaptured();
1791
- const stack = _optionalChain([new Error(), 'access', _65 => _65.stack, 'optionalAccess', _66 => _66.split, 'call', _67 => _67("\n"), 'access', _68 => _68.filter, 'call', _69 => _69((line, i) => i === 0 || !line.includes("captureMessage")), 'access', _70 => _70.join, 'call', _71 => _71("\n")]);
1851
+ _chunkGYTQLITWcjs.telemetryStats.markCaptured();
1852
+ const stack = _optionalChain([new Error(), 'access', _67 => _67.stack, 'optionalAccess', _68 => _68.split, 'call', _69 => _69("\n"), 'access', _70 => _70.filter, 'call', _71 => _71((line, i) => i === 0 || !line.includes("captureMessage")), 'access', _72 => _72.join, 'call', _73 => _73("\n")]);
1792
1853
  const safeMessage = redactor.text(message);
1793
1854
  const span = errorTracer.startSpan("Message", {
1794
1855
  attributes: { "autter.severity": severity, ...redactor(attributes) }
@@ -1798,16 +1859,16 @@ function initAutterServer(options) {
1798
1859
  "exception.message": safeMessage,
1799
1860
  ...stack ? { "exception.stacktrace": redactor.text(stack) } : {},
1800
1861
  "autter.severity": severity,
1801
- ..._chunkUXTIMS3Gcjs.breadcrumbEventAttributes.call(void 0, redactor.text)
1862
+ ..._chunkRV4MJNM2cjs.breadcrumbEventAttributes.call(void 0, redactor.text)
1802
1863
  });
1803
1864
  span.setStatus({ code: _api.SpanStatusCode.ERROR, message: safeMessage });
1804
1865
  span.end();
1805
1866
  }
1806
1867
  function reportOutcome2(name, message, attributes) {
1807
- _optionalChain([errorTraceBuffer, 'optionalAccess', _72 => _72.retainActiveTrace, 'call', _73 => _73()]);
1808
- _chunk4MVWIRBIcjs.telemetryStats.markCaptured();
1868
+ _optionalChain([errorTraceBuffer, 'optionalAccess', _74 => _74.retainActiveTrace, 'call', _75 => _75()]);
1869
+ _chunkGYTQLITWcjs.telemetryStats.markCaptured();
1809
1870
  const activeSpan = _api.trace.getActiveSpan();
1810
- const reuseActive = _optionalChain([activeSpan, 'optionalAccess', _74 => _74.isRecording, 'call', _75 => _75()]) === true;
1871
+ const reuseActive = _optionalChain([activeSpan, 'optionalAccess', _76 => _76.isRecording, 'call', _77 => _77()]) === true;
1811
1872
  const span = reuseActive ? activeSpan : errorTracer.startSpan("OutcomeFailure");
1812
1873
  const safeOutcome = redactor({ "autter.outcome.name": name.slice(0, 200), "autter.outcome.message": message.slice(0, 1e3) });
1813
1874
  const safeName = String(_nullishCoalesce(safeOutcome["autter.outcome.name"], () => ( "operation")));
@@ -1821,7 +1882,7 @@ function initAutterServer(options) {
1821
1882
  span.setStatus({ code: _api.SpanStatusCode.ERROR, message: safeMessage });
1822
1883
  if (!reuseActive) span.end();
1823
1884
  }
1824
- _chunkUXTIMS3Gcjs.configureRuntimeLogger.call(void 0, {
1885
+ _chunkRV4MJNM2cjs.configureRuntimeLogger.call(void 0, {
1825
1886
  endpoint,
1826
1887
  apiKey: options.apiKey,
1827
1888
  service: options.service,
@@ -1833,7 +1894,7 @@ function initAutterServer(options) {
1833
1894
  run: (name, fn, attributes, links) => runWithSpan(processTracer, name, fn, redactor(attributes), links),
1834
1895
  reportOutcome: reportOutcome2
1835
1896
  });
1836
- S.hookRequests = _optionalChain([options, 'access', _76 => _76.logging, 'optionalAccess', _77 => _77.requests]) === true;
1897
+ S.hookRequests = _optionalChain([options, 'access', _78 => _78.logging, 'optionalAccess', _79 => _79.requests]) === true;
1837
1898
  let onCrash = null;
1838
1899
  let uninstallRejections = null;
1839
1900
  if (options.captureGlobalErrors !== false) {
@@ -1853,7 +1914,7 @@ function initAutterServer(options) {
1853
1914
  const flushTarget = {
1854
1915
  forceFlush: async () => {
1855
1916
  const results = await Promise.allSettled([
1856
- _chunkUXTIMS3Gcjs.flushRuntimeLogs.call(void 0, ),
1917
+ _chunkRV4MJNM2cjs.flushRuntimeLogs.call(void 0, ),
1857
1918
  Promise.resolve().then(() => alwaysOnProvider.forceFlush()),
1858
1919
  Promise.resolve().then(() => mainSpanProcessor.forceFlush()),
1859
1920
  ...errorTraceBuffer ? [Promise.resolve().then(() => errorTraceBuffer.forceFlush())] : [],
@@ -1867,10 +1928,10 @@ function initAutterServer(options) {
1867
1928
  }
1868
1929
  }
1869
1930
  };
1870
- _chunk4MVWIRBIcjs.registerFlushTarget.call(void 0, "active-server", flushTarget);
1931
+ _chunkGYTQLITWcjs.registerFlushTarget.call(void 0, "active-server", flushTarget);
1871
1932
  let autoFlushHandle = null;
1872
1933
  if (options.autoFlush !== false) {
1873
- autoFlushHandle = _chunk4MVWIRBIcjs.installAutterAutoFlush.call(void 0, );
1934
+ autoFlushHandle = _chunkGYTQLITWcjs.installAutterAutoFlush.call(void 0, );
1874
1935
  }
1875
1936
  const server = {
1876
1937
  captureException: captureException2,
@@ -1880,22 +1941,22 @@ function initAutterServer(options) {
1880
1941
  withLlmCall: (info, fn) => runLlmSpan(llmTracer, info, fn),
1881
1942
  trackLlmCall: (call) => recordLlmCall(llmTracer, call),
1882
1943
  shutdown: async () => {
1883
- const logShutdown = await Promise.allSettled([_chunkUXTIMS3Gcjs.shutdownRuntimeLogger.call(void 0, )]);
1944
+ const logShutdown = await Promise.allSettled([_chunkRV4MJNM2cjs.shutdownRuntimeLogger.call(void 0, )]);
1884
1945
  if (onCrash) process.off("uncaughtExceptionMonitor", onCrash);
1885
- _optionalChain([uninstallRejections, 'optionalCall', _78 => _78()]);
1886
- _optionalChain([stopMemoryMetrics, 'optionalCall', _79 => _79()]);
1946
+ _optionalChain([uninstallRejections, 'optionalCall', _80 => _80()]);
1947
+ _optionalChain([stopMemoryMetrics, 'optionalCall', _81 => _81()]);
1887
1948
  if (S.active === server) {
1888
1949
  S.active = null;
1889
1950
  S.alwaysOnProvider = null;
1890
1951
  S.hookRequests = false;
1891
- S.redactor = _chunkUXTIMS3Gcjs.makeRedactor.call(void 0, true);
1952
+ S.redactor = _chunkRV4MJNM2cjs.makeRedactor.call(void 0, true);
1892
1953
  }
1893
- _optionalChain([autoFlushHandle, 'optionalAccess', _80 => _80.dispose, 'call', _81 => _81()]);
1954
+ _optionalChain([autoFlushHandle, 'optionalAccess', _82 => _82.dispose, 'call', _83 => _83()]);
1894
1955
  autoFlushHandle = null;
1895
- _chunk4MVWIRBIcjs.unregisterFlushTargets.call(void 0, );
1896
- _chunk4MVWIRBIcjs.telemetryStats.markAllFlushed();
1956
+ _chunkGYTQLITWcjs.unregisterFlushTargets.call(void 0, );
1957
+ _chunkGYTQLITWcjs.telemetryStats.markAllFlushed();
1897
1958
  await Promise.allSettled([alwaysOnProvider.shutdown(), sdk.shutdown()]);
1898
- if (_optionalChain([logShutdown, 'access', _82 => _82[0], 'optionalAccess', _83 => _83.status]) === "rejected") throw logShutdown[0].reason;
1959
+ if (_optionalChain([logShutdown, 'access', _84 => _84[0], 'optionalAccess', _85 => _85.status]) === "rejected") throw logShutdown[0].reason;
1899
1960
  }
1900
1961
  };
1901
1962
  S.active = server;
@@ -1912,11 +1973,11 @@ function captureException(error, attributes) {
1912
1973
  return;
1913
1974
  }
1914
1975
  markCaptured(error);
1915
- _chunkUXTIMS3Gcjs.noteOperationError.call(void 0, error);
1916
- const split = _chunkUXTIMS3Gcjs.splitFingerprint.call(void 0, attributes);
1917
- const fingerprint = _chunkUXTIMS3Gcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, S.redactor.text);
1918
- _chunkUXTIMS3Gcjs.notifyException.call(void 0, error, { ...split.attributes, ...fingerprint });
1919
- const span = _api.trace.getTracer("autter-errors").startSpan(_chunkUXTIMS3Gcjs.isError.call(void 0, error) ? error.name : "Error", {
1976
+ _chunkRV4MJNM2cjs.noteOperationError.call(void 0, error);
1977
+ const split = _chunkRV4MJNM2cjs.splitFingerprint.call(void 0, attributes);
1978
+ const fingerprint = _chunkRV4MJNM2cjs.fingerprintEventAttributes.call(void 0, split.fingerprint, S.redactor.text);
1979
+ _chunkRV4MJNM2cjs.notifyException.call(void 0, error, { ...split.attributes, ...fingerprint });
1980
+ const span = _api.trace.getTracer("autter-errors").startSpan(_chunkRV4MJNM2cjs.isError.call(void 0, error) ? error.name : "Error", {
1920
1981
  attributes: { ...S.redactor(split.attributes), ...fingerprint }
1921
1982
  });
1922
1983
  recordError(span, error);
@@ -1931,7 +1992,7 @@ function serverActive() {
1931
1992
  setRequestExceptionCapturer((error, attributes) => captureException(error, attributes));
1932
1993
  setRequestSpanAnnotator((attributes) => {
1933
1994
  const span = _api.trace.getActiveSpan();
1934
- if (_optionalChain([span, 'optionalAccess', _84 => _84.isRecording, 'call', _85 => _85()])) span.setAttributes(S.redactor(_chunkUXTIMS3Gcjs.splitFingerprint.call(void 0, attributes).attributes));
1995
+ if (_optionalChain([span, 'optionalAccess', _86 => _86.isRecording, 'call', _87 => _87()])) span.setAttributes(S.redactor(_chunkRV4MJNM2cjs.splitFingerprint.call(void 0, attributes).attributes));
1935
1996
  });
1936
1997
  function withProcessSpan(name, fn, attributes) {
1937
1998
  if (S.active) return S.active.withProcessSpan(name, fn, attributes);
@@ -1966,7 +2027,7 @@ function captureMessage(message, severity = "warning", attributes) {
1966
2027
  "exception.type": "Message",
1967
2028
  "exception.message": safeMessage,
1968
2029
  "autter.severity": severity,
1969
- ..._chunkUXTIMS3Gcjs.breadcrumbEventAttributes.call(void 0, S.redactor.text)
2030
+ ..._chunkRV4MJNM2cjs.breadcrumbEventAttributes.call(void 0, S.redactor.text)
1970
2031
  });
1971
2032
  span.setStatus({ code: _api.SpanStatusCode.ERROR, message: safeMessage });
1972
2033
  span.end();
@@ -1974,11 +2035,11 @@ function captureMessage(message, severity = "warning", attributes) {
1974
2035
  function reportOutcome(name, message, attributes) {
1975
2036
  if (S.active) return S.active.reportOutcome(name, message, attributes);
1976
2037
  const span = _api.trace.getTracer("autter-outcomes").startSpan("OutcomeFailure");
1977
- const safeOutcome = _chunkUXTIMS3Gcjs.redactAttributes.call(void 0, { "autter.outcome.name": name.slice(0, 200), "autter.outcome.message": message.slice(0, 1e3) });
2038
+ const safeOutcome = _chunkRV4MJNM2cjs.redactAttributes.call(void 0, { "autter.outcome.name": name.slice(0, 200), "autter.outcome.message": message.slice(0, 1e3) });
1978
2039
  const safeName = String(_nullishCoalesce(safeOutcome["autter.outcome.name"], () => ( "operation")));
1979
2040
  const safeMessage = String(_nullishCoalesce(safeOutcome["autter.outcome.message"], () => ( "failed")));
1980
2041
  span.addEvent("autter.outcome", {
1981
- ..._chunkUXTIMS3Gcjs.redactAttributes.call(void 0, attributes),
2042
+ ..._chunkRV4MJNM2cjs.redactAttributes.call(void 0, attributes),
1982
2043
  "autter.outcome.status": "error",
1983
2044
  "autter.outcome.name": safeName,
1984
2045
  "autter.outcome.message": safeMessage
@@ -1987,7 +2048,7 @@ function reportOutcome(name, message, attributes) {
1987
2048
  span.end();
1988
2049
  }
1989
2050
  function makeSafeCapture(options) {
1990
- const clean = (attributes) => attributes ? { ..._chunkUXTIMS3Gcjs.redactAttributes.call(void 0, attributes, options) } : void 0;
2051
+ const clean = (attributes) => attributes ? { ..._chunkRV4MJNM2cjs.redactAttributes.call(void 0, attributes, options) } : void 0;
1991
2052
  return {
1992
2053
  captureException: (error, attributes) => captureException(error, clean(attributes)),
1993
2054
  captureMessage: (message, severity, attributes) => captureMessage(message, _nullishCoalesce(severity, () => ( "warning")), clean(attributes))
@@ -2014,7 +2075,7 @@ async function emitLlmSelftestTrace() {
2014
2075
  attributes: { "autter.selftest": true }
2015
2076
  },
2016
2077
  (llm) => {
2017
- traceId = _nullishCoalesce(_optionalChain([_api.trace, 'access', _86 => _86.getActiveSpan, 'call', _87 => _87(), 'optionalAccess', _88 => _88.spanContext, 'call', _89 => _89(), 'access', _90 => _90.traceId]), () => ( ""));
2078
+ traceId = _nullishCoalesce(_optionalChain([_api.trace, 'access', _88 => _88.getActiveSpan, 'call', _89 => _89(), 'optionalAccess', _90 => _90.spanContext, 'call', _91 => _91(), 'access', _92 => _92.traceId]), () => ( ""));
2018
2079
  llm.setUsage({ inputTokens: 1, outputTokens: 1 });
2019
2080
  llm.setCost(0);
2020
2081
  }
@@ -2042,7 +2103,7 @@ var CALL_METHODS = /* @__PURE__ */ new Set([
2042
2103
  // openai beta structured outputs
2043
2104
  ]);
2044
2105
  function detectProvider(client) {
2045
- const name = _nullishCoalesce(_optionalChain([client, 'access', _91 => _91.constructor, 'optionalAccess', _92 => _92.name, 'optionalAccess', _93 => _93.toLowerCase, 'call', _94 => _94()]), () => ( ""));
2106
+ const name = _nullishCoalesce(_optionalChain([client, 'access', _93 => _93.constructor, 'optionalAccess', _94 => _94.name, 'optionalAccess', _95 => _95.toLowerCase, 'call', _96 => _96()]), () => ( ""));
2046
2107
  for (const known of ["openai", "anthropic", "mistral", "groq", "cohere"]) {
2047
2108
  if (name.includes(known)) return known;
2048
2109
  }
@@ -2050,7 +2111,7 @@ function detectProvider(client) {
2050
2111
  const baseUrl = String(
2051
2112
  _nullishCoalesce(_nullishCoalesce(client.baseURL, () => ( client.baseUrl)), () => ( ""))
2052
2113
  );
2053
- const host = _nullishCoalesce(_optionalChain([baseUrl, 'access', _95 => _95.match, 'call', _96 => _96(/https?:\/\/([^/]+)/), 'optionalAccess', _97 => _97[1]]), () => ( ""));
2114
+ const host = _nullishCoalesce(_optionalChain([baseUrl, 'access', _97 => _97.match, 'call', _98 => _98(/https?:\/\/([^/]+)/), 'optionalAccess', _99 => _99[1]]), () => ( ""));
2054
2115
  if (host.includes("openai")) return "openai";
2055
2116
  if (host.includes("anthropic")) return "anthropic";
2056
2117
  if (host.includes("googleapis")) return "google";
@@ -2060,13 +2121,13 @@ function detectProvider(client) {
2060
2121
  }
2061
2122
  function extractUsage(result) {
2062
2123
  const r = result;
2063
- const usage = _nullishCoalesce(_optionalChain([r, 'optionalAccess', _98 => _98.usage]), () => ( _optionalChain([r, 'optionalAccess', _99 => _99.message, 'optionalAccess', _100 => _100.usage])));
2064
- const meta = _optionalChain([r, 'optionalAccess', _101 => _101.usageMetadata]);
2065
- const details = _optionalChain([usage, 'optionalAccess', _102 => _102.prompt_tokens_details]);
2066
- const cached = _nullishCoalesce(_nullishCoalesce(_optionalChain([usage, 'optionalAccess', _103 => _103.cache_read_input_tokens]), () => ( (typeof _optionalChain([details, 'optionalAccess', _104 => _104.cached_tokens]) === "number" ? details.cached_tokens : void 0))), () => ( _optionalChain([meta, 'optionalAccess', _105 => _105.cachedContentTokenCount])));
2067
- const input = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([usage, 'optionalAccess', _106 => _106.prompt_tokens]), () => ( _optionalChain([usage, 'optionalAccess', _107 => _107.input_tokens]))), () => ( _optionalChain([meta, 'optionalAccess', _108 => _108.promptTokenCount]))), () => ( void 0));
2068
- const output = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([usage, 'optionalAccess', _109 => _109.completion_tokens]), () => ( _optionalChain([usage, 'optionalAccess', _110 => _110.output_tokens]))), () => ( _optionalChain([meta, 'optionalAccess', _111 => _111.candidatesTokenCount]))), () => ( void 0));
2069
- const responseModel = _nullishCoalesce(_optionalChain([r, 'optionalAccess', _112 => _112.model]), () => ( _optionalChain([r, 'optionalAccess', _113 => _113.modelVersion])));
2124
+ const usage = _nullishCoalesce(_optionalChain([r, 'optionalAccess', _100 => _100.usage]), () => ( _optionalChain([r, 'optionalAccess', _101 => _101.message, 'optionalAccess', _102 => _102.usage])));
2125
+ const meta = _optionalChain([r, 'optionalAccess', _103 => _103.usageMetadata]);
2126
+ const details = _optionalChain([usage, 'optionalAccess', _104 => _104.prompt_tokens_details]);
2127
+ const cached = _nullishCoalesce(_nullishCoalesce(_optionalChain([usage, 'optionalAccess', _105 => _105.cache_read_input_tokens]), () => ( (typeof _optionalChain([details, 'optionalAccess', _106 => _106.cached_tokens]) === "number" ? details.cached_tokens : void 0))), () => ( _optionalChain([meta, 'optionalAccess', _107 => _107.cachedContentTokenCount])));
2128
+ const input = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([usage, 'optionalAccess', _108 => _108.prompt_tokens]), () => ( _optionalChain([usage, 'optionalAccess', _109 => _109.input_tokens]))), () => ( _optionalChain([meta, 'optionalAccess', _110 => _110.promptTokenCount]))), () => ( void 0));
2129
+ const output = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([usage, 'optionalAccess', _111 => _111.completion_tokens]), () => ( _optionalChain([usage, 'optionalAccess', _112 => _112.output_tokens]))), () => ( _optionalChain([meta, 'optionalAccess', _113 => _113.candidatesTokenCount]))), () => ( void 0));
2130
+ const responseModel = _nullishCoalesce(_optionalChain([r, 'optionalAccess', _114 => _114.model]), () => ( _optionalChain([r, 'optionalAccess', _115 => _115.modelVersion])));
2070
2131
  return {
2071
2132
  inputTokens: typeof input === "number" ? input : void 0,
2072
2133
  outputTokens: typeof output === "number" ? output : void 0,
@@ -2075,7 +2136,7 @@ function extractUsage(result) {
2075
2136
  };
2076
2137
  }
2077
2138
  function rollUp(model, usage) {
2078
- _chunkUXTIMS3Gcjs.recordOperationAiUsage.call(void 0, {
2139
+ _chunkRV4MJNM2cjs.recordOperationAiUsage.call(void 0, {
2079
2140
  model: _nullishCoalesce(usage.responseModel, () => ( model)),
2080
2141
  ...usage.inputTokens !== void 0 ? { inputTokens: usage.inputTokens } : {},
2081
2142
  ...usage.outputTokens !== void 0 ? { outputTokens: usage.outputTokens } : {},
@@ -2159,10 +2220,10 @@ function wrapStream(stream, span, model) {
2159
2220
  });
2160
2221
  }
2161
2222
  function instrumentLlmClient(client, options) {
2162
- const provider = (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _114 => _114.provider]), () => ( detectProvider(client)))).toLowerCase();
2223
+ const provider = (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _116 => _116.provider]), () => ( detectProvider(client)))).toLowerCase();
2163
2224
  const proxied = /* @__PURE__ */ new WeakMap();
2164
2225
  function resolveUserId() {
2165
- return typeof _optionalChain([options, 'optionalAccess', _115 => _115.userId]) === "function" ? options.userId() : _optionalChain([options, 'optionalAccess', _116 => _116.userId]);
2226
+ return typeof _optionalChain([options, 'optionalAccess', _117 => _117.userId]) === "function" ? options.userId() : _optionalChain([options, 'optionalAccess', _118 => _118.userId]);
2166
2227
  }
2167
2228
  function traceCall(fn, self, callPath, args) {
2168
2229
  const request = args[0];
@@ -2176,7 +2237,7 @@ function instrumentLlmClient(client, options) {
2176
2237
  "gen_ai.system": provider,
2177
2238
  "gen_ai.request.model": request.model,
2178
2239
  ...userId ? { "autter.user_id": userId } : {},
2179
- ...redactWithActive(_optionalChain([options, 'optionalAccess', _117 => _117.attributes]))
2240
+ ...redactWithActive(_optionalChain([options, 'optionalAccess', _119 => _119.attributes]))
2180
2241
  }
2181
2242
  });
2182
2243
  let result;
@@ -2300,9 +2361,9 @@ ${frames.join("\n")}`;
2300
2361
  function recordBoundaryError(error, req, rule) {
2301
2362
  try {
2302
2363
  const state = requestStateOf(req);
2303
- if (state) _chunkUXTIMS3Gcjs.noteOperationError.call(void 0, error, false, state);
2364
+ if (state) _chunkRV4MJNM2cjs.noteOperationError.call(void 0, error, false, state);
2304
2365
  captureAtBoundary(error, state, rule);
2305
- } catch (e30) {
2366
+ } catch (e32) {
2306
2367
  }
2307
2368
  }
2308
2369
  function autterErrorHandler(options = {}) {
@@ -2312,12 +2373,12 @@ function autterErrorHandler(options = {}) {
2312
2373
  };
2313
2374
  }
2314
2375
  function autterFastifyErrors(fastify, options, done) {
2315
- const rule = _optionalChain([options, 'optionalAccess', _118 => _118.capture]);
2376
+ const rule = _optionalChain([options, 'optionalAccess', _120 => _120.capture]);
2316
2377
  fastify.addHook("onError", ((request, _reply, error, next) => {
2317
- recordBoundaryError(error, _optionalChain([request, 'optionalAccess', _119 => _119.raw]), rule);
2378
+ recordBoundaryError(error, _optionalChain([request, 'optionalAccess', _121 => _121.raw]), rule);
2318
2379
  next();
2319
2380
  }));
2320
- _optionalChain([done, 'optionalCall', _120 => _120()]);
2381
+ _optionalChain([done, 'optionalCall', _122 => _122()]);
2321
2382
  }
2322
2383
  autterFastifyErrors[/* @__PURE__ */ Symbol.for("skip-override")] = true;
2323
2384
  autterFastifyErrors[/* @__PURE__ */ Symbol.for("fastify.display-name")] = "autter-runtime-errors";
@@ -2326,7 +2387,7 @@ function autterKoa(options = {}) {
2326
2387
  try {
2327
2388
  await next();
2328
2389
  } catch (error) {
2329
- recordBoundaryError(error, _optionalChain([ctx, 'optionalAccess', _121 => _121.req]), options.capture);
2390
+ recordBoundaryError(error, _optionalChain([ctx, 'optionalAccess', _123 => _123.req]), options.capture);
2330
2391
  throw error;
2331
2392
  }
2332
2393
  };
@@ -2337,7 +2398,7 @@ function autterKoa(options = {}) {
2337
2398
 
2338
2399
 
2339
2400
 
2340
- var L = _chunk4MVWIRBIcjs.sharedSlot.call(void 0, "logging", () => ({ active: null }));
2401
+ var L = _chunkGYTQLITWcjs.sharedSlot.call(void 0, "logging", () => ({ active: null }));
2341
2402
  function initAutterLogging(options) {
2342
2403
  if (L.active) return L.active;
2343
2404
  if (serverActive()) {
@@ -2346,29 +2407,29 @@ function initAutterLogging(options) {
2346
2407
  );
2347
2408
  return {
2348
2409
  captureException,
2349
- flush: _chunkUXTIMS3Gcjs.flushRuntimeLogs,
2410
+ flush: _chunkRV4MJNM2cjs.flushRuntimeLogs,
2350
2411
  shutdown: async () => {
2351
2412
  }
2352
2413
  };
2353
2414
  }
2354
- if (_chunk4MVWIRBIcjs.isDebugEnabled.call(void 0, ) || options.debug === true) _chunk4MVWIRBIcjs.setDebugMode.call(void 0, true);
2415
+ if (_chunkGYTQLITWcjs.isDebugEnabled.call(void 0, ) || options.debug === true) _chunkGYTQLITWcjs.setDebugMode.call(void 0, true);
2355
2416
  const endpoint = (_nullishCoalesce(options.endpoint, () => ( "https://otlp.autter.dev"))).replace(/\/$/, "");
2356
2417
  const environment = _nullishCoalesce(_nullishCoalesce(options.environment, () => ( process.env.NODE_ENV)), () => ( "production"));
2357
- const redact = _chunkUXTIMS3Gcjs.makeRedactor.call(void 0, _nullishCoalesce(options.redactAttributes, () => ( true)));
2418
+ const redact = _chunkRV4MJNM2cjs.makeRedactor.call(void 0, _nullishCoalesce(options.redactAttributes, () => ( true)));
2358
2419
  const mode = _nullishCoalesce(options.exceptions, () => ( "auto"));
2359
- _chunk4MVWIRBIcjs.debugLog.call(void 0, `initialising logger-only service=${options.service} endpoint=${endpoint}`);
2420
+ _chunkGYTQLITWcjs.debugLog.call(void 0, `initialising logger-only service=${options.service} endpoint=${endpoint}`);
2360
2421
  function captureException2(error, attributes) {
2361
2422
  markCaptured(error);
2362
- const split = _chunkUXTIMS3Gcjs.splitFingerprint.call(void 0, attributes);
2363
- const fingerprint = _chunkUXTIMS3Gcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, redact.text);
2423
+ const split = _chunkRV4MJNM2cjs.splitFingerprint.call(void 0, attributes);
2424
+ const fingerprint = _chunkRV4MJNM2cjs.fingerprintEventAttributes.call(void 0, split.fingerprint, redact.text);
2364
2425
  const redacted = redact(split.attributes);
2365
2426
  const span = _api.trace.getActiveSpan();
2366
- if (mode === "auto" && _optionalChain([span, 'optionalAccess', _122 => _122.isRecording, 'call', _123 => _123()])) {
2367
- _chunkUXTIMS3Gcjs.noteOperationError.call(void 0, error);
2368
- _chunkUXTIMS3Gcjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint });
2427
+ if (mode === "auto" && _optionalChain([span, 'optionalAccess', _124 => _124.isRecording, 'call', _125 => _125()])) {
2428
+ _chunkRV4MJNM2cjs.noteOperationError.call(void 0, error);
2429
+ _chunkRV4MJNM2cjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint });
2369
2430
  span.setAttributes({ "autter.severity": "error", ...redacted, ...structuredErrorAttributes(error) });
2370
- const declared = { ..._chunkUXTIMS3Gcjs.errorAttributes.call(void 0, error), ...fingerprint };
2371
- if (_chunkUXTIMS3Gcjs.isError.call(void 0, error)) {
2431
+ const declared = { ..._chunkRV4MJNM2cjs.errorAttributes.call(void 0, error), ...fingerprint };
2432
+ if (_chunkRV4MJNM2cjs.isError.call(void 0, error)) {
2372
2433
  span.addEvent("exception", {
2373
2434
  "exception.type": error.name,
2374
2435
  "exception.message": error.message,
@@ -2384,15 +2445,15 @@ function initAutterLogging(options) {
2384
2445
  }
2385
2446
  span.setStatus({
2386
2447
  code: _api.SpanStatusCode.ERROR,
2387
- message: _chunkUXTIMS3Gcjs.isError.call(void 0, error) ? error.message : String(error)
2448
+ message: _chunkRV4MJNM2cjs.isError.call(void 0, error) ? error.message : String(error)
2388
2449
  });
2389
2450
  return;
2390
2451
  }
2391
- _chunkUXTIMS3Gcjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint });
2392
- _chunkUXTIMS3Gcjs.captureExceptionAsLog.call(void 0, error, { ...redacted, ...fingerprint });
2452
+ _chunkRV4MJNM2cjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint });
2453
+ _chunkRV4MJNM2cjs.captureExceptionAsLog.call(void 0, error, { ...redacted, ...fingerprint });
2393
2454
  }
2394
2455
  const captured = /* @__PURE__ */ new WeakSet();
2395
- _chunkUXTIMS3Gcjs.configureRuntimeLogger.call(void 0, {
2456
+ _chunkRV4MJNM2cjs.configureRuntimeLogger.call(void 0, {
2396
2457
  endpoint,
2397
2458
  apiKey: _nullishCoalesce(options.apiKey, () => ( "")),
2398
2459
  service: options.service,
@@ -2401,7 +2462,7 @@ function initAutterLogging(options) {
2401
2462
  ...options.logging ? { options: options.logging } : {},
2402
2463
  redact,
2403
2464
  reportOutcome: (name, message, attributes) => {
2404
- _chunkUXTIMS3Gcjs.runtimeLogger.error(message, {
2465
+ _chunkRV4MJNM2cjs.runtimeLogger.error(message, {
2405
2466
  ...attributes,
2406
2467
  "autter.outcome.name": name.slice(0, 200),
2407
2468
  "autter.outcome.message": message.slice(0, 1e3)
@@ -2428,21 +2489,21 @@ function initAutterLogging(options) {
2428
2489
  (reason) => captureException2(reason, { "autter.unhandled_rejection": true })
2429
2490
  );
2430
2491
  }
2431
- _chunk4MVWIRBIcjs.registerFlushTarget.call(void 0, "logging", { forceFlush: () => _chunkUXTIMS3Gcjs.flushRuntimeLogs.call(void 0, ) });
2432
- let autoFlushHandle = options.autoFlush === false ? null : _chunk4MVWIRBIcjs.installAutterAutoFlush.call(void 0, );
2492
+ _chunkGYTQLITWcjs.registerFlushTarget.call(void 0, "logging", { forceFlush: () => _chunkRV4MJNM2cjs.flushRuntimeLogs.call(void 0, ) });
2493
+ let autoFlushHandle = options.autoFlush === false ? null : _chunkGYTQLITWcjs.installAutterAutoFlush.call(void 0, );
2433
2494
  const handle = {
2434
2495
  captureException: captureException2,
2435
- flush: _chunkUXTIMS3Gcjs.flushRuntimeLogs,
2496
+ flush: _chunkRV4MJNM2cjs.flushRuntimeLogs,
2436
2497
  shutdown: async () => {
2437
2498
  process.off("uncaughtExceptionMonitor", onCrash);
2438
- _optionalChain([uninstallRejections, 'optionalCall', _124 => _124()]);
2499
+ _optionalChain([uninstallRejections, 'optionalCall', _126 => _126()]);
2439
2500
  uninstallRejections = null;
2440
2501
  setLoggerOnlyCapture(null);
2441
- _optionalChain([autoFlushHandle, 'optionalAccess', _125 => _125.dispose, 'call', _126 => _126()]);
2502
+ _optionalChain([autoFlushHandle, 'optionalAccess', _127 => _127.dispose, 'call', _128 => _128()]);
2442
2503
  autoFlushHandle = null;
2443
- _chunk4MVWIRBIcjs.unregisterFlushTargets.call(void 0, );
2504
+ _chunkGYTQLITWcjs.unregisterFlushTargets.call(void 0, );
2444
2505
  if (L.active === handle) L.active = null;
2445
- await _chunkUXTIMS3Gcjs.shutdownRuntimeLogger.call(void 0, );
2506
+ await _chunkRV4MJNM2cjs.shutdownRuntimeLogger.call(void 0, );
2446
2507
  }
2447
2508
  };
2448
2509
  L.active = handle;
@@ -2451,7 +2512,7 @@ function initAutterLogging(options) {
2451
2512
 
2452
2513
  // src/enrichers.ts
2453
2514
  function headerOf(req, name) {
2454
- const headers = _optionalChain([req, 'optionalAccess', _127 => _127.headers]);
2515
+ const headers = _optionalChain([req, 'optionalAccess', _129 => _129.headers]);
2455
2516
  if (!headers) return void 0;
2456
2517
  if (typeof headers.get === "function") {
2457
2518
  return _nullishCoalesce(headers.get(name), () => ( void 0));
@@ -2464,7 +2525,7 @@ function enrichUserAgent() {
2464
2525
  return (event, { req }) => {
2465
2526
  const ua = headerOf(req, "user-agent");
2466
2527
  if (!ua) return;
2467
- const info = _chunkUXTIMS3Gcjs.parseUserAgent.call(void 0, ua);
2528
+ const info = _chunkRV4MJNM2cjs.parseUserAgent.call(void 0, ua);
2468
2529
  if (info.browser) event.attributes["user_agent.browser"] = info.browser;
2469
2530
  if (info.os) event.attributes["user_agent.os"] = info.os;
2470
2531
  event.attributes["user_agent.device"] = info.device;
@@ -2476,7 +2537,7 @@ function enrichRequestSize() {
2476
2537
  const request = Number(headerOf(req, "content-length"));
2477
2538
  if (Number.isFinite(request) && request >= 0)
2478
2539
  event.attributes["http.request.body.size"] = request;
2479
- const raw = _optionalChain([res, 'optionalAccess', _128 => _128.getHeader, 'optionalCall', _129 => _129(
2540
+ const raw = _optionalChain([res, 'optionalAccess', _130 => _130.getHeader, 'optionalCall', _131 => _131(
2480
2541
  "content-length"
2481
2542
  )]);
2482
2543
  const response = Number(raw);
@@ -2494,7 +2555,7 @@ var COUNTRY_HEADERS = [
2494
2555
  function enrichEdgeGeo() {
2495
2556
  return (event, { req }) => {
2496
2557
  for (const name of COUNTRY_HEADERS) {
2497
- const value = _optionalChain([headerOf, 'call', _130 => _130(req, name), 'optionalAccess', _131 => _131.trim, 'call', _132 => _132(), 'access', _133 => _133.toUpperCase, 'call', _134 => _134()]);
2558
+ const value = _optionalChain([headerOf, 'call', _132 => _132(req, name), 'optionalAccess', _133 => _133.trim, 'call', _134 => _134(), 'access', _135 => _135.toUpperCase, 'call', _136 => _136()]);
2498
2559
  if (value && /^[A-Z]{2}$/.test(value) && value !== "XX" && value !== "T1") {
2499
2560
  event.attributes["geo.country.iso_code"] = value;
2500
2561
  return;
@@ -2528,9 +2589,9 @@ var COMMIT_VARS = [
2528
2589
  "SOURCE_VERSION"
2529
2590
  ];
2530
2591
  function enrichDeployment(env = process.env) {
2531
- const pick = (names) => names.map((name) => _optionalChain([env, 'access', _135 => _135[name], 'optionalAccess', _136 => _136.trim, 'call', _137 => _137()])).find((value) => value);
2532
- const region = _optionalChain([pick, 'call', _138 => _138(REGION_VARS), 'optionalAccess', _139 => _139.slice, 'call', _140 => _140(0, 64)]);
2533
- const commit = _optionalChain([pick, 'call', _141 => _141(COMMIT_VARS), 'optionalAccess', _142 => _142.slice, 'call', _143 => _143(0, 64)]);
2592
+ const pick = (names) => names.map((name) => _optionalChain([env, 'access', _137 => _137[name], 'optionalAccess', _138 => _138.trim, 'call', _139 => _139()])).find((value) => value);
2593
+ const region = _optionalChain([pick, 'call', _140 => _140(REGION_VARS), 'optionalAccess', _141 => _141.slice, 'call', _142 => _142(0, 64)]);
2594
+ const commit = _optionalChain([pick, 'call', _143 => _143(COMMIT_VARS), 'optionalAccess', _144 => _144.slice, 'call', _145 => _145(0, 64)]);
2534
2595
  return (event) => {
2535
2596
  if (region) event.attributes["deployment.region"] = region;
2536
2597
  if (commit) event.attributes["deployment.commit"] = commit;
@@ -2591,4 +2652,4 @@ function enrichDeployment(env = process.env) {
2591
2652
 
2592
2653
 
2593
2654
 
2594
- exports.CODE_PATTERN = _chunkUXTIMS3Gcjs.CODE_PATTERN; exports.COMPAT_MANIFEST = _chunk4MVWIRBIcjs.COMPAT_MANIFEST; exports.INGESTER_VERSION_HEADER = _chunk4MVWIRBIcjs.INGESTER_VERSION_HEADER; exports.RuntimeError = _chunkUXTIMS3Gcjs.RuntimeError; exports.SDK_IDENTITY = _chunk4MVWIRBIcjs.SDK_IDENTITY; exports.addBreadcrumb = _chunkUXTIMS3Gcjs.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 = _chunkUXTIMS3Gcjs.consoleSink; exports.createBrowserRelayFetchHandler = createBrowserRelayFetchHandler; exports.createBrowserRelayHandler = createBrowserRelayHandler; exports.createRuntimeLogger = _chunkUXTIMS3Gcjs.createRuntimeLogger; exports.defineRuntimeErrors = _chunkUXTIMS3Gcjs.defineRuntimeErrors; exports.emitLlmSelftestTrace = emitLlmSelftestTrace; exports.enrichDeployment = enrichDeployment; exports.enrichEdgeGeo = enrichEdgeGeo; exports.enrichRequestSize = enrichRequestSize; exports.enrichUserAgent = enrichUserAgent; exports.errorAttributes = _chunkUXTIMS3Gcjs.errorAttributes; exports.evaluateCompat = _chunk4MVWIRBIcjs.evaluateCompat; exports.fetchIngesterCompat = _chunk4MVWIRBIcjs.fetchIngesterCompat; exports.fileSink = _chunkUXTIMS3Gcjs.fileSink; exports.flushRuntimeLogs = _chunkUXTIMS3Gcjs.flushRuntimeLogs; exports.initAutterLogging = initAutterLogging; exports.initAutterServer = initAutterServer; exports.installAutterAutoFlush = _chunk4MVWIRBIcjs.installAutterAutoFlush; exports.instrumentLlmClient = instrumentLlmClient; exports.isRuntimeErrorLike = _chunkUXTIMS3Gcjs.isRuntimeErrorLike; exports.makeSafeCapture = makeSafeCapture; exports.otlpSink = _chunkUXTIMS3Gcjs.otlpSink; exports.redactAttributes = _chunkUXTIMS3Gcjs.redactAttributes; exports.redactText = _chunkUXTIMS3Gcjs.redactText; exports.reportOutcome = reportOutcome; exports.runDoctor = _chunk7OTD2YPTcjs.runDoctor; exports.runInBackground = _chunkUXTIMS3Gcjs.runInBackground; exports.runtimeContext = _chunkUXTIMS3Gcjs.runtimeContext; exports.runtimeLogStats = _chunkUXTIMS3Gcjs.runtimeLogStats; exports.runtimeLogger = _chunkUXTIMS3Gcjs.runtimeLogger; exports.sanitizeBrowserPayload = sanitizeBrowserPayload; exports.startCaughtExceptionSampler = startCaughtExceptionSampler; exports.toClientError = _chunkUXTIMS3Gcjs.toClientError; exports.trackLlmCall = trackLlmCall; exports.unhandledRejectionsMode = unhandledRejectionsMode; exports.withLlmCall = withLlmCall; exports.withProcessSpan = withProcessSpan; exports.withRuntimeOperation = _chunkUXTIMS3Gcjs.withRuntimeOperation; exports.withRuntimeRequest = withRuntimeRequest;
2655
+ exports.CODE_PATTERN = _chunkRV4MJNM2cjs.CODE_PATTERN; exports.COMPAT_MANIFEST = _chunkGYTQLITWcjs.COMPAT_MANIFEST; exports.INGESTER_VERSION_HEADER = _chunkGYTQLITWcjs.INGESTER_VERSION_HEADER; exports.RuntimeError = _chunkRV4MJNM2cjs.RuntimeError; exports.SDK_IDENTITY = _chunkGYTQLITWcjs.SDK_IDENTITY; exports.addBreadcrumb = _chunkRV4MJNM2cjs.addBreadcrumb; exports.autterErrorHandler = autterErrorHandler; exports.autterErrorResponse = autterErrorResponse; exports.autterFastify = autterFastify; exports.autterFastifyErrors = autterFastifyErrors; exports.autterKoa = autterKoa; exports.autterRequests = autterRequests; exports.captureException = captureException; exports.captureMessage = captureMessage; exports.captureRequestError = captureRequestError; exports.consoleSink = _chunkRV4MJNM2cjs.consoleSink; exports.createBrowserRelayFetchHandler = createBrowserRelayFetchHandler; exports.createBrowserRelayHandler = createBrowserRelayHandler; exports.createRuntimeLogger = _chunkRV4MJNM2cjs.createRuntimeLogger; exports.defineRuntimeErrors = _chunkRV4MJNM2cjs.defineRuntimeErrors; exports.emitLlmSelftestTrace = emitLlmSelftestTrace; exports.enrichDeployment = enrichDeployment; exports.enrichEdgeGeo = enrichEdgeGeo; exports.enrichRequestSize = enrichRequestSize; exports.enrichUserAgent = enrichUserAgent; exports.errorAttributes = _chunkRV4MJNM2cjs.errorAttributes; exports.evaluateCompat = _chunkGYTQLITWcjs.evaluateCompat; exports.fetchIngesterCompat = _chunkGYTQLITWcjs.fetchIngesterCompat; exports.fileSink = _chunkRV4MJNM2cjs.fileSink; exports.flushRuntimeLogs = _chunkRV4MJNM2cjs.flushRuntimeLogs; exports.initAutterLogging = initAutterLogging; exports.initAutterServer = initAutterServer; exports.installAutterAutoFlush = _chunkGYTQLITWcjs.installAutterAutoFlush; exports.instrumentLlmClient = instrumentLlmClient; exports.isRuntimeErrorLike = _chunkRV4MJNM2cjs.isRuntimeErrorLike; exports.makeSafeCapture = makeSafeCapture; exports.otlpSink = _chunkRV4MJNM2cjs.otlpSink; exports.redactAttributes = _chunkRV4MJNM2cjs.redactAttributes; exports.redactText = _chunkRV4MJNM2cjs.redactText; exports.reportOutcome = reportOutcome; exports.runDoctor = _chunkHKVFURYTcjs.runDoctor; exports.runInBackground = _chunkRV4MJNM2cjs.runInBackground; exports.runtimeContext = _chunkRV4MJNM2cjs.runtimeContext; exports.runtimeLogStats = _chunkRV4MJNM2cjs.runtimeLogStats; exports.runtimeLogger = _chunkRV4MJNM2cjs.runtimeLogger; exports.sanitizeBrowserPayload = sanitizeBrowserPayload; exports.startCaughtExceptionSampler = startCaughtExceptionSampler; exports.toClientError = _chunkRV4MJNM2cjs.toClientError; exports.trackLlmCall = trackLlmCall; exports.unhandledRejectionsMode = unhandledRejectionsMode; exports.withLlmCall = withLlmCall; exports.withProcessSpan = withProcessSpan; exports.withRuntimeOperation = _chunkRV4MJNM2cjs.withRuntimeOperation; exports.withRuntimeRequest = withRuntimeRequest;