import { Writable } from 'stream'; type JsonValue = string | number | boolean | bigint | object | null | undefined; /** * A bunyan record as it reaches a `type: 'raw'` stream: the standard fields (v, level, name, time, * msg, err, ...) plus whatever context tags the logger injected. Values are whatever JSON holds. */ type BunyanRecord = Record; /** * ChunkingRawStream - sits between bunyan and the Cloud Logging stream, SPLITTING an oversized * record into several complete records instead of letting it be rejected. * * WHY: Cloud Logging caps a LogEntry at 256 KiB, and on the API path an oversized entry fails the * whole `entries.write` call — `INVALID_ARGUMENT: Log entry with size X exceeds maximum size of * 256.0K` — which can take good entries batched alongside it down too. A 300KB stack trace or * response body is not exotic; it is exactly what you most want to read. * * WHY NOT TRUNCATE (what this replaces): the previous guard cut a big error down to 5 stack frames. * That kept the line under the limit by destroying its only useful content. Splitting keeps all of * it, addressable by `jsonPayload.logChunk.uid`. * * WHY A STREAM WRAPPER, not the BunyanLogger: bunyan's own machinery (and anything else writing to * the logger) reaches the stream directly, and the stream is where the size limit actually lives. * `loggingBunyan.stream()` is `type: 'raw'`, so we receive the record OBJECT — no parsing needed, * and rebuilding a piece is just a field swap. * * GCP-ONLY: wired in by {@link createGoogleCloudStream}. The local console stream is untouched — a * dev terminal has no size limit, and splitting there would only hurt readability. */ export declare class ChunkingRawStream extends Writable { private readonly target; private readonly budgetBytes; constructor(target: Writable, budgetBytes?: number); _write(record: BunyanRecord, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void; /** The record as-is when it fits; otherwise one complete record per chunk. */ private split; /** One piece: every original field, with `msg`/`err.stack` replaced and a `logChunk` tag added. */ private buildRecord; /** * Serialized size of the record. * * Measured as JSON even though this path ships over gRPC/protobuf, where the true size differs. * JSON over-counts (every key is spelled out, every string escaped), and over-counting is the * safe direction: we chunk slightly sooner than strictly needed rather than one byte too late. * * The replacer is what makes this TOTAL, with no try/catch: a plain JSON.stringify throws on a * circular value — real here, since request/response object cycles are exactly why the winston * backend runs safe-stable-stringify — and on a bigint. A measurement that throws would take * down the very log line this class exists to save. */ private serializedBytes; } export {};