logquill 0.2.0 → 0.4.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 +262 -9
- package/dist/index.cjs +612 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +371 -103
- package/dist/index.d.ts +371 -103
- package/dist/index.mjs +596 -7
- package/dist/index.mjs.map +1 -1
- package/dist/langchain.cjs +114 -0
- package/dist/langchain.cjs.map +1 -0
- package/dist/langchain.d.cts +122 -0
- package/dist/langchain.d.ts +122 -0
- package/dist/langchain.mjs +110 -0
- package/dist/langchain.mjs.map +1 -0
- package/dist/logger-D1_THnBJ.d.cts +163 -0
- package/dist/logger-D1_THnBJ.d.ts +163 -0
- package/package.json +24 -10
package/dist/index.d.ts
CHANGED
|
@@ -1,68 +1,113 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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;
|
|
16
|
-
|
|
17
|
-
/** The cross-language record shape shared with logquill-python. */
|
|
18
|
-
interface LogRecord {
|
|
19
|
-
timestamp: string;
|
|
20
|
-
level: string;
|
|
21
|
-
logger: string;
|
|
22
|
-
message: string;
|
|
23
|
-
meta: Record<string, unknown>;
|
|
1
|
+
import { P as Plugin, L as LogRecord, a as Level, T as Transport, b as LevelInput, F as Formatter } from './logger-D1_THnBJ.js';
|
|
2
|
+
export { C as CollectingTransport, c as FunctionPlugin, J as JSONFormatter, d as Logger, e as LoggerOptions, M as MiddlewareFunc, S as SpanOptions, f as createRecord, l as levelName, p as parseLevel, u as utcTimestamp } from './logger-D1_THnBJ.js';
|
|
3
|
+
|
|
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
|
+
readonly context: Record<string, unknown>;
|
|
10
|
+
constructor(context: Record<string, unknown>);
|
|
11
|
+
beforeLog(record: LogRecord): LogRecord;
|
|
24
12
|
}
|
|
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
13
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
format(record: LogRecord): string;
|
|
14
|
+
interface RunPluginOptions {
|
|
15
|
+
runId?: string;
|
|
37
16
|
}
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Stamps `meta.runId` — a stable id grouping every record from one agent
|
|
19
|
+
* run — plus an incrementing `meta.step` counter, one per record processed
|
|
20
|
+
* through this plugin instance.
|
|
21
|
+
*
|
|
22
|
+
* Distinct from `TraceContextPlugin`'s `traceId`: `runId` scopes one agent
|
|
23
|
+
* run, `traceId` follows one request across services. A run can span
|
|
24
|
+
* multiple traces (e.g. an agent that calls several downstream services);
|
|
25
|
+
* the two ids are independent.
|
|
26
|
+
*
|
|
27
|
+
* One instance is one run: attach a fresh `RunPlugin()` per run (typically
|
|
28
|
+
* via `logger.child("agent").use(new RunPlugin())`), never a process-wide
|
|
29
|
+
* singleton shared across runs — otherwise concurrent runs would share both
|
|
30
|
+
* the run id and the step counter.
|
|
31
|
+
*
|
|
32
|
+
* A record that already carries `meta.runId` (e.g. propagated from an
|
|
33
|
+
* upstream call) keeps its existing value; `meta.step` is always set from
|
|
34
|
+
* this instance's own counter.
|
|
35
|
+
*/
|
|
36
|
+
declare class RunPlugin implements Plugin {
|
|
37
|
+
readonly runId: string;
|
|
38
|
+
private step;
|
|
39
|
+
constructor(options?: RunPluginOptions);
|
|
40
|
+
beforeLog(record: LogRecord): LogRecord;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
44
|
+
* Sets the inbound trace header for the current execution context (e.g.
|
|
45
|
+
* request-scoped HTTP middleware, before the handler runs) — the
|
|
46
|
+
* propagation mechanism framework middleware uses to hand `TraceContextPlugin`
|
|
47
|
+
* an inbound header without threading it through every log call. Backed by
|
|
48
|
+
* `AsyncLocalStorage`, so it's isolated per concurrent request. Returns a
|
|
49
|
+
* function that restores the previous value; call it (typically in a
|
|
50
|
+
* `finally` block) once the request is done.
|
|
48
51
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
declare function setTraceparent(value: string | undefined): () => void;
|
|
53
|
+
/** The header most recently set via `setTraceparent()` for this execution context. */
|
|
54
|
+
declare function getTraceparent(): string | undefined;
|
|
55
|
+
/** A fresh 32-hex-char id, matching the shape of an OTel/W3C trace id. */
|
|
56
|
+
declare function generateTraceId(): string;
|
|
57
|
+
/**
|
|
58
|
+
* Extracts a 32-hex-char trace id from a W3C `traceparent`, AWS X-Ray
|
|
59
|
+
* `X-Amzn-Trace-Id`, or GCP `X-Cloud-Trace-Context` header value. Returns
|
|
60
|
+
* `undefined` if `header` doesn't match any of the three shapes.
|
|
61
|
+
*/
|
|
62
|
+
declare function parseTraceHeader(header: string): string | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Best-effort, synchronous lookup of the active OpenTelemetry span's trace
|
|
65
|
+
* id via a plain `require("@opentelemetry/api")` — `@opentelemetry/api` is
|
|
66
|
+
* never a declared dependency of this package (matching `logquill-python`'s
|
|
67
|
+
* lazy `import opentelemetry`); this returns `undefined` whenever it isn't
|
|
68
|
+
* installed, or no span is currently active, rather than throwing.
|
|
69
|
+
*
|
|
70
|
+
* A `require()` (via `createRequire`) rather than a dynamic `import()` is
|
|
71
|
+
* deliberate: `Plugin.beforeLog` is synchronous, so this has to be too.
|
|
72
|
+
*/
|
|
73
|
+
declare function defaultResolveActiveOtelTraceId(): string | undefined;
|
|
74
|
+
interface TraceContextPluginOptions {
|
|
75
|
+
/** `meta` key the trace id is written to. Default `"traceId"`. */
|
|
76
|
+
traceKey?: string;
|
|
77
|
+
/** An inbound trace header to resolve on every record, bypassing `setTraceparent()`. */
|
|
78
|
+
traceparent?: string;
|
|
79
|
+
/** Override for testing, or to plug in a non-Node OTel API surface. Defaults to `defaultResolveActiveOtelTraceId`. */
|
|
80
|
+
resolveActiveOtelTraceId?: () => string | undefined;
|
|
56
81
|
}
|
|
57
|
-
|
|
58
82
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
83
|
+
* Stamps `meta.traceId` for cross-service correlation — distinct from
|
|
84
|
+
* `RunPlugin`'s `runId`: `traceId` follows one request across services,
|
|
85
|
+
* `runId` scopes one agent run.
|
|
86
|
+
*
|
|
87
|
+
* A record that already carries `meta[traceKey]` (e.g. because
|
|
88
|
+
* `SamplingPlugin`'s tail-based elevation, or an upstream plugin, already
|
|
89
|
+
* set one) is left alone. Otherwise resolves a trace id in priority order:
|
|
90
|
+
*
|
|
91
|
+
* 1. An active OpenTelemetry span's trace id, if `@opentelemetry/api` is
|
|
92
|
+
* installed and a span is current — read directly, not just inbound
|
|
93
|
+
* headers.
|
|
94
|
+
* 2. The `traceparent` constructor option, if given.
|
|
95
|
+
* 3. Whatever `setTraceparent()` most recently set for the current
|
|
96
|
+
* execution context.
|
|
97
|
+
* 4. A freshly generated trace id, if none of the above produced one.
|
|
98
|
+
*
|
|
99
|
+
* Header parsing understands W3C `traceparent`, AWS X-Ray
|
|
100
|
+
* `X-Amzn-Trace-Id`, and GCP `X-Cloud-Trace-Context` — see
|
|
101
|
+
* `parseTraceHeader`. A header that doesn't parse is treated the same as no
|
|
102
|
+
* header: falls through to generating a new trace id.
|
|
61
103
|
*/
|
|
62
|
-
declare class
|
|
63
|
-
readonly
|
|
64
|
-
|
|
104
|
+
declare class TraceContextPlugin implements Plugin {
|
|
105
|
+
readonly traceKey: string;
|
|
106
|
+
private readonly explicitTraceparent;
|
|
107
|
+
private readonly resolveActiveOtelTraceId;
|
|
108
|
+
constructor(options?: TraceContextPluginOptions);
|
|
65
109
|
beforeLog(record: LogRecord): LogRecord;
|
|
110
|
+
private resolveTraceId;
|
|
66
111
|
}
|
|
67
112
|
|
|
68
113
|
declare const DEFAULT_REDACTED_KEYS: readonly string[];
|
|
@@ -78,38 +123,292 @@ declare class RedactPlugin implements Plugin {
|
|
|
78
123
|
beforeLog(record: LogRecord): LogRecord;
|
|
79
124
|
}
|
|
80
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Syntactic (not semantic) patterns — matched on shape, so both false
|
|
128
|
+
* positives (a random 9-digit number) and false negatives (anything that
|
|
129
|
+
* doesn't look like these shapes) are expected. Override via `patterns`
|
|
130
|
+
* for anything stricter.
|
|
131
|
+
*/
|
|
132
|
+
declare const DEFAULT_PII_PATTERNS: Readonly<Record<string, RegExp>>;
|
|
133
|
+
interface PIIRedactPluginOptions {
|
|
134
|
+
patterns?: Readonly<Record<string, RegExp>>;
|
|
135
|
+
replacement?: string;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Regex-based PII redaction over `meta` **values**, not just keys.
|
|
139
|
+
*
|
|
140
|
+
* Complements `RedactPlugin`, which redacts by exact key match —
|
|
141
|
+
* `PIIRedactPlugin` scans string values (recursively through nested
|
|
142
|
+
* objects/arrays) for emails, SSNs, credit-card numbers, and phone
|
|
143
|
+
* numbers, and redacts matches wherever they appear, regardless of which
|
|
144
|
+
* key holds them (a `notes` field containing a stray SSN is still caught).
|
|
145
|
+
*
|
|
146
|
+
* Detection is pattern-based: fast and dependency-free, but it matches on
|
|
147
|
+
* syntactic shape, not meaning — a random 9-digit number can false-positive
|
|
148
|
+
* as an SSN, and anything that doesn't fit these shapes (a name, a street
|
|
149
|
+
* address) is a false negative. Pass your own `patterns` to extend or
|
|
150
|
+
* replace the defaults.
|
|
151
|
+
*
|
|
152
|
+
* Recursion into nested `meta` structures is depth- and cycle-bounded, so a
|
|
153
|
+
* circular reference or a pathologically deep structure can't hang or
|
|
154
|
+
* crash the caller — it's left unredacted past the bound rather than
|
|
155
|
+
* throwing.
|
|
156
|
+
*/
|
|
157
|
+
declare class PIIRedactPlugin implements Plugin {
|
|
158
|
+
readonly patterns: Readonly<Record<string, RegExp>>;
|
|
159
|
+
readonly replacement: string;
|
|
160
|
+
constructor(options?: PIIRedactPluginOptions);
|
|
161
|
+
beforeLog(record: LogRecord): LogRecord;
|
|
162
|
+
private redactValue;
|
|
163
|
+
private redactText;
|
|
164
|
+
}
|
|
165
|
+
|
|
81
166
|
interface SamplingPluginOptions {
|
|
82
167
|
rng?: () => number;
|
|
168
|
+
/** `meta` key holding the trace/run id used to group buffered records. Default `"traceId"`. */
|
|
169
|
+
traceKey?: string;
|
|
170
|
+
/** A record at or above this level elevates its whole trace. Default `Level.ERROR`. */
|
|
171
|
+
elevateAt?: LevelInput;
|
|
172
|
+
/** Enables tail-based elevation, writing straight to these transports on elevation. Omit to disable and get plain rate-based sampling. */
|
|
173
|
+
transports?: Transport[];
|
|
174
|
+
/** Total buffered records allowed across every trace before the oldest trace is evicted. Default 1000. */
|
|
175
|
+
maxBufferedRecords?: number;
|
|
176
|
+
/** Distinct trace ids held at once before the oldest is evicted. Default 200. */
|
|
177
|
+
maxTraces?: number;
|
|
83
178
|
}
|
|
84
|
-
/**
|
|
179
|
+
/**
|
|
180
|
+
* Keeps roughly `rate` of records (0.0-1.0), dropping the rest.
|
|
181
|
+
*
|
|
182
|
+
* With `transports` set, sampling becomes tail-based per trace: a record
|
|
183
|
+
* that would otherwise be dropped is buffered under its `meta[traceKey]`
|
|
184
|
+
* value instead of discarded outright. If any later record sharing that
|
|
185
|
+
* trace id reaches `elevateAt` or above, the whole trace is "elevated" —
|
|
186
|
+
* every buffered record for that trace id is flushed straight to
|
|
187
|
+
* `transports`, and every subsequent record for that trace id ships
|
|
188
|
+
* unconditionally. This is what lets a sampled-out request still produce a
|
|
189
|
+
* complete trace once it turns out to matter (it errored).
|
|
190
|
+
*
|
|
191
|
+
* Flushing writes buffered records directly to `transports` — pass the
|
|
192
|
+
* same array given to the `Logger`. This bypasses `beforeLog`/`afterLog`/
|
|
193
|
+
* `onError` for any plugin *after* `SamplingPlugin` in the pipeline (the
|
|
194
|
+
* plugins before it already ran, since that's how the buffered record was
|
|
195
|
+
* built); put `SamplingPlugin` last if that matters for your pipeline.
|
|
196
|
+
*
|
|
197
|
+
* Without `transports`, tail-based elevation is inactive and this behaves
|
|
198
|
+
* exactly like plain rate-based sampling (the original behavior) — a
|
|
199
|
+
* record without `meta[traceKey]` is also just rate-sampled, since there's
|
|
200
|
+
* no trace to buffer it under.
|
|
201
|
+
*
|
|
202
|
+
* Buffering is bounded: at most `maxBufferedRecords` records total and
|
|
203
|
+
* `maxTraces` distinct trace ids are held at once. Once either limit is
|
|
204
|
+
* hit, the oldest buffered trace is evicted (and its records are lost, not
|
|
205
|
+
* flushed) — a deliberate bounded-memory trade-off, not a bug: an
|
|
206
|
+
* unbounded per-trace buffer would let a single pathologically long-lived
|
|
207
|
+
* or high-cardinality trace grow memory without limit.
|
|
208
|
+
*/
|
|
85
209
|
declare class SamplingPlugin implements Plugin {
|
|
86
210
|
readonly rate: number;
|
|
211
|
+
readonly traceKey: string;
|
|
212
|
+
readonly elevateAt: Level;
|
|
213
|
+
readonly transports: Transport[] | undefined;
|
|
214
|
+
readonly maxBufferedRecords: number;
|
|
215
|
+
readonly maxTraces: number;
|
|
87
216
|
private readonly rng;
|
|
217
|
+
private readonly buffer;
|
|
218
|
+
private bufferedCount;
|
|
219
|
+
private readonly elevated;
|
|
88
220
|
constructor(rate: number, options?: SamplingPluginOptions);
|
|
89
221
|
beforeLog(record: LogRecord): LogRecord | null;
|
|
222
|
+
private elevate;
|
|
223
|
+
private bufferRecord;
|
|
224
|
+
private evictOldestTrace;
|
|
90
225
|
}
|
|
91
226
|
|
|
227
|
+
declare const GENESIS_HASH: string;
|
|
228
|
+
interface TamperEvidentPluginOptions {
|
|
229
|
+
genesisHash?: string;
|
|
230
|
+
}
|
|
92
231
|
/**
|
|
93
|
-
*
|
|
94
|
-
*
|
|
232
|
+
* Hash-chains every record so tampering with a written log can be
|
|
233
|
+
* detected after the fact.
|
|
234
|
+
*
|
|
235
|
+
* Each record gets `meta.hash` — a SHA-256 hex digest over the record's
|
|
236
|
+
* own content plus the previous record's hash (`meta.prevHash`) — the same
|
|
237
|
+
* hash-chain construction used by tamper-evident/append-only logs: editing
|
|
238
|
+
* or deleting any one line breaks every hash after it in the chain, even
|
|
239
|
+
* if the tamperer edits the file directly and not through this plugin.
|
|
240
|
+
* Opt-in — hashing every record has a real, measurable CPU cost, so it
|
|
241
|
+
* isn't part of the default pipeline.
|
|
242
|
+
*
|
|
243
|
+
* Verify a previously-written log with `TamperEvidentPlugin.verifyChain`,
|
|
244
|
+
* which re-derives each record's hash from its content and confirms it
|
|
245
|
+
* matches both the stored `meta.hash` and the chain built from the records
|
|
246
|
+
* before it, in order.
|
|
95
247
|
*/
|
|
96
|
-
declare
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
|
|
248
|
+
declare class TamperEvidentPlugin implements Plugin {
|
|
249
|
+
private readonly genesisHash;
|
|
250
|
+
private lastHash;
|
|
251
|
+
constructor(options?: TamperEvidentPluginOptions);
|
|
252
|
+
beforeLog(record: LogRecord): LogRecord;
|
|
253
|
+
/**
|
|
254
|
+
* Returns `true` iff every record's hash matches its content plus the
|
|
255
|
+
* previous record's hash, in the given order. Returns `false` at the
|
|
256
|
+
* first break in the chain (an edited, removed, or reordered record).
|
|
257
|
+
*/
|
|
258
|
+
static verifyChain(records: Iterable<Pick<LogRecord, "timestamp" | "level" | "logger" | "message" | "meta">>, options?: TamperEvidentPluginOptions): boolean;
|
|
103
259
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
260
|
+
|
|
261
|
+
interface AlertingPluginOptions {
|
|
262
|
+
/** A record at or above this level fires an alert. Default `Level.ERROR`. */
|
|
263
|
+
threshold?: LevelInput;
|
|
264
|
+
/** How long a dedupe window stays open before a collapsed follow-up alert (if any) fires. Default 300_000 (5 minutes). */
|
|
265
|
+
dedupeWindowMs?: number;
|
|
266
|
+
/** Groups records into the same dedupe window. Default: `level:logger:message`. */
|
|
267
|
+
dedupeKey?: (record: LogRecord) => string;
|
|
268
|
+
/** Distinct concurrent dedupe keys tracked at once; beyond this, new keys are dropped rather than tracked. Default 500. */
|
|
269
|
+
maxTrackedKeys?: number;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Base class for plugins that fire an external alert on ERROR/FATAL (or any
|
|
273
|
+
* configurable `threshold`).
|
|
274
|
+
*
|
|
275
|
+
* A concrete subclass implements only `sendAlert(record, occurrences)` —
|
|
276
|
+
* everything else (thresholding, deduplication, never blocking the caller,
|
|
277
|
+
* never letting a broken destination crash logging) lives here.
|
|
278
|
+
*
|
|
279
|
+
* The first record at or above `threshold` for a given dedupe key (by
|
|
280
|
+
* default: level + logger + message) fires `sendAlert` right away, without
|
|
281
|
+
* awaiting it — so the log call that triggered it is never blocked on a
|
|
282
|
+
* webhook, SMTP handshake, or any other I/O, even if the destination is
|
|
283
|
+
* slow or unreachable. This stands in for the shared async dispatch queue
|
|
284
|
+
* a later phase will introduce; once that queue exists, `AlertingPlugin`
|
|
285
|
+
* can route through it instead of firing its own unawaited call per alert.
|
|
286
|
+
*
|
|
287
|
+
* Any further record matching the same dedupe key within
|
|
288
|
+
* `dedupeWindowMs` of the first is *not* sent again — it just increments a
|
|
289
|
+
* counter. When the window closes, if more than one record matched,
|
|
290
|
+
* exactly one follow-up alert is sent with the total occurrence count,
|
|
291
|
+
* instead of spamming the destination once per record. Tracking is bounded
|
|
292
|
+
* to `maxTrackedKeys` distinct concurrent dedupe keys; beyond that, new
|
|
293
|
+
* keys are dropped rather than tracked (alerting degrades under extreme
|
|
294
|
+
* cardinality, logging itself never does).
|
|
295
|
+
*
|
|
296
|
+
* `sendAlert` is always called without being awaited, and any rejection is
|
|
297
|
+
* routed to this plugin's own `onError`, the same as any other plugin hook
|
|
298
|
+
* that throws.
|
|
299
|
+
*/
|
|
300
|
+
declare abstract class AlertingPlugin implements Plugin {
|
|
301
|
+
readonly threshold: Level;
|
|
302
|
+
readonly dedupeWindowMs: number;
|
|
303
|
+
readonly maxTrackedKeys: number;
|
|
304
|
+
private readonly dedupeKeyFn;
|
|
305
|
+
private readonly windows;
|
|
306
|
+
constructor(options?: AlertingPluginOptions);
|
|
307
|
+
afterLog(record: LogRecord): void;
|
|
308
|
+
private flush;
|
|
309
|
+
private safeSend;
|
|
310
|
+
/**
|
|
311
|
+
* Send one alert for `record`, representing `occurrences` collapsed
|
|
312
|
+
* duplicates (1 on first occurrence; the deduped total on a follow-up
|
|
313
|
+
* flush). Override in a concrete subclass — never call this directly,
|
|
314
|
+
* `AlertingPlugin` calls it without awaiting it.
|
|
315
|
+
*/
|
|
316
|
+
protected abstract sendAlert(record: LogRecord, occurrences: number): void | Promise<void>;
|
|
317
|
+
onError?(error: unknown, record: LogRecord): void;
|
|
318
|
+
/** Cancel any pending dedupe-window timers. Call on logger shutdown. */
|
|
110
319
|
close(): void;
|
|
111
320
|
}
|
|
112
321
|
|
|
322
|
+
/** Posts one alert body to a Slack incoming webhook URL. Swap in a fake for tests. */
|
|
323
|
+
type SlackSender = (webhookUrl: string, body: string) => Promise<void> | void;
|
|
324
|
+
interface SlackAlertPluginOptions extends AlertingPluginOptions {
|
|
325
|
+
sender?: SlackSender;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Sends deduplicated `AlertingPlugin` alerts to a Slack incoming webhook.
|
|
329
|
+
*
|
|
330
|
+
* `webhookUrl` is the full "Incoming Webhook" URL from Slack's app config.
|
|
331
|
+
* Uses `fetch` — no extra dependency required. Pass `sender` to swap in a
|
|
332
|
+
* fake for tests or an alternate backend.
|
|
333
|
+
*/
|
|
334
|
+
declare class SlackAlertPlugin extends AlertingPlugin {
|
|
335
|
+
readonly webhookUrl: string;
|
|
336
|
+
private readonly sender;
|
|
337
|
+
constructor(webhookUrl: string, options?: SlackAlertPluginOptions);
|
|
338
|
+
protected sendAlert(record: LogRecord, occurrences: number): Promise<void>;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/** POSTs one PagerDuty Events API v2 payload. Swap in a fake for tests. */
|
|
342
|
+
type PagerDutySender = (body: string) => Promise<void> | void;
|
|
343
|
+
interface PagerDutyAlertPluginOptions extends AlertingPluginOptions {
|
|
344
|
+
sender?: PagerDutySender;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Sends deduplicated `AlertingPlugin` alerts to PagerDuty via the Events
|
|
348
|
+
* API v2 (`POST https://events.pagerduty.com/v2/enqueue`).
|
|
349
|
+
*
|
|
350
|
+
* `routingKey` is an Events API v2 integration key from a PagerDuty
|
|
351
|
+
* service. Uses `fetch` — no extra dependency required. Pass `sender` to
|
|
352
|
+
* swap in a fake for tests or an alternate backend.
|
|
353
|
+
*/
|
|
354
|
+
declare class PagerDutyAlertPlugin extends AlertingPlugin {
|
|
355
|
+
readonly routingKey: string;
|
|
356
|
+
private readonly sender;
|
|
357
|
+
constructor(routingKey: string, options?: PagerDutyAlertPluginOptions);
|
|
358
|
+
protected sendAlert(record: LogRecord, occurrences: number): Promise<void>;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
interface EmailMessage {
|
|
362
|
+
from: string;
|
|
363
|
+
to: string[];
|
|
364
|
+
subject: string;
|
|
365
|
+
text: string;
|
|
366
|
+
}
|
|
367
|
+
/** Sends one email message. Swap in a fake for tests. */
|
|
368
|
+
type EmailSender = (message: EmailMessage) => Promise<void> | void;
|
|
369
|
+
/** The subset of a `nodemailer` transporter that `EmailAlertPlugin` needs. */
|
|
370
|
+
interface NodemailerTransporterLike {
|
|
371
|
+
sendMail(message: {
|
|
372
|
+
from: string;
|
|
373
|
+
to: string;
|
|
374
|
+
subject: string;
|
|
375
|
+
text: string;
|
|
376
|
+
}): Promise<unknown>;
|
|
377
|
+
}
|
|
378
|
+
interface EmailAlertPluginOptions extends AlertingPluginOptions {
|
|
379
|
+
smtpHost: string;
|
|
380
|
+
smtpPort: number;
|
|
381
|
+
fromAddr: string;
|
|
382
|
+
toAddrs: string[];
|
|
383
|
+
username?: string;
|
|
384
|
+
password?: string;
|
|
385
|
+
/** `false` for an SMTP server that doesn't support STARTTLS (e.g. a local relay). Default `true`. */
|
|
386
|
+
useTls?: boolean;
|
|
387
|
+
/** Pre-built sender, e.g. for tests. Skips the `nodemailer` auto-import entirely. */
|
|
388
|
+
sender?: EmailSender;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Sends deduplicated `AlertingPlugin` alerts by email over SMTP.
|
|
392
|
+
*
|
|
393
|
+
* `nodemailer` is an optional peer dependency: install it yourself, or
|
|
394
|
+
* pass `sender` to swap in a fake for tests or an alternate backend —
|
|
395
|
+
* `username`/`password` are only used if both are set.
|
|
396
|
+
*/
|
|
397
|
+
declare class EmailAlertPlugin extends AlertingPlugin {
|
|
398
|
+
readonly smtpHost: string;
|
|
399
|
+
readonly smtpPort: number;
|
|
400
|
+
readonly fromAddr: string;
|
|
401
|
+
readonly toAddrs: string[];
|
|
402
|
+
private readonly username;
|
|
403
|
+
private readonly password;
|
|
404
|
+
private readonly useTls;
|
|
405
|
+
private readonly injectedSender;
|
|
406
|
+
private transporter;
|
|
407
|
+
constructor(options: EmailAlertPluginOptions);
|
|
408
|
+
protected sendAlert(record: LogRecord, occurrences: number): Promise<void>;
|
|
409
|
+
private importTransporter;
|
|
410
|
+
}
|
|
411
|
+
|
|
113
412
|
interface BatchingTransportOptions {
|
|
114
413
|
formatter?: Formatter;
|
|
115
414
|
/** Flush once the buffer holds this many items. Default 100. */
|
|
@@ -943,37 +1242,6 @@ declare class HTTPTransport extends Transport {
|
|
|
943
1242
|
close(): void;
|
|
944
1243
|
}
|
|
945
1244
|
|
|
946
|
-
|
|
947
|
-
level?: LevelInput;
|
|
948
|
-
transports?: Transport[];
|
|
949
|
-
plugins?: Plugin[];
|
|
950
|
-
meta?: Record<string, unknown>;
|
|
951
|
-
}
|
|
952
|
-
declare class Logger {
|
|
953
|
-
readonly name: string;
|
|
954
|
-
readonly transports: Transport[];
|
|
955
|
-
readonly plugins: Plugin[];
|
|
956
|
-
private currentLevel;
|
|
957
|
-
private readonly baseMeta;
|
|
958
|
-
constructor(name: string, options?: LoggerOptions);
|
|
959
|
-
get level(): Level;
|
|
960
|
-
setLevel(level: LevelInput): void;
|
|
961
|
-
/** Register a plugin. Returns `this` so calls can be chained. */
|
|
962
|
-
use(plugin: Plugin): this;
|
|
963
|
-
/** Close every attached transport. Call on shutdown to flush buffered writes. */
|
|
964
|
-
close(): void;
|
|
965
|
-
/** A logger scoped under this one, inheriting its level, transports, and plugins. */
|
|
966
|
-
child(name: string, meta?: Record<string, unknown>): Logger;
|
|
967
|
-
private notifyError;
|
|
968
|
-
private dispatch;
|
|
969
|
-
trace(message: string, meta?: Record<string, unknown>): LogRecord | null;
|
|
970
|
-
debug(message: string, meta?: Record<string, unknown>): LogRecord | null;
|
|
971
|
-
info(message: string, meta?: Record<string, unknown>): LogRecord | null;
|
|
972
|
-
warn(message: string, meta?: Record<string, unknown>): LogRecord | null;
|
|
973
|
-
error(message: string, meta?: Record<string, unknown>): LogRecord | null;
|
|
974
|
-
fatal(message: string, meta?: Record<string, unknown>): LogRecord | null;
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
declare const VERSION = "0.2.0";
|
|
1245
|
+
declare const VERSION = "0.3.0";
|
|
978
1246
|
|
|
979
|
-
export { 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,
|
|
1247
|
+
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, type ConsoleLike, ConsoleTransport, type ConsoleTransportOptions, ContextPlugin, DEFAULT_PII_PATTERNS, 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, LogRecord, type MongoClientLike, type MongoCollectionLike, MongoDBTransport, type MongoDBTransportOptions, type MySQLClientLike, MySQLTransport, type MySQLTransportOptions, type NewRelicRegion, type NewRelicSender, type NewRelicSenderResult, NewRelicTransport, type NewRelicTransportOptions, type NodemailerTransporterLike, PIIRedactPlugin, type PIIRedactPluginOptions, PagerDutyAlertPlugin, type PagerDutyAlertPluginOptions, type PagerDutySender, type PgClientLike, Plugin, PostgresTransport, type PostgresTransportOptions, type PubSubTopicLike, PubSubTransport, type PubSubTransportOptions, RabbitMQTransport, type RabbitMQTransportOptions, 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, SlackAlertPlugin, type SlackAlertPluginOptions, type SlackSender, TamperEvidentPlugin, type TamperEvidentPluginOptions, TraceContextPlugin, type TraceContextPluginOptions, Transport, VERSION, defaultResolveActiveOtelTraceId, generateTraceId, getTraceparent, parseTraceHeader, setTraceparent };
|