@goodtiming/baton-sdk 0.6.3 → 0.6.5
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/README.md +5 -4
- package/dist/index.cjs +474 -195
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +99 -35
- package/dist/index.d.ts +99 -35
- package/dist/index.js +474 -195
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
-
declare const SDK_VERSION = "ts-0.6.
|
|
3
|
+
declare const SDK_VERSION = "ts-0.6.5";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Zod schemas + TS types for the Baton event stream per SPEC §11.4.
|
|
@@ -2188,7 +2188,7 @@ declare const DEPTH_MARKER = "[REDACTED:depth-limit]";
|
|
|
2188
2188
|
/**
|
|
2189
2189
|
* Stateful recursive scrubber with the default ruleset baked in.
|
|
2190
2190
|
*
|
|
2191
|
-
* Construct one per `withBaton`
|
|
2191
|
+
* Construct one per `withBaton` or `createBaton` and reuse for every event. The
|
|
2192
2192
|
* `counts` map accumulates per-category redaction counts across all calls
|
|
2193
2193
|
* so a downstream report can surface "N emails, M bearer tokens" at render
|
|
2194
2194
|
* time. Nothing on the wire carries these today — they exist for parity
|
|
@@ -2232,8 +2232,8 @@ declare function identityScrub(value: unknown): unknown;
|
|
|
2232
2232
|
* for the same reason as Python: MCP stdio transport reserves stdout for
|
|
2233
2233
|
* JSON-RPC framing).
|
|
2234
2234
|
* - `FileSink` — JSONL appended to a file.
|
|
2235
|
-
* - `HttpSink` — POST to any HTTP endpoint with bearer auth;
|
|
2236
|
-
* buffer, retry with backoff, circuit breaker. This is the contract a
|
|
2235
|
+
* - `HttpSink` — POST batches to any HTTP endpoint with bearer auth;
|
|
2236
|
+
* bounded buffer, retry with backoff, circuit breaker. This is the contract a
|
|
2237
2237
|
* Console or any compatible collector consumes.
|
|
2238
2238
|
* - `MultiSink` — every event to each of several sinks.
|
|
2239
2239
|
*/
|
|
@@ -2313,14 +2313,20 @@ interface HttpSinkOptions {
|
|
|
2313
2313
|
/** How long the flush at process exit, or an explicit `flush()` or
|
|
2314
2314
|
* `aclose()`, may take in total, in ms, at most 2^31 - 1. Default 3000. */
|
|
2315
2315
|
shutdownFlushTimeoutMs?: number;
|
|
2316
|
+
/** The longest an event waits before its batch is sent, in ms. Default 5000. */
|
|
2317
|
+
flushIntervalMs?: number;
|
|
2316
2318
|
/** Injectable for tests; defaults to the global `fetch`. */
|
|
2317
2319
|
fetchImpl?: typeof fetch;
|
|
2318
2320
|
}
|
|
2319
|
-
/** POST events to an HTTP endpoint. Bounded buffer + retry +
|
|
2321
|
+
/** POST events to an HTTP endpoint in batches. Bounded buffer + retry +
|
|
2322
|
+
* circuit breaker.
|
|
2320
2323
|
*
|
|
2321
2324
|
* This is the contract a Console or any compatible collector consumes:
|
|
2322
|
-
* `POST {url}/v0/events` with `Authorization: Bearer
|
|
2323
|
-
*
|
|
2325
|
+
* `POST {url}/v0/events/batch` (SPEC §2.5) with `Authorization: Bearer
|
|
2326
|
+
* {apiKey}` and `{"events": [...]}` of SPEC §11.4 envelopes. A batch goes when
|
|
2327
|
+
* 100 events wait, when the next would take the body over 1 MiB, or
|
|
2328
|
+
* `flushIntervalMs` after the oldest waiting one was written. A collector
|
|
2329
|
+
* with no batch endpoint gets one event per `POST {url}/v0/events`.
|
|
2324
2330
|
*
|
|
2325
2331
|
* Failures are bounded — buffer overflow drops the oldest event; network
|
|
2326
2332
|
* failures retry with backoff; the circuit breaker opens after consecutive
|
|
@@ -2328,12 +2334,17 @@ interface HttpSinkOptions {
|
|
|
2328
2334
|
declare class HttpSink implements Sink {
|
|
2329
2335
|
private readonly url;
|
|
2330
2336
|
private readonly apiKey;
|
|
2337
|
+
/** Waiting events only: a batch being sent is out of it, so the bound
|
|
2338
|
+
* never pushes out an event in flight (SPEC §11.2 rule 4). */
|
|
2331
2339
|
private readonly buffer;
|
|
2340
|
+
private bufferedBytes;
|
|
2341
|
+
private sendingEvents;
|
|
2332
2342
|
private readonly bufferSize;
|
|
2333
2343
|
private readonly requestTimeoutMs;
|
|
2334
2344
|
private readonly shutdownFlushTimeoutMs;
|
|
2335
|
-
|
|
2336
|
-
|
|
2345
|
+
private readonly flushIntervalMs;
|
|
2346
|
+
/** Set when an exit pass ends; cleared once a normal drain sends
|
|
2347
|
+
* everything, which means the process went on. */
|
|
2337
2348
|
private exitPassRan;
|
|
2338
2349
|
/** Whether the exit pass warned about every event now buffered. */
|
|
2339
2350
|
private unsentWarned;
|
|
@@ -2343,7 +2354,8 @@ declare class HttpSink implements Sink {
|
|
|
2343
2354
|
private readonly circuit;
|
|
2344
2355
|
private readonly fetchImpl;
|
|
2345
2356
|
private overflowWarned;
|
|
2346
|
-
/** Per status, so a new kind of refusal, such as a 401
|
|
2357
|
+
/** Per status or refusal code, so a new kind of refusal, such as a 401
|
|
2358
|
+
* after a 422, still warns. */
|
|
2347
2359
|
private readonly refusals;
|
|
2348
2360
|
/** Aborted once `aclose()` returns: nothing Baton started may keep the
|
|
2349
2361
|
* process alive after the vendor closed it. */
|
|
@@ -2353,6 +2365,16 @@ declare class HttpSink implements Sink {
|
|
|
2353
2365
|
private skipWarnedFor;
|
|
2354
2366
|
private closeOnce;
|
|
2355
2367
|
private drainChain;
|
|
2368
|
+
private queuedDrain;
|
|
2369
|
+
/** Whether the queued pass sends everything waiting, not only what is due. */
|
|
2370
|
+
private forceNext;
|
|
2371
|
+
private flushTimer;
|
|
2372
|
+
/** Set by a failed batch: only the timer, a flush or a close tries again. */
|
|
2373
|
+
private waitForTimer;
|
|
2374
|
+
/** Nothing is sent before this `Date.now()`, from a 429's `Retry-After`. */
|
|
2375
|
+
private retryAt;
|
|
2376
|
+
/** Set for the life of the sink by a 404 or 405 on the batch path. */
|
|
2377
|
+
private batchless;
|
|
2356
2378
|
private exitHooks;
|
|
2357
2379
|
/** The least time between two of this sink's loss reports. */
|
|
2358
2380
|
private static reportIntervalMs;
|
|
@@ -2360,7 +2382,10 @@ declare class HttpSink implements Sink {
|
|
|
2360
2382
|
private reportedSum;
|
|
2361
2383
|
private lastReportAt;
|
|
2362
2384
|
private reportsStopped;
|
|
2363
|
-
|
|
2385
|
+
/** The envelope of a report due to ride the next batch, and when it was set up.
|
|
2386
|
+
* `built` is the report once taken: a kept batch resends it unchanged (SPEC §11.4.7). */
|
|
2387
|
+
private pendingReport;
|
|
2388
|
+
private reportSetAt;
|
|
2364
2389
|
constructor(url: string, options: HttpSinkOptions);
|
|
2365
2390
|
/**
|
|
2366
2391
|
* What this sink shows when something prints it — never the bearer.
|
|
@@ -2375,6 +2400,9 @@ declare class HttpSink implements Sink {
|
|
|
2375
2400
|
*/
|
|
2376
2401
|
toJSON(): Record<string, unknown>;
|
|
2377
2402
|
private get closed();
|
|
2403
|
+
private get unsent();
|
|
2404
|
+
/** Encodes at once, not when the batch is cut, because the byte cap
|
|
2405
|
+
* decides when a batch goes. */
|
|
2378
2406
|
write(event: Event): Promise<void>;
|
|
2379
2407
|
flush(): Promise<void>;
|
|
2380
2408
|
/** A second call waits for the first (SPEC §11.2 rule 7). */
|
|
@@ -2388,54 +2416,89 @@ declare class HttpSink implements Sink {
|
|
|
2388
2416
|
* drain is not cancelled here, so after `flush()` it goes on sending;
|
|
2389
2417
|
* `aclose()` stops it. */
|
|
2390
2418
|
private drainWithinBudget;
|
|
2391
|
-
/** A full buffer may already have pushed `event` out while it was being sent. */
|
|
2392
|
-
private dequeue;
|
|
2393
2419
|
private enqueue;
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
*
|
|
2398
|
-
|
|
2420
|
+
private dropOverflow;
|
|
2421
|
+
private batchIsFull;
|
|
2422
|
+
/** The timer must not keep the vendor's process alive: the exit hooks send
|
|
2423
|
+
* what is left. */
|
|
2424
|
+
private armTimer;
|
|
2425
|
+
private clearTimer;
|
|
2426
|
+
/** Runs `drainLocked` after the pass under way, one pass at a time, so two
|
|
2427
|
+
* never send at once or race on the buffer. A pass not yet started is
|
|
2428
|
+
* shared by every caller: one per write would grow without bound while a
|
|
2429
|
+
* slow collector holds a pass. */
|
|
2399
2430
|
private scheduleDrain;
|
|
2400
2431
|
/** Best-effort flush when the process is about to exit without an
|
|
2401
2432
|
* explicit `aclose()`. SIGKILL, or SIGTERM with no installed handler, skip
|
|
2402
2433
|
* both hooks: a vendor needing that guarantee must call `aclose()` from
|
|
2403
2434
|
* their own handler. */
|
|
2404
2435
|
private ensureExitHooksRegistered;
|
|
2405
|
-
/** One attempt per
|
|
2436
|
+
/** One attempt per batch, no retry, within `shutdownFlushTimeoutMs` in
|
|
2406
2437
|
* total (SPEC §11.2); what is left is reported, not sent. */
|
|
2407
2438
|
private exitPass;
|
|
2408
2439
|
private unsentAtExit;
|
|
2409
|
-
private events_url;
|
|
2410
2440
|
private authHeaders;
|
|
2411
2441
|
private static classifyStatus;
|
|
2412
|
-
/**
|
|
2413
|
-
*
|
|
2414
|
-
*
|
|
2442
|
+
/** Counts `n` refused events and logs them, at most once a minute per
|
|
2443
|
+
* kind. A refused event is otherwise dropped silently, which looks the same
|
|
2444
|
+
* from the vendor's process as an accepted one. The collector's own message
|
|
2445
|
+
* is logged because it names the field at fault; it is capped and escaped
|
|
2415
2446
|
* because it is a remote server's text landing in the vendor's log. */
|
|
2416
|
-
private
|
|
2447
|
+
private refuse;
|
|
2417
2448
|
private warnUnloggedRefusals;
|
|
2418
|
-
/** How many refusals
|
|
2419
|
-
* when
|
|
2449
|
+
/** How many refusals of `kind` went unlogged before these `n`, or `null`
|
|
2450
|
+
* when these go unlogged too. */
|
|
2420
2451
|
private refusalToLog;
|
|
2421
2452
|
/** Enough of the body for `REFUSAL_BODY_MAX_LEN` code points; the rest is
|
|
2422
2453
|
* cancelled unread, so a large error page does not hold the drain. */
|
|
2423
2454
|
private static readHead;
|
|
2455
|
+
/** Sends what is due, one batch at a time; `force` (a flush or close) sends
|
|
2456
|
+
* everything waiting. A report set up before the pass rides along; one set
|
|
2457
|
+
* up by this pass's own delivery waits for the next batch. */
|
|
2424
2458
|
private drainLocked;
|
|
2425
|
-
/**
|
|
2426
|
-
*
|
|
2427
|
-
*
|
|
2459
|
+
/** A due report makes the next batch due only when it can ride it; the
|
|
2460
|
+
* timer is armed the same way, so a pass that sends nothing never re-arms
|
|
2461
|
+
* it at a time already past. */
|
|
2462
|
+
private isDue;
|
|
2463
|
+
/** A pending report can go in the next batch: alone, or with the head event's tenant and vendor. */
|
|
2464
|
+
private reportRidesHead;
|
|
2465
|
+
/** Takes the head of the buffer that fits one batch: one tenant and vendor
|
|
2466
|
+
* (SPEC §2.5), at most 100 events and 1 MiB. A due report with the head
|
|
2467
|
+
* event's tenant and vendor takes one of those places, and goes alone when
|
|
2468
|
+
* the head event fits only without it. A report that cannot ride the head
|
|
2469
|
+
* waits for a batch it can ride. Without a batch endpoint the same events
|
|
2470
|
+
* go one per request. */
|
|
2471
|
+
private takeBatch;
|
|
2472
|
+
/** Puts what a failure `kept` of the batch `taken` back at the head of the
|
|
2473
|
+
* buffer, and keeps its report unless `taken` had no events; `true` when
|
|
2474
|
+
* nothing was kept. */
|
|
2475
|
+
private putBack;
|
|
2476
|
+
/** After a delivery, sets up a report of this process's loss totals (SPEC
|
|
2477
|
+
* §11.4.7) to ride the next batch. It stays outside the buffer, so it never
|
|
2478
|
+
* pushes an event out and is never counted as one. */
|
|
2428
2479
|
private maybeReport;
|
|
2429
2480
|
private stopReports;
|
|
2430
|
-
private
|
|
2431
|
-
|
|
2481
|
+
private buildReport;
|
|
2482
|
+
/** Sends one batch, splitting it on 413, until every event in it is
|
|
2483
|
+
* delivered or refused. Returns what a failure kept, to go back in the
|
|
2484
|
+
* buffer. */
|
|
2485
|
+
private sendBatch;
|
|
2486
|
+
private sendEachAlone;
|
|
2487
|
+
/** `alone` is one event per request (SPEC §2.5), so a whole refusal there is that event's own. */
|
|
2488
|
+
private settle;
|
|
2432
2489
|
/** `null`, with a warning, for an event `JSON.stringify` rejects. */
|
|
2433
2490
|
private encode;
|
|
2434
2491
|
private sleepUnlessClosed;
|
|
2435
2492
|
/** Aborted by the timeout or by `aclose()`. Built by hand: `AbortSignal.any`
|
|
2436
2493
|
* is missing before Node 20.3, and on some later versions it keeps every
|
|
2437
|
-
* combined signal alive as long as the long-lived `closing` signal.
|
|
2438
|
-
|
|
2494
|
+
* combined signal alive as long as the long-lived `closing` signal. Any body
|
|
2495
|
+
* read is under the same signal, so a stalled body cannot hold the drain. */
|
|
2496
|
+
private post;
|
|
2497
|
+
/** Every answer but a 2xx and a refusal of the whole batch. */
|
|
2498
|
+
private static otherAnswer;
|
|
2499
|
+
/** The refused results by `event_id` (SPEC §2.5). An event with no readable
|
|
2500
|
+
* result was delivered. */
|
|
2501
|
+
private static refusedIn;
|
|
2439
2502
|
}
|
|
2440
2503
|
|
|
2441
2504
|
/** Principal identity — what a vendor's resolver hands back, and how it goes
|
|
@@ -2596,7 +2659,8 @@ interface BatonConfig {
|
|
|
2596
2659
|
* (`{vendorId}_annotate`). This is not the account — see `tenantId`.
|
|
2597
2660
|
*
|
|
2598
2661
|
* Required unless a `dsn` supplies it — the DSN's last path segment IS this
|
|
2599
|
-
* value, and it is what the key is BOUND to.
|
|
2662
|
+
* value, and it is what the key is BOUND to. With no DSN, `tenantId` or sink
|
|
2663
|
+
* either, the install adds nothing instead (SPEC §11.2 rule 10). */
|
|
2600
2664
|
vendorId?: string;
|
|
2601
2665
|
/** Account identifier for the envelope's `tenant_id` (SPEC §11.4).
|
|
2602
2666
|
*
|
|
@@ -2643,7 +2707,7 @@ interface BatonConfig {
|
|
|
2643
2707
|
* one. Adding the read here would make this arm honour a variable the
|
|
2644
2708
|
* equivalent Python door ignores. */
|
|
2645
2709
|
consentToken?: string;
|
|
2646
|
-
/** Where events go.
|
|
2710
|
+
/** Where events go. With a `vendorId` and no DSN, defaults to `new StdoutSink()`. */
|
|
2647
2711
|
sink?: Sink;
|
|
2648
2712
|
/** PII scrubber per SPEC §7, applied to tool params/results, `_meta`,
|
|
2649
2713
|
* intent strings and error bodies before they reach the sink. Defaults to
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
-
declare const SDK_VERSION = "ts-0.6.
|
|
3
|
+
declare const SDK_VERSION = "ts-0.6.5";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Zod schemas + TS types for the Baton event stream per SPEC §11.4.
|
|
@@ -2188,7 +2188,7 @@ declare const DEPTH_MARKER = "[REDACTED:depth-limit]";
|
|
|
2188
2188
|
/**
|
|
2189
2189
|
* Stateful recursive scrubber with the default ruleset baked in.
|
|
2190
2190
|
*
|
|
2191
|
-
* Construct one per `withBaton`
|
|
2191
|
+
* Construct one per `withBaton` or `createBaton` and reuse for every event. The
|
|
2192
2192
|
* `counts` map accumulates per-category redaction counts across all calls
|
|
2193
2193
|
* so a downstream report can surface "N emails, M bearer tokens" at render
|
|
2194
2194
|
* time. Nothing on the wire carries these today — they exist for parity
|
|
@@ -2232,8 +2232,8 @@ declare function identityScrub(value: unknown): unknown;
|
|
|
2232
2232
|
* for the same reason as Python: MCP stdio transport reserves stdout for
|
|
2233
2233
|
* JSON-RPC framing).
|
|
2234
2234
|
* - `FileSink` — JSONL appended to a file.
|
|
2235
|
-
* - `HttpSink` — POST to any HTTP endpoint with bearer auth;
|
|
2236
|
-
* buffer, retry with backoff, circuit breaker. This is the contract a
|
|
2235
|
+
* - `HttpSink` — POST batches to any HTTP endpoint with bearer auth;
|
|
2236
|
+
* bounded buffer, retry with backoff, circuit breaker. This is the contract a
|
|
2237
2237
|
* Console or any compatible collector consumes.
|
|
2238
2238
|
* - `MultiSink` — every event to each of several sinks.
|
|
2239
2239
|
*/
|
|
@@ -2313,14 +2313,20 @@ interface HttpSinkOptions {
|
|
|
2313
2313
|
/** How long the flush at process exit, or an explicit `flush()` or
|
|
2314
2314
|
* `aclose()`, may take in total, in ms, at most 2^31 - 1. Default 3000. */
|
|
2315
2315
|
shutdownFlushTimeoutMs?: number;
|
|
2316
|
+
/** The longest an event waits before its batch is sent, in ms. Default 5000. */
|
|
2317
|
+
flushIntervalMs?: number;
|
|
2316
2318
|
/** Injectable for tests; defaults to the global `fetch`. */
|
|
2317
2319
|
fetchImpl?: typeof fetch;
|
|
2318
2320
|
}
|
|
2319
|
-
/** POST events to an HTTP endpoint. Bounded buffer + retry +
|
|
2321
|
+
/** POST events to an HTTP endpoint in batches. Bounded buffer + retry +
|
|
2322
|
+
* circuit breaker.
|
|
2320
2323
|
*
|
|
2321
2324
|
* This is the contract a Console or any compatible collector consumes:
|
|
2322
|
-
* `POST {url}/v0/events` with `Authorization: Bearer
|
|
2323
|
-
*
|
|
2325
|
+
* `POST {url}/v0/events/batch` (SPEC §2.5) with `Authorization: Bearer
|
|
2326
|
+
* {apiKey}` and `{"events": [...]}` of SPEC §11.4 envelopes. A batch goes when
|
|
2327
|
+
* 100 events wait, when the next would take the body over 1 MiB, or
|
|
2328
|
+
* `flushIntervalMs` after the oldest waiting one was written. A collector
|
|
2329
|
+
* with no batch endpoint gets one event per `POST {url}/v0/events`.
|
|
2324
2330
|
*
|
|
2325
2331
|
* Failures are bounded — buffer overflow drops the oldest event; network
|
|
2326
2332
|
* failures retry with backoff; the circuit breaker opens after consecutive
|
|
@@ -2328,12 +2334,17 @@ interface HttpSinkOptions {
|
|
|
2328
2334
|
declare class HttpSink implements Sink {
|
|
2329
2335
|
private readonly url;
|
|
2330
2336
|
private readonly apiKey;
|
|
2337
|
+
/** Waiting events only: a batch being sent is out of it, so the bound
|
|
2338
|
+
* never pushes out an event in flight (SPEC §11.2 rule 4). */
|
|
2331
2339
|
private readonly buffer;
|
|
2340
|
+
private bufferedBytes;
|
|
2341
|
+
private sendingEvents;
|
|
2332
2342
|
private readonly bufferSize;
|
|
2333
2343
|
private readonly requestTimeoutMs;
|
|
2334
2344
|
private readonly shutdownFlushTimeoutMs;
|
|
2335
|
-
|
|
2336
|
-
|
|
2345
|
+
private readonly flushIntervalMs;
|
|
2346
|
+
/** Set when an exit pass ends; cleared once a normal drain sends
|
|
2347
|
+
* everything, which means the process went on. */
|
|
2337
2348
|
private exitPassRan;
|
|
2338
2349
|
/** Whether the exit pass warned about every event now buffered. */
|
|
2339
2350
|
private unsentWarned;
|
|
@@ -2343,7 +2354,8 @@ declare class HttpSink implements Sink {
|
|
|
2343
2354
|
private readonly circuit;
|
|
2344
2355
|
private readonly fetchImpl;
|
|
2345
2356
|
private overflowWarned;
|
|
2346
|
-
/** Per status, so a new kind of refusal, such as a 401
|
|
2357
|
+
/** Per status or refusal code, so a new kind of refusal, such as a 401
|
|
2358
|
+
* after a 422, still warns. */
|
|
2347
2359
|
private readonly refusals;
|
|
2348
2360
|
/** Aborted once `aclose()` returns: nothing Baton started may keep the
|
|
2349
2361
|
* process alive after the vendor closed it. */
|
|
@@ -2353,6 +2365,16 @@ declare class HttpSink implements Sink {
|
|
|
2353
2365
|
private skipWarnedFor;
|
|
2354
2366
|
private closeOnce;
|
|
2355
2367
|
private drainChain;
|
|
2368
|
+
private queuedDrain;
|
|
2369
|
+
/** Whether the queued pass sends everything waiting, not only what is due. */
|
|
2370
|
+
private forceNext;
|
|
2371
|
+
private flushTimer;
|
|
2372
|
+
/** Set by a failed batch: only the timer, a flush or a close tries again. */
|
|
2373
|
+
private waitForTimer;
|
|
2374
|
+
/** Nothing is sent before this `Date.now()`, from a 429's `Retry-After`. */
|
|
2375
|
+
private retryAt;
|
|
2376
|
+
/** Set for the life of the sink by a 404 or 405 on the batch path. */
|
|
2377
|
+
private batchless;
|
|
2356
2378
|
private exitHooks;
|
|
2357
2379
|
/** The least time between two of this sink's loss reports. */
|
|
2358
2380
|
private static reportIntervalMs;
|
|
@@ -2360,7 +2382,10 @@ declare class HttpSink implements Sink {
|
|
|
2360
2382
|
private reportedSum;
|
|
2361
2383
|
private lastReportAt;
|
|
2362
2384
|
private reportsStopped;
|
|
2363
|
-
|
|
2385
|
+
/** The envelope of a report due to ride the next batch, and when it was set up.
|
|
2386
|
+
* `built` is the report once taken: a kept batch resends it unchanged (SPEC §11.4.7). */
|
|
2387
|
+
private pendingReport;
|
|
2388
|
+
private reportSetAt;
|
|
2364
2389
|
constructor(url: string, options: HttpSinkOptions);
|
|
2365
2390
|
/**
|
|
2366
2391
|
* What this sink shows when something prints it — never the bearer.
|
|
@@ -2375,6 +2400,9 @@ declare class HttpSink implements Sink {
|
|
|
2375
2400
|
*/
|
|
2376
2401
|
toJSON(): Record<string, unknown>;
|
|
2377
2402
|
private get closed();
|
|
2403
|
+
private get unsent();
|
|
2404
|
+
/** Encodes at once, not when the batch is cut, because the byte cap
|
|
2405
|
+
* decides when a batch goes. */
|
|
2378
2406
|
write(event: Event): Promise<void>;
|
|
2379
2407
|
flush(): Promise<void>;
|
|
2380
2408
|
/** A second call waits for the first (SPEC §11.2 rule 7). */
|
|
@@ -2388,54 +2416,89 @@ declare class HttpSink implements Sink {
|
|
|
2388
2416
|
* drain is not cancelled here, so after `flush()` it goes on sending;
|
|
2389
2417
|
* `aclose()` stops it. */
|
|
2390
2418
|
private drainWithinBudget;
|
|
2391
|
-
/** A full buffer may already have pushed `event` out while it was being sent. */
|
|
2392
|
-
private dequeue;
|
|
2393
2419
|
private enqueue;
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
*
|
|
2398
|
-
|
|
2420
|
+
private dropOverflow;
|
|
2421
|
+
private batchIsFull;
|
|
2422
|
+
/** The timer must not keep the vendor's process alive: the exit hooks send
|
|
2423
|
+
* what is left. */
|
|
2424
|
+
private armTimer;
|
|
2425
|
+
private clearTimer;
|
|
2426
|
+
/** Runs `drainLocked` after the pass under way, one pass at a time, so two
|
|
2427
|
+
* never send at once or race on the buffer. A pass not yet started is
|
|
2428
|
+
* shared by every caller: one per write would grow without bound while a
|
|
2429
|
+
* slow collector holds a pass. */
|
|
2399
2430
|
private scheduleDrain;
|
|
2400
2431
|
/** Best-effort flush when the process is about to exit without an
|
|
2401
2432
|
* explicit `aclose()`. SIGKILL, or SIGTERM with no installed handler, skip
|
|
2402
2433
|
* both hooks: a vendor needing that guarantee must call `aclose()` from
|
|
2403
2434
|
* their own handler. */
|
|
2404
2435
|
private ensureExitHooksRegistered;
|
|
2405
|
-
/** One attempt per
|
|
2436
|
+
/** One attempt per batch, no retry, within `shutdownFlushTimeoutMs` in
|
|
2406
2437
|
* total (SPEC §11.2); what is left is reported, not sent. */
|
|
2407
2438
|
private exitPass;
|
|
2408
2439
|
private unsentAtExit;
|
|
2409
|
-
private events_url;
|
|
2410
2440
|
private authHeaders;
|
|
2411
2441
|
private static classifyStatus;
|
|
2412
|
-
/**
|
|
2413
|
-
*
|
|
2414
|
-
*
|
|
2442
|
+
/** Counts `n` refused events and logs them, at most once a minute per
|
|
2443
|
+
* kind. A refused event is otherwise dropped silently, which looks the same
|
|
2444
|
+
* from the vendor's process as an accepted one. The collector's own message
|
|
2445
|
+
* is logged because it names the field at fault; it is capped and escaped
|
|
2415
2446
|
* because it is a remote server's text landing in the vendor's log. */
|
|
2416
|
-
private
|
|
2447
|
+
private refuse;
|
|
2417
2448
|
private warnUnloggedRefusals;
|
|
2418
|
-
/** How many refusals
|
|
2419
|
-
* when
|
|
2449
|
+
/** How many refusals of `kind` went unlogged before these `n`, or `null`
|
|
2450
|
+
* when these go unlogged too. */
|
|
2420
2451
|
private refusalToLog;
|
|
2421
2452
|
/** Enough of the body for `REFUSAL_BODY_MAX_LEN` code points; the rest is
|
|
2422
2453
|
* cancelled unread, so a large error page does not hold the drain. */
|
|
2423
2454
|
private static readHead;
|
|
2455
|
+
/** Sends what is due, one batch at a time; `force` (a flush or close) sends
|
|
2456
|
+
* everything waiting. A report set up before the pass rides along; one set
|
|
2457
|
+
* up by this pass's own delivery waits for the next batch. */
|
|
2424
2458
|
private drainLocked;
|
|
2425
|
-
/**
|
|
2426
|
-
*
|
|
2427
|
-
*
|
|
2459
|
+
/** A due report makes the next batch due only when it can ride it; the
|
|
2460
|
+
* timer is armed the same way, so a pass that sends nothing never re-arms
|
|
2461
|
+
* it at a time already past. */
|
|
2462
|
+
private isDue;
|
|
2463
|
+
/** A pending report can go in the next batch: alone, or with the head event's tenant and vendor. */
|
|
2464
|
+
private reportRidesHead;
|
|
2465
|
+
/** Takes the head of the buffer that fits one batch: one tenant and vendor
|
|
2466
|
+
* (SPEC §2.5), at most 100 events and 1 MiB. A due report with the head
|
|
2467
|
+
* event's tenant and vendor takes one of those places, and goes alone when
|
|
2468
|
+
* the head event fits only without it. A report that cannot ride the head
|
|
2469
|
+
* waits for a batch it can ride. Without a batch endpoint the same events
|
|
2470
|
+
* go one per request. */
|
|
2471
|
+
private takeBatch;
|
|
2472
|
+
/** Puts what a failure `kept` of the batch `taken` back at the head of the
|
|
2473
|
+
* buffer, and keeps its report unless `taken` had no events; `true` when
|
|
2474
|
+
* nothing was kept. */
|
|
2475
|
+
private putBack;
|
|
2476
|
+
/** After a delivery, sets up a report of this process's loss totals (SPEC
|
|
2477
|
+
* §11.4.7) to ride the next batch. It stays outside the buffer, so it never
|
|
2478
|
+
* pushes an event out and is never counted as one. */
|
|
2428
2479
|
private maybeReport;
|
|
2429
2480
|
private stopReports;
|
|
2430
|
-
private
|
|
2431
|
-
|
|
2481
|
+
private buildReport;
|
|
2482
|
+
/** Sends one batch, splitting it on 413, until every event in it is
|
|
2483
|
+
* delivered or refused. Returns what a failure kept, to go back in the
|
|
2484
|
+
* buffer. */
|
|
2485
|
+
private sendBatch;
|
|
2486
|
+
private sendEachAlone;
|
|
2487
|
+
/** `alone` is one event per request (SPEC §2.5), so a whole refusal there is that event's own. */
|
|
2488
|
+
private settle;
|
|
2432
2489
|
/** `null`, with a warning, for an event `JSON.stringify` rejects. */
|
|
2433
2490
|
private encode;
|
|
2434
2491
|
private sleepUnlessClosed;
|
|
2435
2492
|
/** Aborted by the timeout or by `aclose()`. Built by hand: `AbortSignal.any`
|
|
2436
2493
|
* is missing before Node 20.3, and on some later versions it keeps every
|
|
2437
|
-
* combined signal alive as long as the long-lived `closing` signal.
|
|
2438
|
-
|
|
2494
|
+
* combined signal alive as long as the long-lived `closing` signal. Any body
|
|
2495
|
+
* read is under the same signal, so a stalled body cannot hold the drain. */
|
|
2496
|
+
private post;
|
|
2497
|
+
/** Every answer but a 2xx and a refusal of the whole batch. */
|
|
2498
|
+
private static otherAnswer;
|
|
2499
|
+
/** The refused results by `event_id` (SPEC §2.5). An event with no readable
|
|
2500
|
+
* result was delivered. */
|
|
2501
|
+
private static refusedIn;
|
|
2439
2502
|
}
|
|
2440
2503
|
|
|
2441
2504
|
/** Principal identity — what a vendor's resolver hands back, and how it goes
|
|
@@ -2596,7 +2659,8 @@ interface BatonConfig {
|
|
|
2596
2659
|
* (`{vendorId}_annotate`). This is not the account — see `tenantId`.
|
|
2597
2660
|
*
|
|
2598
2661
|
* Required unless a `dsn` supplies it — the DSN's last path segment IS this
|
|
2599
|
-
* value, and it is what the key is BOUND to.
|
|
2662
|
+
* value, and it is what the key is BOUND to. With no DSN, `tenantId` or sink
|
|
2663
|
+
* either, the install adds nothing instead (SPEC §11.2 rule 10). */
|
|
2600
2664
|
vendorId?: string;
|
|
2601
2665
|
/** Account identifier for the envelope's `tenant_id` (SPEC §11.4).
|
|
2602
2666
|
*
|
|
@@ -2643,7 +2707,7 @@ interface BatonConfig {
|
|
|
2643
2707
|
* one. Adding the read here would make this arm honour a variable the
|
|
2644
2708
|
* equivalent Python door ignores. */
|
|
2645
2709
|
consentToken?: string;
|
|
2646
|
-
/** Where events go.
|
|
2710
|
+
/** Where events go. With a `vendorId` and no DSN, defaults to `new StdoutSink()`. */
|
|
2647
2711
|
sink?: Sink;
|
|
2648
2712
|
/** PII scrubber per SPEC §7, applied to tool params/results, `_meta`,
|
|
2649
2713
|
* intent strings and error bodies before they reach the sink. Defaults to
|