logquill 0.3.0 → 1.0.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/README.md +392 -6
- package/dist/browser.d.ts +468 -0
- package/dist/browser.mjs +783 -0
- package/dist/browser.mjs.map +1 -0
- package/dist/index.cjs +756 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +561 -126
- package/dist/index.d.ts +561 -126
- package/dist/index.mjs +736 -9
- package/dist/index.mjs.map +1 -1
- package/dist/langchain.cjs +120 -0
- package/dist/langchain.cjs.map +1 -0
- package/dist/langchain.d.cts +128 -0
- package/dist/langchain.d.ts +128 -0
- package/dist/langchain.mjs +116 -0
- package/dist/langchain.mjs.map +1 -0
- package/dist/logger-CRdmCDfC.d.cts +299 -0
- package/dist/logger-CRdmCDfC.d.ts +299 -0
- package/dist/winston.cjs +108 -0
- package/dist/winston.cjs.map +1 -0
- package/dist/winston.d.cts +55 -0
- package/dist/winston.d.ts +55 -0
- package/dist/winston.mjs +101 -0
- package/dist/winston.mjs.map +1 -0
- package/package.json +57 -12
package/dist/index.d.ts
CHANGED
|
@@ -1,93 +1,350 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
TRACE = 5,
|
|
4
|
-
DEBUG = 10,
|
|
5
|
-
INFO = 20,
|
|
6
|
-
WARN = 30,
|
|
7
|
-
ERROR = 40,
|
|
8
|
-
FATAL = 50
|
|
9
|
-
}
|
|
10
|
-
/** A level given as a `Level`, a level name (any case), or its numeric weight. */
|
|
11
|
-
type LevelInput = Level | number | string;
|
|
12
|
-
/** The level's name, e.g. `levelName(Level.INFO) === "INFO"`. */
|
|
13
|
-
declare function levelName(level: Level): string;
|
|
14
|
-
/** Normalize a level given as a `Level`, level name, or numeric weight. Throws if unknown. */
|
|
15
|
-
declare function parseLevel(level: LevelInput): Level;
|
|
1
|
+
import { P as Plugin, L as LogRecord, a as Level, b as Logger, T as Transport, c as LevelInput, F as Formatter } from './logger-CRdmCDfC.js';
|
|
2
|
+
export { B as BackpressurePolicy, C as CollectingTransport, D as DispatchQueue, d as DispatchQueueOptions, e as FlushableTransport, f as FunctionPlugin, J as JSONFormatter, g as LoggerOptions, M as MiddlewareFunc, S as SpanOptions, h as Task, i as createRecord, j as hasFlush, l as levelName, p as parseLevel, u as utcTimestamp } from './logger-CRdmCDfC.js';
|
|
16
3
|
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Injects fixed key/value pairs into every record's `meta`.
|
|
6
|
+
* A value already present in a record's own `meta` wins over the fixed context.
|
|
7
|
+
*/
|
|
8
|
+
declare class ContextPlugin implements Plugin {
|
|
9
|
+
/** Fixed key/value pairs merged into every record's `meta`. */
|
|
10
|
+
readonly context: Record<string, unknown>;
|
|
11
|
+
constructor(context: Record<string, unknown>);
|
|
12
|
+
beforeLog(record: LogRecord): LogRecord;
|
|
24
13
|
}
|
|
25
|
-
/** ISO8601 UTC timestamp with millisecond precision, matching Python's `utc_timestamp()`. */
|
|
26
|
-
declare function utcTimestamp(): string;
|
|
27
|
-
declare function createRecord(params: {
|
|
28
|
-
level: Level;
|
|
29
|
-
logger: string;
|
|
30
|
-
message: string;
|
|
31
|
-
meta: Record<string, unknown>;
|
|
32
|
-
}): LogRecord;
|
|
33
14
|
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
|
|
15
|
+
/**
|
|
16
|
+
* The merged key/value pairs bound by every `bindContext()` block currently
|
|
17
|
+
* active in this execution context, or `{}` outside any block. Backed by
|
|
18
|
+
* `AsyncLocalStorage` (not a plain module variable) so concurrent async
|
|
19
|
+
* operations sharing one `Logger` don't see each other's bound context —
|
|
20
|
+
* the Node equivalent of Python's `contextvars`-based `current_context()`.
|
|
21
|
+
*/
|
|
22
|
+
declare function currentContext(): Record<string, unknown>;
|
|
23
|
+
/**
|
|
24
|
+
* Runs `fn` with `values` merged into the request-scoped context for the
|
|
25
|
+
* rest of its execution — every `Logger` call underneath it, through any
|
|
26
|
+
* number of function calls and `await`s deep, picks them up in `meta`
|
|
27
|
+
* automatically, without threading them through every signature by hand:
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* await bindContext({ requestId: "abc123" }, async () => {
|
|
31
|
+
* await handleRequest(); // any logging in here, or in what it calls,
|
|
32
|
+
* // gets meta.requestId = "abc123" for free
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* Calls nest by merging: an inner `bindContext`'s value wins over an outer
|
|
37
|
+
* one on key collision, the same way an explicit call-site `meta` value
|
|
38
|
+
* always wins over anything bound here. `fn`'s return value (including a
|
|
39
|
+
* `Promise`, whose continuations stay inside the bound context across any
|
|
40
|
+
* `await`) is returned unchanged.
|
|
41
|
+
*/
|
|
42
|
+
declare function bindContext<T>(values: Record<string, unknown>, fn: () => T): T;
|
|
43
|
+
|
|
44
|
+
/** Derives the key a record is rate-limited under. Any hashable value works — it's used as a `Map` key. */
|
|
45
|
+
type RateLimitKeyFunc = (record: LogRecord) => unknown;
|
|
46
|
+
/** Options for {@link RateLimitPlugin}. */
|
|
47
|
+
interface RateLimitPluginOptions {
|
|
48
|
+
/** Groups records into independent windows. Default: `(logger, level)`. */
|
|
49
|
+
keyFunc?: RateLimitKeyFunc;
|
|
50
|
+
/** Distinct keys tracked at once before the least-recently-seen one is evicted. Default 1000. */
|
|
51
|
+
maxKeys?: number;
|
|
52
|
+
/** Injectable clock (seconds), for deterministic window-rollover tests. Defaults to `performance.now() / 1000` — monotonic, so a wall-clock adjustment can't shrink or extend a window. */
|
|
53
|
+
clock?: () => number;
|
|
37
54
|
}
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Drops records once a key — by default `(logger, level)` — exceeds
|
|
57
|
+
* `maxRecords` within a rolling `perSeconds` window, capping a noisy loop
|
|
58
|
+
* (a retry that logs the same error every iteration, a hot path that logs
|
|
59
|
+
* once per request) without silencing the logger's other messages.
|
|
60
|
+
*
|
|
61
|
+
* Each key gets its own fixed window: the count for a key resets
|
|
62
|
+
* `perSeconds` after that *key's own* first record in the current window,
|
|
63
|
+
* not a shared global clock, so unrelated keys never reset in lockstep.
|
|
64
|
+
*
|
|
65
|
+
* Pass `keyFunc` to rate-limit on something other than `(logger, level)` —
|
|
66
|
+
* e.g. per error message, or per a `meta` field identifying the caller.
|
|
67
|
+
*
|
|
68
|
+
* Bounded by `maxKeys` distinct keys tracked at once; past that, the
|
|
69
|
+
* least-recently-seen key's window is evicted to make room for a new one —
|
|
70
|
+
* the same bounded-memory trade-off `SamplingPlugin` makes for trace
|
|
71
|
+
* buffering, since an unbounded key space (e.g. rate-limiting per user id)
|
|
72
|
+
* would otherwise grow memory without limit.
|
|
73
|
+
*/
|
|
74
|
+
declare class RateLimitPlugin implements Plugin {
|
|
75
|
+
/** Records allowed per key within a `perSeconds` window before further records for that key are dropped. */
|
|
76
|
+
readonly maxRecords: number;
|
|
77
|
+
/** Length, in seconds, of each key's rolling window. */
|
|
78
|
+
readonly perSeconds: number;
|
|
79
|
+
/** Distinct keys tracked at once before the least-recently-seen one is evicted. */
|
|
80
|
+
readonly maxKeys: number;
|
|
81
|
+
private readonly keyFunc;
|
|
82
|
+
private readonly clock;
|
|
83
|
+
private readonly windows;
|
|
84
|
+
constructor(maxRecords: number, perSeconds: number, options?: RateLimitPluginOptions);
|
|
85
|
+
beforeLog(record: LogRecord): LogRecord | null;
|
|
86
|
+
private evictOldest;
|
|
41
87
|
}
|
|
42
88
|
|
|
89
|
+
/** Maps a pino numeric level to a LogQuill level. */
|
|
90
|
+
type PinoLevelMap = Readonly<Record<number, Level>>;
|
|
91
|
+
/** pino's default numeric levels (`trace`=10 … `fatal`=60), mapped onto the matching LogQuill level. */
|
|
92
|
+
declare const DEFAULT_PINO_LEVEL_MAP: PinoLevelMap;
|
|
93
|
+
/** Options for {@link LogQuillPinoDestination}. */
|
|
94
|
+
interface LogQuillPinoDestinationOptions {
|
|
95
|
+
/** Overrides `DEFAULT_PINO_LEVEL_MAP` — useful for a pino instance configured with custom levels. An unmapped level falls back to `INFO`. */
|
|
96
|
+
levelMap?: PinoLevelMap;
|
|
97
|
+
}
|
|
43
98
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
99
|
+
* A pino `destination` — pass an instance directly as `pino(destination)`
|
|
100
|
+
* to have pino's own NDJSON output parsed back into LogQuill calls, so an
|
|
101
|
+
* existing `pino()` call site keeps working exactly as it does today while
|
|
102
|
+
* its records also flow through every LogQuill `Transport`/`Plugin`
|
|
103
|
+
* attached to the given `Logger` — handy for migrating incrementally
|
|
104
|
+
* rather than in one PR.
|
|
105
|
+
*
|
|
106
|
+
* ```ts
|
|
107
|
+
* import pino from "pino";
|
|
108
|
+
* import { Logger, LogQuillPinoDestination } from "logquill";
|
|
109
|
+
*
|
|
110
|
+
* const logquill = new Logger("app");
|
|
111
|
+
* const log = pino(new LogQuillPinoDestination(logquill));
|
|
112
|
+
*
|
|
113
|
+
* log.info({ userId: 42 }, "still works exactly as before");
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* No `pino` import needed here — a destination only has to be duck-type
|
|
117
|
+
* compatible with a Node `Writable`'s `.write(chunk)`, so unlike the
|
|
118
|
+
* `winston-transport`-based bridge, this needs no dependency on `pino`
|
|
119
|
+
* itself and ships from the main entry point.
|
|
120
|
+
*
|
|
121
|
+
* pino batches writes over a fast, buffered stream, so a single `write()`
|
|
122
|
+
* call can carry more than one NDJSON line; each complete line is parsed
|
|
123
|
+
* and dispatched independently, and a line that fails to parse as JSON is
|
|
124
|
+
* skipped rather than crashing the destination.
|
|
48
125
|
*/
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
126
|
+
declare class LogQuillPinoDestination {
|
|
127
|
+
/**
|
|
128
|
+
* Pino only recognizes a bare object passed as its sole argument
|
|
129
|
+
* (`pino(destination)`, without a separate options argument) as a
|
|
130
|
+
* destination stream, rather than an options object, if it looks
|
|
131
|
+
* stream-like — checking for `.writable`/`._writableState`, the same
|
|
132
|
+
* duck-typing `stream.Writable` itself satisfies. Without this, `pino()`
|
|
133
|
+
* would silently fall back to writing to `process.stdout` instead.
|
|
134
|
+
*/
|
|
135
|
+
readonly writable = true;
|
|
136
|
+
private readonly target;
|
|
137
|
+
private readonly levelMap;
|
|
138
|
+
constructor(logquillLogger: Logger, options?: LogQuillPinoDestinationOptions);
|
|
139
|
+
/** Node `Writable`-compatible write hook — splits `chunk` into NDJSON lines and dispatches each as a `Logger` call. */
|
|
140
|
+
write(chunk: string): boolean;
|
|
141
|
+
private writeLine;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Options for {@link RunPlugin}. */
|
|
145
|
+
interface RunPluginOptions {
|
|
146
|
+
/** Adopt an id handed in from elsewhere (e.g. an upstream call) instead of generating a fresh `randomUUID()`. */
|
|
147
|
+
runId?: string;
|
|
56
148
|
}
|
|
57
|
-
/** A plain `beforeLog`-style function, as accepted by `Logger.use()` in place of a `Plugin`. */
|
|
58
|
-
type MiddlewareFunc = (record: LogRecord) => LogRecord | null;
|
|
59
149
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
150
|
+
* Stamps `meta.runId` — a stable id grouping every record from one agent
|
|
151
|
+
* run — plus an incrementing `meta.step` counter, one per record processed
|
|
152
|
+
* through this plugin instance.
|
|
153
|
+
*
|
|
154
|
+
* Distinct from `TraceContextPlugin`'s `traceId`: `runId` scopes one agent
|
|
155
|
+
* run, `traceId` follows one request across services. A run can span
|
|
156
|
+
* multiple traces (e.g. an agent that calls several downstream services);
|
|
157
|
+
* the two ids are independent.
|
|
158
|
+
*
|
|
159
|
+
* One instance is one run: attach a fresh `RunPlugin()` per run (typically
|
|
160
|
+
* via `logger.child("agent").use(new RunPlugin())`), never a process-wide
|
|
161
|
+
* singleton shared across runs — otherwise concurrent runs would share both
|
|
162
|
+
* the run id and the step counter.
|
|
163
|
+
*
|
|
164
|
+
* A record that already carries `meta.runId` (e.g. propagated from an
|
|
165
|
+
* upstream call) keeps its existing value; `meta.step` is always set from
|
|
166
|
+
* this instance's own counter.
|
|
66
167
|
*/
|
|
67
|
-
declare class
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
168
|
+
declare class RunPlugin implements Plugin {
|
|
169
|
+
/** Id stamped onto `meta.runId` for every record this instance processes. */
|
|
170
|
+
readonly runId: string;
|
|
171
|
+
private step;
|
|
172
|
+
constructor(options?: RunPluginOptions);
|
|
173
|
+
beforeLog(record: LogRecord): LogRecord;
|
|
71
174
|
}
|
|
72
175
|
|
|
73
176
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
177
|
+
* Sets the inbound trace header for the current execution context (e.g.
|
|
178
|
+
* request-scoped HTTP middleware, before the handler runs) — the
|
|
179
|
+
* propagation mechanism framework middleware uses to hand `TraceContextPlugin`
|
|
180
|
+
* an inbound header without threading it through every log call. Backed by
|
|
181
|
+
* `AsyncLocalStorage`, so it's isolated per concurrent request. Returns a
|
|
182
|
+
* function that restores the previous value; call it (typically in a
|
|
183
|
+
* `finally` block) once the request is done.
|
|
76
184
|
*/
|
|
77
|
-
declare
|
|
78
|
-
|
|
79
|
-
|
|
185
|
+
declare function setTraceparent(value: string | undefined): () => void;
|
|
186
|
+
/** The header most recently set via `setTraceparent()` for this execution context. */
|
|
187
|
+
declare function getTraceparent(): string | undefined;
|
|
188
|
+
/** A fresh 32-hex-char id, matching the shape of an OTel/W3C trace id. */
|
|
189
|
+
declare function generateTraceId(): string;
|
|
190
|
+
/**
|
|
191
|
+
* Extracts a 32-hex-char trace id from a W3C `traceparent`, AWS X-Ray
|
|
192
|
+
* `X-Amzn-Trace-Id`, or GCP `X-Cloud-Trace-Context` header value. Returns
|
|
193
|
+
* `undefined` if `header` doesn't match any of the three shapes.
|
|
194
|
+
*/
|
|
195
|
+
declare function parseTraceHeader(header: string): string | undefined;
|
|
196
|
+
/**
|
|
197
|
+
* Best-effort, synchronous lookup of the active OpenTelemetry span's trace
|
|
198
|
+
* id via a plain `require("@opentelemetry/api")` — `@opentelemetry/api` is
|
|
199
|
+
* never a declared dependency of this package (matching `logquill-python`'s
|
|
200
|
+
* lazy `import opentelemetry`); this returns `undefined` whenever it isn't
|
|
201
|
+
* installed, or no span is currently active, rather than throwing.
|
|
202
|
+
*
|
|
203
|
+
* A `require()` (via `createRequire`) rather than a dynamic `import()` is
|
|
204
|
+
* deliberate: `Plugin.beforeLog` is synchronous, so this has to be too.
|
|
205
|
+
*/
|
|
206
|
+
declare function defaultResolveActiveOtelTraceId(): string | undefined;
|
|
207
|
+
/** Options for {@link TraceContextPlugin}. */
|
|
208
|
+
interface TraceContextPluginOptions {
|
|
209
|
+
/** `meta` key the trace id is written to. Default `"traceId"`. */
|
|
210
|
+
traceKey?: string;
|
|
211
|
+
/** An inbound trace header to resolve on every record, bypassing `setTraceparent()`. */
|
|
212
|
+
traceparent?: string;
|
|
213
|
+
/** Override for testing, or to plug in a non-Node OTel API surface. Defaults to `defaultResolveActiveOtelTraceId`. */
|
|
214
|
+
resolveActiveOtelTraceId?: () => string | undefined;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Stamps `meta.traceId` for cross-service correlation — distinct from
|
|
218
|
+
* `RunPlugin`'s `runId`: `traceId` follows one request across services,
|
|
219
|
+
* `runId` scopes one agent run.
|
|
220
|
+
*
|
|
221
|
+
* A record that already carries `meta[traceKey]` (e.g. because
|
|
222
|
+
* `SamplingPlugin`'s tail-based elevation, or an upstream plugin, already
|
|
223
|
+
* set one) is left alone. Otherwise resolves a trace id in priority order:
|
|
224
|
+
*
|
|
225
|
+
* 1. An active OpenTelemetry span's trace id, if `@opentelemetry/api` is
|
|
226
|
+
* installed and a span is current — read directly, not just inbound
|
|
227
|
+
* headers.
|
|
228
|
+
* 2. The `traceparent` constructor option, if given.
|
|
229
|
+
* 3. Whatever `setTraceparent()` most recently set for the current
|
|
230
|
+
* execution context.
|
|
231
|
+
* 4. A freshly generated trace id, if none of the above produced one.
|
|
232
|
+
*
|
|
233
|
+
* Header parsing understands W3C `traceparent`, AWS X-Ray
|
|
234
|
+
* `X-Amzn-Trace-Id`, and GCP `X-Cloud-Trace-Context` — see
|
|
235
|
+
* `parseTraceHeader`. A header that doesn't parse is treated the same as no
|
|
236
|
+
* header: falls through to generating a new trace id.
|
|
237
|
+
*/
|
|
238
|
+
declare class TraceContextPlugin implements Plugin {
|
|
239
|
+
/** `meta` key the trace id is written to. */
|
|
240
|
+
readonly traceKey: string;
|
|
241
|
+
private readonly explicitTraceparent;
|
|
242
|
+
private readonly resolveActiveOtelTraceId;
|
|
243
|
+
constructor(options?: TraceContextPluginOptions);
|
|
80
244
|
beforeLog(record: LogRecord): LogRecord;
|
|
245
|
+
private resolveTraceId;
|
|
81
246
|
}
|
|
82
247
|
|
|
248
|
+
/** The subset of an OTel `SpanContext` this processor reads. */
|
|
249
|
+
interface OtelSpanContextLike {
|
|
250
|
+
/** 16-hex-char span id. */
|
|
251
|
+
spanId: string;
|
|
252
|
+
}
|
|
253
|
+
/** The subset of an OTel `SpanStatus` this processor reads. */
|
|
254
|
+
interface OtelStatusLike {
|
|
255
|
+
/** Numeric status code — compared against OTel's `SpanStatusCode.ERROR` (`2`). */
|
|
256
|
+
code: number;
|
|
257
|
+
/** Present when the span ended with an error status; used as the `.error()` message. */
|
|
258
|
+
message?: string;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* The subset of an OTel `Span`/`ReadableSpan`'s shape this processor reads,
|
|
262
|
+
* duck-typed so this package never declares a real dependency on
|
|
263
|
+
* `@opentelemetry/api`/`@opentelemetry/sdk-trace-base` — the same approach
|
|
264
|
+
* `TraceContextPlugin` uses for its own OTel lookup. Matches what any
|
|
265
|
+
* standard `@opentelemetry/sdk-trace-base`-backed tracer provider actually
|
|
266
|
+
* passes to a registered `SpanProcessor`.
|
|
267
|
+
*/
|
|
268
|
+
interface OtelSpanLike {
|
|
269
|
+
/** Span name — becomes the `.action()`/`.observation()`/`.error()` message. */
|
|
270
|
+
name: string;
|
|
271
|
+
/** Returns this span's own id (and trace id), matching an OTel `Span`'s `spanContext()`. */
|
|
272
|
+
spanContext(): OtelSpanContextLike;
|
|
273
|
+
/** Present on `@opentelemetry/sdk-trace-base` >=1.9's `Span`. */
|
|
274
|
+
parentSpanContext?: OtelSpanContextLike;
|
|
275
|
+
/** Pre-1.9 `@opentelemetry/sdk-trace-base` shape (superseded by `parentSpanContext`) — read as a fallback when that isn't present. */
|
|
276
|
+
parentSpanId?: string;
|
|
277
|
+
/** Span attributes, copied verbatim onto `meta[attributesKey]` when non-empty. */
|
|
278
|
+
attributes: Record<string, unknown>;
|
|
279
|
+
/** This span's OTel status — an error status routes the end record through `.error()` instead of `.observation()`. */
|
|
280
|
+
status: OtelStatusLike;
|
|
281
|
+
/** Wall-clock duration as an OTel `HrTime` tuple, only meaningful once the span has ended. */
|
|
282
|
+
duration: readonly [seconds: number, nanoseconds: number];
|
|
283
|
+
}
|
|
284
|
+
/** Options for {@link OtelSpanProcessor}. */
|
|
285
|
+
interface OtelSpanProcessorOptions {
|
|
286
|
+
/** `meta` key non-empty span attributes are copied onto. Default `"attributes"`. */
|
|
287
|
+
attributesKey?: string;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Bridges an OpenTelemetry-native integration — the Vercel AI SDK's
|
|
291
|
+
* `experimental_telemetry` is the main JS example — into LogQuill without
|
|
292
|
+
* forcing it through the callback-handler-object model `LangChainAdapter`
|
|
293
|
+
* uses. Register an instance the same way any other span processor is
|
|
294
|
+
* registered:
|
|
295
|
+
*
|
|
296
|
+
* ```ts
|
|
297
|
+
* import { BasicTracerProvider } from "@opentelemetry/sdk-trace-base";
|
|
298
|
+
* import { OtelSpanProcessor } from "logquill";
|
|
299
|
+
*
|
|
300
|
+
* const provider = new BasicTracerProvider();
|
|
301
|
+
* provider.addSpanProcessor(new OtelSpanProcessor(log.child("agent")));
|
|
302
|
+
* ```
|
|
303
|
+
*
|
|
304
|
+
* Every span the SDK creates becomes one `.action()` call on start and one
|
|
305
|
+
* `.observation()` (or `.error()`, if the span ended with an error status)
|
|
306
|
+
* call on end — the same two-call shape `LangChainAdapter` uses for
|
|
307
|
+
* `handleToolStart`/`handleToolEnd`. Both carry the span's own `spanId`/
|
|
308
|
+
* `parentSpanId` — OTel span ids are already the same 16-hex-char shape
|
|
309
|
+
* LogQuill's own `spanId` uses, so no translation is needed — and the end
|
|
310
|
+
* call additionally carries `meta.durationMs`. Non-empty span attributes are
|
|
311
|
+
* copied onto `meta[attributesKey]` verbatim, unrenamed — mapping onto the
|
|
312
|
+
* OTel `gen_ai.*` semantic conventions is deliberately out of scope here
|
|
313
|
+
* (see the v2.0 `OTLPTransport`/`gen_ai.*` plan).
|
|
314
|
+
*
|
|
315
|
+
* Never imports `@opentelemetry/api` or `@opentelemetry/sdk-trace-base` —
|
|
316
|
+
* duck-typed against the shape a `Span`/`ReadableSpan` actually has, so
|
|
317
|
+
* `import { Logger } from "logquill"` still never requires either package
|
|
318
|
+
* to be installed.
|
|
319
|
+
*/
|
|
320
|
+
declare class OtelSpanProcessor {
|
|
321
|
+
private readonly log;
|
|
322
|
+
private readonly attributesKey;
|
|
323
|
+
constructor(log: Logger, options?: OtelSpanProcessorOptions);
|
|
324
|
+
/** Called by the tracer provider when a span starts — emits `.action()`. */
|
|
325
|
+
onStart(span: OtelSpanLike): void;
|
|
326
|
+
/** Called by the tracer provider when a span ends — emits `.observation()`, or `.error()` if the span's status is an error. */
|
|
327
|
+
onEnd(span: OtelSpanLike): void;
|
|
328
|
+
/** No internal buffering to flush — every span is forwarded to the `Logger` immediately. */
|
|
329
|
+
forceFlush(): Promise<void>;
|
|
330
|
+
/** No resources of its own to release; flush/close the wrapped `Logger` separately. */
|
|
331
|
+
shutdown(): Promise<void>;
|
|
332
|
+
private baseMeta;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/** `meta` keys (case-insensitive) `RedactPlugin` replaces by default. */
|
|
83
336
|
declare const DEFAULT_REDACTED_KEYS: readonly string[];
|
|
337
|
+
/** Options for {@link RedactPlugin}. */
|
|
84
338
|
interface RedactPluginOptions {
|
|
339
|
+
/** Keys (case-insensitive) to redact. Default `DEFAULT_REDACTED_KEYS`. */
|
|
85
340
|
keys?: readonly string[];
|
|
341
|
+
/** Placeholder a matched value is replaced with. Default `"***"`. */
|
|
86
342
|
replacement?: string;
|
|
87
343
|
}
|
|
88
344
|
/** Replaces sensitive `meta` values, matched by key (case-insensitive), with a placeholder. */
|
|
89
345
|
declare class RedactPlugin implements Plugin {
|
|
90
346
|
private readonly keys;
|
|
347
|
+
/** Placeholder a matched value is replaced with. */
|
|
91
348
|
readonly replacement: string;
|
|
92
349
|
constructor(options?: RedactPluginOptions);
|
|
93
350
|
beforeLog(record: LogRecord): LogRecord;
|
|
@@ -100,8 +357,11 @@ declare class RedactPlugin implements Plugin {
|
|
|
100
357
|
* for anything stricter.
|
|
101
358
|
*/
|
|
102
359
|
declare const DEFAULT_PII_PATTERNS: Readonly<Record<string, RegExp>>;
|
|
360
|
+
/** Options for {@link PIIRedactPlugin}. */
|
|
103
361
|
interface PIIRedactPluginOptions {
|
|
362
|
+
/** Named patterns to scan for. Default `DEFAULT_PII_PATTERNS`. */
|
|
104
363
|
patterns?: Readonly<Record<string, RegExp>>;
|
|
364
|
+
/** Placeholder a matched substring is replaced with. Default `"***"`. */
|
|
105
365
|
replacement?: string;
|
|
106
366
|
}
|
|
107
367
|
/**
|
|
@@ -125,7 +385,9 @@ interface PIIRedactPluginOptions {
|
|
|
125
385
|
* throwing.
|
|
126
386
|
*/
|
|
127
387
|
declare class PIIRedactPlugin implements Plugin {
|
|
388
|
+
/** Named patterns scanned for in every string `meta` value. */
|
|
128
389
|
readonly patterns: Readonly<Record<string, RegExp>>;
|
|
390
|
+
/** Placeholder a matched substring is replaced with. */
|
|
129
391
|
readonly replacement: string;
|
|
130
392
|
constructor(options?: PIIRedactPluginOptions);
|
|
131
393
|
beforeLog(record: LogRecord): LogRecord;
|
|
@@ -133,28 +395,9 @@ declare class PIIRedactPlugin implements Plugin {
|
|
|
133
395
|
private redactText;
|
|
134
396
|
}
|
|
135
397
|
|
|
136
|
-
/**
|
|
137
|
-
* Sink for log records, per the cross-language transport contract:
|
|
138
|
-
* `format(record) -> string`, `write(formatted, record)`, `close()` on shutdown.
|
|
139
|
-
*/
|
|
140
|
-
declare abstract class Transport {
|
|
141
|
-
formatter: Formatter;
|
|
142
|
-
constructor(formatter?: Formatter);
|
|
143
|
-
format(record: LogRecord): string;
|
|
144
|
-
abstract write(formatted: string, record: LogRecord): void;
|
|
145
|
-
/** Flush/release resources on shutdown. No-op unless a transport overrides it. */
|
|
146
|
-
close(): void;
|
|
147
|
-
}
|
|
148
|
-
/** In-memory transport for tests: collects every (formatted, record) pair written to it. */
|
|
149
|
-
declare class CollectingTransport extends Transport {
|
|
150
|
-
readonly formatted: string[];
|
|
151
|
-
readonly records: LogRecord[];
|
|
152
|
-
closed: boolean;
|
|
153
|
-
write(formatted: string, record: LogRecord): void;
|
|
154
|
-
close(): void;
|
|
155
|
-
}
|
|
156
|
-
|
|
398
|
+
/** Options for {@link SamplingPlugin}. */
|
|
157
399
|
interface SamplingPluginOptions {
|
|
400
|
+
/** Source of randomness for the rate check. Defaults to `Math.random`; override with a seeded/fake generator for deterministic tests. */
|
|
158
401
|
rng?: () => number;
|
|
159
402
|
/** `meta` key holding the trace/run id used to group buffered records. Default `"traceId"`. */
|
|
160
403
|
traceKey?: string;
|
|
@@ -198,11 +441,17 @@ interface SamplingPluginOptions {
|
|
|
198
441
|
* or high-cardinality trace grow memory without limit.
|
|
199
442
|
*/
|
|
200
443
|
declare class SamplingPlugin implements Plugin {
|
|
444
|
+
/** Fraction of non-elevated records kept, in `[0, 1]`. */
|
|
201
445
|
readonly rate: number;
|
|
446
|
+
/** `meta` key holding the trace/run id used to group buffered records. */
|
|
202
447
|
readonly traceKey: string;
|
|
448
|
+
/** A record at or above this level elevates its whole trace. */
|
|
203
449
|
readonly elevateAt: Level;
|
|
450
|
+
/** Transports buffered records are flushed straight to on elevation; `undefined` disables tail-based elevation. */
|
|
204
451
|
readonly transports: Transport[] | undefined;
|
|
452
|
+
/** Total buffered records allowed across every trace before the oldest trace is evicted. */
|
|
205
453
|
readonly maxBufferedRecords: number;
|
|
454
|
+
/** Distinct trace ids held at once before the oldest is evicted. */
|
|
206
455
|
readonly maxTraces: number;
|
|
207
456
|
private readonly rng;
|
|
208
457
|
private readonly buffer;
|
|
@@ -215,8 +464,11 @@ declare class SamplingPlugin implements Plugin {
|
|
|
215
464
|
private evictOldestTrace;
|
|
216
465
|
}
|
|
217
466
|
|
|
467
|
+
/** The hash chain's starting value — a record's `prevHash` when it's the first record in the chain. */
|
|
218
468
|
declare const GENESIS_HASH: string;
|
|
469
|
+
/** Options for {@link TamperEvidentPlugin}. */
|
|
219
470
|
interface TamperEvidentPluginOptions {
|
|
471
|
+
/** Starting hash the chain builds from. Default `GENESIS_HASH`. Override to continue a chain started elsewhere (e.g. a previous process). */
|
|
220
472
|
genesisHash?: string;
|
|
221
473
|
}
|
|
222
474
|
/**
|
|
@@ -249,6 +501,7 @@ declare class TamperEvidentPlugin implements Plugin {
|
|
|
249
501
|
static verifyChain(records: Iterable<Pick<LogRecord, "timestamp" | "level" | "logger" | "message" | "meta">>, options?: TamperEvidentPluginOptions): boolean;
|
|
250
502
|
}
|
|
251
503
|
|
|
504
|
+
/** Options for {@link AlertingPlugin} and every concrete alert plugin that extends it. */
|
|
252
505
|
interface AlertingPluginOptions {
|
|
253
506
|
/** A record at or above this level fires an alert. Default `Level.ERROR`. */
|
|
254
507
|
threshold?: LevelInput;
|
|
@@ -271,9 +524,10 @@ interface AlertingPluginOptions {
|
|
|
271
524
|
* default: level + logger + message) fires `sendAlert` right away, without
|
|
272
525
|
* awaiting it — so the log call that triggered it is never blocked on a
|
|
273
526
|
* webhook, SMTP handshake, or any other I/O, even if the destination is
|
|
274
|
-
* slow or unreachable. This stands in for
|
|
275
|
-
*
|
|
276
|
-
*
|
|
527
|
+
* slow or unreachable. This stands in for `Logger`'s own async dispatch
|
|
528
|
+
* queue, which doesn't yet handle alert delivery; `AlertingPlugin` could
|
|
529
|
+
* route through it instead of firing its own unawaited call per alert
|
|
530
|
+
* once it does.
|
|
277
531
|
*
|
|
278
532
|
* Any further record matching the same dedupe key within
|
|
279
533
|
* `dedupeWindowMs` of the first is *not* sent again — it just increments a
|
|
@@ -289,8 +543,11 @@ interface AlertingPluginOptions {
|
|
|
289
543
|
* that throws.
|
|
290
544
|
*/
|
|
291
545
|
declare abstract class AlertingPlugin implements Plugin {
|
|
546
|
+
/** A record at or above this level fires an alert. */
|
|
292
547
|
readonly threshold: Level;
|
|
548
|
+
/** How long a dedupe window stays open before a collapsed follow-up alert (if any) fires. */
|
|
293
549
|
readonly dedupeWindowMs: number;
|
|
550
|
+
/** Distinct concurrent dedupe keys tracked at once; beyond this, new keys are dropped rather than tracked. */
|
|
294
551
|
readonly maxTrackedKeys: number;
|
|
295
552
|
private readonly dedupeKeyFn;
|
|
296
553
|
private readonly windows;
|
|
@@ -312,7 +569,9 @@ declare abstract class AlertingPlugin implements Plugin {
|
|
|
312
569
|
|
|
313
570
|
/** Posts one alert body to a Slack incoming webhook URL. Swap in a fake for tests. */
|
|
314
571
|
type SlackSender = (webhookUrl: string, body: string) => Promise<void> | void;
|
|
572
|
+
/** Options for {@link SlackAlertPlugin}. */
|
|
315
573
|
interface SlackAlertPluginOptions extends AlertingPluginOptions {
|
|
574
|
+
/** Posts one alert. Defaults to a `fetch` POST; override for a fake or an alternate backend. */
|
|
316
575
|
sender?: SlackSender;
|
|
317
576
|
}
|
|
318
577
|
/**
|
|
@@ -323,6 +582,7 @@ interface SlackAlertPluginOptions extends AlertingPluginOptions {
|
|
|
323
582
|
* fake for tests or an alternate backend.
|
|
324
583
|
*/
|
|
325
584
|
declare class SlackAlertPlugin extends AlertingPlugin {
|
|
585
|
+
/** Slack "Incoming Webhook" URL every alert is posted to. */
|
|
326
586
|
readonly webhookUrl: string;
|
|
327
587
|
private readonly sender;
|
|
328
588
|
constructor(webhookUrl: string, options?: SlackAlertPluginOptions);
|
|
@@ -331,7 +591,9 @@ declare class SlackAlertPlugin extends AlertingPlugin {
|
|
|
331
591
|
|
|
332
592
|
/** POSTs one PagerDuty Events API v2 payload. Swap in a fake for tests. */
|
|
333
593
|
type PagerDutySender = (body: string) => Promise<void> | void;
|
|
594
|
+
/** Options for {@link PagerDutyAlertPlugin}. */
|
|
334
595
|
interface PagerDutyAlertPluginOptions extends AlertingPluginOptions {
|
|
596
|
+
/** Posts one Events API v2 payload. Defaults to a `fetch` POST; override for a fake or an alternate backend. */
|
|
335
597
|
sender?: PagerDutySender;
|
|
336
598
|
}
|
|
337
599
|
/**
|
|
@@ -343,22 +605,29 @@ interface PagerDutyAlertPluginOptions extends AlertingPluginOptions {
|
|
|
343
605
|
* swap in a fake for tests or an alternate backend.
|
|
344
606
|
*/
|
|
345
607
|
declare class PagerDutyAlertPlugin extends AlertingPlugin {
|
|
608
|
+
/** PagerDuty Events API v2 integration key every alert is sent under. */
|
|
346
609
|
readonly routingKey: string;
|
|
347
610
|
private readonly sender;
|
|
348
611
|
constructor(routingKey: string, options?: PagerDutyAlertPluginOptions);
|
|
349
612
|
protected sendAlert(record: LogRecord, occurrences: number): Promise<void>;
|
|
350
613
|
}
|
|
351
614
|
|
|
615
|
+
/** One email alert, as built from a deduplicated record before being handed to `nodemailer` (or an injected `sender`). */
|
|
352
616
|
interface EmailMessage {
|
|
617
|
+
/** Envelope `From` address. */
|
|
353
618
|
from: string;
|
|
619
|
+
/** Envelope `To` addresses. */
|
|
354
620
|
to: string[];
|
|
621
|
+
/** Subject line — the record's level and logger, with an occurrence count appended on a deduped follow-up. */
|
|
355
622
|
subject: string;
|
|
623
|
+
/** Plain-text body: the message, occurrence count, timestamp, and JSON-serialized `meta`. */
|
|
356
624
|
text: string;
|
|
357
625
|
}
|
|
358
626
|
/** Sends one email message. Swap in a fake for tests. */
|
|
359
627
|
type EmailSender = (message: EmailMessage) => Promise<void> | void;
|
|
360
628
|
/** The subset of a `nodemailer` transporter that `EmailAlertPlugin` needs. */
|
|
361
629
|
interface NodemailerTransporterLike {
|
|
630
|
+
/** Sends one message; matches `nodemailer`'s own `Transporter.sendMail`. */
|
|
362
631
|
sendMail(message: {
|
|
363
632
|
from: string;
|
|
364
633
|
to: string;
|
|
@@ -366,12 +635,19 @@ interface NodemailerTransporterLike {
|
|
|
366
635
|
text: string;
|
|
367
636
|
}): Promise<unknown>;
|
|
368
637
|
}
|
|
638
|
+
/** Options for {@link EmailAlertPlugin}. */
|
|
369
639
|
interface EmailAlertPluginOptions extends AlertingPluginOptions {
|
|
640
|
+
/** SMTP server hostname. */
|
|
370
641
|
smtpHost: string;
|
|
642
|
+
/** SMTP server port. */
|
|
371
643
|
smtpPort: number;
|
|
644
|
+
/** Envelope `From` address for every alert. */
|
|
372
645
|
fromAddr: string;
|
|
646
|
+
/** Envelope `To` addresses for every alert. */
|
|
373
647
|
toAddrs: string[];
|
|
648
|
+
/** SMTP auth username. Only used if `password` is also set. */
|
|
374
649
|
username?: string;
|
|
650
|
+
/** SMTP auth password. Only used if `username` is also set. */
|
|
375
651
|
password?: string;
|
|
376
652
|
/** `false` for an SMTP server that doesn't support STARTTLS (e.g. a local relay). Default `true`. */
|
|
377
653
|
useTls?: boolean;
|
|
@@ -386,9 +662,13 @@ interface EmailAlertPluginOptions extends AlertingPluginOptions {
|
|
|
386
662
|
* `username`/`password` are only used if both are set.
|
|
387
663
|
*/
|
|
388
664
|
declare class EmailAlertPlugin extends AlertingPlugin {
|
|
665
|
+
/** SMTP server hostname. */
|
|
389
666
|
readonly smtpHost: string;
|
|
667
|
+
/** SMTP server port. */
|
|
390
668
|
readonly smtpPort: number;
|
|
669
|
+
/** Envelope `From` address for every alert. */
|
|
391
670
|
readonly fromAddr: string;
|
|
671
|
+
/** Envelope `To` addresses for every alert. */
|
|
392
672
|
readonly toAddrs: string[];
|
|
393
673
|
private readonly username;
|
|
394
674
|
private readonly password;
|
|
@@ -400,7 +680,9 @@ declare class EmailAlertPlugin extends AlertingPlugin {
|
|
|
400
680
|
private importTransporter;
|
|
401
681
|
}
|
|
402
682
|
|
|
683
|
+
/** Options for {@link BatchingTransport} and every concrete batching transport that extends it. */
|
|
403
684
|
interface BatchingTransportOptions {
|
|
685
|
+
/** Turns a `LogRecord` into the string this transport writes. Defaults to `JSONFormatter`. */
|
|
404
686
|
formatter?: Formatter;
|
|
405
687
|
/** Flush once the buffer holds this many items. Default 100. */
|
|
406
688
|
maxRecords?: number;
|
|
@@ -418,7 +700,9 @@ interface BatchingTransportOptions {
|
|
|
418
700
|
* matching `HTTPTransport`'s contract.
|
|
419
701
|
*/
|
|
420
702
|
declare abstract class BatchingTransport<T = LogRecord> extends Transport {
|
|
703
|
+
/** Buffer is flushed once it holds this many items. */
|
|
421
704
|
readonly maxRecords: number;
|
|
705
|
+
/** Buffer is flushed once its estimated byte size reaches this many bytes. */
|
|
422
706
|
readonly maxBytes: number;
|
|
423
707
|
private buffer;
|
|
424
708
|
private bufferBytes;
|
|
@@ -427,6 +711,7 @@ declare abstract class BatchingTransport<T = LogRecord> extends Transport {
|
|
|
427
711
|
protected toItem(formatted: string, record: LogRecord): T;
|
|
428
712
|
/** Estimated byte size of one buffered item, used for the `maxBytes` bound. */
|
|
429
713
|
protected sizeOf(item: T): number;
|
|
714
|
+
/** Buffers the record, flushing the batch once `maxRecords`/`maxBytes` is reached. */
|
|
430
715
|
write(formatted: string, record: LogRecord): void;
|
|
431
716
|
/** Send the current batch now, even if it hasn't reached a bound. */
|
|
432
717
|
flush(): void;
|
|
@@ -437,17 +722,26 @@ declare abstract class BatchingTransport<T = LogRecord> extends Transport {
|
|
|
437
722
|
|
|
438
723
|
/** One row of the fixed `logs` table schema shared across every SQL transport. */
|
|
439
724
|
interface SQLLogRow {
|
|
725
|
+
/** `record.timestamp`, as ISO8601. */
|
|
440
726
|
timestamp: string;
|
|
727
|
+
/** `record.level`. */
|
|
441
728
|
level: string;
|
|
729
|
+
/** `record.logger`. */
|
|
442
730
|
logger: string;
|
|
731
|
+
/** `record.message`. */
|
|
443
732
|
message: string;
|
|
444
733
|
/** `record.meta`, JSON-serialized — every SQL dialect can store this as TEXT/JSON/JSONB. */
|
|
445
734
|
meta: string;
|
|
735
|
+
/** `record.meta.runId`, if present. */
|
|
446
736
|
runId: string | null;
|
|
737
|
+
/** `record.meta.spanId`, if present. */
|
|
447
738
|
spanId: string | null;
|
|
739
|
+
/** `record.meta.parentSpanId`, if present. */
|
|
448
740
|
parentSpanId: string | null;
|
|
741
|
+
/** `record.meta.traceId`, if present. */
|
|
449
742
|
traceId: string | null;
|
|
450
743
|
}
|
|
744
|
+
/** Options for {@link BaseSQLTransport} and every concrete SQL transport that extends it. */
|
|
451
745
|
interface BaseSQLTransportOptions extends BatchingTransportOptions {
|
|
452
746
|
/** Table to write into. Default `"logs"`. */
|
|
453
747
|
tableName?: string;
|
|
@@ -465,7 +759,9 @@ interface BaseSQLTransportOptions extends BatchingTransportOptions {
|
|
|
465
759
|
* Inserts are always batched — never one query per log call.
|
|
466
760
|
*/
|
|
467
761
|
declare abstract class BaseSQLTransport extends BatchingTransport<SQLLogRow> {
|
|
762
|
+
/** Table records are inserted into. */
|
|
468
763
|
readonly tableName: string;
|
|
764
|
+
/** Whether `createTableSQL()` runs before the first insert. Dev/test convenience only. */
|
|
469
765
|
readonly ensureSchema: boolean;
|
|
470
766
|
private schemaEnsured;
|
|
471
767
|
constructor(options?: BaseSQLTransportOptions);
|
|
@@ -487,12 +783,16 @@ declare abstract class BaseSQLTransport extends BatchingTransport<SQLLogRow> {
|
|
|
487
783
|
|
|
488
784
|
/** The subset of a `better-sqlite3` prepared statement that `SQLiteTransport` needs. */
|
|
489
785
|
interface SQLiteStatementLike {
|
|
786
|
+
/** Executes the prepared statement with `params` bound positionally. */
|
|
490
787
|
run(...params: unknown[]): unknown;
|
|
491
788
|
}
|
|
492
789
|
/** The subset of a `better-sqlite3` `Database` that `SQLiteTransport` needs. Inject a fake in tests. */
|
|
493
790
|
interface SQLiteClientLike {
|
|
791
|
+
/** Runs one or more SQL statements with no return value, e.g. `createTableSQL()`. */
|
|
494
792
|
exec(sql: string): unknown;
|
|
793
|
+
/** Compiles `sql` into a reusable, repeatedly-`run`-able statement. */
|
|
495
794
|
prepare(sql: string): SQLiteStatementLike;
|
|
795
|
+
/** Wraps `fn` so every call runs inside a single SQLite transaction. */
|
|
496
796
|
transaction<Args extends unknown[]>(fn: (...args: Args) => void): (...args: Args) => void;
|
|
497
797
|
}
|
|
498
798
|
interface SQLiteTransportOptions extends BaseSQLTransportOptions {
|
|
@@ -523,6 +823,7 @@ declare class SQLiteTransport extends BaseSQLTransport {
|
|
|
523
823
|
|
|
524
824
|
/** The subset of a `pg` `Pool`/`Client` that `PostgresTransport` needs. Inject a fake in tests. */
|
|
525
825
|
interface PgClientLike {
|
|
826
|
+
/** Runs a parameterized query, matching `pg`'s own `Pool`/`Client.query(text, values)`. */
|
|
526
827
|
query(text: string, values: unknown[]): Promise<unknown>;
|
|
527
828
|
}
|
|
528
829
|
interface PostgresTransportOptions extends BaseSQLTransportOptions {
|
|
@@ -558,6 +859,7 @@ declare class PostgresTransport extends BaseSQLTransport {
|
|
|
558
859
|
|
|
559
860
|
/** The subset of a `mysql2/promise` connection/pool that `MySQLTransport` needs. Inject a fake in tests. */
|
|
560
861
|
interface MySQLClientLike {
|
|
862
|
+
/** Runs a parameterized query, matching `mysql2`'s own `Connection`/`Pool.execute(sql, values)`. */
|
|
561
863
|
execute(sql: string, values: unknown[]): Promise<unknown>;
|
|
562
864
|
}
|
|
563
865
|
interface MySQLTransportOptions extends BaseSQLTransportOptions {
|
|
@@ -594,15 +896,20 @@ declare class MySQLTransport extends BaseSQLTransport {
|
|
|
594
896
|
|
|
595
897
|
/** The subset of a `mongodb` `Collection` that `MongoDBTransport` needs. Inject a fake in tests. */
|
|
596
898
|
interface MongoCollectionLike {
|
|
899
|
+
/** Inserts every document in one call, matching `mongodb`'s own `Collection.insertMany()`. */
|
|
597
900
|
insertMany(docs: readonly unknown[]): Promise<unknown>;
|
|
598
901
|
}
|
|
599
902
|
/** The subset of a `mongodb` `MongoClient` that `MongoDBTransport` needs to lazily connect. */
|
|
600
903
|
interface MongoClientLike {
|
|
904
|
+
/** Opens the connection, matching `mongodb`'s own `MongoClient.connect()`. */
|
|
601
905
|
connect(): Promise<unknown>;
|
|
906
|
+
/** Returns a database handle, from which a collection is looked up by name. */
|
|
602
907
|
db(name: string): {
|
|
908
|
+
/** Returns a collection handle for `name`, matching `mongodb`'s own `Db.collection()`. */
|
|
603
909
|
collection(name: string): MongoCollectionLike;
|
|
604
910
|
};
|
|
605
911
|
}
|
|
912
|
+
/** Options for {@link MongoDBTransport}. */
|
|
606
913
|
interface MongoDBTransportOptions extends BatchingTransportOptions {
|
|
607
914
|
/** Pre-built collection, e.g. for tests, or an already-connected app. Skips the `mongodb` auto-import entirely. */
|
|
608
915
|
collection?: MongoCollectionLike;
|
|
@@ -636,14 +943,23 @@ declare class MongoDBTransport extends BatchingTransport {
|
|
|
636
943
|
|
|
637
944
|
/** One item written to DynamoDB: `runId` is the partition key, `timestamp` is the sort key. */
|
|
638
945
|
interface DynamoLogItem {
|
|
946
|
+
/** Partition key: `record.meta.runId`, else `record.meta.traceId`, else the logger name. */
|
|
639
947
|
runId: string;
|
|
948
|
+
/** Sort key: `record.timestamp`, as ISO8601. */
|
|
640
949
|
timestamp: string;
|
|
950
|
+
/** `record.level`. */
|
|
641
951
|
level: string;
|
|
952
|
+
/** `record.logger`. */
|
|
642
953
|
logger: string;
|
|
954
|
+
/** `record.message`. */
|
|
643
955
|
message: string;
|
|
956
|
+
/** `record.meta`, stored as-is (DynamoDB items are schemaless). */
|
|
644
957
|
meta: Record<string, unknown>;
|
|
958
|
+
/** `record.meta.spanId`, if present. */
|
|
645
959
|
spanId?: string;
|
|
960
|
+
/** `record.meta.parentSpanId`, if present. */
|
|
646
961
|
parentSpanId?: string;
|
|
962
|
+
/** `record.meta.traceId`, if present. */
|
|
647
963
|
traceId?: string;
|
|
648
964
|
}
|
|
649
965
|
/**
|
|
@@ -656,8 +972,10 @@ interface DynamoLogItem {
|
|
|
656
972
|
* `@aws-sdk/client-dynamodb` wrapper by not injecting a `client`.
|
|
657
973
|
*/
|
|
658
974
|
interface DynamoClientLike {
|
|
975
|
+
/** Writes one chunk of items (already capped at `DYNAMO_BATCH_LIMIT`) to `tableName` via a `BatchWriteItem`-equivalent call. */
|
|
659
976
|
batchWriteItems(tableName: string, items: readonly DynamoLogItem[]): Promise<unknown>;
|
|
660
977
|
}
|
|
978
|
+
/** Options for {@link DynamoDBTransport}. */
|
|
661
979
|
interface DynamoDBTransportOptions extends BatchingTransportOptions {
|
|
662
980
|
/** Pre-built client, e.g. for tests, or a custom wrapper. Skips the `@aws-sdk/client-dynamodb` auto-import entirely. */
|
|
663
981
|
client?: DynamoClientLike;
|
|
@@ -698,8 +1016,10 @@ declare class DynamoDBTransport extends BatchingTransport {
|
|
|
698
1016
|
|
|
699
1017
|
/** The subset of a `redis` (node-redis v4) client that `RedisTransport` needs. Inject a fake in tests. */
|
|
700
1018
|
interface RedisClientLike {
|
|
1019
|
+
/** Appends one entry to `stream`, matching `node-redis`'s own `client.xAdd()`. */
|
|
701
1020
|
xAdd(stream: string, id: string, fields: Record<string, string>): Promise<unknown>;
|
|
702
1021
|
}
|
|
1022
|
+
/** Options for {@link RedisTransport}. */
|
|
703
1023
|
interface RedisTransportOptions extends BatchingTransportOptions {
|
|
704
1024
|
/** Pre-built, already-connected client, e.g. for tests. Skips the `redis` auto-import entirely. */
|
|
705
1025
|
client?: RedisClientLike;
|
|
@@ -709,9 +1029,9 @@ interface RedisTransportOptions extends BatchingTransportOptions {
|
|
|
709
1029
|
stream?: string;
|
|
710
1030
|
}
|
|
711
1031
|
/**
|
|
712
|
-
* Sink for Redis, via Redis Streams (`XADD`) —
|
|
713
|
-
*
|
|
714
|
-
*
|
|
1032
|
+
* Sink for Redis, via Redis Streams (`XADD`) — a fast local buffer, a
|
|
1033
|
+
* different use case from durable storage, not a replacement for the
|
|
1034
|
+
* others. Reach for this when you want a low-latency
|
|
715
1035
|
* local tail (e.g. feeding a `redis-cli XREAD`-based live viewer) rather than
|
|
716
1036
|
* a system of record.
|
|
717
1037
|
*
|
|
@@ -738,6 +1058,7 @@ declare class RedisTransport extends BatchingTransport {
|
|
|
738
1058
|
protected sendBatch(batch: readonly LogRecord[]): Promise<void>;
|
|
739
1059
|
}
|
|
740
1060
|
|
|
1061
|
+
/** Options for {@link BaseQueueTransport} and every concrete queue transport that extends it. */
|
|
741
1062
|
interface BaseQueueTransportOptions extends BatchingTransportOptions {
|
|
742
1063
|
/**
|
|
743
1064
|
* Destination name on the backend — a Kafka topic, a RabbitMQ queue name,
|
|
@@ -756,6 +1077,7 @@ interface BaseQueueTransportOptions extends BatchingTransportOptions {
|
|
|
756
1077
|
* `publishBatch()` against its own driver's publish API.
|
|
757
1078
|
*/
|
|
758
1079
|
declare abstract class BaseQueueTransport extends BatchingTransport {
|
|
1080
|
+
/** Destination name on the backend — a Kafka topic, a RabbitMQ queue name, an SQS queue URL, or a GCP Pub/Sub topic. */
|
|
759
1081
|
readonly topic: string;
|
|
760
1082
|
constructor(options: BaseQueueTransportOptions);
|
|
761
1083
|
protected sendBatch(batch: readonly LogRecord[]): Promise<void>;
|
|
@@ -767,6 +1089,7 @@ declare abstract class BaseQueueTransport extends BatchingTransport {
|
|
|
767
1089
|
interface KafkaProducerLike {
|
|
768
1090
|
/** Optional: some injected producers (or fakes) are already connected. */
|
|
769
1091
|
connect?(): Promise<void>;
|
|
1092
|
+
/** Publishes one batch of messages to a topic, matching `kafkajs`'s own `Producer.send()`. */
|
|
770
1093
|
send(record: {
|
|
771
1094
|
topic: string;
|
|
772
1095
|
messages: {
|
|
@@ -813,6 +1136,7 @@ declare class KafkaTransport extends BaseQueueTransport {
|
|
|
813
1136
|
interface AmqpChannelLike {
|
|
814
1137
|
/** Optional: only called once, and only when provided, to ensure the queue exists. */
|
|
815
1138
|
assertQueue?(queue: string, options?: unknown): Promise<unknown>;
|
|
1139
|
+
/** Publishes one message directly to `queue`, matching `amqplib`'s own `Channel.sendToQueue()`. */
|
|
816
1140
|
sendToQueue(queue: string, content: Buffer, options?: unknown): boolean;
|
|
817
1141
|
}
|
|
818
1142
|
interface RabbitMQTransportOptions extends BaseQueueTransportOptions {
|
|
@@ -860,6 +1184,7 @@ declare class RabbitMQTransport extends BaseQueueTransport {
|
|
|
860
1184
|
* a fake in tests, or wrap a real `SQSClient` to match this shape.
|
|
861
1185
|
*/
|
|
862
1186
|
interface SQSClientLike {
|
|
1187
|
+
/** Sends one chunk of entries (already capped at SQS's 10-message `SendMessageBatch` limit) to `queueUrl`. */
|
|
863
1188
|
sendMessageBatch(queueUrl: string, entries: {
|
|
864
1189
|
id: string;
|
|
865
1190
|
body: string;
|
|
@@ -898,6 +1223,7 @@ declare class SQSTransport extends BaseQueueTransport {
|
|
|
898
1223
|
* needs. Inject a fake in tests, or an already-resolved `Topic` instance.
|
|
899
1224
|
*/
|
|
900
1225
|
interface PubSubTopicLike {
|
|
1226
|
+
/** Publishes one message, matching `@google-cloud/pubsub`'s own `Topic.publishMessage()`. */
|
|
901
1227
|
publishMessage(message: {
|
|
902
1228
|
data: Buffer;
|
|
903
1229
|
}): Promise<string>;
|
|
@@ -932,7 +1258,9 @@ declare class PubSubTransport extends BaseQueueTransport {
|
|
|
932
1258
|
|
|
933
1259
|
/** One CloudWatch Logs event: epoch-milliseconds timestamp plus a single log line. */
|
|
934
1260
|
interface CloudWatchLogEvent {
|
|
1261
|
+
/** Epoch-milliseconds timestamp. */
|
|
935
1262
|
timestamp: number;
|
|
1263
|
+
/** Formatted log line. */
|
|
936
1264
|
message: string;
|
|
937
1265
|
}
|
|
938
1266
|
/**
|
|
@@ -943,8 +1271,10 @@ interface CloudWatchLogEvent {
|
|
|
943
1271
|
* small for tests; `importClient()` builds the real adapter around it.
|
|
944
1272
|
*/
|
|
945
1273
|
interface CloudWatchClientLike {
|
|
1274
|
+
/** Sends one already timestamp-sorted batch of events to `logGroupName`/`logStreamName`. */
|
|
946
1275
|
putLogEvents(logGroupName: string, logStreamName: string, events: readonly CloudWatchLogEvent[]): Promise<unknown>;
|
|
947
1276
|
}
|
|
1277
|
+
/** Options for {@link CloudWatchTransport}. */
|
|
948
1278
|
interface CloudWatchTransportOptions extends BatchingTransportOptions {
|
|
949
1279
|
/** CloudWatch Logs log group to write into. */
|
|
950
1280
|
logGroupName: string;
|
|
@@ -966,8 +1296,11 @@ interface CloudWatchTransportOptions extends BatchingTransportOptions {
|
|
|
966
1296
|
* `CloudWatchLogsClient` wrapped to match `CloudWatchClientLike`).
|
|
967
1297
|
*/
|
|
968
1298
|
declare class CloudWatchTransport extends BatchingTransport {
|
|
1299
|
+
/** CloudWatch Logs log group written into. */
|
|
969
1300
|
readonly logGroupName: string;
|
|
1301
|
+
/** CloudWatch Logs log stream, within `logGroupName`, written into. */
|
|
970
1302
|
readonly logStreamName: string;
|
|
1303
|
+
/** AWS region passed to the real SDK client; `undefined` when `client` is injected or the SDK's own credential-chain resolution is used. */
|
|
971
1304
|
readonly region: string | undefined;
|
|
972
1305
|
private readonly injectedClient;
|
|
973
1306
|
private client;
|
|
@@ -980,8 +1313,11 @@ declare class CloudWatchTransport extends BatchingTransport {
|
|
|
980
1313
|
|
|
981
1314
|
/** One GCP Cloud Logging entry, shaped for `Log#write`. */
|
|
982
1315
|
interface CloudLoggingEntry {
|
|
1316
|
+
/** Cloud Logging `LogSeverity` value, mapped from the record's level. */
|
|
983
1317
|
severity: string;
|
|
1318
|
+
/** ISO8601 timestamp. */
|
|
984
1319
|
timestamp: string;
|
|
1320
|
+
/** The record, JSON-decoded, as Cloud Logging's structured payload. */
|
|
985
1321
|
jsonPayload: Record<string, unknown>;
|
|
986
1322
|
}
|
|
987
1323
|
/**
|
|
@@ -990,8 +1326,10 @@ interface CloudLoggingEntry {
|
|
|
990
1326
|
* `importClient()` builds the real adapter around `logging.log(name).write(entries)`.
|
|
991
1327
|
*/
|
|
992
1328
|
interface CloudLoggingClientLike {
|
|
1329
|
+
/** Writes one batch of entries to the configured log. */
|
|
993
1330
|
writeLogEntries(entries: readonly CloudLoggingEntry[]): Promise<unknown>;
|
|
994
1331
|
}
|
|
1332
|
+
/** Options for {@link CloudLoggingTransport}. */
|
|
995
1333
|
interface CloudLoggingTransportOptions extends BatchingTransportOptions {
|
|
996
1334
|
/** GCP log name (the last segment of the log resource path). Default `"logquill"`. */
|
|
997
1335
|
logName?: string;
|
|
@@ -1010,7 +1348,9 @@ interface CloudLoggingTransportOptions extends BatchingTransportOptions {
|
|
|
1010
1348
|
* `Log` wrapped to match `CloudLoggingClientLike`).
|
|
1011
1349
|
*/
|
|
1012
1350
|
declare class CloudLoggingTransport extends BatchingTransport {
|
|
1351
|
+
/** GCP log name (the last segment of the log resource path). */
|
|
1013
1352
|
readonly logName: string;
|
|
1353
|
+
/** GCP project ID passed to the real SDK client; `undefined` when `client` is injected or Application Default Credentials' project is used. */
|
|
1014
1354
|
readonly projectId: string | undefined;
|
|
1015
1355
|
private readonly injectedClient;
|
|
1016
1356
|
private client;
|
|
@@ -1023,7 +1363,9 @@ declare class CloudLoggingTransport extends BatchingTransport {
|
|
|
1023
1363
|
|
|
1024
1364
|
/** One Application Insights trace: a message plus its `SeverityLevel`. */
|
|
1025
1365
|
interface AppInsightsTrace {
|
|
1366
|
+
/** Formatted log line. */
|
|
1026
1367
|
message: string;
|
|
1368
|
+
/** Application Insights `SeverityLevel` value, mapped from the record's level. */
|
|
1027
1369
|
severity: number;
|
|
1028
1370
|
}
|
|
1029
1371
|
/**
|
|
@@ -1039,8 +1381,10 @@ interface AppInsightsTrace {
|
|
|
1039
1381
|
* batch call — Application Insights doesn't offer one.
|
|
1040
1382
|
*/
|
|
1041
1383
|
interface AppInsightsClientLike {
|
|
1384
|
+
/** Tracks every trace in the batch, then flushes once at the end. */
|
|
1042
1385
|
trackTraceBatch(traces: readonly AppInsightsTrace[]): Promise<unknown>;
|
|
1043
1386
|
}
|
|
1387
|
+
/** Options for {@link AppInsightsTransport}. */
|
|
1044
1388
|
interface AppInsightsTransportOptions extends BatchingTransportOptions {
|
|
1045
1389
|
/** Azure Application Insights connection string. Passed to the real SDK client; ignored when `client` is injected. */
|
|
1046
1390
|
connectionString?: string;
|
|
@@ -1059,6 +1403,7 @@ interface AppInsightsTransportOptions extends BatchingTransportOptions {
|
|
|
1059
1403
|
* wrapped to match `AppInsightsClientLike`).
|
|
1060
1404
|
*/
|
|
1061
1405
|
declare class AppInsightsTransport extends BatchingTransport {
|
|
1406
|
+
/** Azure Application Insights connection string passed to the real SDK client; `undefined` when `client` is injected. */
|
|
1062
1407
|
readonly connectionString: string | undefined;
|
|
1063
1408
|
private readonly injectedClient;
|
|
1064
1409
|
private client;
|
|
@@ -1071,6 +1416,7 @@ declare class AppInsightsTransport extends BatchingTransport {
|
|
|
1071
1416
|
|
|
1072
1417
|
/** Sends one batch of formatted lines to Datadog's Logs intake API at `url`. Swap in a fake for tests. */
|
|
1073
1418
|
type DatadogSender = (url: string, apiKey: string, batch: readonly string[]) => Promise<void> | void;
|
|
1419
|
+
/** Options for {@link DatadogTransport}. */
|
|
1074
1420
|
interface DatadogTransportOptions extends BatchingTransportOptions {
|
|
1075
1421
|
/** Datadog API key, sent in the `DD-API-KEY` header. */
|
|
1076
1422
|
apiKey: string;
|
|
@@ -1081,6 +1427,7 @@ interface DatadogTransportOptions extends BatchingTransportOptions {
|
|
|
1081
1427
|
* region's intake host silently fails to deliver logs to your account.
|
|
1082
1428
|
*/
|
|
1083
1429
|
site?: string;
|
|
1430
|
+
/** Delivers one batch. Defaults to a `fetch` POST; override for a fake or a different delivery mechanism. */
|
|
1084
1431
|
sender?: DatadogSender;
|
|
1085
1432
|
}
|
|
1086
1433
|
/**
|
|
@@ -1089,8 +1436,11 @@ interface DatadogTransportOptions extends BatchingTransportOptions {
|
|
|
1089
1436
|
* `sender` to swap in a fake for tests, or a different delivery mechanism.
|
|
1090
1437
|
*/
|
|
1091
1438
|
declare class DatadogTransport extends BatchingTransport {
|
|
1439
|
+
/** Logs intake endpoint derived from `site`. */
|
|
1092
1440
|
readonly url: string;
|
|
1441
|
+
/** Datadog API key sent in the `DD-API-KEY` header. */
|
|
1093
1442
|
readonly apiKey: string;
|
|
1443
|
+
/** Datadog site (region) this transport sends to. */
|
|
1094
1444
|
readonly site: string;
|
|
1095
1445
|
private readonly sender;
|
|
1096
1446
|
constructor(options: DatadogTransportOptions);
|
|
@@ -1099,6 +1449,7 @@ declare class DatadogTransport extends BatchingTransport {
|
|
|
1099
1449
|
|
|
1100
1450
|
/** Sends one pre-built NDJSON `_bulk` body to `url` with the given headers. Swap in a fake for tests. */
|
|
1101
1451
|
type ElasticsearchSender = (url: string, headers: Readonly<Record<string, string>>, body: string) => Promise<void> | void;
|
|
1452
|
+
/** Options for {@link ElasticsearchTransport}. */
|
|
1102
1453
|
interface ElasticsearchTransportOptions extends BatchingTransportOptions {
|
|
1103
1454
|
/** Cluster base URL, e.g. `"https://localhost:9200"`. */
|
|
1104
1455
|
node: string;
|
|
@@ -1106,6 +1457,7 @@ interface ElasticsearchTransportOptions extends BatchingTransportOptions {
|
|
|
1106
1457
|
index?: string;
|
|
1107
1458
|
/** Elasticsearch API key (base64 `id:api_key`), sent as `Authorization: ApiKey <apiKey>`. Omit to send no auth header (e.g. behind a proxy that adds its own). */
|
|
1108
1459
|
apiKey?: string;
|
|
1460
|
+
/** Delivers one NDJSON `_bulk` body. Defaults to a `fetch` POST; override for a fake or a different delivery mechanism. */
|
|
1109
1461
|
sender?: ElasticsearchSender;
|
|
1110
1462
|
}
|
|
1111
1463
|
/**
|
|
@@ -1115,7 +1467,9 @@ interface ElasticsearchTransportOptions extends BatchingTransportOptions {
|
|
|
1115
1467
|
* to swap in a fake for tests, or a different delivery mechanism.
|
|
1116
1468
|
*/
|
|
1117
1469
|
declare class ElasticsearchTransport extends BatchingTransport {
|
|
1470
|
+
/** `_bulk` endpoint derived from the `node` option. */
|
|
1118
1471
|
readonly url: string;
|
|
1472
|
+
/** Index written into. */
|
|
1119
1473
|
readonly index: string;
|
|
1120
1474
|
private readonly apiKey;
|
|
1121
1475
|
private readonly sender;
|
|
@@ -1127,13 +1481,16 @@ declare class ElasticsearchTransport extends BatchingTransport {
|
|
|
1127
1481
|
type NewRelicRegion = "US" | "EU";
|
|
1128
1482
|
/** What `NewRelicSender` reports back about one delivery attempt, so the transport can drive its own 429 backoff logic. */
|
|
1129
1483
|
interface NewRelicSenderResult {
|
|
1484
|
+
/** `true` for a 2xx response. */
|
|
1130
1485
|
ok: boolean;
|
|
1486
|
+
/** HTTP status code of the response. */
|
|
1131
1487
|
status: number;
|
|
1132
1488
|
/** The raw `Retry-After` response header value, if present — either a number of seconds or an HTTP-date, per RFC 9110. */
|
|
1133
1489
|
retryAfter: string | null;
|
|
1134
1490
|
}
|
|
1135
1491
|
/** Sends one gzip-compressed batch to New Relic's Log API at `url`. Swap in a fake for tests. */
|
|
1136
1492
|
type NewRelicSender = (url: string, headers: Readonly<Record<string, string>>, body: Buffer) => Promise<NewRelicSenderResult> | NewRelicSenderResult;
|
|
1493
|
+
/** Options for {@link NewRelicTransport}. */
|
|
1137
1494
|
interface NewRelicTransportOptions extends BatchingTransportOptions {
|
|
1138
1495
|
/** New Relic license key, sent in the `Api-Key` header. */
|
|
1139
1496
|
licenseKey: string;
|
|
@@ -1144,6 +1501,7 @@ interface NewRelicTransportOptions extends BatchingTransportOptions {
|
|
|
1144
1501
|
* vice versa) is rejected. Default `"US"`.
|
|
1145
1502
|
*/
|
|
1146
1503
|
region?: NewRelicRegion;
|
|
1504
|
+
/** Delivers one gzip-compressed batch. Defaults to a `fetch` POST; override for a fake or to intercept 429s in tests. */
|
|
1147
1505
|
sender?: NewRelicSender;
|
|
1148
1506
|
/** Injectable clock for the 429 backoff window, matching `SamplingPlugin`'s injectable `rng`. Default `Date.now`. */
|
|
1149
1507
|
clock?: () => number;
|
|
@@ -1160,7 +1518,9 @@ interface NewRelicTransportOptions extends BatchingTransportOptions {
|
|
|
1160
1518
|
* backoff tests without waiting on a real clock.
|
|
1161
1519
|
*/
|
|
1162
1520
|
declare class NewRelicTransport extends BatchingTransport {
|
|
1521
|
+
/** Ingest endpoint derived from `region`. */
|
|
1163
1522
|
readonly url: string;
|
|
1523
|
+
/** New Relic account region this transport sends to. */
|
|
1164
1524
|
readonly region: NewRelicRegion;
|
|
1165
1525
|
private readonly licenseKey;
|
|
1166
1526
|
private readonly sender;
|
|
@@ -1172,12 +1532,18 @@ declare class NewRelicTransport extends BatchingTransport {
|
|
|
1172
1532
|
|
|
1173
1533
|
/** The subset of `console` this transport needs — swap in a fake for tests. */
|
|
1174
1534
|
interface ConsoleLike {
|
|
1535
|
+
/** Writes one already-formatted line, e.g. for a TRACE–WARN record. */
|
|
1175
1536
|
log(message: string): void;
|
|
1537
|
+
/** Writes one already-formatted line, e.g. for an ERROR/FATAL record. */
|
|
1176
1538
|
error(message: string): void;
|
|
1177
1539
|
}
|
|
1540
|
+
/** Options for {@link ConsoleTransport}. */
|
|
1178
1541
|
interface ConsoleTransportOptions {
|
|
1542
|
+
/** Turns a `LogRecord` into the string this transport writes. Defaults to `JSONFormatter`. */
|
|
1179
1543
|
formatter?: Formatter;
|
|
1544
|
+
/** Wrap each line in an ANSI color escape for its level. Defaults to `true` unless the `NO_COLOR` env var is set. */
|
|
1180
1545
|
colorize?: boolean;
|
|
1546
|
+
/** Sink to write through instead of the global `console` — swap in a fake for tests. */
|
|
1181
1547
|
console?: ConsoleLike;
|
|
1182
1548
|
}
|
|
1183
1549
|
/**
|
|
@@ -1186,25 +1552,68 @@ interface ConsoleTransportOptions {
|
|
|
1186
1552
|
* so this transport works unmodified in a browser bundle.
|
|
1187
1553
|
*/
|
|
1188
1554
|
declare class ConsoleTransport extends Transport {
|
|
1555
|
+
/** Whether each line is wrapped in an ANSI color escape for its level. */
|
|
1189
1556
|
colorize: boolean;
|
|
1190
1557
|
private readonly out;
|
|
1191
1558
|
constructor(options?: ConsoleTransportOptions);
|
|
1559
|
+
/** Writes `formatted` via `console.log`, or `console.error` for ERROR/FATAL records. */
|
|
1192
1560
|
write(formatted: string, record: LogRecord): void;
|
|
1193
1561
|
private applyColor;
|
|
1194
1562
|
}
|
|
1195
1563
|
|
|
1564
|
+
/** Sends one batch of formatted lines to `url`. Swap in a fake for tests. */
|
|
1565
|
+
type BeaconSender = (url: string, batch: readonly string[]) => void;
|
|
1566
|
+
/** Options for {@link BeaconTransport}. */
|
|
1567
|
+
interface BeaconTransportOptions {
|
|
1568
|
+
/** Turns a `LogRecord` into the string this transport writes. Defaults to `JSONFormatter`. */
|
|
1569
|
+
formatter?: Formatter;
|
|
1570
|
+
/** Flush once the buffer holds this many lines. Default 20 — kept low since `sendBeacon` payloads are capped. */
|
|
1571
|
+
batchSize?: number;
|
|
1572
|
+
/** Delivers one batch. Defaults to `sendBeacon` with a `fetch(..., { keepalive: true })` fallback; override for a fake or a different backend. */
|
|
1573
|
+
sender?: BeaconSender;
|
|
1574
|
+
}
|
|
1575
|
+
/**
|
|
1576
|
+
* Batches formatted records and sends them via `navigator.sendBeacon`,
|
|
1577
|
+
* falling back to a `keepalive` `fetch` where `sendBeacon` isn't available.
|
|
1578
|
+
* Meant for the browser: unlike `HTTPTransport`, a beacon send can complete
|
|
1579
|
+
* even after the page that queued it starts unloading. Keep `batchSize`
|
|
1580
|
+
* small — `sendBeacon` payloads are capped (64KB in most browsers).
|
|
1581
|
+
*/
|
|
1582
|
+
declare class BeaconTransport extends Transport {
|
|
1583
|
+
/** Endpoint each batch is sent to. */
|
|
1584
|
+
readonly url: string;
|
|
1585
|
+
/** Buffer is flushed once it holds this many lines. */
|
|
1586
|
+
readonly batchSize: number;
|
|
1587
|
+
private readonly sender;
|
|
1588
|
+
private batch;
|
|
1589
|
+
constructor(url: string, options?: BeaconTransportOptions);
|
|
1590
|
+
/** Buffers the formatted line, flushing the batch once `batchSize` is reached. */
|
|
1591
|
+
write(formatted: string): void;
|
|
1592
|
+
/** Send the current batch now, even if it hasn't reached `batchSize`. */
|
|
1593
|
+
flush(): void;
|
|
1594
|
+
close(): void;
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
/** Options for {@link FileTransport}. */
|
|
1196
1598
|
interface FileTransportOptions {
|
|
1599
|
+
/** Turns a `LogRecord` into the string this transport writes. Defaults to `JSONFormatter`. */
|
|
1197
1600
|
formatter?: Formatter;
|
|
1601
|
+
/** Rotate once the file reaches this many bytes. `0` disables rotation. Default 10MB. */
|
|
1198
1602
|
maxBytes?: number;
|
|
1603
|
+
/** How many rotated backups (`.1`, `.2`, ...) to keep. The oldest is deleted once exceeded. Default 5. */
|
|
1199
1604
|
backupCount?: number;
|
|
1200
1605
|
}
|
|
1201
1606
|
/** Appends formatted records to a file, rotating when it exceeds `maxBytes`. */
|
|
1202
1607
|
declare class FileTransport extends Transport {
|
|
1608
|
+
/** Path of the file records are appended to. */
|
|
1203
1609
|
readonly path: string;
|
|
1610
|
+
/** File is rotated once it reaches this many bytes. `0` disables rotation. */
|
|
1204
1611
|
readonly maxBytes: number;
|
|
1612
|
+
/** How many rotated backups (`.1`, `.2`, ...) are kept. */
|
|
1205
1613
|
readonly backupCount: number;
|
|
1206
1614
|
private fd;
|
|
1207
1615
|
constructor(path: string, options?: FileTransportOptions);
|
|
1616
|
+
/** Appends one formatted line to the file, rotating first if `maxBytes` has been exceeded. */
|
|
1208
1617
|
write(formatted: string): void;
|
|
1209
1618
|
private rotate;
|
|
1210
1619
|
close(): void;
|
|
@@ -1212,9 +1621,13 @@ declare class FileTransport extends Transport {
|
|
|
1212
1621
|
|
|
1213
1622
|
/** Sends one batch of formatted lines to `url`. Swap in a fake for tests. */
|
|
1214
1623
|
type Sender = (url: string, batch: readonly string[]) => Promise<void> | void;
|
|
1624
|
+
/** Options for {@link HTTPTransport}. */
|
|
1215
1625
|
interface HTTPTransportOptions {
|
|
1626
|
+
/** Turns a `LogRecord` into the string this transport writes. Defaults to `JSONFormatter`. */
|
|
1216
1627
|
formatter?: Formatter;
|
|
1628
|
+
/** Flush once the buffer holds this many lines. Default 50. */
|
|
1217
1629
|
batchSize?: number;
|
|
1630
|
+
/** Delivers one batch. Defaults to a `fetch` POST of newline-delimited JSON; override for a fake or a different backend. */
|
|
1218
1631
|
sender?: Sender;
|
|
1219
1632
|
}
|
|
1220
1633
|
/**
|
|
@@ -1222,53 +1635,75 @@ interface HTTPTransportOptions {
|
|
|
1222
1635
|
* Pass `sender` to swap in a fake for tests, or a different backend.
|
|
1223
1636
|
*/
|
|
1224
1637
|
declare class HTTPTransport extends Transport {
|
|
1638
|
+
/** Endpoint each batch is POSTed to. */
|
|
1225
1639
|
readonly url: string;
|
|
1640
|
+
/** Buffer is flushed once it holds this many lines. */
|
|
1226
1641
|
readonly batchSize: number;
|
|
1227
1642
|
private readonly sender;
|
|
1228
1643
|
private batch;
|
|
1229
1644
|
constructor(url: string, options?: HTTPTransportOptions);
|
|
1645
|
+
/** Buffers the formatted line, flushing the batch once `batchSize` is reached. */
|
|
1230
1646
|
write(formatted: string): void;
|
|
1231
1647
|
/** Send the current batch now, even if it hasn't reached `batchSize`. */
|
|
1232
1648
|
flush(): void;
|
|
1233
1649
|
close(): void;
|
|
1234
1650
|
}
|
|
1235
1651
|
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1652
|
+
/**
|
|
1653
|
+
* Wraps a serverless handler so `logger.flush()` is awaited before the
|
|
1654
|
+
* wrapped function returns or throws. A serverless runtime can freeze or
|
|
1655
|
+
* recycle its execution environment the instant a handler settles, so
|
|
1656
|
+
* anything still sitting in the dispatch queue — or a batching transport's
|
|
1657
|
+
* own buffer — needs to be sent before that happens, not left for an
|
|
1658
|
+
* invocation that may not come for a while (or ever, if the environment is
|
|
1659
|
+
* torn down instead of frozen).
|
|
1660
|
+
*
|
|
1661
|
+
* The handler shape itself doesn't matter here — only that `fn` is an async
|
|
1662
|
+
* function whose settling is the runtime's cue to freeze — so the same
|
|
1663
|
+
* wrapper covers AWS Lambda, GCP Cloud Functions, and Azure Functions
|
|
1664
|
+
* equally; `withLambda`/`withCloudFunction`/`withAzureFunction` are the same
|
|
1665
|
+
* function under names that match each platform's docs.
|
|
1666
|
+
*
|
|
1667
|
+
* ```ts
|
|
1668
|
+
* export const handler = withLambda(logger, async (event) => {
|
|
1669
|
+
* logger.info("handling request", { requestId: event.requestId });
|
|
1670
|
+
* return { statusCode: 200 };
|
|
1671
|
+
* });
|
|
1672
|
+
* ```
|
|
1673
|
+
*/
|
|
1674
|
+
declare function withFlush<Args extends unknown[], TResult>(logger: Logger, fn: (...args: Args) => Promise<TResult>): (...args: Args) => Promise<TResult>;
|
|
1675
|
+
/** `withFlush`, named for an AWS Lambda handler. */
|
|
1676
|
+
declare const withLambda: typeof withFlush;
|
|
1677
|
+
/** `withFlush`, named for a GCP Cloud Functions handler. */
|
|
1678
|
+
declare const withCloudFunction: typeof withFlush;
|
|
1679
|
+
/** `withFlush`, named for an Azure Functions handler. */
|
|
1680
|
+
declare const withAzureFunction: typeof withFlush;
|
|
1681
|
+
|
|
1682
|
+
/** Options for {@link installShutdownHandlers}. */
|
|
1683
|
+
interface ShutdownHandlerOptions {
|
|
1684
|
+
/** Signals to flush-and-close on (e.g. an orchestrator's SIGTERM). Default `["SIGTERM", "SIGINT"]`. */
|
|
1685
|
+
signals?: NodeJS.Signals[];
|
|
1270
1686
|
}
|
|
1687
|
+
/**
|
|
1688
|
+
* Registers listeners so `logger.close()` runs once as the process ends —
|
|
1689
|
+
* on `beforeExit` (the event loop draining naturally) and on the given
|
|
1690
|
+
* `signals` (a container/orchestrator asking the process to stop) — so
|
|
1691
|
+
* whatever is still in the dispatch queue or a batching transport's buffer
|
|
1692
|
+
* isn't silently lost. Node-only (uses `process`); don't call this from a
|
|
1693
|
+
* browser bundle.
|
|
1694
|
+
*
|
|
1695
|
+
* Registering a listener for a signal like `SIGTERM` opts this process out
|
|
1696
|
+
* of Node's default "terminate immediately" behavior for it, so this
|
|
1697
|
+
* function calls `process.exit(0)` itself once `close()` settles — `
|
|
1698
|
+
* beforeExit` doesn't need that, since the process is already on its way
|
|
1699
|
+
* out there.
|
|
1700
|
+
*
|
|
1701
|
+
* Returns a function that removes the listeners again — call it in tests,
|
|
1702
|
+
* or if the caller wants to manage its own shutdown lifecycle instead.
|
|
1703
|
+
*/
|
|
1704
|
+
declare function installShutdownHandlers(logger: Logger, options?: ShutdownHandlerOptions): () => void;
|
|
1271
1705
|
|
|
1706
|
+
/** This package's version, matching `package.json`'s `version` field. */
|
|
1272
1707
|
declare const VERSION = "0.3.0";
|
|
1273
1708
|
|
|
1274
|
-
export { AlertingPlugin, type AlertingPluginOptions, type AmqpChannelLike, type AppInsightsClientLike, type AppInsightsTrace, AppInsightsTransport, type AppInsightsTransportOptions, BaseQueueTransport, type BaseQueueTransportOptions, BaseSQLTransport, type BaseSQLTransportOptions, BatchingTransport, type BatchingTransportOptions, type CloudLoggingClientLike, type CloudLoggingEntry, CloudLoggingTransport, type CloudLoggingTransportOptions, type CloudWatchClientLike, type CloudWatchLogEvent, CloudWatchTransport, type CloudWatchTransportOptions,
|
|
1709
|
+
export { AlertingPlugin, type AlertingPluginOptions, type AmqpChannelLike, type AppInsightsClientLike, type AppInsightsTrace, AppInsightsTransport, type AppInsightsTransportOptions, BaseQueueTransport, type BaseQueueTransportOptions, BaseSQLTransport, type BaseSQLTransportOptions, BatchingTransport, type BatchingTransportOptions, type BeaconSender, BeaconTransport, type BeaconTransportOptions, type CloudLoggingClientLike, type CloudLoggingEntry, CloudLoggingTransport, type CloudLoggingTransportOptions, type CloudWatchClientLike, type CloudWatchLogEvent, CloudWatchTransport, type CloudWatchTransportOptions, type ConsoleLike, ConsoleTransport, type ConsoleTransportOptions, ContextPlugin, DEFAULT_PII_PATTERNS, DEFAULT_PINO_LEVEL_MAP, DEFAULT_REDACTED_KEYS, type DatadogSender, DatadogTransport, type DatadogTransportOptions, type DynamoClientLike, DynamoDBTransport, type DynamoDBTransportOptions, type DynamoLogItem, type ElasticsearchSender, ElasticsearchTransport, type ElasticsearchTransportOptions, EmailAlertPlugin, type EmailAlertPluginOptions, type EmailMessage, type EmailSender, FileTransport, type FileTransportOptions, Formatter, GENESIS_HASH, HTTPTransport, type HTTPTransportOptions, type KafkaProducerLike, KafkaTransport, type KafkaTransportOptions, Level, LevelInput, LogQuillPinoDestination, type LogQuillPinoDestinationOptions, LogRecord, Logger, type MongoClientLike, type MongoCollectionLike, MongoDBTransport, type MongoDBTransportOptions, type MySQLClientLike, MySQLTransport, type MySQLTransportOptions, type NewRelicRegion, type NewRelicSender, type NewRelicSenderResult, NewRelicTransport, type NewRelicTransportOptions, type NodemailerTransporterLike, type OtelSpanContextLike, type OtelSpanLike, OtelSpanProcessor, type OtelSpanProcessorOptions, type OtelStatusLike, PIIRedactPlugin, type PIIRedactPluginOptions, PagerDutyAlertPlugin, type PagerDutyAlertPluginOptions, type PagerDutySender, type PgClientLike, type PinoLevelMap, Plugin, PostgresTransport, type PostgresTransportOptions, type PubSubTopicLike, PubSubTransport, type PubSubTransportOptions, RabbitMQTransport, type RabbitMQTransportOptions, type RateLimitKeyFunc, RateLimitPlugin, type RateLimitPluginOptions, RedactPlugin, type RedactPluginOptions, type RedisClientLike, RedisTransport, type RedisTransportOptions, RunPlugin, type RunPluginOptions, type SQLLogRow, type SQLiteClientLike, type SQLiteStatementLike, SQLiteTransport, type SQLiteTransportOptions, type SQSClientLike, SQSTransport, type SQSTransportOptions, SamplingPlugin, type SamplingPluginOptions, type Sender, type ShutdownHandlerOptions, SlackAlertPlugin, type SlackAlertPluginOptions, type SlackSender, TamperEvidentPlugin, type TamperEvidentPluginOptions, TraceContextPlugin, type TraceContextPluginOptions, Transport, VERSION, bindContext, currentContext, defaultResolveActiveOtelTraceId, generateTraceId, getTraceparent, installShutdownHandlers, parseTraceHeader, setTraceparent, withAzureFunction, withCloudFunction, withFlush, withLambda };
|