@loggerjs/node 0.0.1
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/LICENSE +21 -0
- package/README.md +53 -0
- package/dist/cli-integration.d.ts +25 -0
- package/dist/cli-integration.d.ts.map +1 -0
- package/dist/context.d.ts +9 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/database-integration.d.ts +34 -0
- package/dist/database-integration.d.ts.map +1 -0
- package/dist/diagnostics-channel-integration.d.ts +12 -0
- package/dist/diagnostics-channel-integration.d.ts.map +1 -0
- package/dist/express-integration.d.ts +47 -0
- package/dist/express-integration.d.ts.map +1 -0
- package/dist/fastify-integration.d.ts +44 -0
- package/dist/fastify-integration.d.ts.map +1 -0
- package/dist/file-transport.d.ts +15 -0
- package/dist/file-transport.d.ts.map +1 -0
- package/dist/http-transport.d.ts +12 -0
- package/dist/http-transport.d.ts.map +1 -0
- package/dist/index.cjs +1757 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1730 -0
- package/dist/index.js.map +1 -0
- package/dist/internal-types.d.ts +6 -0
- package/dist/internal-types.d.ts.map +1 -0
- package/dist/node-fetch-integration.d.ts +42 -0
- package/dist/node-fetch-integration.d.ts.map +1 -0
- package/dist/node-http-client-integration.d.ts +39 -0
- package/dist/node-http-client-integration.d.ts.map +1 -0
- package/dist/process-integration.d.ts +13 -0
- package/dist/process-integration.d.ts.map +1 -0
- package/dist/queue-integration.d.ts +40 -0
- package/dist/queue-integration.d.ts.map +1 -0
- package/dist/rotating-file-transport.d.ts +18 -0
- package/dist/rotating-file-transport.d.ts.map +1 -0
- package/dist/serverless-integration.d.ts +50 -0
- package/dist/serverless-integration.d.ts.map +1 -0
- package/dist/stdout-transport.d.ts +11 -0
- package/dist/stdout-transport.d.ts.map +1 -0
- package/dist/syslog-transport.d.ts +47 -0
- package/dist/syslog-transport.d.ts.map +1 -0
- package/dist/worker-transport.d.ts +27 -0
- package/dist/worker-transport.d.ts.map +1 -0
- package/package.json +132 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1757 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _loggerjs_core = require("@loggerjs/core");
|
|
3
|
+
let fs = require("fs");
|
|
4
|
+
let dgram = require("dgram");
|
|
5
|
+
let net = require("net");
|
|
6
|
+
let os = require("os");
|
|
7
|
+
let node_worker_threads = require("node:worker_threads");
|
|
8
|
+
let node_async_hooks = require("node:async_hooks");
|
|
9
|
+
let node_module = require("node:module");
|
|
10
|
+
//#region src/stdout-transport.ts
|
|
11
|
+
const normalizeError = (error) => error instanceof Error ? error : new Error(String(error));
|
|
12
|
+
function stdoutTransport(options = {}) {
|
|
13
|
+
const codec = options.codec ?? (0, _loggerjs_core.ndjsonCodec)();
|
|
14
|
+
const stream = options.stream ?? process.stdout;
|
|
15
|
+
const transportName = options.name ?? "stdout";
|
|
16
|
+
const waiters = [];
|
|
17
|
+
let pendingWrites = 0;
|
|
18
|
+
let pendingDrains = 0;
|
|
19
|
+
let lastError;
|
|
20
|
+
let lastContext;
|
|
21
|
+
const reportInternalError = (error, operation) => {
|
|
22
|
+
lastContext?.reportInternalError(error, {
|
|
23
|
+
phase: "transport",
|
|
24
|
+
transport: transportName,
|
|
25
|
+
operation
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const settleWaitersIfIdle = () => {
|
|
29
|
+
if (pendingWrites + pendingDrains > 0) return;
|
|
30
|
+
const error = lastError;
|
|
31
|
+
lastError = void 0;
|
|
32
|
+
for (const waiter of waiters.splice(0)) if (error) waiter.reject(error);
|
|
33
|
+
else waiter.resolve();
|
|
34
|
+
};
|
|
35
|
+
const recordError = (error, operation) => {
|
|
36
|
+
lastError = normalizeError(error);
|
|
37
|
+
reportInternalError(lastError, operation);
|
|
38
|
+
};
|
|
39
|
+
const waitForDrain = () => {
|
|
40
|
+
if (!stream.once) return;
|
|
41
|
+
pendingDrains += 1;
|
|
42
|
+
stream.once("drain", () => {
|
|
43
|
+
pendingDrains -= 1;
|
|
44
|
+
settleWaitersIfIdle();
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
const writePayload = (payload) => {
|
|
48
|
+
pendingWrites += 1;
|
|
49
|
+
try {
|
|
50
|
+
if (stream.write(payload, (error) => {
|
|
51
|
+
pendingWrites -= 1;
|
|
52
|
+
if (error) recordError(error, "write");
|
|
53
|
+
settleWaitersIfIdle();
|
|
54
|
+
}) === false) waitForDrain();
|
|
55
|
+
} catch (error) {
|
|
56
|
+
pendingWrites -= 1;
|
|
57
|
+
recordError(error, "write");
|
|
58
|
+
settleWaitersIfIdle();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
name: transportName,
|
|
63
|
+
minLevel: options.minLevel,
|
|
64
|
+
log(event, context) {
|
|
65
|
+
if (options.minLevel !== void 0 && event.level < (0, _loggerjs_core.toLevelValue)(options.minLevel)) return;
|
|
66
|
+
lastContext = context;
|
|
67
|
+
writePayload(codec.encode(event));
|
|
68
|
+
},
|
|
69
|
+
flush() {
|
|
70
|
+
if (pendingWrites + pendingDrains === 0) {
|
|
71
|
+
const error = lastError;
|
|
72
|
+
lastError = void 0;
|
|
73
|
+
if (error) return Promise.reject(error);
|
|
74
|
+
return Promise.resolve();
|
|
75
|
+
}
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
waiters.push({
|
|
78
|
+
resolve,
|
|
79
|
+
reject
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function stderrTransport(options = {}) {
|
|
86
|
+
return stdoutTransport({
|
|
87
|
+
...options,
|
|
88
|
+
name: options.name ?? "stderr",
|
|
89
|
+
stream: process.stderr
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/file-transport.ts
|
|
94
|
+
function fileTransport(options) {
|
|
95
|
+
const codec = options.codec ?? (0, _loggerjs_core.ndjsonCodec)();
|
|
96
|
+
const flags = options.flags ?? "a";
|
|
97
|
+
const stream = (0, fs.createWriteStream)(options.path, { flags });
|
|
98
|
+
let syncFd;
|
|
99
|
+
const pending = [];
|
|
100
|
+
const removePending = (payload) => {
|
|
101
|
+
const index = pending.indexOf(payload);
|
|
102
|
+
if (index >= 0) pending.splice(index, 1);
|
|
103
|
+
};
|
|
104
|
+
const getSyncFd = () => {
|
|
105
|
+
syncFd ??= (0, fs.openSync)(options.path, flags);
|
|
106
|
+
return syncFd;
|
|
107
|
+
};
|
|
108
|
+
return {
|
|
109
|
+
name: options.name ?? "file",
|
|
110
|
+
minLevel: options.minLevel,
|
|
111
|
+
stream,
|
|
112
|
+
log(event) {
|
|
113
|
+
if (options.minLevel !== void 0 && event.level < (0, _loggerjs_core.toLevelValue)(options.minLevel)) return;
|
|
114
|
+
const payload = codec.encode(event);
|
|
115
|
+
pending.push(payload);
|
|
116
|
+
stream.write(payload, (error) => {
|
|
117
|
+
if (!error) removePending(payload);
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
flush() {
|
|
121
|
+
return new Promise((resolve, reject) => {
|
|
122
|
+
stream.write("", (error) => {
|
|
123
|
+
if (error) {
|
|
124
|
+
reject(error);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
pending.splice(0, pending.length);
|
|
128
|
+
resolve();
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
flushSync() {
|
|
133
|
+
if (pending.length === 0) return;
|
|
134
|
+
const fd = getSyncFd();
|
|
135
|
+
for (const payload of pending.splice(0)) if (typeof payload === "string") (0, fs.writeSync)(fd, payload);
|
|
136
|
+
else (0, fs.writeSync)(fd, payload);
|
|
137
|
+
},
|
|
138
|
+
close() {
|
|
139
|
+
return new Promise((resolve, reject) => {
|
|
140
|
+
stream.end?.((error) => {
|
|
141
|
+
if (syncFd !== void 0) {
|
|
142
|
+
(0, fs.closeSync)(syncFd);
|
|
143
|
+
syncFd = void 0;
|
|
144
|
+
}
|
|
145
|
+
if (error) reject(error);
|
|
146
|
+
else resolve();
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/rotating-file-transport.ts
|
|
154
|
+
const textEncoder = new TextEncoder();
|
|
155
|
+
function payloadBytes(payload) {
|
|
156
|
+
return typeof payload === "string" ? textEncoder.encode(payload).byteLength : payload.byteLength;
|
|
157
|
+
}
|
|
158
|
+
function normalizePositiveInteger(value, fallback) {
|
|
159
|
+
if (value === void 0 || !Number.isFinite(value) || value <= 0) return fallback;
|
|
160
|
+
return Math.floor(value);
|
|
161
|
+
}
|
|
162
|
+
function normalizeNonNegativeInteger(value, fallback) {
|
|
163
|
+
if (value === void 0 || !Number.isFinite(value) || value < 0) return fallback;
|
|
164
|
+
return Math.floor(value);
|
|
165
|
+
}
|
|
166
|
+
function defaultArchivePath(path, index) {
|
|
167
|
+
return `${path}.${index}`;
|
|
168
|
+
}
|
|
169
|
+
function fileSize(path) {
|
|
170
|
+
try {
|
|
171
|
+
return (0, fs.statSync)(path).size;
|
|
172
|
+
} catch {
|
|
173
|
+
return 0;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function rotatingFileTransport(options) {
|
|
177
|
+
const codec = options.codec ?? (0, _loggerjs_core.ndjsonCodec)();
|
|
178
|
+
const flags = options.flags ?? "a";
|
|
179
|
+
const maxBytes = normalizePositiveInteger(options.maxBytes, 10 * 1024 * 1024);
|
|
180
|
+
const maxFiles = normalizeNonNegativeInteger(options.maxFiles, 5);
|
|
181
|
+
const archivePath = options.archivePath ?? defaultArchivePath;
|
|
182
|
+
let fd;
|
|
183
|
+
let bytes = fileSize(options.path);
|
|
184
|
+
const closeFd = () => {
|
|
185
|
+
if (fd === void 0) return;
|
|
186
|
+
(0, fs.closeSync)(fd);
|
|
187
|
+
fd = void 0;
|
|
188
|
+
};
|
|
189
|
+
const getFd = () => {
|
|
190
|
+
fd ??= (0, fs.openSync)(options.path, flags);
|
|
191
|
+
return fd;
|
|
192
|
+
};
|
|
193
|
+
const rotate = () => {
|
|
194
|
+
closeFd();
|
|
195
|
+
if (maxFiles === 0) {
|
|
196
|
+
if ((0, fs.existsSync)(options.path)) (0, fs.unlinkSync)(options.path);
|
|
197
|
+
bytes = 0;
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const oldest = archivePath(options.path, maxFiles);
|
|
201
|
+
if ((0, fs.existsSync)(oldest)) (0, fs.unlinkSync)(oldest);
|
|
202
|
+
for (let index = maxFiles - 1; index >= 1; index -= 1) {
|
|
203
|
+
const source = archivePath(options.path, index);
|
|
204
|
+
if ((0, fs.existsSync)(source)) (0, fs.renameSync)(source, archivePath(options.path, index + 1));
|
|
205
|
+
}
|
|
206
|
+
if ((0, fs.existsSync)(options.path)) (0, fs.renameSync)(options.path, archivePath(options.path, 1));
|
|
207
|
+
bytes = 0;
|
|
208
|
+
};
|
|
209
|
+
const writePayload = (payload) => {
|
|
210
|
+
const size = payloadBytes(payload);
|
|
211
|
+
if (bytes > 0 && bytes + size > maxBytes) rotate();
|
|
212
|
+
if (typeof payload === "string") (0, fs.writeSync)(getFd(), payload);
|
|
213
|
+
else (0, fs.writeSync)(getFd(), payload);
|
|
214
|
+
bytes += size;
|
|
215
|
+
};
|
|
216
|
+
return {
|
|
217
|
+
name: options.name ?? "rotating-file",
|
|
218
|
+
minLevel: options.minLevel,
|
|
219
|
+
log(event) {
|
|
220
|
+
if (options.minLevel !== void 0 && event.level < (0, _loggerjs_core.toLevelValue)(options.minLevel)) return;
|
|
221
|
+
writePayload(codec.encode(event));
|
|
222
|
+
},
|
|
223
|
+
logBatch(events) {
|
|
224
|
+
for (const event of events) {
|
|
225
|
+
if (options.minLevel !== void 0 && event.level < (0, _loggerjs_core.toLevelValue)(options.minLevel)) continue;
|
|
226
|
+
writePayload(codec.encode(event));
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
flush() {
|
|
230
|
+
return Promise.resolve();
|
|
231
|
+
},
|
|
232
|
+
flushSync() {},
|
|
233
|
+
close() {
|
|
234
|
+
closeFd();
|
|
235
|
+
return Promise.resolve();
|
|
236
|
+
},
|
|
237
|
+
rotate,
|
|
238
|
+
currentBytes: () => bytes
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region src/http-transport.ts
|
|
243
|
+
function payloadToBody(payload) {
|
|
244
|
+
if (typeof payload === "string") return payload;
|
|
245
|
+
return Uint8Array.from(payload);
|
|
246
|
+
}
|
|
247
|
+
function nodeHttpTransport(options) {
|
|
248
|
+
const codec = options.codec ?? (0, _loggerjs_core.safeJsonCodec)();
|
|
249
|
+
const fetchFn = options.fetchFn ?? globalThis.fetch?.bind(globalThis);
|
|
250
|
+
return (0, _loggerjs_core.batchTransport)({
|
|
251
|
+
name: options.name ?? "node-http-inner",
|
|
252
|
+
minLevel: options.minLevel,
|
|
253
|
+
async logBatch(events) {
|
|
254
|
+
if (!fetchFn) throw new Error("fetch is not available. Use Node.js 18+ or pass fetchFn.");
|
|
255
|
+
const response = await fetchFn(options.url, {
|
|
256
|
+
method: options.method ?? "POST",
|
|
257
|
+
headers: {
|
|
258
|
+
"content-type": codec.contentType,
|
|
259
|
+
...options.headers
|
|
260
|
+
},
|
|
261
|
+
body: payloadToBody(codec.encode(events))
|
|
262
|
+
});
|
|
263
|
+
if (!response.ok) throw new Error(`nodeHttpTransport failed with status ${response.status}`);
|
|
264
|
+
}
|
|
265
|
+
}, {
|
|
266
|
+
name: options.name ?? "node-http",
|
|
267
|
+
maxRecords: options.maxRecords,
|
|
268
|
+
maxBatchSize: options.maxBatchSize,
|
|
269
|
+
maxBytes: options.maxBytes,
|
|
270
|
+
maxWaitMs: options.maxWaitMs,
|
|
271
|
+
flushIntervalMs: options.flushIntervalMs,
|
|
272
|
+
concurrency: options.concurrency,
|
|
273
|
+
maxQueueSize: options.maxQueueSize,
|
|
274
|
+
dropPolicy: options.dropPolicy,
|
|
275
|
+
estimateEventBytes: options.estimateEventBytes,
|
|
276
|
+
maxRetries: options.maxRetries,
|
|
277
|
+
retryBaseDelayMs: options.retryBaseDelayMs,
|
|
278
|
+
retryMaxDelayMs: options.retryMaxDelayMs,
|
|
279
|
+
random: options.random,
|
|
280
|
+
circuitBreakerFailureThreshold: options.circuitBreakerFailureThreshold,
|
|
281
|
+
circuitBreakerResetMs: options.circuitBreakerResetMs,
|
|
282
|
+
onDrop: options.onDrop
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region src/syslog-transport.ts
|
|
287
|
+
const severityByLevel = {
|
|
288
|
+
trace: 7,
|
|
289
|
+
debug: 7,
|
|
290
|
+
info: 6,
|
|
291
|
+
warn: 4,
|
|
292
|
+
error: 3,
|
|
293
|
+
fatal: 2
|
|
294
|
+
};
|
|
295
|
+
function defaultUdpSocketFactory(protocol) {
|
|
296
|
+
return (0, dgram.createSocket)(protocol);
|
|
297
|
+
}
|
|
298
|
+
function defaultTcpSocketFactory(options) {
|
|
299
|
+
return (0, net.createConnection)(options);
|
|
300
|
+
}
|
|
301
|
+
function headerValue$4(value, fallback, maxLength) {
|
|
302
|
+
const text = String(value ?? fallback).trim().replace(/\s+/g, "_");
|
|
303
|
+
if (!text) return fallback;
|
|
304
|
+
return text.length > maxLength ? text.slice(0, maxLength) : text;
|
|
305
|
+
}
|
|
306
|
+
function timestamp(time) {
|
|
307
|
+
const value = new Date(time).toISOString();
|
|
308
|
+
return value === "Invalid Date" ? "-" : value;
|
|
309
|
+
}
|
|
310
|
+
function valueFor(value, event, fallback) {
|
|
311
|
+
return typeof value === "function" ? value(event) : value ?? fallback;
|
|
312
|
+
}
|
|
313
|
+
function defaultMessage(event) {
|
|
314
|
+
const extra = {};
|
|
315
|
+
if (event.data !== void 0) extra.data = event.data;
|
|
316
|
+
if (event.context !== void 0) extra.context = event.context;
|
|
317
|
+
if (event.error !== void 0) extra.error = event.error;
|
|
318
|
+
if (Object.keys(extra).length === 0) return event.message;
|
|
319
|
+
return `${event.message} ${(0, _loggerjs_core.safeJsonStringify)(extra)}`;
|
|
320
|
+
}
|
|
321
|
+
function formatSyslogMessage(event, options = {}) {
|
|
322
|
+
const facility = Math.max(0, Math.min(23, Math.trunc(options.facility ?? 1)));
|
|
323
|
+
const severity = severityByLevel[event.levelName] ?? 6;
|
|
324
|
+
const priority = facility * 8 + severity;
|
|
325
|
+
const host = headerValue$4(options.hostname, (0, os.hostname)(), 255);
|
|
326
|
+
const appName = headerValue$4(valueFor(options.appName, event, event.logger), "-", 48);
|
|
327
|
+
const procId = headerValue$4(valueFor(options.procId, event, "-"), "-", 128);
|
|
328
|
+
const msgId = headerValue$4(valueFor(options.msgId, event, event.type ?? event.levelName), "-", 32);
|
|
329
|
+
const structuredData = valueFor(options.structuredData, event, "-") || "-";
|
|
330
|
+
const message = options.formatMessage ? options.formatMessage(event) : defaultMessage(event);
|
|
331
|
+
return `<${priority}>1 ${timestamp(event.time)} ${host} ${appName} ${procId} ${msgId} ${structuredData} ${message}`;
|
|
332
|
+
}
|
|
333
|
+
function nodeSyslogTransport(options = {}) {
|
|
334
|
+
const protocol = options.protocol ?? "udp4";
|
|
335
|
+
const host = options.host ?? "127.0.0.1";
|
|
336
|
+
const port = options.port ?? 514;
|
|
337
|
+
const transportName = options.name ?? "syslog";
|
|
338
|
+
const unref = options.unref ?? true;
|
|
339
|
+
const tcpFraming = options.tcpFraming ?? "newline";
|
|
340
|
+
const udpSocketFactory = options.udpSocketFactory ?? defaultUdpSocketFactory;
|
|
341
|
+
const tcpSocketFactory = options.tcpSocketFactory ?? defaultTcpSocketFactory;
|
|
342
|
+
let udpSocket;
|
|
343
|
+
let tcpSocket;
|
|
344
|
+
let lastContext;
|
|
345
|
+
const reportError = (error, context, operation) => {
|
|
346
|
+
try {
|
|
347
|
+
options.onError?.(error, { operation });
|
|
348
|
+
} catch (onErrorError) {
|
|
349
|
+
context?.reportInternalError(onErrorError, {
|
|
350
|
+
operation: "on-error",
|
|
351
|
+
phase: "transport",
|
|
352
|
+
transport: transportName
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
context?.reportInternalError(error, {
|
|
356
|
+
operation,
|
|
357
|
+
phase: "transport",
|
|
358
|
+
transport: transportName
|
|
359
|
+
});
|
|
360
|
+
};
|
|
361
|
+
const getUdpSocket = (context) => {
|
|
362
|
+
if (udpSocket) return udpSocket;
|
|
363
|
+
const socket = udpSocketFactory(protocol === "udp6" ? "udp6" : "udp4");
|
|
364
|
+
socket.on?.("error", (error) => reportError(error, lastContext ?? context, "socket-error"));
|
|
365
|
+
if (unref) socket.unref?.();
|
|
366
|
+
udpSocket = socket;
|
|
367
|
+
return socket;
|
|
368
|
+
};
|
|
369
|
+
const getTcpSocket = (context) => {
|
|
370
|
+
if (tcpSocket) return tcpSocket;
|
|
371
|
+
const socket = tcpSocketFactory({
|
|
372
|
+
host,
|
|
373
|
+
port
|
|
374
|
+
});
|
|
375
|
+
socket.on?.("error", (error) => reportError(error, lastContext ?? context, "socket-error"));
|
|
376
|
+
if (unref) socket.unref?.();
|
|
377
|
+
tcpSocket = socket;
|
|
378
|
+
return socket;
|
|
379
|
+
};
|
|
380
|
+
const send = (message, context) => {
|
|
381
|
+
lastContext = context;
|
|
382
|
+
if (protocol === "tcp") {
|
|
383
|
+
const bytes = new TextEncoder().encode(message).byteLength;
|
|
384
|
+
const payload = tcpFraming === "octet-counting" ? `${bytes} ${message}` : `${message}\n`;
|
|
385
|
+
getTcpSocket(context).write(payload, (error) => {
|
|
386
|
+
if (error) reportError(error, context, "send");
|
|
387
|
+
});
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
getUdpSocket(context).send(message, port, host, (error) => {
|
|
391
|
+
if (error) reportError(error, context, "send");
|
|
392
|
+
});
|
|
393
|
+
};
|
|
394
|
+
return {
|
|
395
|
+
name: transportName,
|
|
396
|
+
minLevel: options.minLevel,
|
|
397
|
+
log(event, context) {
|
|
398
|
+
send(formatSyslogMessage(event, options), context);
|
|
399
|
+
},
|
|
400
|
+
logBatch(events, context) {
|
|
401
|
+
for (const event of events) send(formatSyslogMessage(event, options), context);
|
|
402
|
+
},
|
|
403
|
+
async close() {
|
|
404
|
+
udpSocket?.close?.();
|
|
405
|
+
udpSocket = void 0;
|
|
406
|
+
tcpSocket?.end?.();
|
|
407
|
+
tcpSocket = void 0;
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
//#endregion
|
|
412
|
+
//#region src/worker-transport.ts
|
|
413
|
+
function createDefaultWorker(options) {
|
|
414
|
+
if (!options.workerScript) throw new Error("workerTransport requires worker, workerFactory, or workerScript.");
|
|
415
|
+
return new node_worker_threads.Worker(options.workerScript, options.workerOptions);
|
|
416
|
+
}
|
|
417
|
+
function payloadToBytes(payload) {
|
|
418
|
+
if (typeof payload !== "string") return payload;
|
|
419
|
+
return new TextEncoder().encode(payload);
|
|
420
|
+
}
|
|
421
|
+
function transferablePayload(payload) {
|
|
422
|
+
const copy = Uint8Array.from(payload);
|
|
423
|
+
return {
|
|
424
|
+
payload: copy,
|
|
425
|
+
transferList: [copy.buffer]
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
function workerTransport(options = {}) {
|
|
429
|
+
const codec = options.codec ?? (0, _loggerjs_core.safeJsonCodec)();
|
|
430
|
+
const transportName = options.name ?? "worker";
|
|
431
|
+
const fallback = options.fallback;
|
|
432
|
+
let worker;
|
|
433
|
+
let failed = false;
|
|
434
|
+
let lastContext;
|
|
435
|
+
const reportInternalError = (error, operation) => {
|
|
436
|
+
lastContext?.reportInternalError(error, {
|
|
437
|
+
phase: "transport",
|
|
438
|
+
transport: transportName,
|
|
439
|
+
operation
|
|
440
|
+
});
|
|
441
|
+
};
|
|
442
|
+
const markFailed = (error, operation) => {
|
|
443
|
+
failed = true;
|
|
444
|
+
(0, _loggerjs_core.incrementLoggerMetaCounter)("transport.worker.failed");
|
|
445
|
+
reportInternalError(error, operation);
|
|
446
|
+
};
|
|
447
|
+
const onWorkerError = (error) => markFailed(error, "worker-error");
|
|
448
|
+
const onWorkerExit = (code) => {
|
|
449
|
+
if (typeof code === "number" && code !== 0) markFailed(code, "worker-exit");
|
|
450
|
+
};
|
|
451
|
+
const getWorker = () => {
|
|
452
|
+
if (failed) return void 0;
|
|
453
|
+
if (worker) return worker;
|
|
454
|
+
try {
|
|
455
|
+
worker = options.worker ?? options.workerFactory?.() ?? createDefaultWorker(options);
|
|
456
|
+
worker.on?.("error", onWorkerError);
|
|
457
|
+
worker.on?.("exit", onWorkerExit);
|
|
458
|
+
return worker;
|
|
459
|
+
} catch (error) {
|
|
460
|
+
markFailed(error, "create-worker");
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
const fallbackBatch = async (events, context) => {
|
|
465
|
+
if (fallback?.logBatch) {
|
|
466
|
+
await fallback.logBatch(events, context);
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
if (fallback?.log) for (const event of events) await fallback.log(event, context);
|
|
470
|
+
};
|
|
471
|
+
const postBatch = async (events, context) => {
|
|
472
|
+
lastContext = context;
|
|
473
|
+
const currentWorker = getWorker();
|
|
474
|
+
if (!currentWorker) {
|
|
475
|
+
await fallbackBatch(events, context);
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
const encoded = payloadToBytes(codec.encode(events));
|
|
479
|
+
const transferable = options.transferBuffers === false ? {
|
|
480
|
+
payload: encoded,
|
|
481
|
+
transferList: void 0
|
|
482
|
+
} : transferablePayload(encoded);
|
|
483
|
+
const message = {
|
|
484
|
+
type: "loggerjs:batch",
|
|
485
|
+
codec: codec.name,
|
|
486
|
+
contentType: codec.contentType,
|
|
487
|
+
count: events.length,
|
|
488
|
+
payload: transferable.payload
|
|
489
|
+
};
|
|
490
|
+
try {
|
|
491
|
+
currentWorker.postMessage(message, transferable.transferList);
|
|
492
|
+
} catch (error) {
|
|
493
|
+
markFailed(error, "post-message");
|
|
494
|
+
await fallbackBatch(events, context);
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
return {
|
|
498
|
+
name: transportName,
|
|
499
|
+
minLevel: options.minLevel,
|
|
500
|
+
log(event, context) {
|
|
501
|
+
if (options.minLevel !== void 0 && event.level < (0, _loggerjs_core.toLevelValue)(options.minLevel)) return;
|
|
502
|
+
return postBatch([event], context);
|
|
503
|
+
},
|
|
504
|
+
logBatch(events, context) {
|
|
505
|
+
return postBatch(events, context);
|
|
506
|
+
},
|
|
507
|
+
async flush() {
|
|
508
|
+
await fallback?.flush?.();
|
|
509
|
+
},
|
|
510
|
+
async close() {
|
|
511
|
+
worker?.off?.("error", onWorkerError);
|
|
512
|
+
worker?.off?.("exit", onWorkerExit);
|
|
513
|
+
await fallback?.close?.();
|
|
514
|
+
await worker?.terminate?.();
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
//#endregion
|
|
519
|
+
//#region src/context.ts
|
|
520
|
+
function mergeContext(...items) {
|
|
521
|
+
const out = {};
|
|
522
|
+
for (const item of items) {
|
|
523
|
+
if (!item) continue;
|
|
524
|
+
Object.assign(out, item);
|
|
525
|
+
}
|
|
526
|
+
return (0, _loggerjs_core.createBoundContext)(out) ?? void 0;
|
|
527
|
+
}
|
|
528
|
+
function createAsyncLocalStorageContextManager(storage = new node_async_hooks.AsyncLocalStorage()) {
|
|
529
|
+
return {
|
|
530
|
+
get() {
|
|
531
|
+
return storage.getStore();
|
|
532
|
+
},
|
|
533
|
+
with(context, fn) {
|
|
534
|
+
return storage.run(mergeContext(storage.getStore(), context) ?? Object.freeze({}), fn);
|
|
535
|
+
},
|
|
536
|
+
disable() {
|
|
537
|
+
storage.disable();
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
function installAsyncLocalStorageContext(manager = createAsyncLocalStorageContextManager()) {
|
|
542
|
+
(0, _loggerjs_core.setContextManager)(manager);
|
|
543
|
+
return () => {
|
|
544
|
+
(0, _loggerjs_core.resetContextManager)();
|
|
545
|
+
manager.disable();
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
//#endregion
|
|
549
|
+
//#region src/cli-integration.ts
|
|
550
|
+
const defaultSignals = ["SIGINT", "SIGTERM"];
|
|
551
|
+
function defaultProcess() {
|
|
552
|
+
return globalThis.process;
|
|
553
|
+
}
|
|
554
|
+
function defaultSanitizeArg(arg) {
|
|
555
|
+
if (/^(--?[^=\s]*(token|password|passwd|secret|key)[^=\s]*=)/i.test(arg)) return arg.replace(/=.*/, "=[redacted]");
|
|
556
|
+
return arg;
|
|
557
|
+
}
|
|
558
|
+
function defaultCommand(argv) {
|
|
559
|
+
return argv[1] ?? argv[0];
|
|
560
|
+
}
|
|
561
|
+
function levelFor(level, event, code) {
|
|
562
|
+
if (typeof level === "function") return level(event, code);
|
|
563
|
+
if (level) return level;
|
|
564
|
+
if (event === "signal") return "warn";
|
|
565
|
+
if (event === "exit" && Number(code ?? 0) !== 0) return "error";
|
|
566
|
+
return "info";
|
|
567
|
+
}
|
|
568
|
+
function pickEnv(env, names) {
|
|
569
|
+
if (!env || !names || names.length === 0) return void 0;
|
|
570
|
+
const out = {};
|
|
571
|
+
for (const name of names) {
|
|
572
|
+
const value = env[name];
|
|
573
|
+
if (value !== void 0) out[name] = value;
|
|
574
|
+
}
|
|
575
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
576
|
+
}
|
|
577
|
+
function removeListener$1(processLike, event, listener) {
|
|
578
|
+
if (processLike.off) {
|
|
579
|
+
processLike.off(event, listener);
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
processLike.removeListener?.(event, listener);
|
|
583
|
+
}
|
|
584
|
+
function captureCliIntegration(options = {}) {
|
|
585
|
+
const name = options.name ?? "cli";
|
|
586
|
+
const captureStart = options.captureStart ?? true;
|
|
587
|
+
const captureExit = options.captureExit ?? true;
|
|
588
|
+
const captureSignals = options.captureSignals ?? true;
|
|
589
|
+
const captureCwd = options.captureCwd ?? true;
|
|
590
|
+
const signals = options.signals ?? defaultSignals;
|
|
591
|
+
const sanitizeArg = options.sanitizeArg ?? defaultSanitizeArg;
|
|
592
|
+
const commandFor = options.getCommand ?? defaultCommand;
|
|
593
|
+
return {
|
|
594
|
+
name: "capture-cli",
|
|
595
|
+
setup(api) {
|
|
596
|
+
const processLike = options.process ?? defaultProcess();
|
|
597
|
+
if (!processLike) return;
|
|
598
|
+
const argv = processLike.argv ?? [];
|
|
599
|
+
const command = commandFor(argv);
|
|
600
|
+
const sanitizedArgv = argv.map((arg, index) => sanitizeArg(arg, index, argv));
|
|
601
|
+
const disposers = [];
|
|
602
|
+
let disposed = false;
|
|
603
|
+
const capture = api.guard((input) => {
|
|
604
|
+
if (!disposed) api.capture(input);
|
|
605
|
+
});
|
|
606
|
+
const cliBase = {
|
|
607
|
+
kind: name,
|
|
608
|
+
command,
|
|
609
|
+
argv: sanitizedArgv,
|
|
610
|
+
cwd: captureCwd ? processLike.cwd?.() : void 0,
|
|
611
|
+
env: pickEnv(processLike.env, options.captureEnv)
|
|
612
|
+
};
|
|
613
|
+
if (captureStart) capture({
|
|
614
|
+
level: levelFor(options.level, "start"),
|
|
615
|
+
message: `CLI start${command ? ` ${command}` : ""}`,
|
|
616
|
+
props: { cli: {
|
|
617
|
+
...cliBase,
|
|
618
|
+
lifecycle: "start"
|
|
619
|
+
} }
|
|
620
|
+
});
|
|
621
|
+
if (captureExit && processLike.on) {
|
|
622
|
+
const onExit = (code) => {
|
|
623
|
+
const exitCode = code ?? processLike.exitCode ?? 0;
|
|
624
|
+
capture({
|
|
625
|
+
level: levelFor(options.level, "exit", exitCode),
|
|
626
|
+
message: `CLI exit ${String(exitCode)}`,
|
|
627
|
+
props: { cli: {
|
|
628
|
+
...cliBase,
|
|
629
|
+
lifecycle: "exit",
|
|
630
|
+
exitCode
|
|
631
|
+
} }
|
|
632
|
+
});
|
|
633
|
+
};
|
|
634
|
+
processLike.on("exit", onExit);
|
|
635
|
+
disposers.push(() => removeListener$1(processLike, "exit", onExit));
|
|
636
|
+
}
|
|
637
|
+
if (captureSignals && processLike.on) for (const signal of signals) {
|
|
638
|
+
const onSignal = () => {
|
|
639
|
+
capture({
|
|
640
|
+
level: levelFor(options.level, "signal", signal),
|
|
641
|
+
message: `CLI signal ${signal}`,
|
|
642
|
+
props: { cli: {
|
|
643
|
+
...cliBase,
|
|
644
|
+
lifecycle: "signal",
|
|
645
|
+
signal
|
|
646
|
+
} }
|
|
647
|
+
});
|
|
648
|
+
};
|
|
649
|
+
processLike.on(signal, onSignal);
|
|
650
|
+
disposers.push(() => removeListener$1(processLike, signal, onSignal));
|
|
651
|
+
}
|
|
652
|
+
return () => {
|
|
653
|
+
if (disposed) return;
|
|
654
|
+
disposed = true;
|
|
655
|
+
for (const dispose of disposers) dispose();
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
//#endregion
|
|
661
|
+
//#region src/database-integration.ts
|
|
662
|
+
const defaultMethods$1 = [
|
|
663
|
+
"query",
|
|
664
|
+
"execute",
|
|
665
|
+
"run",
|
|
666
|
+
"all",
|
|
667
|
+
"get"
|
|
668
|
+
];
|
|
669
|
+
const defaultRandom$6 = () => Math.random();
|
|
670
|
+
function defaultLevel$6(_durationMs, error) {
|
|
671
|
+
return error ? "error" : "debug";
|
|
672
|
+
}
|
|
673
|
+
function isPromiseLike$2(value) {
|
|
674
|
+
return typeof value === "object" && value !== null && typeof value.then === "function";
|
|
675
|
+
}
|
|
676
|
+
function defaultStatement(args) {
|
|
677
|
+
const first = args[0];
|
|
678
|
+
if (typeof first === "string") return first;
|
|
679
|
+
if (typeof first !== "object" || first === null) return void 0;
|
|
680
|
+
const input = first;
|
|
681
|
+
if (typeof input.sql === "string") return input.sql;
|
|
682
|
+
if (typeof input.text === "string") return input.text;
|
|
683
|
+
if (typeof input.query === "string") return input.query;
|
|
684
|
+
}
|
|
685
|
+
function statementFor(args, method, options) {
|
|
686
|
+
const statement = options.getStatement?.(args, method) ?? defaultStatement(args);
|
|
687
|
+
return statement && options.sanitizeStatement ? options.sanitizeStatement(statement) : statement;
|
|
688
|
+
}
|
|
689
|
+
function parametersFor(args, captureParameters) {
|
|
690
|
+
if (!captureParameters) return void 0;
|
|
691
|
+
const first = args[0];
|
|
692
|
+
const parameters = args[1] ?? (typeof first === "object" && first ? first.values ?? first.params ?? first.parameters : void 0);
|
|
693
|
+
return parameters === void 0 ? void 0 : (0, _loggerjs_core.normalizeValue)(parameters, {
|
|
694
|
+
maxDepth: 4,
|
|
695
|
+
maxObjectKeys: 80
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
function databaseIntegration(options = {}) {
|
|
699
|
+
const targets = options.targets ?? (options.client ? [{
|
|
700
|
+
client: options.client,
|
|
701
|
+
name: options.name,
|
|
702
|
+
system: options.system,
|
|
703
|
+
methods: options.methods
|
|
704
|
+
}] : []);
|
|
705
|
+
const captureAll = options.captureAll ?? options.captureSuccessful ?? false;
|
|
706
|
+
const sampleRate = options.sampleRate ?? 1;
|
|
707
|
+
const random = options.random ?? defaultRandom$6;
|
|
708
|
+
const levelFor = options.level ?? defaultLevel$6;
|
|
709
|
+
const shouldCapture = (durationMs, error) => {
|
|
710
|
+
if (error) return true;
|
|
711
|
+
if (options.minDurationMs !== void 0 && durationMs >= options.minDurationMs) return true;
|
|
712
|
+
if (!captureAll) return false;
|
|
713
|
+
return sampleRate >= 1 || random() < sampleRate;
|
|
714
|
+
};
|
|
715
|
+
return {
|
|
716
|
+
name: "database",
|
|
717
|
+
setup(api) {
|
|
718
|
+
const capture = api.guard((input) => api.capture(input));
|
|
719
|
+
const disposers = [];
|
|
720
|
+
let disposed = false;
|
|
721
|
+
const captureResult = (info, started, args, error) => {
|
|
722
|
+
const durationMs = Date.now() - started;
|
|
723
|
+
if (disposed || !shouldCapture(durationMs, error)) return;
|
|
724
|
+
capture({
|
|
725
|
+
level: levelFor(durationMs, error, info),
|
|
726
|
+
message: error ? `Database error ${info.method}${info.statement ? ` ${info.statement}` : ""}` : `Database ${info.method}${info.statement ? ` ${info.statement}` : ""}`,
|
|
727
|
+
error,
|
|
728
|
+
props: { db: {
|
|
729
|
+
kind: info.target,
|
|
730
|
+
system: info.system,
|
|
731
|
+
method: info.method,
|
|
732
|
+
statement: info.statement,
|
|
733
|
+
durationMs,
|
|
734
|
+
parameters: parametersFor(args, options.captureParameters ?? false)
|
|
735
|
+
} }
|
|
736
|
+
});
|
|
737
|
+
};
|
|
738
|
+
for (const target of targets) {
|
|
739
|
+
const methods = target.methods ?? options.methods ?? defaultMethods$1;
|
|
740
|
+
for (const method of methods) {
|
|
741
|
+
const original = target.client[method];
|
|
742
|
+
if (typeof original !== "function") continue;
|
|
743
|
+
const originalMethod = original;
|
|
744
|
+
const targetName = target.name ?? options.name ?? "database";
|
|
745
|
+
const system = target.system ?? options.system;
|
|
746
|
+
target.client[method] = function wrappedDatabaseMethod(...args) {
|
|
747
|
+
const started = Date.now();
|
|
748
|
+
const info = {
|
|
749
|
+
target: targetName,
|
|
750
|
+
system,
|
|
751
|
+
method,
|
|
752
|
+
statement: statementFor(args, method, options)
|
|
753
|
+
};
|
|
754
|
+
try {
|
|
755
|
+
const result = originalMethod.apply(this, args);
|
|
756
|
+
if (isPromiseLike$2(result)) return result.then((value) => {
|
|
757
|
+
captureResult(info, started, args, void 0);
|
|
758
|
+
return value;
|
|
759
|
+
}, (error) => {
|
|
760
|
+
captureResult(info, started, args, error);
|
|
761
|
+
throw error;
|
|
762
|
+
});
|
|
763
|
+
captureResult(info, started, args, void 0);
|
|
764
|
+
return result;
|
|
765
|
+
} catch (error) {
|
|
766
|
+
captureResult(info, started, args, error);
|
|
767
|
+
throw error;
|
|
768
|
+
}
|
|
769
|
+
};
|
|
770
|
+
disposers.push(() => {
|
|
771
|
+
target.client[method] = originalMethod;
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
return () => {
|
|
776
|
+
if (disposed) return;
|
|
777
|
+
disposed = true;
|
|
778
|
+
for (const dispose of disposers) dispose();
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
//#endregion
|
|
784
|
+
//#region src/express-integration.ts
|
|
785
|
+
const defaultRandom$5 = () => Math.random();
|
|
786
|
+
function defaultSanitizeUrl$3(url) {
|
|
787
|
+
const queryIndex = url.indexOf("?");
|
|
788
|
+
const hashIndex = url.indexOf("#");
|
|
789
|
+
const end = Math.min(queryIndex >= 0 ? queryIndex : url.length, hashIndex >= 0 ? hashIndex : url.length);
|
|
790
|
+
return url.slice(0, end);
|
|
791
|
+
}
|
|
792
|
+
function defaultLevel$5(status, _req, _res, aborted) {
|
|
793
|
+
if (aborted) return "warn";
|
|
794
|
+
if (status >= 500) return "error";
|
|
795
|
+
if (status >= 400) return "warn";
|
|
796
|
+
return "info";
|
|
797
|
+
}
|
|
798
|
+
function requestUrl(req) {
|
|
799
|
+
return req.originalUrl ?? req.url ?? req.path ?? "/";
|
|
800
|
+
}
|
|
801
|
+
function headerValue$3(value) {
|
|
802
|
+
if (typeof value === "number") return String(value);
|
|
803
|
+
return value;
|
|
804
|
+
}
|
|
805
|
+
function pickRequestHeaders$1(req, names) {
|
|
806
|
+
if (!names || names.length === 0 || !req.headers) return void 0;
|
|
807
|
+
const out = {};
|
|
808
|
+
for (const name of names) {
|
|
809
|
+
const value = req.headers[name.toLowerCase()] ?? req.headers[name];
|
|
810
|
+
if (value !== void 0) out[name.toLowerCase()] = value;
|
|
811
|
+
}
|
|
812
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
813
|
+
}
|
|
814
|
+
function pickResponseHeaders$1(res, names) {
|
|
815
|
+
if (!names || names.length === 0 || !res.getHeader) return void 0;
|
|
816
|
+
const out = {};
|
|
817
|
+
for (const name of names) {
|
|
818
|
+
const value = headerValue$3(res.getHeader(name));
|
|
819
|
+
if (value !== void 0) out[name.toLowerCase()] = value;
|
|
820
|
+
}
|
|
821
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
822
|
+
}
|
|
823
|
+
function defaultRoute$1(req) {
|
|
824
|
+
const path = req.route?.path;
|
|
825
|
+
return typeof path === "string" ? path : void 0;
|
|
826
|
+
}
|
|
827
|
+
function removeListener(res, event, listener) {
|
|
828
|
+
if (res.off) {
|
|
829
|
+
res.off(event, listener);
|
|
830
|
+
return;
|
|
831
|
+
}
|
|
832
|
+
res.removeListener?.(event, listener);
|
|
833
|
+
}
|
|
834
|
+
function onResponseDone(res, event, listener) {
|
|
835
|
+
if (res.once) {
|
|
836
|
+
res.once(event, listener);
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
res.on?.(event, listener);
|
|
840
|
+
}
|
|
841
|
+
function expressIntegration(logger, options = {}) {
|
|
842
|
+
const name = options.name ?? "express";
|
|
843
|
+
const minStatus = options.minStatus ?? 400;
|
|
844
|
+
const captureAll = options.captureAll ?? options.captureSuccessful ?? false;
|
|
845
|
+
const captureAborted = options.captureAborted ?? true;
|
|
846
|
+
const sampleRate = options.sampleRate ?? 1;
|
|
847
|
+
const random = options.random ?? defaultRandom$5;
|
|
848
|
+
const sanitizeUrl = options.sanitizeUrl ?? defaultSanitizeUrl$3;
|
|
849
|
+
const levelFor = options.level ?? defaultLevel$5;
|
|
850
|
+
const routeFor = options.getRoute ?? defaultRoute$1;
|
|
851
|
+
const bindContext = options.bindContext ?? true;
|
|
852
|
+
return (req, res, next) => {
|
|
853
|
+
const started = Date.now();
|
|
854
|
+
const method = (req.method ?? "GET").toUpperCase();
|
|
855
|
+
const url = sanitizeUrl(requestUrl(req));
|
|
856
|
+
const requestId = options.getRequestId?.(req, res);
|
|
857
|
+
let completed = false;
|
|
858
|
+
const context = {
|
|
859
|
+
httpMethod: method,
|
|
860
|
+
httpUrl: url,
|
|
861
|
+
requestId,
|
|
862
|
+
...options.context?.(req, res)
|
|
863
|
+
};
|
|
864
|
+
const shouldCapture = (status, aborted) => {
|
|
865
|
+
if (aborted && captureAborted) return true;
|
|
866
|
+
if (status >= minStatus) return true;
|
|
867
|
+
if (!captureAll) return false;
|
|
868
|
+
return sampleRate >= 1 || random() < sampleRate;
|
|
869
|
+
};
|
|
870
|
+
const cleanup = () => {
|
|
871
|
+
removeListener(res, "finish", onFinish);
|
|
872
|
+
removeListener(res, "close", onClose);
|
|
873
|
+
};
|
|
874
|
+
const logRequest = (event) => {
|
|
875
|
+
if (completed) return;
|
|
876
|
+
completed = true;
|
|
877
|
+
cleanup();
|
|
878
|
+
const status = res.statusCode ?? 0;
|
|
879
|
+
const aborted = event === "close" && res.writableEnded !== true;
|
|
880
|
+
if (!shouldCapture(status, aborted)) return;
|
|
881
|
+
const http = {
|
|
882
|
+
kind: name,
|
|
883
|
+
framework: "express",
|
|
884
|
+
method,
|
|
885
|
+
url,
|
|
886
|
+
route: routeFor(req),
|
|
887
|
+
status,
|
|
888
|
+
durationMs: Date.now() - started,
|
|
889
|
+
aborted,
|
|
890
|
+
requestId,
|
|
891
|
+
remoteAddress: req.ip ?? req.socket?.remoteAddress,
|
|
892
|
+
requestHeaders: pickRequestHeaders$1(req, options.captureRequestHeaders),
|
|
893
|
+
responseHeaders: pickResponseHeaders$1(res, options.captureResponseHeaders)
|
|
894
|
+
};
|
|
895
|
+
logger.log(levelFor(status, req, res, aborted), `Express ${status} ${method} ${url}`, { http });
|
|
896
|
+
};
|
|
897
|
+
const onFinish = () => logRequest("finish");
|
|
898
|
+
const onClose = () => logRequest("close");
|
|
899
|
+
onResponseDone(res, "finish", onFinish);
|
|
900
|
+
onResponseDone(res, "close", onClose);
|
|
901
|
+
if (bindContext) {
|
|
902
|
+
(0, _loggerjs_core.withContext)(context, () => next());
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
next();
|
|
906
|
+
};
|
|
907
|
+
}
|
|
908
|
+
//#endregion
|
|
909
|
+
//#region src/fastify-integration.ts
|
|
910
|
+
const defaultRandom$4 = () => Math.random();
|
|
911
|
+
function defaultSanitizeUrl$2(url) {
|
|
912
|
+
const queryIndex = url.indexOf("?");
|
|
913
|
+
const hashIndex = url.indexOf("#");
|
|
914
|
+
const end = Math.min(queryIndex >= 0 ? queryIndex : url.length, hashIndex >= 0 ? hashIndex : url.length);
|
|
915
|
+
return url.slice(0, end);
|
|
916
|
+
}
|
|
917
|
+
function defaultLevel$4(status, _request, _reply, error) {
|
|
918
|
+
if (error || status >= 500) return "error";
|
|
919
|
+
if (status >= 400) return "warn";
|
|
920
|
+
return "info";
|
|
921
|
+
}
|
|
922
|
+
function headerValue$2(value) {
|
|
923
|
+
if (typeof value === "number") return String(value);
|
|
924
|
+
return value;
|
|
925
|
+
}
|
|
926
|
+
function pickRequestHeaders(request, names) {
|
|
927
|
+
if (!names || names.length === 0 || !request.headers) return void 0;
|
|
928
|
+
const out = {};
|
|
929
|
+
for (const name of names) {
|
|
930
|
+
const value = request.headers[name.toLowerCase()] ?? request.headers[name];
|
|
931
|
+
if (value !== void 0) out[name.toLowerCase()] = value;
|
|
932
|
+
}
|
|
933
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
934
|
+
}
|
|
935
|
+
function pickResponseHeaders(reply, names) {
|
|
936
|
+
if (!names || names.length === 0 || !reply.getHeader) return void 0;
|
|
937
|
+
const out = {};
|
|
938
|
+
for (const name of names) {
|
|
939
|
+
const value = headerValue$2(reply.getHeader(name));
|
|
940
|
+
if (value !== void 0) out[name.toLowerCase()] = value;
|
|
941
|
+
}
|
|
942
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
943
|
+
}
|
|
944
|
+
function defaultRoute(request) {
|
|
945
|
+
return request.routeOptions?.url ?? request.routerPath;
|
|
946
|
+
}
|
|
947
|
+
function fastifyIntegration(logger, options = {}) {
|
|
948
|
+
const name = options.name ?? "fastify";
|
|
949
|
+
const minStatus = options.minStatus ?? 400;
|
|
950
|
+
const captureAll = options.captureAll ?? options.captureSuccessful ?? false;
|
|
951
|
+
const sampleRate = options.sampleRate ?? 1;
|
|
952
|
+
const random = options.random ?? defaultRandom$4;
|
|
953
|
+
const sanitizeUrl = options.sanitizeUrl ?? defaultSanitizeUrl$2;
|
|
954
|
+
const levelFor = options.level ?? defaultLevel$4;
|
|
955
|
+
const routeFor = options.getRoute ?? defaultRoute;
|
|
956
|
+
const bindContext = options.bindContext ?? true;
|
|
957
|
+
const states = /* @__PURE__ */ new WeakMap();
|
|
958
|
+
const shouldCapture = (status, error) => {
|
|
959
|
+
if (error) return true;
|
|
960
|
+
if (status >= minStatus) return true;
|
|
961
|
+
if (!captureAll) return false;
|
|
962
|
+
return sampleRate >= 1 || random() < sampleRate;
|
|
963
|
+
};
|
|
964
|
+
return (instance, _pluginOptions, done) => {
|
|
965
|
+
instance.addHook("onRequest", (request, reply, next) => {
|
|
966
|
+
const method = (request.method ?? "GET").toUpperCase();
|
|
967
|
+
const url = sanitizeUrl(request.url ?? "/");
|
|
968
|
+
const requestId = options.getRequestId?.(request, reply) ?? request.id;
|
|
969
|
+
states.set(request, { started: Date.now() });
|
|
970
|
+
const context = {
|
|
971
|
+
httpMethod: method,
|
|
972
|
+
httpUrl: url,
|
|
973
|
+
requestId,
|
|
974
|
+
...options.context?.(request, reply)
|
|
975
|
+
};
|
|
976
|
+
if (bindContext) {
|
|
977
|
+
(0, _loggerjs_core.withContext)(context, () => next());
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
next();
|
|
981
|
+
});
|
|
982
|
+
instance.addHook("onError", (request, _reply, error, next) => {
|
|
983
|
+
const state = states.get(request);
|
|
984
|
+
if (state) state.error = error;
|
|
985
|
+
else states.set(request, {
|
|
986
|
+
started: Date.now(),
|
|
987
|
+
error
|
|
988
|
+
});
|
|
989
|
+
next();
|
|
990
|
+
});
|
|
991
|
+
instance.addHook("onResponse", (request, reply, next) => {
|
|
992
|
+
const state = states.get(request) ?? { started: Date.now() };
|
|
993
|
+
states.delete(request);
|
|
994
|
+
const status = reply.statusCode ?? 0;
|
|
995
|
+
const error = state.error;
|
|
996
|
+
if (!shouldCapture(status, error)) {
|
|
997
|
+
next();
|
|
998
|
+
return;
|
|
999
|
+
}
|
|
1000
|
+
const method = (request.method ?? "GET").toUpperCase();
|
|
1001
|
+
const url = sanitizeUrl(request.url ?? "/");
|
|
1002
|
+
const requestId = options.getRequestId?.(request, reply) ?? request.id;
|
|
1003
|
+
const data = { http: {
|
|
1004
|
+
kind: name,
|
|
1005
|
+
framework: "fastify",
|
|
1006
|
+
method,
|
|
1007
|
+
url,
|
|
1008
|
+
route: routeFor(request),
|
|
1009
|
+
status,
|
|
1010
|
+
durationMs: Date.now() - state.started,
|
|
1011
|
+
requestId,
|
|
1012
|
+
remoteAddress: request.ip,
|
|
1013
|
+
requestHeaders: pickRequestHeaders(request, options.captureRequestHeaders),
|
|
1014
|
+
responseHeaders: pickResponseHeaders(reply, options.captureResponseHeaders)
|
|
1015
|
+
} };
|
|
1016
|
+
if (error) data.error = error;
|
|
1017
|
+
logger.log(levelFor(status, request, reply, error), `Fastify ${status} ${method} ${url}`, { ...data });
|
|
1018
|
+
next();
|
|
1019
|
+
});
|
|
1020
|
+
done?.();
|
|
1021
|
+
};
|
|
1022
|
+
}
|
|
1023
|
+
//#endregion
|
|
1024
|
+
//#region src/node-fetch-integration.ts
|
|
1025
|
+
const defaultRandom$3 = () => Math.random();
|
|
1026
|
+
function defaultSanitizeUrl$1(url) {
|
|
1027
|
+
const queryIndex = url.indexOf("?");
|
|
1028
|
+
const hashIndex = url.indexOf("#");
|
|
1029
|
+
const end = Math.min(queryIndex >= 0 ? queryIndex : url.length, hashIndex >= 0 ? hashIndex : url.length);
|
|
1030
|
+
return url.slice(0, end);
|
|
1031
|
+
}
|
|
1032
|
+
function defaultLevel$3(status, error) {
|
|
1033
|
+
if (error || status === void 0 || status >= 500) return "error";
|
|
1034
|
+
if (status >= 400) return "warn";
|
|
1035
|
+
return "info";
|
|
1036
|
+
}
|
|
1037
|
+
function isUrlLike$1(value) {
|
|
1038
|
+
return typeof URL !== "undefined" && value instanceof URL;
|
|
1039
|
+
}
|
|
1040
|
+
function isObject(value) {
|
|
1041
|
+
return typeof value === "object" && value !== null;
|
|
1042
|
+
}
|
|
1043
|
+
function headerValue$1(headers, name) {
|
|
1044
|
+
if (!isObject(headers)) return void 0;
|
|
1045
|
+
if (typeof headers.get === "function") return headers.get?.(name) ?? void 0;
|
|
1046
|
+
const value = headers[name.toLowerCase()] ?? headers[name];
|
|
1047
|
+
return value === void 0 ? void 0 : String(value);
|
|
1048
|
+
}
|
|
1049
|
+
function pickHeaders$1(headers, names) {
|
|
1050
|
+
if (!names || names.length === 0) return void 0;
|
|
1051
|
+
const out = {};
|
|
1052
|
+
for (const name of names) {
|
|
1053
|
+
const lowerName = name.toLowerCase();
|
|
1054
|
+
const value = headerValue$1(headers, lowerName) ?? headerValue$1(headers, name);
|
|
1055
|
+
if (value !== void 0) out[lowerName] = value;
|
|
1056
|
+
}
|
|
1057
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
1058
|
+
}
|
|
1059
|
+
function requestInfo$1(input, init, sanitizeUrl, captureRequestHeaders) {
|
|
1060
|
+
const request = isObject(input) && !isUrlLike$1(input) ? input : void 0;
|
|
1061
|
+
return {
|
|
1062
|
+
method: (init?.method ?? request?.method ?? "GET").toUpperCase(),
|
|
1063
|
+
url: sanitizeUrl(isUrlLike$1(input) ? input.href : typeof input === "string" ? input : request?.url ?? "/"),
|
|
1064
|
+
requestHeaders: pickHeaders$1(init?.headers ?? request?.headers, captureRequestHeaders)
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
function statusMessage$1(status) {
|
|
1068
|
+
return status === void 0 ? "unknown" : String(status);
|
|
1069
|
+
}
|
|
1070
|
+
function nodeFetchIntegration(options = {}) {
|
|
1071
|
+
const name = options.name ?? "node-fetch";
|
|
1072
|
+
const minStatus = options.minStatus ?? 400;
|
|
1073
|
+
const captureAll = options.captureAll ?? options.captureSuccessful ?? false;
|
|
1074
|
+
const sampleRate = options.sampleRate ?? 1;
|
|
1075
|
+
const random = options.random ?? defaultRandom$3;
|
|
1076
|
+
const sanitizeUrl = options.sanitizeUrl ?? defaultSanitizeUrl$1;
|
|
1077
|
+
const levelFor = options.level ?? defaultLevel$3;
|
|
1078
|
+
const shouldCapture = (status, error) => {
|
|
1079
|
+
if (error) return true;
|
|
1080
|
+
if (status !== void 0 && status >= minStatus) return true;
|
|
1081
|
+
if (!captureAll) return false;
|
|
1082
|
+
return sampleRate >= 1 || random() < sampleRate;
|
|
1083
|
+
};
|
|
1084
|
+
return {
|
|
1085
|
+
name: "node-fetch",
|
|
1086
|
+
setup(api) {
|
|
1087
|
+
const target = options.target ?? globalThis;
|
|
1088
|
+
if (!target.fetch) return;
|
|
1089
|
+
const originalFetch = target.fetch;
|
|
1090
|
+
const capture = api.guard((input) => api.capture(input));
|
|
1091
|
+
let disposed = false;
|
|
1092
|
+
const captureResult = (info, durationMs, status, error, responseHeaders) => {
|
|
1093
|
+
if (disposed || !shouldCapture(status, error)) return;
|
|
1094
|
+
capture({
|
|
1095
|
+
level: levelFor(status, error, info),
|
|
1096
|
+
message: error ? `Fetch error ${info.method} ${info.url}` : `Fetch ${statusMessage$1(status)} ${info.method} ${info.url}`,
|
|
1097
|
+
error,
|
|
1098
|
+
props: { http: {
|
|
1099
|
+
kind: name,
|
|
1100
|
+
runtime: "node",
|
|
1101
|
+
instrument: "fetch",
|
|
1102
|
+
direction: "outgoing",
|
|
1103
|
+
method: info.method,
|
|
1104
|
+
url: info.url,
|
|
1105
|
+
status,
|
|
1106
|
+
durationMs,
|
|
1107
|
+
requestHeaders: info.requestHeaders,
|
|
1108
|
+
responseHeaders
|
|
1109
|
+
} }
|
|
1110
|
+
});
|
|
1111
|
+
};
|
|
1112
|
+
target.fetch = async function patchedFetch(input, init) {
|
|
1113
|
+
const started = Date.now();
|
|
1114
|
+
const info = requestInfo$1(input, init, sanitizeUrl, options.captureRequestHeaders);
|
|
1115
|
+
try {
|
|
1116
|
+
const response = await originalFetch.call(this, input, init);
|
|
1117
|
+
captureResult(info, Date.now() - started, response.status, void 0, pickHeaders$1(response.headers, options.captureResponseHeaders));
|
|
1118
|
+
return response;
|
|
1119
|
+
} catch (error) {
|
|
1120
|
+
captureResult(info, Date.now() - started, void 0, error);
|
|
1121
|
+
throw error;
|
|
1122
|
+
}
|
|
1123
|
+
};
|
|
1124
|
+
return () => {
|
|
1125
|
+
if (disposed) return;
|
|
1126
|
+
disposed = true;
|
|
1127
|
+
target.fetch = originalFetch;
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
};
|
|
1131
|
+
}
|
|
1132
|
+
//#endregion
|
|
1133
|
+
//#region src/node-http-client-integration.ts
|
|
1134
|
+
const requireBuiltin$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
1135
|
+
const defaultRandom$2 = () => Math.random();
|
|
1136
|
+
let cachedHttpModule;
|
|
1137
|
+
let cachedHttpsModule;
|
|
1138
|
+
function loadBuiltin(name, fallback) {
|
|
1139
|
+
try {
|
|
1140
|
+
return requireBuiltin$1(name);
|
|
1141
|
+
} catch {
|
|
1142
|
+
try {
|
|
1143
|
+
return requireBuiltin$1(fallback);
|
|
1144
|
+
} catch {
|
|
1145
|
+
return null;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
function loadHttpModule() {
|
|
1150
|
+
if (cachedHttpModule !== void 0) return cachedHttpModule;
|
|
1151
|
+
cachedHttpModule = loadBuiltin("node:http", "http");
|
|
1152
|
+
return cachedHttpModule;
|
|
1153
|
+
}
|
|
1154
|
+
function loadHttpsModule() {
|
|
1155
|
+
if (cachedHttpsModule !== void 0) return cachedHttpsModule;
|
|
1156
|
+
cachedHttpsModule = loadBuiltin("node:https", "https");
|
|
1157
|
+
return cachedHttpsModule;
|
|
1158
|
+
}
|
|
1159
|
+
function defaultSanitizeUrl(url) {
|
|
1160
|
+
const queryIndex = url.indexOf("?");
|
|
1161
|
+
const hashIndex = url.indexOf("#");
|
|
1162
|
+
const end = Math.min(queryIndex >= 0 ? queryIndex : url.length, hashIndex >= 0 ? hashIndex : url.length);
|
|
1163
|
+
return url.slice(0, end);
|
|
1164
|
+
}
|
|
1165
|
+
function defaultLevel$2(status, error) {
|
|
1166
|
+
if (error || status === void 0 || status >= 500) return "error";
|
|
1167
|
+
if (status >= 400) return "warn";
|
|
1168
|
+
return "info";
|
|
1169
|
+
}
|
|
1170
|
+
function isUrlLike(value) {
|
|
1171
|
+
return typeof URL !== "undefined" && value instanceof URL;
|
|
1172
|
+
}
|
|
1173
|
+
function isOptionsObject(value) {
|
|
1174
|
+
return typeof value === "object" && value !== null && !isUrlLike(value);
|
|
1175
|
+
}
|
|
1176
|
+
function headerValue(value) {
|
|
1177
|
+
if (value === void 0) return void 0;
|
|
1178
|
+
if (Array.isArray(value)) return value.map(String);
|
|
1179
|
+
return String(value);
|
|
1180
|
+
}
|
|
1181
|
+
function pickHeaders(headers, names) {
|
|
1182
|
+
if (!names || names.length === 0 || !isOptionsObject(headers)) return void 0;
|
|
1183
|
+
const out = {};
|
|
1184
|
+
for (const name of names) {
|
|
1185
|
+
const lowerName = name.toLowerCase();
|
|
1186
|
+
const value = headerValue(headers[lowerName] ?? headers[name]);
|
|
1187
|
+
if (value !== void 0) out[lowerName] = value;
|
|
1188
|
+
}
|
|
1189
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
1190
|
+
}
|
|
1191
|
+
function maybeUrl(value) {
|
|
1192
|
+
if (isUrlLike(value)) return value;
|
|
1193
|
+
if (typeof value !== "string") return void 0;
|
|
1194
|
+
try {
|
|
1195
|
+
return new URL(value);
|
|
1196
|
+
} catch {
|
|
1197
|
+
return;
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
function pathFromUrl(url) {
|
|
1201
|
+
if (!url) return "/";
|
|
1202
|
+
return `${url.pathname || "/"}${url.search}`;
|
|
1203
|
+
}
|
|
1204
|
+
function optionString(options, key) {
|
|
1205
|
+
const value = options[key];
|
|
1206
|
+
if (value === void 0) return void 0;
|
|
1207
|
+
return String(value);
|
|
1208
|
+
}
|
|
1209
|
+
function requestInfo(args, defaultProtocol, sanitizeUrl, captureRequestHeaders) {
|
|
1210
|
+
const first = args[0];
|
|
1211
|
+
const second = args[1];
|
|
1212
|
+
const parsed = maybeUrl(first);
|
|
1213
|
+
const options = isOptionsObject(first) ? first : isOptionsObject(second) ? second : void 0;
|
|
1214
|
+
const protocol = optionString(options ?? {}, "protocol") ?? parsed?.protocol ?? defaultProtocol;
|
|
1215
|
+
const method = (optionString(options ?? {}, "method") ?? "GET").toUpperCase();
|
|
1216
|
+
const host = optionString(options ?? {}, "host") ?? optionString(options ?? {}, "hostname") ?? parsed?.host;
|
|
1217
|
+
const port = optionString(options ?? {}, "port");
|
|
1218
|
+
const path = optionString(options ?? {}, "path") ?? pathFromUrl(parsed);
|
|
1219
|
+
const requestHeaders = pickHeaders(options?.headers, captureRequestHeaders);
|
|
1220
|
+
return {
|
|
1221
|
+
protocol,
|
|
1222
|
+
method,
|
|
1223
|
+
url: sanitizeUrl(parsed?.href ?? (host ? `${protocol}//${host}${port ? `:${port}` : ""}${path}` : path)),
|
|
1224
|
+
requestHeaders
|
|
1225
|
+
};
|
|
1226
|
+
}
|
|
1227
|
+
function listenOnce(request, event, listener) {
|
|
1228
|
+
let active = true;
|
|
1229
|
+
const wrapped = (...args) => {
|
|
1230
|
+
if (!active) return;
|
|
1231
|
+
active = false;
|
|
1232
|
+
cleanup();
|
|
1233
|
+
listener(...args);
|
|
1234
|
+
};
|
|
1235
|
+
const cleanup = () => {
|
|
1236
|
+
request.off?.(event, wrapped);
|
|
1237
|
+
request.removeListener?.(event, wrapped);
|
|
1238
|
+
};
|
|
1239
|
+
if (request.once) request.once(event, wrapped);
|
|
1240
|
+
else request.on?.(event, wrapped);
|
|
1241
|
+
}
|
|
1242
|
+
function statusMessage(status) {
|
|
1243
|
+
return status === void 0 ? "unknown" : String(status);
|
|
1244
|
+
}
|
|
1245
|
+
function nodeHttpClientIntegration(options = {}) {
|
|
1246
|
+
const name = options.name ?? "node-http-client";
|
|
1247
|
+
const minStatus = options.minStatus ?? 400;
|
|
1248
|
+
const captureAll = options.captureAll ?? options.captureSuccessful ?? false;
|
|
1249
|
+
const sampleRate = options.sampleRate ?? 1;
|
|
1250
|
+
const random = options.random ?? defaultRandom$2;
|
|
1251
|
+
const sanitizeUrl = options.sanitizeUrl ?? defaultSanitizeUrl;
|
|
1252
|
+
const levelFor = options.level ?? defaultLevel$2;
|
|
1253
|
+
const shouldCapture = (status, error) => {
|
|
1254
|
+
if (error) return true;
|
|
1255
|
+
if (status !== void 0 && status >= minStatus) return true;
|
|
1256
|
+
if (!captureAll) return false;
|
|
1257
|
+
return sampleRate >= 1 || random() < sampleRate;
|
|
1258
|
+
};
|
|
1259
|
+
return {
|
|
1260
|
+
name: "node-http-client",
|
|
1261
|
+
setup(api) {
|
|
1262
|
+
const httpModule = options.httpModule === void 0 ? loadHttpModule() : options.httpModule;
|
|
1263
|
+
const httpsModule = options.httpsModule === void 0 ? loadHttpsModule() : options.httpsModule;
|
|
1264
|
+
const capture = api.guard((input) => api.capture(input));
|
|
1265
|
+
const disposers = [];
|
|
1266
|
+
let disposed = false;
|
|
1267
|
+
const captureResult = (info, status, error, responseHeaders) => {
|
|
1268
|
+
if (disposed || !shouldCapture(status, error)) return;
|
|
1269
|
+
capture({
|
|
1270
|
+
level: levelFor(status, error, info),
|
|
1271
|
+
message: error ? `HTTP error ${info.method} ${info.url}` : `HTTP ${statusMessage(status)} ${info.method} ${info.url}`,
|
|
1272
|
+
error,
|
|
1273
|
+
props: { http: {
|
|
1274
|
+
kind: name,
|
|
1275
|
+
runtime: "node",
|
|
1276
|
+
direction: "outgoing",
|
|
1277
|
+
protocol: info.protocol,
|
|
1278
|
+
method: info.method,
|
|
1279
|
+
url: info.url,
|
|
1280
|
+
status,
|
|
1281
|
+
requestHeaders: info.requestHeaders,
|
|
1282
|
+
responseHeaders
|
|
1283
|
+
} }
|
|
1284
|
+
});
|
|
1285
|
+
};
|
|
1286
|
+
const patchModule = (module, defaultProtocol) => {
|
|
1287
|
+
if (!module?.request) return;
|
|
1288
|
+
const originalRequest = module.request;
|
|
1289
|
+
const originalGet = module.get;
|
|
1290
|
+
module.request = function patchedRequest(...args) {
|
|
1291
|
+
const info = requestInfo(args, defaultProtocol, sanitizeUrl, options.captureRequestHeaders);
|
|
1292
|
+
const request = originalRequest.apply(this, args);
|
|
1293
|
+
listenOnce(request, "response", (message) => {
|
|
1294
|
+
const response = message;
|
|
1295
|
+
captureResult(info, response.statusCode, void 0, pickHeaders(response.headers, options.captureResponseHeaders));
|
|
1296
|
+
});
|
|
1297
|
+
listenOnce(request, "error", (error) => captureResult(info, void 0, error));
|
|
1298
|
+
return request;
|
|
1299
|
+
};
|
|
1300
|
+
if (originalGet) module.get = function patchedGet(...args) {
|
|
1301
|
+
const request = module.request?.apply(this, args) ?? originalGet.apply(this, args);
|
|
1302
|
+
request.end?.();
|
|
1303
|
+
return request;
|
|
1304
|
+
};
|
|
1305
|
+
disposers.push(() => {
|
|
1306
|
+
module.request = originalRequest;
|
|
1307
|
+
if (originalGet) module.get = originalGet;
|
|
1308
|
+
});
|
|
1309
|
+
};
|
|
1310
|
+
patchModule(httpModule, "http:");
|
|
1311
|
+
patchModule(httpsModule, "https:");
|
|
1312
|
+
return () => {
|
|
1313
|
+
if (disposed) return;
|
|
1314
|
+
disposed = true;
|
|
1315
|
+
for (const dispose of disposers) dispose();
|
|
1316
|
+
};
|
|
1317
|
+
}
|
|
1318
|
+
};
|
|
1319
|
+
}
|
|
1320
|
+
//#endregion
|
|
1321
|
+
//#region src/process-integration.ts
|
|
1322
|
+
function captureProcessIntegration(options = {}) {
|
|
1323
|
+
const uncaughtException = options.uncaughtException ?? true;
|
|
1324
|
+
const unhandledRejection = options.unhandledRejection ?? true;
|
|
1325
|
+
const warning = options.warning ?? true;
|
|
1326
|
+
const beforeExitFlush = options.beforeExitFlush ?? true;
|
|
1327
|
+
const exitFlush = options.exitFlush ?? true;
|
|
1328
|
+
const exitOnUncaught = options.exitOnUncaught ?? true;
|
|
1329
|
+
const flushTimeoutMs = options.flushTimeoutMs ?? 250;
|
|
1330
|
+
const exitFn = options.exitFn ?? ((code) => process.exit(code));
|
|
1331
|
+
return {
|
|
1332
|
+
name: "capture-process",
|
|
1333
|
+
setup(api) {
|
|
1334
|
+
const disposers = [];
|
|
1335
|
+
let disposed = false;
|
|
1336
|
+
const capture = api.guard((input) => api.capture(input));
|
|
1337
|
+
const flushSync = () => {
|
|
1338
|
+
try {
|
|
1339
|
+
api.flushSync?.();
|
|
1340
|
+
} catch {}
|
|
1341
|
+
};
|
|
1342
|
+
const flushBounded = async () => {
|
|
1343
|
+
let timer;
|
|
1344
|
+
try {
|
|
1345
|
+
await Promise.race([api.flush(), new Promise((resolve) => {
|
|
1346
|
+
timer = setTimeout(resolve, flushTimeoutMs);
|
|
1347
|
+
})]);
|
|
1348
|
+
} catch {} finally {
|
|
1349
|
+
if (timer) clearTimeout(timer);
|
|
1350
|
+
}
|
|
1351
|
+
};
|
|
1352
|
+
const flushBestEffort = () => {
|
|
1353
|
+
flushSync();
|
|
1354
|
+
flushBounded();
|
|
1355
|
+
};
|
|
1356
|
+
if (uncaughtException) {
|
|
1357
|
+
const onUncaughtException = (error) => {
|
|
1358
|
+
capture({
|
|
1359
|
+
level: "fatal",
|
|
1360
|
+
message: error.message,
|
|
1361
|
+
error,
|
|
1362
|
+
props: { process: { kind: "uncaughtException" } }
|
|
1363
|
+
});
|
|
1364
|
+
flushSync();
|
|
1365
|
+
const flushed = flushBounded();
|
|
1366
|
+
if (exitOnUncaught) flushed.finally(() => exitFn(1));
|
|
1367
|
+
};
|
|
1368
|
+
process.on("uncaughtException", onUncaughtException);
|
|
1369
|
+
disposers.push(() => process.off("uncaughtException", onUncaughtException));
|
|
1370
|
+
}
|
|
1371
|
+
if (unhandledRejection) {
|
|
1372
|
+
const onUnhandledRejection = (reason) => {
|
|
1373
|
+
capture({
|
|
1374
|
+
level: "error",
|
|
1375
|
+
message: reason instanceof Error ? reason.message : "Unhandled promise rejection",
|
|
1376
|
+
error: reason,
|
|
1377
|
+
props: {
|
|
1378
|
+
process: { kind: "unhandledRejection" },
|
|
1379
|
+
reason: (0, _loggerjs_core.normalizeValue)(reason, { maxDepth: 5 })
|
|
1380
|
+
}
|
|
1381
|
+
});
|
|
1382
|
+
flushBestEffort();
|
|
1383
|
+
};
|
|
1384
|
+
process.on("unhandledRejection", onUnhandledRejection);
|
|
1385
|
+
disposers.push(() => process.off("unhandledRejection", onUnhandledRejection));
|
|
1386
|
+
}
|
|
1387
|
+
if (warning) {
|
|
1388
|
+
const onWarning = (warn) => {
|
|
1389
|
+
capture({
|
|
1390
|
+
level: "warn",
|
|
1391
|
+
message: warn.message,
|
|
1392
|
+
error: warn,
|
|
1393
|
+
props: { process: {
|
|
1394
|
+
kind: "warning",
|
|
1395
|
+
name: warn.name,
|
|
1396
|
+
code: warn.code
|
|
1397
|
+
} }
|
|
1398
|
+
});
|
|
1399
|
+
};
|
|
1400
|
+
process.on("warning", onWarning);
|
|
1401
|
+
disposers.push(() => process.off("warning", onWarning));
|
|
1402
|
+
}
|
|
1403
|
+
if (beforeExitFlush) {
|
|
1404
|
+
const onBeforeExit = () => {
|
|
1405
|
+
flushBounded();
|
|
1406
|
+
};
|
|
1407
|
+
process.on("beforeExit", onBeforeExit);
|
|
1408
|
+
disposers.push(() => process.off("beforeExit", onBeforeExit));
|
|
1409
|
+
}
|
|
1410
|
+
if (exitFlush) {
|
|
1411
|
+
const onExit = () => {
|
|
1412
|
+
flushSync();
|
|
1413
|
+
};
|
|
1414
|
+
process.on("exit", onExit);
|
|
1415
|
+
disposers.push(() => process.off("exit", onExit));
|
|
1416
|
+
}
|
|
1417
|
+
return () => {
|
|
1418
|
+
if (disposed) return;
|
|
1419
|
+
disposed = true;
|
|
1420
|
+
for (const dispose of disposers) dispose();
|
|
1421
|
+
};
|
|
1422
|
+
}
|
|
1423
|
+
};
|
|
1424
|
+
}
|
|
1425
|
+
//#endregion
|
|
1426
|
+
//#region src/queue-integration.ts
|
|
1427
|
+
const defaultMethods = [
|
|
1428
|
+
"add",
|
|
1429
|
+
"ack",
|
|
1430
|
+
"consume",
|
|
1431
|
+
"dequeue",
|
|
1432
|
+
"nack",
|
|
1433
|
+
"process",
|
|
1434
|
+
"publish",
|
|
1435
|
+
"receive",
|
|
1436
|
+
"send",
|
|
1437
|
+
"sendToQueue"
|
|
1438
|
+
];
|
|
1439
|
+
const defaultRandom$1 = () => Math.random();
|
|
1440
|
+
function defaultLevel$1(_durationMs, error) {
|
|
1441
|
+
return error ? "error" : "debug";
|
|
1442
|
+
}
|
|
1443
|
+
function isPromiseLike$1(value) {
|
|
1444
|
+
return typeof value === "object" && value !== null && typeof value.then === "function";
|
|
1445
|
+
}
|
|
1446
|
+
function defaultOperation$1(method) {
|
|
1447
|
+
switch (method) {
|
|
1448
|
+
case "add":
|
|
1449
|
+
case "publish":
|
|
1450
|
+
case "send":
|
|
1451
|
+
case "sendToQueue": return "publish";
|
|
1452
|
+
case "consume":
|
|
1453
|
+
case "dequeue":
|
|
1454
|
+
case "process":
|
|
1455
|
+
case "receive": return "consume";
|
|
1456
|
+
case "ack": return "ack";
|
|
1457
|
+
case "nack": return "nack";
|
|
1458
|
+
default: return "other";
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
function defaultPayload(args) {
|
|
1462
|
+
return typeof args[0] === "string" && args.length > 1 ? args[1] : args[0];
|
|
1463
|
+
}
|
|
1464
|
+
function defaultMessageId(args) {
|
|
1465
|
+
const payload = defaultPayload(args);
|
|
1466
|
+
if (typeof payload !== "object" || payload === null) return void 0;
|
|
1467
|
+
const value = payload.messageId ?? payload.id;
|
|
1468
|
+
return value === void 0 ? void 0 : String(value);
|
|
1469
|
+
}
|
|
1470
|
+
function payloadFor(args, method, options) {
|
|
1471
|
+
if (!options.capturePayload) return void 0;
|
|
1472
|
+
const payload = options.getPayload?.(args, method) ?? defaultPayload(args);
|
|
1473
|
+
return payload === void 0 ? void 0 : (0, _loggerjs_core.normalizeValue)(payload, {
|
|
1474
|
+
maxDepth: 4,
|
|
1475
|
+
maxObjectKeys: 80
|
|
1476
|
+
});
|
|
1477
|
+
}
|
|
1478
|
+
function queueIntegration(options = {}) {
|
|
1479
|
+
const targets = options.targets ?? (options.client ? [{
|
|
1480
|
+
client: options.client,
|
|
1481
|
+
name: options.name,
|
|
1482
|
+
system: options.system,
|
|
1483
|
+
queueName: options.queueName,
|
|
1484
|
+
methods: options.methods
|
|
1485
|
+
}] : []);
|
|
1486
|
+
const captureAll = options.captureAll ?? options.captureSuccessful ?? false;
|
|
1487
|
+
const sampleRate = options.sampleRate ?? 1;
|
|
1488
|
+
const random = options.random ?? defaultRandom$1;
|
|
1489
|
+
const levelFor = options.level ?? defaultLevel$1;
|
|
1490
|
+
const shouldCapture = (durationMs, error) => {
|
|
1491
|
+
if (error) return true;
|
|
1492
|
+
if (options.minDurationMs !== void 0 && durationMs >= options.minDurationMs) return true;
|
|
1493
|
+
if (!captureAll) return false;
|
|
1494
|
+
return sampleRate >= 1 || random() < sampleRate;
|
|
1495
|
+
};
|
|
1496
|
+
return {
|
|
1497
|
+
name: "queue",
|
|
1498
|
+
setup(api) {
|
|
1499
|
+
const capture = api.guard((input) => api.capture(input));
|
|
1500
|
+
const disposers = [];
|
|
1501
|
+
let disposed = false;
|
|
1502
|
+
const captureResult = (info, started, args, error) => {
|
|
1503
|
+
const durationMs = Date.now() - started;
|
|
1504
|
+
if (disposed || !shouldCapture(durationMs, error)) return;
|
|
1505
|
+
capture({
|
|
1506
|
+
level: levelFor(durationMs, error, info),
|
|
1507
|
+
message: error ? `Queue error ${info.operation} ${info.queueName ?? info.method}` : `Queue ${info.operation} ${info.queueName ?? info.method}`,
|
|
1508
|
+
error,
|
|
1509
|
+
props: { queue: {
|
|
1510
|
+
kind: info.target,
|
|
1511
|
+
system: info.system,
|
|
1512
|
+
queueName: info.queueName,
|
|
1513
|
+
method: info.method,
|
|
1514
|
+
operation: info.operation,
|
|
1515
|
+
durationMs,
|
|
1516
|
+
messageId: options.getMessageId?.(args, info.method) ?? defaultMessageId(args),
|
|
1517
|
+
payload: payloadFor(args, info.method, options)
|
|
1518
|
+
} }
|
|
1519
|
+
});
|
|
1520
|
+
};
|
|
1521
|
+
for (const target of targets) {
|
|
1522
|
+
const methods = target.methods ?? options.methods ?? defaultMethods;
|
|
1523
|
+
for (const method of methods) {
|
|
1524
|
+
const original = target.client[method];
|
|
1525
|
+
if (typeof original !== "function") continue;
|
|
1526
|
+
const originalMethod = original;
|
|
1527
|
+
const targetName = target.name ?? options.name ?? "queue";
|
|
1528
|
+
const system = target.system ?? options.system;
|
|
1529
|
+
target.client[method] = function wrappedQueueMethod(...args) {
|
|
1530
|
+
const started = Date.now();
|
|
1531
|
+
const operation = options.getOperation?.(method, args) ?? defaultOperation$1(method);
|
|
1532
|
+
const info = {
|
|
1533
|
+
target: targetName,
|
|
1534
|
+
system,
|
|
1535
|
+
queueName: options.getQueueName?.(args, method) ?? target.queueName ?? options.queueName ?? (typeof args[0] === "string" ? args[0] : void 0),
|
|
1536
|
+
method,
|
|
1537
|
+
operation
|
|
1538
|
+
};
|
|
1539
|
+
try {
|
|
1540
|
+
const result = originalMethod.apply(this, args);
|
|
1541
|
+
if (isPromiseLike$1(result)) return result.then((value) => {
|
|
1542
|
+
captureResult(info, started, args, void 0);
|
|
1543
|
+
return value;
|
|
1544
|
+
}, (error) => {
|
|
1545
|
+
captureResult(info, started, args, error);
|
|
1546
|
+
throw error;
|
|
1547
|
+
});
|
|
1548
|
+
captureResult(info, started, args, void 0);
|
|
1549
|
+
return result;
|
|
1550
|
+
} catch (error) {
|
|
1551
|
+
captureResult(info, started, args, error);
|
|
1552
|
+
throw error;
|
|
1553
|
+
}
|
|
1554
|
+
};
|
|
1555
|
+
disposers.push(() => {
|
|
1556
|
+
target.client[method] = originalMethod;
|
|
1557
|
+
});
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
return () => {
|
|
1561
|
+
if (disposed) return;
|
|
1562
|
+
disposed = true;
|
|
1563
|
+
for (const dispose of disposers) dispose();
|
|
1564
|
+
};
|
|
1565
|
+
}
|
|
1566
|
+
};
|
|
1567
|
+
}
|
|
1568
|
+
//#endregion
|
|
1569
|
+
//#region src/serverless-integration.ts
|
|
1570
|
+
const defaultRandom = () => Math.random();
|
|
1571
|
+
let coldStart = true;
|
|
1572
|
+
function isPromiseLike(value) {
|
|
1573
|
+
return typeof value === "object" && value !== null && typeof value.then === "function";
|
|
1574
|
+
}
|
|
1575
|
+
function defaultLevel(error) {
|
|
1576
|
+
return error ? "error" : "info";
|
|
1577
|
+
}
|
|
1578
|
+
function defaultRequestId(event, context) {
|
|
1579
|
+
const ctx = context;
|
|
1580
|
+
const evt = event;
|
|
1581
|
+
return ctx?.awsRequestId ?? evt?.requestContext?.requestId ?? evt?.headers?.["x-request-id"] ?? evt?.headers?.["X-Request-Id"];
|
|
1582
|
+
}
|
|
1583
|
+
function defaultOperation(event, context) {
|
|
1584
|
+
const ctx = context;
|
|
1585
|
+
const evt = event;
|
|
1586
|
+
return evt?.routeKey ?? evt?.requestContext?.routeKey ?? (evt?.requestContext?.http?.method && evt.requestContext.http.path ? `${evt.requestContext.http.method} ${evt.requestContext.http.path}` : void 0) ?? (evt?.httpMethod && (evt.rawPath ?? evt.path) ? `${evt.httpMethod} ${evt.rawPath ?? evt.path}` : void 0) ?? ctx?.functionName;
|
|
1587
|
+
}
|
|
1588
|
+
function normalizeUnknown(value) {
|
|
1589
|
+
return (0, _loggerjs_core.normalizeValue)(value, {
|
|
1590
|
+
maxDepth: 5,
|
|
1591
|
+
maxObjectKeys: 120
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
1594
|
+
function serverlessIntegration(logger, handler, options = {}) {
|
|
1595
|
+
const name = options.name ?? "serverless";
|
|
1596
|
+
const platform = options.platform ?? "serverless";
|
|
1597
|
+
const captureSuccessful = options.captureSuccessful ?? options.captureAll ?? true;
|
|
1598
|
+
const sampleRate = options.sampleRate ?? 1;
|
|
1599
|
+
const random = options.random ?? defaultRandom;
|
|
1600
|
+
const bindContext = options.bindContext ?? true;
|
|
1601
|
+
const levelFor = options.level ?? defaultLevel;
|
|
1602
|
+
return (event, context, callback) => {
|
|
1603
|
+
const started = Date.now();
|
|
1604
|
+
const currentColdStart = coldStart;
|
|
1605
|
+
coldStart = false;
|
|
1606
|
+
const requestId = options.getRequestId?.(event, context) ?? defaultRequestId(event, context);
|
|
1607
|
+
const operation = options.getOperation?.(event, context) ?? defaultOperation(event, context);
|
|
1608
|
+
let captured = false;
|
|
1609
|
+
const shouldCapture = (error) => {
|
|
1610
|
+
if (error) return true;
|
|
1611
|
+
if (!captureSuccessful) return false;
|
|
1612
|
+
return sampleRate >= 1 || random() < sampleRate;
|
|
1613
|
+
};
|
|
1614
|
+
const capture = (error, result) => {
|
|
1615
|
+
if (captured || !shouldCapture(error)) return;
|
|
1616
|
+
captured = true;
|
|
1617
|
+
const durationMs = Date.now() - started;
|
|
1618
|
+
const info = {
|
|
1619
|
+
context,
|
|
1620
|
+
event,
|
|
1621
|
+
operation,
|
|
1622
|
+
requestId
|
|
1623
|
+
};
|
|
1624
|
+
logger.log(levelFor(error, durationMs, info), `Serverless ${operation ?? name}`, {
|
|
1625
|
+
error,
|
|
1626
|
+
serverless: {
|
|
1627
|
+
kind: name,
|
|
1628
|
+
platform,
|
|
1629
|
+
operation,
|
|
1630
|
+
requestId,
|
|
1631
|
+
coldStart: currentColdStart,
|
|
1632
|
+
durationMs,
|
|
1633
|
+
event: options.captureEvent ? options.normalizeEvent?.(event) ?? normalizeUnknown(event) : void 0,
|
|
1634
|
+
result: options.captureResult && result !== void 0 ? options.normalizeResult?.(result) ?? normalizeUnknown(result) : void 0
|
|
1635
|
+
}
|
|
1636
|
+
});
|
|
1637
|
+
};
|
|
1638
|
+
const wrappedCallback = callback ? (error, result) => {
|
|
1639
|
+
capture(error, result);
|
|
1640
|
+
callback(error, result);
|
|
1641
|
+
} : void 0;
|
|
1642
|
+
const invoke = () => {
|
|
1643
|
+
try {
|
|
1644
|
+
const result = handler(event, context, wrappedCallback);
|
|
1645
|
+
if (isPromiseLike(result)) return result.then((value) => {
|
|
1646
|
+
capture(void 0, value);
|
|
1647
|
+
return value;
|
|
1648
|
+
}, (error) => {
|
|
1649
|
+
capture(error);
|
|
1650
|
+
throw error;
|
|
1651
|
+
});
|
|
1652
|
+
if (result !== void 0 || !wrappedCallback) capture(void 0, result);
|
|
1653
|
+
return result;
|
|
1654
|
+
} catch (error) {
|
|
1655
|
+
capture(error);
|
|
1656
|
+
throw error;
|
|
1657
|
+
}
|
|
1658
|
+
};
|
|
1659
|
+
if (!bindContext) return invoke();
|
|
1660
|
+
return (0, _loggerjs_core.withContext)({
|
|
1661
|
+
functionName: context?.functionName,
|
|
1662
|
+
requestId,
|
|
1663
|
+
serverlessPlatform: platform
|
|
1664
|
+
}, invoke);
|
|
1665
|
+
};
|
|
1666
|
+
}
|
|
1667
|
+
//#endregion
|
|
1668
|
+
//#region src/diagnostics-channel-integration.ts
|
|
1669
|
+
const defaultChannels = [
|
|
1670
|
+
"http.client.request.start",
|
|
1671
|
+
"http.client.response.finish",
|
|
1672
|
+
"http.server.request.start",
|
|
1673
|
+
"http.server.response.finish",
|
|
1674
|
+
"undici:request:create",
|
|
1675
|
+
"undici:request:headers",
|
|
1676
|
+
"undici:request:trailers",
|
|
1677
|
+
"undici:request:error"
|
|
1678
|
+
];
|
|
1679
|
+
const requireBuiltin = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
1680
|
+
let cachedDiagnosticsChannel;
|
|
1681
|
+
function diagnosticsChannelIntegration(options = {}) {
|
|
1682
|
+
const channels = options.channels ?? defaultChannels;
|
|
1683
|
+
const captureMessage = options.captureMessage ?? false;
|
|
1684
|
+
return {
|
|
1685
|
+
name: "diagnostics-channel",
|
|
1686
|
+
setup(api) {
|
|
1687
|
+
const diagnosticsChannel = options.diagnosticsChannel === void 0 ? loadDiagnosticsChannel() : options.diagnosticsChannel;
|
|
1688
|
+
if (!diagnosticsChannel) return;
|
|
1689
|
+
const disposers = [];
|
|
1690
|
+
let disposed = false;
|
|
1691
|
+
const capture = api.guard((input) => api.capture(input));
|
|
1692
|
+
for (const channel of channels) {
|
|
1693
|
+
const listener = (message, name) => {
|
|
1694
|
+
capture({
|
|
1695
|
+
level: name.endsWith(":error") ? "error" : "debug",
|
|
1696
|
+
message: `diagnostics_channel ${name}`,
|
|
1697
|
+
props: { diagnostics: {
|
|
1698
|
+
channel: name,
|
|
1699
|
+
message: captureMessage ? (0, _loggerjs_core.normalizeValue)(message, { maxDepth: 4 }) : void 0
|
|
1700
|
+
} }
|
|
1701
|
+
});
|
|
1702
|
+
};
|
|
1703
|
+
diagnosticsChannel.subscribe(channel, listener);
|
|
1704
|
+
disposers.push(() => diagnosticsChannel.unsubscribe?.(channel, listener));
|
|
1705
|
+
}
|
|
1706
|
+
return () => {
|
|
1707
|
+
if (disposed) return;
|
|
1708
|
+
disposed = true;
|
|
1709
|
+
for (const dispose of disposers) dispose();
|
|
1710
|
+
};
|
|
1711
|
+
}
|
|
1712
|
+
};
|
|
1713
|
+
}
|
|
1714
|
+
function loadDiagnosticsChannel() {
|
|
1715
|
+
if (cachedDiagnosticsChannel !== void 0) return cachedDiagnosticsChannel;
|
|
1716
|
+
try {
|
|
1717
|
+
cachedDiagnosticsChannel = requireBuiltin("node:diagnostics_channel");
|
|
1718
|
+
} catch {
|
|
1719
|
+
try {
|
|
1720
|
+
cachedDiagnosticsChannel = requireBuiltin("diagnostics_channel");
|
|
1721
|
+
} catch {
|
|
1722
|
+
cachedDiagnosticsChannel = null;
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
return cachedDiagnosticsChannel;
|
|
1726
|
+
}
|
|
1727
|
+
//#endregion
|
|
1728
|
+
exports.captureCliIntegration = captureCliIntegration;
|
|
1729
|
+
exports.captureProcessIntegration = captureProcessIntegration;
|
|
1730
|
+
exports.createAsyncLocalStorageContextManager = createAsyncLocalStorageContextManager;
|
|
1731
|
+
exports.databaseIntegration = databaseIntegration;
|
|
1732
|
+
exports.diagnosticsChannelIntegration = diagnosticsChannelIntegration;
|
|
1733
|
+
exports.expressIntegration = expressIntegration;
|
|
1734
|
+
exports.fastifyIntegration = fastifyIntegration;
|
|
1735
|
+
exports.fileTransport = fileTransport;
|
|
1736
|
+
exports.formatSyslogMessage = formatSyslogMessage;
|
|
1737
|
+
exports.installAsyncLocalStorageContext = installAsyncLocalStorageContext;
|
|
1738
|
+
exports.nodeFetchIntegration = nodeFetchIntegration;
|
|
1739
|
+
exports.nodeHttpClientIntegration = nodeHttpClientIntegration;
|
|
1740
|
+
exports.nodeHttpTransport = nodeHttpTransport;
|
|
1741
|
+
exports.nodeSyslogTransport = nodeSyslogTransport;
|
|
1742
|
+
exports.queueIntegration = queueIntegration;
|
|
1743
|
+
exports.rotatingFileTransport = rotatingFileTransport;
|
|
1744
|
+
exports.serverlessIntegration = serverlessIntegration;
|
|
1745
|
+
exports.stderrTransport = stderrTransport;
|
|
1746
|
+
exports.stdoutTransport = stdoutTransport;
|
|
1747
|
+
exports.workerTransport = workerTransport;
|
|
1748
|
+
Object.keys(_loggerjs_core).forEach(function(k) {
|
|
1749
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
1750
|
+
enumerable: true,
|
|
1751
|
+
get: function() {
|
|
1752
|
+
return _loggerjs_core[k];
|
|
1753
|
+
}
|
|
1754
|
+
});
|
|
1755
|
+
});
|
|
1756
|
+
|
|
1757
|
+
//# sourceMappingURL=index.cjs.map
|