@autter/runtime-node 1.9.0 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -552,7 +552,7 @@ var _https = require('https');
552
552
  // package.json
553
553
  var package_default = {
554
554
  name: "@autter/runtime-node",
555
- version: "1.9.0",
555
+ version: "1.9.1",
556
556
  description: "Autter Runtime for Node.js: request wide events, coded errors, operation logging, same-origin browser relay and a curated OpenTelemetry server tracker",
557
557
  license: "MIT",
558
558
  type: "module",
@@ -2,7 +2,7 @@ import {
2
2
  noteCompatFeature,
3
3
  observeIngesterResponse,
4
4
  sharedSlot
5
- } from "./chunk-ZKM76SDP.js";
5
+ } from "./chunk-VIP2EL47.js";
6
6
 
7
7
  // ../runtime-core/dist/index.js
8
8
  var SENSITIVE_KEY_PATTERNS = [
@@ -1496,6 +1496,7 @@ function otlpSink(options = {}) {
1496
1496
  let flushing = null;
1497
1497
  let stopping = false;
1498
1498
  let failureStreak = 0;
1499
+ let nextFlushAfter = 0;
1499
1500
  const scheduleFlush = () => {
1500
1501
  if (!timer && context && !stopping && queue.length) {
1501
1502
  timer = setTimeout(
@@ -1504,7 +1505,7 @@ function otlpSink(options = {}) {
1504
1505
  void flush().catch(() => {
1505
1506
  });
1506
1507
  },
1507
- Math.min(3e4, 2e3 * 2 ** Math.min(failureStreak, 4))
1508
+ Math.max(nextFlushAfter, Math.min(3e4, 2e3 * 2 ** Math.min(failureStreak, 4)))
1508
1509
  );
1509
1510
  timer.unref();
1510
1511
  }
@@ -1547,6 +1548,7 @@ function otlpSink(options = {}) {
1547
1548
  );
1548
1549
  let failure;
1549
1550
  for (let attempt = 0; attempt < 3; attempt++) {
1551
+ let retryAfter = null;
1550
1552
  try {
1551
1553
  if (Date.now() >= deadline)
1552
1554
  throw new Error("Runtime log flush exceeded 10 seconds");
@@ -1562,13 +1564,22 @@ function otlpSink(options = {}) {
1562
1564
  )
1563
1565
  });
1564
1566
  observeIngesterResponse({ status: response.status, headers: response.headers, route: "/v1/logs" });
1565
- if (!response.ok)
1566
- throw new Error(`Runtime log export failed (${response.status})`);
1567
- failure = void 0;
1568
- break;
1567
+ if (!response.ok) {
1568
+ failure = new Error(`Runtime log export failed (${response.status})`);
1569
+ if (response.status !== 429 && response.status < 500) break;
1570
+ retryAfter = response.headers.get("retry-after");
1571
+ } else {
1572
+ failure = void 0;
1573
+ break;
1574
+ }
1569
1575
  } catch (error) {
1570
1576
  failure = error;
1571
1577
  }
1578
+ const seconds = Number(retryAfter);
1579
+ const wait = seconds > 0 ? Math.min(seconds * 1e3, 3e5) : 500 * 2 ** attempt;
1580
+ nextFlushAfter = Math.max(nextFlushAfter, wait);
1581
+ if (attempt >= 2 || Date.now() + wait >= deadline) break;
1582
+ await new Promise((resolve2) => setTimeout(resolve2, wait));
1572
1583
  }
1573
1584
  inFlight = 0;
1574
1585
  if (failure) {
@@ -1580,6 +1591,7 @@ function otlpSink(options = {}) {
1580
1591
  }
1581
1592
  inFlightBytes = 0;
1582
1593
  failureStreak = 0;
1594
+ nextFlushAfter = 0;
1583
1595
  }
1584
1596
  })().finally(() => {
1585
1597
  flushing = null;
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkBHYHORUDcjs = require('./chunk-BHYHORUD.cjs');
5
+ var _chunk3P573RHAcjs = require('./chunk-3P573RHA.cjs');
6
6
 
7
7
  // ../runtime-core/dist/index.js
8
8
  var SENSITIVE_KEY_PATTERNS = [
@@ -1222,7 +1222,7 @@ var _util = require('util');
1222
1222
  var _requireinthemiddle = require('require-in-the-middle');
1223
1223
 
1224
1224
  // src/captured.ts
1225
- var CAPTURED = _chunkBHYHORUDcjs.sharedSlot.call(void 0, "requests", () => ({ captured: /* @__PURE__ */ new WeakSet() })).captured;
1225
+ var CAPTURED = _chunk3P573RHAcjs.sharedSlot.call(void 0, "requests", () => ({ captured: /* @__PURE__ */ new WeakSet() })).captured;
1226
1226
  function markCaptured(error) {
1227
1227
  if (error && typeof error === "object") CAPTURED.add(error);
1228
1228
  }
@@ -1231,7 +1231,7 @@ function isCaptured(error) {
1231
1231
  }
1232
1232
 
1233
1233
  // src/caught-errors.ts
1234
- var S = _chunkBHYHORUDcjs.sharedSlot.call(void 0, "handled", () => ({
1234
+ var S = _chunk3P573RHAcjs.sharedSlot.call(void 0, "handled", () => ({
1235
1235
  sources: null,
1236
1236
  capture: null,
1237
1237
  tail: null,
@@ -1485,7 +1485,7 @@ function stopLoggedErrorCapture() {
1485
1485
 
1486
1486
  var _fs = require('fs');
1487
1487
 
1488
- var sinkStats = _chunkBHYHORUDcjs.sharedSlot.call(void 0, "sinks", () => ({ dropped: 0 }));
1488
+ var sinkStats = _chunk3P573RHAcjs.sharedSlot.call(void 0, "sinks", () => ({ dropped: 0 }));
1489
1489
  function otlpSink(options = {}) {
1490
1490
  let context = null;
1491
1491
  let queue = [];
@@ -1496,6 +1496,7 @@ function otlpSink(options = {}) {
1496
1496
  let flushing = null;
1497
1497
  let stopping = false;
1498
1498
  let failureStreak = 0;
1499
+ let nextFlushAfter = 0;
1499
1500
  const scheduleFlush = () => {
1500
1501
  if (!timer && context && !stopping && queue.length) {
1501
1502
  timer = setTimeout(
@@ -1504,7 +1505,7 @@ function otlpSink(options = {}) {
1504
1505
  void flush().catch(() => {
1505
1506
  });
1506
1507
  },
1507
- Math.min(3e4, 2e3 * 2 ** Math.min(failureStreak, 4))
1508
+ Math.max(nextFlushAfter, Math.min(3e4, 2e3 * 2 ** Math.min(failureStreak, 4)))
1508
1509
  );
1509
1510
  timer.unref();
1510
1511
  }
@@ -1547,6 +1548,7 @@ function otlpSink(options = {}) {
1547
1548
  );
1548
1549
  let failure;
1549
1550
  for (let attempt = 0; attempt < 3; attempt++) {
1551
+ let retryAfter = null;
1550
1552
  try {
1551
1553
  if (Date.now() >= deadline)
1552
1554
  throw new Error("Runtime log flush exceeded 10 seconds");
@@ -1561,14 +1563,23 @@ function otlpSink(options = {}) {
1561
1563
  Math.max(1, Math.min(3e3, deadline - Date.now()))
1562
1564
  )
1563
1565
  });
1564
- _chunkBHYHORUDcjs.observeIngesterResponse.call(void 0, { status: response.status, headers: response.headers, route: "/v1/logs" });
1565
- if (!response.ok)
1566
- throw new Error(`Runtime log export failed (${response.status})`);
1567
- failure = void 0;
1568
- break;
1566
+ _chunk3P573RHAcjs.observeIngesterResponse.call(void 0, { status: response.status, headers: response.headers, route: "/v1/logs" });
1567
+ if (!response.ok) {
1568
+ failure = new Error(`Runtime log export failed (${response.status})`);
1569
+ if (response.status !== 429 && response.status < 500) break;
1570
+ retryAfter = response.headers.get("retry-after");
1571
+ } else {
1572
+ failure = void 0;
1573
+ break;
1574
+ }
1569
1575
  } catch (error) {
1570
1576
  failure = error;
1571
1577
  }
1578
+ const seconds = Number(retryAfter);
1579
+ const wait = seconds > 0 ? Math.min(seconds * 1e3, 3e5) : 500 * 2 ** attempt;
1580
+ nextFlushAfter = Math.max(nextFlushAfter, wait);
1581
+ if (attempt >= 2 || Date.now() + wait >= deadline) break;
1582
+ await new Promise((resolve2) => setTimeout(resolve2, wait));
1572
1583
  }
1573
1584
  inFlight = 0;
1574
1585
  if (failure) {
@@ -1580,6 +1591,7 @@ function otlpSink(options = {}) {
1580
1591
  }
1581
1592
  inFlightBytes = 0;
1582
1593
  failureStreak = 0;
1594
+ nextFlushAfter = 0;
1583
1595
  }
1584
1596
  })().finally(() => {
1585
1597
  flushing = null;
@@ -1611,7 +1623,7 @@ function otlpSink(options = {}) {
1611
1623
  }
1612
1624
  queue.push({ record, bytes });
1613
1625
  queueBytes += bytes;
1614
- _chunkBHYHORUDcjs.noteCompatFeature.call(void 0, "operation_logging");
1626
+ _chunk3P573RHAcjs.noteCompatFeature.call(void 0, "operation_logging");
1615
1627
  scheduleFlush();
1616
1628
  },
1617
1629
  flush,
@@ -1854,7 +1866,7 @@ function memorySink() {
1854
1866
  }
1855
1867
 
1856
1868
  // src/logger.ts
1857
- var shared = _chunkBHYHORUDcjs.sharedSlot.call(void 0, "logger", () => ({
1869
+ var shared = _chunk3P573RHAcjs.sharedSlot.call(void 0, "logger", () => ({
1858
1870
  local: new (0, _async_hooks.AsyncLocalStorage)(),
1859
1871
  config: null,
1860
1872
  sinks: [],
@@ -2354,7 +2366,7 @@ setHandledTail(
2354
2366
  // src/breadcrumbs.ts
2355
2367
  var INVALID_TRACE_ID = "00000000000000000000000000000000";
2356
2368
  var MAX_TRACE_TRAILS = 200;
2357
- var trails = _chunkBHYHORUDcjs.sharedSlot.call(void 0, "breadcrumbs", () => ({
2369
+ var trails = _chunk3P573RHAcjs.sharedSlot.call(void 0, "breadcrumbs", () => ({
2358
2370
  byTrace: /* @__PURE__ */ new Map(),
2359
2371
  process: new BreadcrumbTrail(),
2360
2372
  thrown: /* @__PURE__ */ new WeakMap()
@@ -2390,7 +2402,7 @@ function addBreadcrumb(input) {
2390
2402
  const crumb = normalizeBreadcrumb(input, redact2);
2391
2403
  if (!crumb) return;
2392
2404
  _optionalChain([trailFor, 'call', _122 => _122(true), 'optionalAccess', _123 => _123.add, 'call', _124 => _124(crumb)]);
2393
- _chunkBHYHORUDcjs.noteCompatFeature.call(void 0, "breadcrumbs");
2405
+ _chunk3P573RHAcjs.noteCompatFeature.call(void 0, "breadcrumbs");
2394
2406
  } catch (e39) {
2395
2407
  }
2396
2408
  }
@@ -5,7 +5,7 @@ import {
5
5
  evaluateCompat,
6
6
  fetchIngesterCompat,
7
7
  versionAtLeast
8
- } from "./chunk-ZKM76SDP.js";
8
+ } from "./chunk-VIP2EL47.js";
9
9
 
10
10
  // src/doctor.ts
11
11
  import { existsSync, readFileSync } from "fs";
@@ -52,7 +52,7 @@ async function checkKey(endpoint, key, timeoutMs) {
52
52
  if (res.status >= 200 && res.status < 300) return "accepted";
53
53
  if (res.status === 401) return "rejected";
54
54
  if (res.status === 403) return "client_key";
55
- if (res.status === 503) return "storage_unavailable";
55
+ if (res.status === 503) return res.headers["retry-after"] ? "unverified" : "storage_unavailable";
56
56
  return "unknown";
57
57
  }
58
58
  async function runDoctor(options = {}) {
@@ -89,7 +89,7 @@ async function runDoctor(options = {}) {
89
89
  const known = info?.version != null || feature.route !== void 0 && info?.routes?.[feature.route] !== void 0;
90
90
  return [{ id, title: feature.title, status: bad ? "incompatible" : known ? "ok" : "unknown" }];
91
91
  });
92
- const exitCode = !info ? 2 : issues.length || key === "rejected" || key === "client_key" || key === "storage_unavailable" ? 1 : 0;
92
+ const exitCode = !info ? 2 : issues.length || key === "rejected" || key === "client_key" || key === "storage_unavailable" || key === "unverified" ? 1 : 0;
93
93
  return {
94
94
  endpoint,
95
95
  sdks,
@@ -125,6 +125,7 @@ function formatDoctorReport(report) {
125
125
  rejected: "REJECTED (401): check AUTTER_RUNTIME_KEY",
126
126
  client_key: "is a client/browser key; server SDKs need a server key",
127
127
  storage_unavailable: "accepted, but the ingester's ClickHouse is unavailable (503)",
128
+ unverified: "could not be checked: the ingester's key validator is unavailable (503); exporters retry",
128
129
  unknown: "could not be verified"
129
130
  }[report.key];
130
131
  lines.push(` key ${text}`);
@@ -5,7 +5,7 @@
5
5
 
6
6
 
7
7
 
8
- var _chunkBHYHORUDcjs = require('./chunk-BHYHORUD.cjs');
8
+ var _chunk3P573RHAcjs = require('./chunk-3P573RHA.cjs');
9
9
 
10
10
  // src/doctor.ts
11
11
  var _fs = require('fs');
@@ -30,19 +30,19 @@ function installedSdks(cwd) {
30
30
  }
31
31
  if (_path.dirname.call(void 0, dir) === dir) break;
32
32
  }
33
- if (!found.has(_chunkBHYHORUDcjs.SDK_IDENTITY.name)) found.set(_chunkBHYHORUDcjs.SDK_IDENTITY.name, _chunkBHYHORUDcjs.SDK_IDENTITY.version);
33
+ if (!found.has(_chunk3P573RHAcjs.SDK_IDENTITY.name)) found.set(_chunk3P573RHAcjs.SDK_IDENTITY.name, _chunk3P573RHAcjs.SDK_IDENTITY.version);
34
34
  return [...found].map(([name, version]) => ({ name, version }));
35
35
  }
36
36
  function featuresInUse(sdks) {
37
- return _chunkBHYHORUDcjs.COMPAT_MANIFEST.features.filter(
37
+ return _chunk3P573RHAcjs.COMPAT_MANIFEST.features.filter(
38
38
  (feature) => sdks.some((sdk) => {
39
39
  const min = feature.sdks[sdk.name];
40
- return min !== void 0 && _chunkBHYHORUDcjs.versionAtLeast.call(void 0, sdk.version, min) === true;
40
+ return min !== void 0 && _chunk3P573RHAcjs.versionAtLeast.call(void 0, sdk.version, min) === true;
41
41
  })
42
42
  ).map((feature) => feature.id);
43
43
  }
44
44
  async function checkKey(endpoint, key, timeoutMs) {
45
- const res = await _chunkBHYHORUDcjs.compatRequest.call(void 0, "POST", `${endpoint}/v1/traces`, {
45
+ const res = await _chunk3P573RHAcjs.compatRequest.call(void 0, "POST", `${endpoint}/v1/traces`, {
46
46
  body: JSON.stringify({ resourceSpans: [] }),
47
47
  headers: { authorization: `Bearer ${key}` },
48
48
  unref: false,
@@ -52,7 +52,7 @@ async function checkKey(endpoint, key, timeoutMs) {
52
52
  if (res.status >= 200 && res.status < 300) return "accepted";
53
53
  if (res.status === 401) return "rejected";
54
54
  if (res.status === 403) return "client_key";
55
- if (res.status === 503) return "storage_unavailable";
55
+ if (res.status === 503) return res.headers["retry-after"] ? "unverified" : "storage_unavailable";
56
56
  return "unknown";
57
57
  }
58
58
  async function runDoctor(options = {}) {
@@ -62,10 +62,10 @@ async function runDoctor(options = {}) {
62
62
  const features = _optionalChain([options, 'access', _ => _.features, 'optionalAccess', _2 => _2.length]) ? options.features : featuresInUse(sdks);
63
63
  const routes = [
64
64
  ...new Set(
65
- features.map((id) => _optionalChain([_chunkBHYHORUDcjs.COMPAT_MANIFEST, 'access', _3 => _3.features, 'access', _4 => _4.find, 'call', _5 => _5((f) => f.id === id), 'optionalAccess', _6 => _6.route])).filter((route) => Boolean(route))
65
+ features.map((id) => _optionalChain([_chunk3P573RHAcjs.COMPAT_MANIFEST, 'access', _3 => _3.features, 'access', _4 => _4.find, 'call', _5 => _5((f) => f.id === id), 'optionalAccess', _6 => _6.route])).filter((route) => Boolean(route))
66
66
  )
67
67
  ];
68
- const { info, error } = await _chunkBHYHORUDcjs.fetchIngesterCompat.call(void 0, endpoint, { probeRoutes: routes, unref: false, timeoutMs });
68
+ const { info, error } = await _chunk3P573RHAcjs.fetchIngesterCompat.call(void 0, endpoint, { probeRoutes: routes, unref: false, timeoutMs });
69
69
  const issues = [];
70
70
  const seen = /* @__PURE__ */ new Set();
71
71
  const add = (issue) => {
@@ -75,21 +75,21 @@ async function runDoctor(options = {}) {
75
75
  issues.push(issue);
76
76
  }
77
77
  };
78
- _chunkBHYHORUDcjs.evaluateCompat.call(void 0, { features, ingester: info }).forEach(add);
78
+ _chunk3P573RHAcjs.evaluateCompat.call(void 0, { features, ingester: info }).forEach(add);
79
79
  for (const sdk of sdks) {
80
80
  if (_optionalChain([options, 'access', _7 => _7.features, 'optionalAccess', _8 => _8.length])) {
81
- _chunkBHYHORUDcjs.evaluateCompat.call(void 0, { features: options.features, ingester: null, sdk }).forEach(add);
81
+ _chunk3P573RHAcjs.evaluateCompat.call(void 0, { features: options.features, ingester: null, sdk }).forEach(add);
82
82
  }
83
83
  }
84
84
  const key = options.key ? await checkKey(endpoint, options.key, timeoutMs) : void 0;
85
85
  const featureRows = features.flatMap((id) => {
86
- const feature = _chunkBHYHORUDcjs.COMPAT_MANIFEST.features.find((f) => f.id === id);
86
+ const feature = _chunk3P573RHAcjs.COMPAT_MANIFEST.features.find((f) => f.id === id);
87
87
  if (!feature) return [];
88
88
  const bad = issues.some((issue) => issue.feature === id);
89
89
  const known = _optionalChain([info, 'optionalAccess', _9 => _9.version]) != null || feature.route !== void 0 && _optionalChain([info, 'optionalAccess', _10 => _10.routes, 'optionalAccess', _11 => _11[feature.route]]) !== void 0;
90
90
  return [{ id, title: feature.title, status: bad ? "incompatible" : known ? "ok" : "unknown" }];
91
91
  });
92
- const exitCode = !info ? 2 : issues.length || key === "rejected" || key === "client_key" || key === "storage_unavailable" ? 1 : 0;
92
+ const exitCode = !info ? 2 : issues.length || key === "rejected" || key === "client_key" || key === "storage_unavailable" || key === "unverified" ? 1 : 0;
93
93
  return {
94
94
  endpoint,
95
95
  sdks,
@@ -125,6 +125,7 @@ function formatDoctorReport(report) {
125
125
  rejected: "REJECTED (401): check AUTTER_RUNTIME_KEY",
126
126
  client_key: "is a client/browser key; server SDKs need a server key",
127
127
  storage_unavailable: "accepted, but the ingester's ClickHouse is unavailable (503)",
128
+ unverified: "could not be checked: the ingester's key validator is unavailable (503); exporters retry",
128
129
  unknown: "could not be verified"
129
130
  }[report.key];
130
131
  lines.push(` key ${text}`);
@@ -153,7 +154,7 @@ Checks that your Autter SDKs, ingester and ClickHouse schema versions match.
153
154
  Options:
154
155
  --endpoint <url> Ingester base URL (default: $AUTTER_ENDPOINT, $OTEL_EXPORTER_OTLP_ENDPOINT, or ${DEFAULT_ENDPOINT})
155
156
  --key <key> Also verify an ingest key (default: $AUTTER_RUNTIME_KEY)
156
- --features <a,b> Only check these features (${_chunkBHYHORUDcjs.COMPAT_MANIFEST.features.map((f) => f.id).join(", ")})
157
+ --features <a,b> Only check these features (${_chunk3P573RHAcjs.COMPAT_MANIFEST.features.map((f) => f.id).join(", ")})
157
158
  --json Machine-readable output
158
159
  --timeout <ms> Per-request timeout (default 5000)
159
160
 
@@ -552,7 +552,7 @@ import { request as httpsRequest } from "https";
552
552
  // package.json
553
553
  var package_default = {
554
554
  name: "@autter/runtime-node",
555
- version: "1.9.0",
555
+ version: "1.9.1",
556
556
  description: "Autter Runtime for Node.js: request wide events, coded errors, operation logging, same-origin browser relay and a curated OpenTelemetry server tracker",
557
557
  license: "MIT",
558
558
  type: "module",
package/dist/cli.cjs CHANGED
@@ -4,8 +4,8 @@
4
4
 
5
5
 
6
6
 
7
- var _chunkAN45KLWDcjs = require('./chunk-AN45KLWD.cjs');
8
- require('./chunk-BHYHORUD.cjs');
7
+ var _chunkLYXQC4FIcjs = require('./chunk-LYXQC4FI.cjs');
8
+ require('./chunk-3P573RHA.cjs');
9
9
 
10
10
  // src/cli.ts
11
11
  var _child_process = require('child_process');
@@ -31,22 +31,22 @@ async function main(argv) {
31
31
  return 64;
32
32
  }
33
33
  if (command !== "doctor") {
34
- console.log(_chunkAN45KLWDcjs.DOCTOR_USAGE);
34
+ console.log(_chunkLYXQC4FIcjs.DOCTOR_USAGE);
35
35
  return command === void 0 || command === "--help" || command === "-h" ? 0 : 64;
36
36
  }
37
- const parsed = _chunkAN45KLWDcjs.parseDoctorArgs.call(void 0, rest);
37
+ const parsed = _chunkLYXQC4FIcjs.parseDoctorArgs.call(void 0, rest);
38
38
  if ("help" in parsed) {
39
- console.log(_chunkAN45KLWDcjs.DOCTOR_USAGE);
39
+ console.log(_chunkLYXQC4FIcjs.DOCTOR_USAGE);
40
40
  return 0;
41
41
  }
42
42
  if ("error" in parsed) {
43
43
  console.error(`${parsed.error}
44
44
 
45
- ${_chunkAN45KLWDcjs.DOCTOR_USAGE}`);
45
+ ${_chunkLYXQC4FIcjs.DOCTOR_USAGE}`);
46
46
  return 64;
47
47
  }
48
- const report = await _chunkAN45KLWDcjs.runDoctor.call(void 0, parsed);
49
- console.log(parsed.json ? JSON.stringify(report, null, 2) : _chunkAN45KLWDcjs.formatDoctorReport.call(void 0, report));
48
+ const report = await _chunkLYXQC4FIcjs.runDoctor.call(void 0, parsed);
49
+ console.log(parsed.json ? JSON.stringify(report, null, 2) : _chunkLYXQC4FIcjs.formatDoctorReport.call(void 0, report));
50
50
  return report.exitCode;
51
51
  }
52
52
  main(process.argv.slice(2)).then(
package/dist/cli.js CHANGED
@@ -4,8 +4,8 @@ import {
4
4
  formatDoctorReport,
5
5
  parseDoctorArgs,
6
6
  runDoctor
7
- } from "./chunk-JSGGUWRD.js";
8
- import "./chunk-ZKM76SDP.js";
7
+ } from "./chunk-FYMEBULO.js";
8
+ import "./chunk-VIP2EL47.js";
9
9
 
10
10
  // src/cli.ts
11
11
  import { spawnSync } from "child_process";