@cultured_computer/sight 0.4.3 → 0.4.4

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
@@ -58,6 +58,19 @@ var IngestClient = class {
58
58
  this.inFlight--;
59
59
  }
60
60
  }
61
+ /**
62
+ * Await all in-flight sends (bounded). Called by Probe.shutdown() so
63
+ * short-lived processes (serverless, CLI scripts) can actually exit after
64
+ * it — the documented "in-flight sends finish within 15s" only holds while
65
+ * the process lives. Polling is coarse on purpose: sends report through
66
+ * guardedFetch's counter, never awaited individually.
67
+ */
68
+ async drainInFlight(timeoutMs = SEND_TIMEOUT_MS) {
69
+ const deadline = Date.now() + timeoutMs;
70
+ while (this.inFlight > 0 && Date.now() < deadline) {
71
+ await new Promise((r) => setTimeout(r, 50));
72
+ }
73
+ }
61
74
  constructor(opts) {
62
75
  this.apiKey = opts.apiKey;
63
76
  this.endpoint = opts.endpoint.replace(/\/$/, "");
@@ -283,7 +296,7 @@ var IngestClient = class {
283
296
  if (!this.rateLimitAnnounced) {
284
297
  this.rateLimitAnnounced = true;
285
298
  console.error(
286
- "Sight: ingest rate limit (429) \u2014 retrying once per Retry-After; sustained limiting drops captures. See https://field.cultured.computer/sight/sdk-reference#rate-limits"
299
+ "Sight: ingest rate limit (429) \u2014 retrying once per Retry-After; sustained limiting drops captures. See https://sight.cultured.computer/docs/sdk-reference#rate-limits"
287
300
  );
288
301
  } else {
289
302
  this.log("[sight] ingest rate limited (429), retrying once");
@@ -2062,8 +2075,10 @@ var Probe = class {
2062
2075
  if (state === null) {
2063
2076
  return;
2064
2077
  }
2078
+ const client = state.client;
2065
2079
  detachOtelState();
2066
2080
  state = null;
2081
+ await client.drainInFlight();
2067
2082
  }
2068
2083
  // ── Internal helpers ─────────────────────────────────────────────────────
2069
2084
  /** Package-internal: instrumentation adapters read this to build turns. */