unnbound-events 1.0.20 → 1.0.21
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/dist/events/src/index.d.ts +9 -1
- package/dist/events/src/index.js +23 -8
- package/dist/events/src/lib/adapters/express.d.ts +12 -10
- package/dist/events/src/lib/adapters/express.js +27 -31
- package/dist/events/src/lib/adapters/sqs.d.ts +27 -27
- package/dist/events/src/lib/adapters/sqs.js +39 -39
- package/dist/events/src/lib/client.js +242 -247
- package/dist/events/src/lib/types.d.ts +45 -45
- package/dist/events/src/lib/types.js +2 -2
- package/dist/lib/client.js +30 -33
- package/dist/logger/src/axios.d.ts +4 -1
- package/dist/logger/src/axios.js +70 -59
- package/dist/logger/src/index.js +50 -14
- package/dist/logger/src/logger.d.ts +18 -12
- package/dist/logger/src/logger.js +41 -39
- package/dist/logger/src/middleware.d.ts +4 -1
- package/dist/logger/src/middleware.js +74 -58
- package/dist/logger/src/span.d.ts +14 -8
- package/dist/logger/src/span.js +35 -28
- package/dist/logger/src/storage.d.ts +2 -2
- package/dist/logger/src/storage.js +3 -3
- package/dist/logger/src/trace.d.ts +8 -2
- package/dist/logger/src/trace.js +12 -5
- package/dist/logger/src/types.d.ts +56 -37
- package/dist/logger/src/types.js +2 -2
- package/dist/logger/src/utils.js +24 -26
- package/package.json +2 -2
package/dist/lib/client.js
CHANGED
|
@@ -7,9 +7,9 @@ exports.defaultIgnoreTraceRoutes = exports.shouldIgnorePath = void 0;
|
|
|
7
7
|
exports.createEventsClient = createEventsClient;
|
|
8
8
|
const unnbound_logger_sdk_1 = require("unnbound-logger-sdk");
|
|
9
9
|
const internal_1 = require("unnbound-logger-sdk/dist/internal");
|
|
10
|
+
const types_1 = require("unnbound-logger-sdk/dist/types");
|
|
10
11
|
const axios_1 = __importDefault(require("axios"));
|
|
11
|
-
const
|
|
12
|
-
const MESSAGE_HEADER_KEY = 'x-message-id';
|
|
12
|
+
const logger = unnbound_logger_sdk_1.logger.child((0, internal_1.internal)());
|
|
13
13
|
const http = require('http');
|
|
14
14
|
function matchPath(matcher, path) {
|
|
15
15
|
if (typeof matcher === 'string') {
|
|
@@ -75,9 +75,9 @@ async function fetchS3Payload(s3Client, bucket, key, versionId) {
|
|
|
75
75
|
return buffer.toString('utf-8');
|
|
76
76
|
}
|
|
77
77
|
catch (error) {
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
throw new Error(`Failed to fetch S3 payload: ${
|
|
78
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
79
|
+
logger.error({ err: error, bucket, key }, 'Failed to fetch S3 payload');
|
|
80
|
+
throw new Error(`Failed to fetch S3 payload: ${message}`);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
// Helper function to decompress payload
|
|
@@ -126,12 +126,12 @@ function createEventsClient(ignoreTraceRoutes = exports.defaultIgnoreTraceRoutes
|
|
|
126
126
|
}
|
|
127
127
|
const metadataTraceId = typeof request.metadata?.traceId === 'string' ? request.metadata.traceId : undefined;
|
|
128
128
|
const metadataMessageId = typeof request.metadata?.messageId === 'string' ? request.metadata.messageId : undefined;
|
|
129
|
-
const headerMessageId = getHeaderValue(request.headers,
|
|
129
|
+
const headerMessageId = getHeaderValue(request.headers, types_1.defaultTraceHeaderKey);
|
|
130
130
|
if (metadataMessageId && headerMessageId && metadataMessageId !== headerMessageId) {
|
|
131
|
-
|
|
131
|
+
logger.warn({ metadataMessageId, headerMessageId }, 'Message ID mismatch detected; defaulting to header value.');
|
|
132
132
|
}
|
|
133
133
|
const messageId = headerMessageId ?? metadataMessageId;
|
|
134
|
-
const headerTraceId = getHeaderValue(request.headers,
|
|
134
|
+
const headerTraceId = getHeaderValue(request.headers, types_1.defaultMessageHeaderKey);
|
|
135
135
|
const traceId = metadataTraceId ?? headerTraceId;
|
|
136
136
|
const context = traceId || messageId
|
|
137
137
|
? {
|
|
@@ -235,8 +235,7 @@ function createEventsClient(ignoreTraceRoutes = exports.defaultIgnoreTraceRoutes
|
|
|
235
235
|
return response;
|
|
236
236
|
}
|
|
237
237
|
catch (error) {
|
|
238
|
-
|
|
239
|
-
unnbound_logger_sdk_1.logger.error({ err, path: request.path }, 'Handler error');
|
|
238
|
+
logger.error({ err: error, path: request.path }, 'Handler error');
|
|
240
239
|
return { status: 500, body: { message: 'Internal Server Error' } };
|
|
241
240
|
}
|
|
242
241
|
},
|
|
@@ -302,7 +301,7 @@ function createEventsClient(ignoreTraceRoutes = exports.defaultIgnoreTraceRoutes
|
|
|
302
301
|
});
|
|
303
302
|
});
|
|
304
303
|
await new Promise((resolve) => server.listen(port, resolve));
|
|
305
|
-
|
|
304
|
+
logger.info({ port }, 'HTTP server started');
|
|
306
305
|
return {
|
|
307
306
|
close() {
|
|
308
307
|
return new Promise((resolve, reject) => {
|
|
@@ -344,7 +343,7 @@ function createEventsClient(ignoreTraceRoutes = exports.defaultIgnoreTraceRoutes
|
|
|
344
343
|
if (!s3Client) {
|
|
345
344
|
throw new Error('S3 client not initialized but S3 pointer message received');
|
|
346
345
|
}
|
|
347
|
-
|
|
346
|
+
logger.info({ bucket: pointer.s3BucketName, key: pointer.s3Key }, 'Fetching S3 pointer payload');
|
|
348
347
|
recordBody = await fetchS3Payload(s3Client, pointer.s3BucketName, pointer.s3Key);
|
|
349
348
|
envelope = JSON.parse(recordBody);
|
|
350
349
|
}
|
|
@@ -353,8 +352,7 @@ function createEventsClient(ignoreTraceRoutes = exports.defaultIgnoreTraceRoutes
|
|
|
353
352
|
}
|
|
354
353
|
}
|
|
355
354
|
catch (error) {
|
|
356
|
-
|
|
357
|
-
unnbound_logger_sdk_1.logger.error({ err }, 'Failed to parse SQS record body');
|
|
355
|
+
logger.error({ err: error }, 'Failed to parse SQS record body');
|
|
358
356
|
throw error;
|
|
359
357
|
}
|
|
360
358
|
// Check if envelope payload is stored in S3
|
|
@@ -366,7 +364,7 @@ function createEventsClient(ignoreTraceRoutes = exports.defaultIgnoreTraceRoutes
|
|
|
366
364
|
if (!s3Client) {
|
|
367
365
|
throw new Error('S3 client not initialized but S3 payload message received');
|
|
368
366
|
}
|
|
369
|
-
|
|
367
|
+
logger.info({
|
|
370
368
|
type: envelope.payload.type,
|
|
371
369
|
bucket: envelope.payload.location.bucket,
|
|
372
370
|
key: envelope.payload.location.key,
|
|
@@ -374,7 +372,7 @@ function createEventsClient(ignoreTraceRoutes = exports.defaultIgnoreTraceRoutes
|
|
|
374
372
|
let payloadData = await fetchS3Payload(s3Client, envelope.payload.location.bucket, envelope.payload.location.key, envelope.payload.location.versionId);
|
|
375
373
|
// Handle decompression if needed
|
|
376
374
|
if (envelope.payload.compressed && envelope.payload.compressionType) {
|
|
377
|
-
|
|
375
|
+
logger.info({ compressionType: envelope.payload.compressionType }, 'Decompressing payload');
|
|
378
376
|
payloadData = await decompressPayload(new TextEncoder().encode(payloadData), envelope.payload.compressionType);
|
|
379
377
|
}
|
|
380
378
|
// Parse the payload and set it as the request body
|
|
@@ -386,14 +384,14 @@ function createEventsClient(ignoreTraceRoutes = exports.defaultIgnoreTraceRoutes
|
|
|
386
384
|
}
|
|
387
385
|
}
|
|
388
386
|
// Continue with standard envelope processing
|
|
389
|
-
const headerMessageId = getHeaderValue(envelope.request.headers,
|
|
387
|
+
const headerMessageId = getHeaderValue(envelope.request.headers, types_1.defaultMessageHeaderKey);
|
|
390
388
|
const envelopeMessageId = typeof envelope.metadata?.messageId === 'string'
|
|
391
389
|
? envelope.metadata.messageId
|
|
392
390
|
: typeof envelope.messageId === 'string'
|
|
393
391
|
? envelope.messageId
|
|
394
392
|
: undefined;
|
|
395
393
|
if (envelopeMessageId && headerMessageId && envelopeMessageId !== headerMessageId) {
|
|
396
|
-
|
|
394
|
+
logger.warn({ envelopeMessageId, headerMessageId }, 'Message ID mismatch detected in SQS envelope; defaulting to header value.');
|
|
397
395
|
}
|
|
398
396
|
const messageId = headerMessageId ?? envelopeMessageId ?? record.messageId ?? undefined;
|
|
399
397
|
const originalMessageId = envelopeMessageId && envelopeMessageId !== messageId
|
|
@@ -441,10 +439,10 @@ function createEventsClient(ignoreTraceRoutes = exports.defaultIgnoreTraceRoutes
|
|
|
441
439
|
}, traceContext);
|
|
442
440
|
}
|
|
443
441
|
catch (error) {
|
|
444
|
-
const
|
|
442
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
445
443
|
failures.push({
|
|
446
444
|
messageId: record.messageId,
|
|
447
|
-
reason:
|
|
445
|
+
reason: reason ?? 'Unknown error',
|
|
448
446
|
});
|
|
449
447
|
}
|
|
450
448
|
}));
|
|
@@ -459,16 +457,15 @@ function createEventsClient(ignoreTraceRoutes = exports.defaultIgnoreTraceRoutes
|
|
|
459
457
|
if (bucketName || options?.s3) {
|
|
460
458
|
s3Options = options?.s3 || {};
|
|
461
459
|
if (!bucketName) {
|
|
462
|
-
|
|
460
|
+
logger.error('S3 options provided but no bucket name specified. S3 payload support disabled.');
|
|
463
461
|
}
|
|
464
462
|
else {
|
|
465
463
|
try {
|
|
466
464
|
s3Client = createS3Client({ ...s3Options, bucketName });
|
|
467
|
-
|
|
465
|
+
logger.info({ bucket: bucketName }, 'S3 client initialized for payload offloading');
|
|
468
466
|
}
|
|
469
467
|
catch (error) {
|
|
470
|
-
|
|
471
|
-
unnbound_logger_sdk_1.logger.error({ err }, 'Failed to initialize S3 client');
|
|
468
|
+
logger.error({ err: error }, 'Failed to initialize S3 client');
|
|
472
469
|
throw error;
|
|
473
470
|
}
|
|
474
471
|
}
|
|
@@ -518,7 +515,7 @@ function createEventsClient(ignoreTraceRoutes = exports.defaultIgnoreTraceRoutes
|
|
|
518
515
|
}
|
|
519
516
|
}
|
|
520
517
|
catch (err) {
|
|
521
|
-
|
|
518
|
+
logger.error({ err }, 'SQS listen loop error');
|
|
522
519
|
}
|
|
523
520
|
}
|
|
524
521
|
}
|
|
@@ -542,7 +539,7 @@ function createEventsClient(ignoreTraceRoutes = exports.defaultIgnoreTraceRoutes
|
|
|
542
539
|
});
|
|
543
540
|
}
|
|
544
541
|
catch (error) {
|
|
545
|
-
|
|
542
|
+
logger.error({ err: error, queueUrl: queueUrl.replace(/\/[^/]+$/, '/***') }, 'SQS connection test failed');
|
|
546
543
|
reject(error instanceof Error ? error : new Error(String(error)));
|
|
547
544
|
}
|
|
548
545
|
};
|
|
@@ -556,8 +553,8 @@ function createEventsClient(ignoreTraceRoutes = exports.defaultIgnoreTraceRoutes
|
|
|
556
553
|
const config = {
|
|
557
554
|
headers: {
|
|
558
555
|
...event.headers,
|
|
559
|
-
[
|
|
560
|
-
[
|
|
556
|
+
[types_1.defaultTraceHeaderKey]: event.metadata?.traceId,
|
|
557
|
+
[types_1.defaultMessageHeaderKey]: event.metadata?.messageId,
|
|
561
558
|
},
|
|
562
559
|
params: event.query,
|
|
563
560
|
};
|
|
@@ -585,7 +582,7 @@ function createEventsClient(ignoreTraceRoutes = exports.defaultIgnoreTraceRoutes
|
|
|
585
582
|
httpServer = await this.http(httpOptions);
|
|
586
583
|
}
|
|
587
584
|
catch (error) {
|
|
588
|
-
|
|
585
|
+
logger.error({ err: error }, 'Failed to start HTTP server, continuing without it');
|
|
589
586
|
}
|
|
590
587
|
// Start SQS listener
|
|
591
588
|
let sqsListener;
|
|
@@ -593,7 +590,7 @@ function createEventsClient(ignoreTraceRoutes = exports.defaultIgnoreTraceRoutes
|
|
|
593
590
|
sqsListener = await this.sqsListen(sqsListenOptions);
|
|
594
591
|
}
|
|
595
592
|
catch (error) {
|
|
596
|
-
|
|
593
|
+
logger.error({ err: error }, 'Failed to start SQS listener, continuing without it');
|
|
597
594
|
}
|
|
598
595
|
// If neither HTTP nor SQS started successfully, throw an error
|
|
599
596
|
if (!httpServer && !sqsListener) {
|
|
@@ -602,14 +599,14 @@ function createEventsClient(ignoreTraceRoutes = exports.defaultIgnoreTraceRoutes
|
|
|
602
599
|
// Set up graceful shutdown
|
|
603
600
|
const g = globalThis;
|
|
604
601
|
const shutdown = async () => {
|
|
605
|
-
|
|
602
|
+
logger.info('Received shutdown signal, closing servers...');
|
|
606
603
|
const promises = [];
|
|
607
604
|
if (httpServer)
|
|
608
605
|
promises.push(httpServer.close());
|
|
609
606
|
if (sqsListener)
|
|
610
607
|
promises.push(sqsListener.stop());
|
|
611
608
|
await Promise.all(promises);
|
|
612
|
-
|
|
609
|
+
logger.info('All servers closed');
|
|
613
610
|
g.process?.exit?.(0);
|
|
614
611
|
};
|
|
615
612
|
// Handle SIGINT and SIGTERM
|
|
@@ -621,7 +618,7 @@ function createEventsClient(ignoreTraceRoutes = exports.defaultIgnoreTraceRoutes
|
|
|
621
618
|
services.push(`HTTP on port ${httpOptions?.port ?? 3000}`);
|
|
622
619
|
if (sqsListener)
|
|
623
620
|
services.push('SQS listener');
|
|
624
|
-
|
|
621
|
+
logger.info({ services: services.join(' and ') }, 'Services started. Press Ctrl+C to stop.');
|
|
625
622
|
},
|
|
626
623
|
};
|
|
627
624
|
}
|
|
@@ -6,4 +6,7 @@ import { HttpOptions } from './types';
|
|
|
6
6
|
* @param options - Configuration options for HTTP tracing
|
|
7
7
|
* @returns The wrapped axios instance with span tracking
|
|
8
8
|
*/
|
|
9
|
-
export declare const traceAxios: (
|
|
9
|
+
export declare const traceAxios: (
|
|
10
|
+
client: Axios,
|
|
11
|
+
{ ignoreTraceRoutes, traceHeaderKey }?: HttpOptions
|
|
12
|
+
) => Axios;
|
package/dist/logger/src/axios.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
3
|
exports.traceAxios = void 0;
|
|
4
|
-
const axios_1 = require(
|
|
5
|
-
const types_1 = require(
|
|
6
|
-
const storage_1 = require(
|
|
7
|
-
const utils_1 = require(
|
|
8
|
-
const span_1 = require(
|
|
4
|
+
const axios_1 = require('axios');
|
|
5
|
+
const types_1 = require('./types');
|
|
6
|
+
const storage_1 = require('./storage');
|
|
7
|
+
const utils_1 = require('./utils');
|
|
8
|
+
const span_1 = require('./span');
|
|
9
9
|
const buildOutgoingHttpPayload = (config, res) => ({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
},
|
|
19
|
-
response: res
|
|
20
|
-
? {
|
|
21
|
-
headers: res?.headers,
|
|
22
|
-
status: res.status,
|
|
23
|
-
body: (0, utils_1.safeJsonParse)(res.data),
|
|
24
|
-
}
|
|
25
|
-
: undefined,
|
|
10
|
+
type: 'http',
|
|
11
|
+
http: {
|
|
12
|
+
url: [config.baseURL, config.url].filter(Boolean).join(''),
|
|
13
|
+
method: config.method?.toLowerCase() ?? 'get',
|
|
14
|
+
incoming: false,
|
|
15
|
+
request: {
|
|
16
|
+
headers: config.headers,
|
|
17
|
+
body: (0, utils_1.safeJsonParse)(config.data),
|
|
26
18
|
},
|
|
19
|
+
response: res
|
|
20
|
+
? {
|
|
21
|
+
headers: res?.headers,
|
|
22
|
+
status: res.status,
|
|
23
|
+
body: (0, utils_1.safeJsonParse)(res.data),
|
|
24
|
+
}
|
|
25
|
+
: undefined,
|
|
26
|
+
},
|
|
27
27
|
});
|
|
28
28
|
/**
|
|
29
29
|
* Wraps an axios instance to add tracing and span tracking
|
|
@@ -31,44 +31,55 @@ const buildOutgoingHttpPayload = (config, res) => ({
|
|
|
31
31
|
* @param options - Configuration options for HTTP tracing
|
|
32
32
|
* @returns The wrapped axios instance with span tracking
|
|
33
33
|
*/
|
|
34
|
-
const traceAxios = (
|
|
34
|
+
const traceAxios = (
|
|
35
|
+
client,
|
|
36
|
+
{
|
|
37
|
+
ignoreTraceRoutes = types_1.defaultIgnoreTraceRoutes,
|
|
38
|
+
traceHeaderKey = types_1.defaultTraceHeaderKey,
|
|
39
|
+
} = {
|
|
35
40
|
ignoreTraceRoutes: types_1.defaultIgnoreTraceRoutes,
|
|
36
41
|
traceHeaderKey: types_1.defaultTraceHeaderKey,
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
42
|
+
}
|
|
43
|
+
) => {
|
|
44
|
+
const createSpanWrappedRequest = (originalMethod, method) => {
|
|
45
|
+
const { headers: defaultHeaders, ...partialDefaultConfig } = client.defaults;
|
|
46
|
+
const headers = { ...defaultHeaders.common, ...(method && defaultHeaders[method]) };
|
|
47
|
+
const defaultConfig = { ...partialDefaultConfig, headers };
|
|
48
|
+
return async (config) => {
|
|
49
|
+
config = (0, axios_1.mergeConfig)(defaultConfig, config);
|
|
50
|
+
// Determine the actual config and URL
|
|
51
|
+
const url = [config.baseURL, config.url].filter(Boolean).join('');
|
|
52
|
+
// Check if this request should be ignored
|
|
53
|
+
if ((0, utils_1.shouldIgnorePath)(url, ignoreTraceRoutes)) return originalMethod(config);
|
|
54
|
+
const traceId = storage_1.storage.getStore()?.traceId;
|
|
55
|
+
config = { ...config, headers: { ...config.headers, [traceHeaderKey]: traceId } };
|
|
56
|
+
// Execute the request within a span
|
|
57
|
+
return (0, span_1.startSpan)(
|
|
58
|
+
`Outgoing HTTP request`,
|
|
59
|
+
() => originalMethod(config),
|
|
60
|
+
(options) => {
|
|
61
|
+
if (!options) return buildOutgoingHttpPayload(config);
|
|
62
|
+
if (options.error)
|
|
63
|
+
return buildOutgoingHttpPayload(
|
|
64
|
+
config,
|
|
65
|
+
(0, axios_1.isAxiosError)(options.error) ? options.error.response : undefined
|
|
66
|
+
);
|
|
67
|
+
return buildOutgoingHttpPayload(config, options.result);
|
|
68
|
+
}
|
|
69
|
+
);
|
|
60
70
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
});
|
|
72
|
-
|
|
71
|
+
};
|
|
72
|
+
const request = client.request.bind(client);
|
|
73
|
+
const tracedRequest = createSpanWrappedRequest(request);
|
|
74
|
+
client.request = tracedRequest;
|
|
75
|
+
['post', 'put', 'patch'].forEach((method) => {
|
|
76
|
+
const func = createSpanWrappedRequest(request, method);
|
|
77
|
+
client[method] = (url, data, config) => func({ ...config, method, url, data });
|
|
78
|
+
});
|
|
79
|
+
['delete', 'get', 'head', 'options'].forEach((method) => {
|
|
80
|
+
const func = createSpanWrappedRequest(request, method);
|
|
81
|
+
client[method] = (url, config) => func({ ...config, method, url });
|
|
82
|
+
});
|
|
83
|
+
return client;
|
|
73
84
|
};
|
|
74
85
|
exports.traceAxios = traceAxios;
|
package/dist/logger/src/index.js
CHANGED
|
@@ -1,14 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.traceMiddleware =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
exports.traceMiddleware =
|
|
4
|
+
exports.traceAxios =
|
|
5
|
+
exports.startSpan =
|
|
6
|
+
exports.getTraceId =
|
|
7
|
+
exports.withTrace =
|
|
8
|
+
exports.logger =
|
|
9
|
+
void 0;
|
|
10
|
+
var logger_1 = require('./logger');
|
|
11
|
+
Object.defineProperty(exports, 'logger', {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () {
|
|
14
|
+
return logger_1.logger;
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
var trace_1 = require('./trace');
|
|
18
|
+
Object.defineProperty(exports, 'withTrace', {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return trace_1.withTrace;
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, 'getTraceId', {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return trace_1.getTraceId;
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
var span_1 = require('./span');
|
|
31
|
+
Object.defineProperty(exports, 'startSpan', {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () {
|
|
34
|
+
return span_1.startSpan;
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
var axios_1 = require('./axios');
|
|
38
|
+
Object.defineProperty(exports, 'traceAxios', {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function () {
|
|
41
|
+
return axios_1.traceAxios;
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
var middleware_1 = require('./middleware');
|
|
45
|
+
Object.defineProperty(exports, 'traceMiddleware', {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function () {
|
|
48
|
+
return middleware_1.traceMiddleware;
|
|
49
|
+
},
|
|
50
|
+
});
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import pino from 'pino';
|
|
2
|
-
export interface UnnboundLogger
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
export interface UnnboundLogger
|
|
3
|
+
extends Omit<pino.Logger, 'trace' | 'debug' | 'error' | 'info' | 'warn'> {
|
|
4
|
+
trace(object: {}, message: string): void;
|
|
5
|
+
trace(message: string): void;
|
|
6
|
+
debug(object: {}, message: string): void;
|
|
7
|
+
debug(message: string): void;
|
|
8
|
+
info(object: {}, message: string): void;
|
|
9
|
+
info(message: string): void;
|
|
10
|
+
warn(object: {}, message: string): void;
|
|
11
|
+
warn(message: string): void;
|
|
12
|
+
error<
|
|
13
|
+
O extends {
|
|
14
|
+
err: unknown;
|
|
15
|
+
},
|
|
16
|
+
>(
|
|
17
|
+
object: O,
|
|
18
|
+
message: string
|
|
19
|
+
): void;
|
|
14
20
|
}
|
|
15
21
|
export declare const logger: UnnboundLogger;
|
|
@@ -1,44 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
var __importDefault =
|
|
3
|
+
(this && this.__importDefault) ||
|
|
4
|
+
function (mod) {
|
|
5
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
6
8
|
exports.logger = void 0;
|
|
7
|
-
const pino_1 = __importDefault(require(
|
|
8
|
-
const uuid_1 = require(
|
|
9
|
-
const storage_1 = require(
|
|
9
|
+
const pino_1 = __importDefault(require('pino'));
|
|
10
|
+
const uuid_1 = require('uuid');
|
|
11
|
+
const storage_1 = require('./storage');
|
|
10
12
|
exports.logger = (0, pino_1.default)({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
13
|
+
level: process.env.LOG_LEVEL ?? 'info',
|
|
14
|
+
base: {
|
|
15
|
+
environment: process.env.ENVIRONMENT,
|
|
16
|
+
workflowId: process.env.UNNBOUND_WORKFLOW_ID,
|
|
17
|
+
serviceId: process.env.UNNBOUND_SERVICE_ID,
|
|
18
|
+
deploymentId: process.env.UNNBOUND_DEPLOYMENT_ID,
|
|
19
|
+
},
|
|
20
|
+
mixin: () => ({ ...storage_1.storage.getStore(), logId: (0, uuid_1.v4)() }),
|
|
21
|
+
serializers: {
|
|
22
|
+
req: pino_1.default.stdSerializers.req,
|
|
23
|
+
res: pino_1.default.stdSerializers.res,
|
|
24
|
+
err: pino_1.default.stdSerializers.err,
|
|
25
|
+
},
|
|
26
|
+
// Let CloudWatch handle timestamps
|
|
27
|
+
timestamp: false,
|
|
28
|
+
// Change message field from 'msg' to 'message'
|
|
29
|
+
messageKey: 'message',
|
|
30
|
+
formatters: {
|
|
31
|
+
level: (level) => ({ level }),
|
|
32
|
+
},
|
|
33
|
+
redact: {
|
|
34
|
+
paths: [
|
|
35
|
+
'http.request.headers.authorization',
|
|
36
|
+
'http.response.headers.authorization',
|
|
37
|
+
'http.request.headers.Authorization',
|
|
38
|
+
'http.response.headers.Authorization',
|
|
39
|
+
'err.config',
|
|
40
|
+
],
|
|
41
|
+
remove: true,
|
|
42
|
+
},
|
|
41
43
|
});
|
|
42
44
|
process.on('uncaughtException', (err, origin) => {
|
|
43
|
-
|
|
45
|
+
exports.logger.error({ err, origin }, `Uncaught exception.`);
|
|
44
46
|
});
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { RequestHandler } from 'express';
|
|
2
2
|
import { HttpOptions } from './types';
|
|
3
|
-
export declare const traceMiddleware: ({
|
|
3
|
+
export declare const traceMiddleware: ({
|
|
4
|
+
ignoreTraceRoutes,
|
|
5
|
+
traceHeaderKey,
|
|
6
|
+
}?: HttpOptions) => RequestHandler;
|