@cultured_computer/sight 0.4.3 → 0.5.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.d.cts CHANGED
@@ -989,6 +989,14 @@ declare class IngestClient {
989
989
  * the first shed per process warns on stderr, the rest debug-log.
990
990
  */
991
991
  private guardedFetch;
992
+ /**
993
+ * Await all in-flight sends (bounded). Called by Probe.shutdown() so
994
+ * short-lived processes (serverless, CLI scripts) can actually exit after
995
+ * it — the documented "in-flight sends finish within 15s" only holds while
996
+ * the process lives. Polling is coarse on purpose: sends report through
997
+ * guardedFetch's counter, never awaited individually.
998
+ */
999
+ drainInFlight(timeoutMs?: number): Promise<void>;
992
1000
  constructor(opts: IngestClientOptions);
993
1001
  /**
994
1002
  * Send a turn to the ingest API. Fire-and-log: errors are logged but never
package/dist/index.d.ts CHANGED
@@ -989,6 +989,14 @@ declare class IngestClient {
989
989
  * the first shed per process warns on stderr, the rest debug-log.
990
990
  */
991
991
  private guardedFetch;
992
+ /**
993
+ * Await all in-flight sends (bounded). Called by Probe.shutdown() so
994
+ * short-lived processes (serverless, CLI scripts) can actually exit after
995
+ * it — the documented "in-flight sends finish within 15s" only holds while
996
+ * the process lives. Polling is coarse on purpose: sends report through
997
+ * guardedFetch's counter, never awaited individually.
998
+ */
999
+ drainInFlight(timeoutMs?: number): Promise<void>;
992
1000
  constructor(opts: IngestClientOptions);
993
1001
  /**
994
1002
  * Send a turn to the ingest API. Fire-and-log: errors are logged but never
package/dist/index.js CHANGED
@@ -56,6 +56,19 @@ var IngestClient = class {
56
56
  this.inFlight--;
57
57
  }
58
58
  }
59
+ /**
60
+ * Await all in-flight sends (bounded). Called by Probe.shutdown() so
61
+ * short-lived processes (serverless, CLI scripts) can actually exit after
62
+ * it — the documented "in-flight sends finish within 15s" only holds while
63
+ * the process lives. Polling is coarse on purpose: sends report through
64
+ * guardedFetch's counter, never awaited individually.
65
+ */
66
+ async drainInFlight(timeoutMs = SEND_TIMEOUT_MS) {
67
+ const deadline = Date.now() + timeoutMs;
68
+ while (this.inFlight > 0 && Date.now() < deadline) {
69
+ await new Promise((r) => setTimeout(r, 50));
70
+ }
71
+ }
59
72
  constructor(opts) {
60
73
  this.apiKey = opts.apiKey;
61
74
  this.endpoint = opts.endpoint.replace(/\/$/, "");
@@ -281,7 +294,7 @@ var IngestClient = class {
281
294
  if (!this.rateLimitAnnounced) {
282
295
  this.rateLimitAnnounced = true;
283
296
  console.error(
284
- "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"
297
+ "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"
285
298
  );
286
299
  } else {
287
300
  this.log("[sight] ingest rate limited (429), retrying once");
@@ -2060,8 +2073,10 @@ var Probe = class {
2060
2073
  if (state === null) {
2061
2074
  return;
2062
2075
  }
2076
+ const client = state.client;
2063
2077
  detachOtelState();
2064
2078
  state = null;
2079
+ await client.drainInFlight();
2065
2080
  }
2066
2081
  // ── Internal helpers ─────────────────────────────────────────────────────
2067
2082
  /** Package-internal: instrumentation adapters read this to build turns. */