@autter/runtime-node 1.9.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,10 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkBHYHORUDcjs = require('./chunk-BHYHORUD.cjs');
5
+
6
+
7
+
8
+ var _chunkS6WJ5YLPcjs = require('./chunk-S6WJ5YLP.cjs');
6
9
 
7
10
  // ../runtime-core/dist/index.js
8
11
  var SENSITIVE_KEY_PATTERNS = [
@@ -1222,7 +1225,7 @@ var _util = require('util');
1222
1225
  var _requireinthemiddle = require('require-in-the-middle');
1223
1226
 
1224
1227
  // src/captured.ts
1225
- var CAPTURED = _chunkBHYHORUDcjs.sharedSlot.call(void 0, "requests", () => ({ captured: /* @__PURE__ */ new WeakSet() })).captured;
1228
+ var CAPTURED = _chunkS6WJ5YLPcjs.sharedSlot.call(void 0, "requests", () => ({ captured: /* @__PURE__ */ new WeakSet() })).captured;
1226
1229
  function markCaptured(error) {
1227
1230
  if (error && typeof error === "object") CAPTURED.add(error);
1228
1231
  }
@@ -1231,7 +1234,7 @@ function isCaptured(error) {
1231
1234
  }
1232
1235
 
1233
1236
  // src/caught-errors.ts
1234
- var S = _chunkBHYHORUDcjs.sharedSlot.call(void 0, "handled", () => ({
1237
+ var S = _chunkS6WJ5YLPcjs.sharedSlot.call(void 0, "handled", () => ({
1235
1238
  sources: null,
1236
1239
  capture: null,
1237
1240
  tail: null,
@@ -1485,7 +1488,7 @@ function stopLoggedErrorCapture() {
1485
1488
 
1486
1489
  var _fs = require('fs');
1487
1490
 
1488
- var sinkStats = _chunkBHYHORUDcjs.sharedSlot.call(void 0, "sinks", () => ({ dropped: 0 }));
1491
+ var sinkStats = _chunkS6WJ5YLPcjs.sharedSlot.call(void 0, "sinks", () => ({ dropped: 0 }));
1489
1492
  function otlpSink(options = {}) {
1490
1493
  let context = null;
1491
1494
  let queue = [];
@@ -1496,6 +1499,7 @@ function otlpSink(options = {}) {
1496
1499
  let flushing = null;
1497
1500
  let stopping = false;
1498
1501
  let failureStreak = 0;
1502
+ let nextFlushAfter = 0;
1499
1503
  const scheduleFlush = () => {
1500
1504
  if (!timer && context && !stopping && queue.length) {
1501
1505
  timer = setTimeout(
@@ -1504,7 +1508,7 @@ function otlpSink(options = {}) {
1504
1508
  void flush().catch(() => {
1505
1509
  });
1506
1510
  },
1507
- Math.min(3e4, 2e3 * 2 ** Math.min(failureStreak, 4))
1511
+ Math.max(nextFlushAfter, Math.min(3e4, 2e3 * 2 ** Math.min(failureStreak, 4)))
1508
1512
  );
1509
1513
  timer.unref();
1510
1514
  }
@@ -1547,6 +1551,7 @@ function otlpSink(options = {}) {
1547
1551
  );
1548
1552
  let failure;
1549
1553
  for (let attempt = 0; attempt < 3; attempt++) {
1554
+ let retryAfter = null;
1550
1555
  try {
1551
1556
  if (Date.now() >= deadline)
1552
1557
  throw new Error("Runtime log flush exceeded 10 seconds");
@@ -1554,21 +1559,38 @@ function otlpSink(options = {}) {
1554
1559
  method: "POST",
1555
1560
  headers: {
1556
1561
  "content-type": "application/json",
1557
- authorization: `Bearer ${apiKey}`
1562
+ ..._chunkS6WJ5YLPcjs.authHeaders.call(void 0, _chunkS6WJ5YLPcjs.resolveIngestKey.call(void 0, apiKey, {}))
1558
1563
  },
1559
1564
  body,
1560
1565
  signal: AbortSignal.timeout(
1561
1566
  Math.max(1, Math.min(3e3, deadline - Date.now()))
1562
1567
  )
1563
1568
  });
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;
1569
+ _chunkS6WJ5YLPcjs.observeIngesterResponse.call(void 0, { status: response.status, headers: response.headers, route: "/v1/logs" });
1570
+ if (!response.ok) {
1571
+ failure = new Error(`Runtime log export failed (${response.status})`);
1572
+ if (response.status !== 429 && response.status < 500) {
1573
+ _chunkS6WJ5YLPcjs.noteIngestRefusal.call(void 0, {
1574
+ status: response.status,
1575
+ route: "/v1/logs",
1576
+ endpoint,
1577
+ body: await response.text().catch(() => "")
1578
+ });
1579
+ }
1580
+ if (response.status !== 429 && response.status < 500) break;
1581
+ retryAfter = response.headers.get("retry-after");
1582
+ } else {
1583
+ failure = void 0;
1584
+ break;
1585
+ }
1569
1586
  } catch (error) {
1570
1587
  failure = error;
1571
1588
  }
1589
+ const seconds = Number(retryAfter);
1590
+ const wait = seconds > 0 ? Math.min(seconds * 1e3, 3e5) : 500 * 2 ** attempt;
1591
+ nextFlushAfter = Math.max(nextFlushAfter, wait);
1592
+ if (attempt >= 2 || Date.now() + wait >= deadline) break;
1593
+ await new Promise((resolve2) => setTimeout(resolve2, wait));
1572
1594
  }
1573
1595
  inFlight = 0;
1574
1596
  if (failure) {
@@ -1580,6 +1602,7 @@ function otlpSink(options = {}) {
1580
1602
  }
1581
1603
  inFlightBytes = 0;
1582
1604
  failureStreak = 0;
1605
+ nextFlushAfter = 0;
1583
1606
  }
1584
1607
  })().finally(() => {
1585
1608
  flushing = null;
@@ -1611,7 +1634,7 @@ function otlpSink(options = {}) {
1611
1634
  }
1612
1635
  queue.push({ record, bytes });
1613
1636
  queueBytes += bytes;
1614
- _chunkBHYHORUDcjs.noteCompatFeature.call(void 0, "operation_logging");
1637
+ _chunkS6WJ5YLPcjs.noteCompatFeature.call(void 0, "operation_logging");
1615
1638
  scheduleFlush();
1616
1639
  },
1617
1640
  flush,
@@ -1854,7 +1877,7 @@ function memorySink() {
1854
1877
  }
1855
1878
 
1856
1879
  // src/logger.ts
1857
- var shared = _chunkBHYHORUDcjs.sharedSlot.call(void 0, "logger", () => ({
1880
+ var shared = _chunkS6WJ5YLPcjs.sharedSlot.call(void 0, "logger", () => ({
1858
1881
  local: new (0, _async_hooks.AsyncLocalStorage)(),
1859
1882
  config: null,
1860
1883
  sinks: [],
@@ -2354,7 +2377,7 @@ setHandledTail(
2354
2377
  // src/breadcrumbs.ts
2355
2378
  var INVALID_TRACE_ID = "00000000000000000000000000000000";
2356
2379
  var MAX_TRACE_TRAILS = 200;
2357
- var trails = _chunkBHYHORUDcjs.sharedSlot.call(void 0, "breadcrumbs", () => ({
2380
+ var trails = _chunkS6WJ5YLPcjs.sharedSlot.call(void 0, "breadcrumbs", () => ({
2358
2381
  byTrace: /* @__PURE__ */ new Map(),
2359
2382
  process: new BreadcrumbTrail(),
2360
2383
  thrown: /* @__PURE__ */ new WeakMap()
@@ -2390,7 +2413,7 @@ function addBreadcrumb(input) {
2390
2413
  const crumb = normalizeBreadcrumb(input, redact2);
2391
2414
  if (!crumb) return;
2392
2415
  _optionalChain([trailFor, 'call', _122 => _122(true), 'optionalAccess', _123 => _123.add, 'call', _124 => _124(crumb)]);
2393
- _chunkBHYHORUDcjs.noteCompatFeature.call(void 0, "breadcrumbs");
2416
+ _chunkS6WJ5YLPcjs.noteCompatFeature.call(void 0, "breadcrumbs");
2394
2417
  } catch (e39) {
2395
2418
  }
2396
2419
  }
@@ -1,8 +1,11 @@
1
1
  import {
2
+ authHeaders,
2
3
  noteCompatFeature,
4
+ noteIngestRefusal,
3
5
  observeIngesterResponse,
6
+ resolveIngestKey,
4
7
  sharedSlot
5
- } from "./chunk-ZKM76SDP.js";
8
+ } from "./chunk-KWAJIELR.js";
6
9
 
7
10
  // ../runtime-core/dist/index.js
8
11
  var SENSITIVE_KEY_PATTERNS = [
@@ -1496,6 +1499,7 @@ function otlpSink(options = {}) {
1496
1499
  let flushing = null;
1497
1500
  let stopping = false;
1498
1501
  let failureStreak = 0;
1502
+ let nextFlushAfter = 0;
1499
1503
  const scheduleFlush = () => {
1500
1504
  if (!timer && context && !stopping && queue.length) {
1501
1505
  timer = setTimeout(
@@ -1504,7 +1508,7 @@ function otlpSink(options = {}) {
1504
1508
  void flush().catch(() => {
1505
1509
  });
1506
1510
  },
1507
- Math.min(3e4, 2e3 * 2 ** Math.min(failureStreak, 4))
1511
+ Math.max(nextFlushAfter, Math.min(3e4, 2e3 * 2 ** Math.min(failureStreak, 4)))
1508
1512
  );
1509
1513
  timer.unref();
1510
1514
  }
@@ -1547,6 +1551,7 @@ function otlpSink(options = {}) {
1547
1551
  );
1548
1552
  let failure;
1549
1553
  for (let attempt = 0; attempt < 3; attempt++) {
1554
+ let retryAfter = null;
1550
1555
  try {
1551
1556
  if (Date.now() >= deadline)
1552
1557
  throw new Error("Runtime log flush exceeded 10 seconds");
@@ -1554,7 +1559,7 @@ function otlpSink(options = {}) {
1554
1559
  method: "POST",
1555
1560
  headers: {
1556
1561
  "content-type": "application/json",
1557
- authorization: `Bearer ${apiKey}`
1562
+ ...authHeaders(resolveIngestKey(apiKey, {}))
1558
1563
  },
1559
1564
  body,
1560
1565
  signal: AbortSignal.timeout(
@@ -1562,13 +1567,30 @@ function otlpSink(options = {}) {
1562
1567
  )
1563
1568
  });
1564
1569
  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;
1570
+ if (!response.ok) {
1571
+ failure = new Error(`Runtime log export failed (${response.status})`);
1572
+ if (response.status !== 429 && response.status < 500) {
1573
+ noteIngestRefusal({
1574
+ status: response.status,
1575
+ route: "/v1/logs",
1576
+ endpoint,
1577
+ body: await response.text().catch(() => "")
1578
+ });
1579
+ }
1580
+ if (response.status !== 429 && response.status < 500) break;
1581
+ retryAfter = response.headers.get("retry-after");
1582
+ } else {
1583
+ failure = void 0;
1584
+ break;
1585
+ }
1569
1586
  } catch (error) {
1570
1587
  failure = error;
1571
1588
  }
1589
+ const seconds = Number(retryAfter);
1590
+ const wait = seconds > 0 ? Math.min(seconds * 1e3, 3e5) : 500 * 2 ** attempt;
1591
+ nextFlushAfter = Math.max(nextFlushAfter, wait);
1592
+ if (attempt >= 2 || Date.now() + wait >= deadline) break;
1593
+ await new Promise((resolve2) => setTimeout(resolve2, wait));
1572
1594
  }
1573
1595
  inFlight = 0;
1574
1596
  if (failure) {
@@ -1580,6 +1602,7 @@ function otlpSink(options = {}) {
1580
1602
  }
1581
1603
  inFlightBytes = 0;
1582
1604
  failureStreak = 0;
1605
+ nextFlushAfter = 0;
1583
1606
  }
1584
1607
  })().finally(() => {
1585
1608
  flushing = null;
package/dist/cli.cjs CHANGED
@@ -4,14 +4,25 @@
4
4
 
5
5
 
6
6
 
7
- var _chunkAN45KLWDcjs = require('./chunk-AN45KLWD.cjs');
8
- require('./chunk-BHYHORUD.cjs');
7
+
8
+
9
+
10
+
11
+ var _chunkHBH64LWQcjs = require('./chunk-HBH64LWQ.cjs');
12
+ require('./chunk-S6WJ5YLP.cjs');
9
13
 
10
14
  // src/cli.ts
11
15
  var _child_process = require('child_process');
12
16
  var _fs = require('fs');
13
17
  var _module = require('module');
14
18
  var _path = require('path');
19
+ var USAGE = `Usage: npx @autter/runtime-node <command> [options]
20
+
21
+ Commands:
22
+ doctor Versions, storage, features and the key, in one report
23
+ verify Send a test event end to end and name the first failing step
24
+
25
+ Run a command with --help for its options.`;
15
26
  function delegateToRuntimeCli(argv) {
16
27
  try {
17
28
  const manifest = _module.createRequire.call(void 0, _path.join.call(void 0, process.cwd(), "package.json")).resolve("@autter/runtime-cli/package.json");
@@ -30,23 +41,39 @@ async function main(argv) {
30
41
  console.error("autter-runtime sourcemaps is part of @autter/runtime-cli: npm install -D @autter/runtime-cli");
31
42
  return 64;
32
43
  }
44
+ if (command === "verify") {
45
+ const parsed2 = _chunkHBH64LWQcjs.parseVerifyArgs.call(void 0, rest);
46
+ if ("help" in parsed2) {
47
+ console.log(_chunkHBH64LWQcjs.VERIFY_USAGE);
48
+ return 0;
49
+ }
50
+ if ("error" in parsed2) {
51
+ console.error(`${parsed2.error}
52
+
53
+ ${_chunkHBH64LWQcjs.VERIFY_USAGE}`);
54
+ return 64;
55
+ }
56
+ const report2 = await _chunkHBH64LWQcjs.runVerify.call(void 0, parsed2);
57
+ console.log(parsed2.json ? JSON.stringify(report2, null, 2) : _chunkHBH64LWQcjs.formatVerifyReport.call(void 0, report2));
58
+ return report2.exitCode;
59
+ }
33
60
  if (command !== "doctor") {
34
- console.log(_chunkAN45KLWDcjs.DOCTOR_USAGE);
61
+ console.log(USAGE);
35
62
  return command === void 0 || command === "--help" || command === "-h" ? 0 : 64;
36
63
  }
37
- const parsed = _chunkAN45KLWDcjs.parseDoctorArgs.call(void 0, rest);
64
+ const parsed = _chunkHBH64LWQcjs.parseDoctorArgs.call(void 0, rest);
38
65
  if ("help" in parsed) {
39
- console.log(_chunkAN45KLWDcjs.DOCTOR_USAGE);
66
+ console.log(_chunkHBH64LWQcjs.DOCTOR_USAGE);
40
67
  return 0;
41
68
  }
42
69
  if ("error" in parsed) {
43
70
  console.error(`${parsed.error}
44
71
 
45
- ${_chunkAN45KLWDcjs.DOCTOR_USAGE}`);
72
+ ${_chunkHBH64LWQcjs.DOCTOR_USAGE}`);
46
73
  return 64;
47
74
  }
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));
75
+ const report = await _chunkHBH64LWQcjs.runDoctor.call(void 0, parsed);
76
+ console.log(parsed.json ? JSON.stringify(report, null, 2) : _chunkHBH64LWQcjs.formatDoctorReport.call(void 0, report));
50
77
  return report.exitCode;
51
78
  }
52
79
  main(process.argv.slice(2)).then(
@@ -54,7 +81,7 @@ main(process.argv.slice(2)).then(
54
81
  process.exitCode = code;
55
82
  },
56
83
  (err) => {
57
- console.error("autter doctor failed:", err instanceof Error ? err.message : err);
84
+ console.error("autter-runtime failed:", err instanceof Error ? err.message : err);
58
85
  process.exitCode = 2;
59
86
  }
60
87
  );
package/dist/cli.js CHANGED
@@ -1,17 +1,28 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  DOCTOR_USAGE,
4
+ VERIFY_USAGE,
4
5
  formatDoctorReport,
6
+ formatVerifyReport,
5
7
  parseDoctorArgs,
6
- runDoctor
7
- } from "./chunk-JSGGUWRD.js";
8
- import "./chunk-ZKM76SDP.js";
8
+ parseVerifyArgs,
9
+ runDoctor,
10
+ runVerify
11
+ } from "./chunk-3UODRQBD.js";
12
+ import "./chunk-KWAJIELR.js";
9
13
 
10
14
  // src/cli.ts
11
15
  import { spawnSync } from "child_process";
12
16
  import { readFileSync } from "fs";
13
17
  import { createRequire } from "module";
14
18
  import { dirname, join, resolve } from "path";
19
+ var USAGE = `Usage: npx @autter/runtime-node <command> [options]
20
+
21
+ Commands:
22
+ doctor Versions, storage, features and the key, in one report
23
+ verify Send a test event end to end and name the first failing step
24
+
25
+ Run a command with --help for its options.`;
15
26
  function delegateToRuntimeCli(argv) {
16
27
  try {
17
28
  const manifest = createRequire(join(process.cwd(), "package.json")).resolve("@autter/runtime-cli/package.json");
@@ -30,8 +41,24 @@ async function main(argv) {
30
41
  console.error("autter-runtime sourcemaps is part of @autter/runtime-cli: npm install -D @autter/runtime-cli");
31
42
  return 64;
32
43
  }
44
+ if (command === "verify") {
45
+ const parsed2 = parseVerifyArgs(rest);
46
+ if ("help" in parsed2) {
47
+ console.log(VERIFY_USAGE);
48
+ return 0;
49
+ }
50
+ if ("error" in parsed2) {
51
+ console.error(`${parsed2.error}
52
+
53
+ ${VERIFY_USAGE}`);
54
+ return 64;
55
+ }
56
+ const report2 = await runVerify(parsed2);
57
+ console.log(parsed2.json ? JSON.stringify(report2, null, 2) : formatVerifyReport(report2));
58
+ return report2.exitCode;
59
+ }
33
60
  if (command !== "doctor") {
34
- console.log(DOCTOR_USAGE);
61
+ console.log(USAGE);
35
62
  return command === void 0 || command === "--help" || command === "-h" ? 0 : 64;
36
63
  }
37
64
  const parsed = parseDoctorArgs(rest);
@@ -54,7 +81,7 @@ main(process.argv.slice(2)).then(
54
81
  process.exitCode = code;
55
82
  },
56
83
  (err) => {
57
- console.error("autter doctor failed:", err instanceof Error ? err.message : err);
84
+ console.error("autter-runtime failed:", err instanceof Error ? err.message : err);
58
85
  process.exitCode = 2;
59
86
  }
60
87
  );