unnbound-events 1.0.19 → 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/LICENSE +21 -0
- package/README.md +50 -11
- 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 +241 -298
- package/dist/events/src/lib/types.d.ts +45 -58
- package/dist/events/src/lib/types.js +2 -2
- package/dist/lib/client.js +71 -67
- package/dist/lib/types.d.ts +1 -0
- package/dist/logger/src/axios.d.ts +5 -4
- package/dist/logger/src/axios.js +70 -64
- 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 +5 -9
- package/dist/logger/src/middleware.js +76 -64
- 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 +57 -39
- package/dist/logger/src/types.js +2 -2
- package/dist/logger/src/utils.js +24 -26
- package/package.json +22 -22
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,10 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RequestHandler } from 'express';
|
|
2
2
|
import { HttpOptions } from './types';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
type GetPayload = (config: Request, res?: Response) => object;
|
|
9
|
-
export declare const traceMiddleware: ({ ignoreTraceRoutes, traceHeaderKey, getPayload, }?: HttpOptions<GetPayload>) => RequestHandler;
|
|
10
|
-
export {};
|
|
3
|
+
export declare const traceMiddleware: ({
|
|
4
|
+
ignoreTraceRoutes,
|
|
5
|
+
traceHeaderKey,
|
|
6
|
+
}?: HttpOptions) => RequestHandler;
|
|
@@ -1,76 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
3
|
exports.traceMiddleware = void 0;
|
|
4
|
-
const span_1 = require(
|
|
5
|
-
const types_1 = require(
|
|
6
|
-
const utils_1 = require(
|
|
7
|
-
const trace_1 = require(
|
|
4
|
+
const span_1 = require('./span');
|
|
5
|
+
const types_1 = require('./types');
|
|
6
|
+
const utils_1 = require('./utils');
|
|
7
|
+
const trace_1 = require('./trace');
|
|
8
8
|
const getFullUrl = (req) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return `${protocol}://${host}${url}`;
|
|
9
|
+
const url = req.originalUrl || req.url;
|
|
10
|
+
if (url?.startsWith('http://') || url?.startsWith('https://')) return url;
|
|
11
|
+
// Check if we have a workflow URL configured (preferred method)
|
|
12
|
+
if (process.env.UNNBOUND_WORKFLOW_URL) {
|
|
13
|
+
// Use workflow URL as the base URL
|
|
14
|
+
return `${process.env.UNNBOUND_WORKFLOW_URL.replace(/\/$/, '')}${url}`;
|
|
15
|
+
}
|
|
16
|
+
// Fallback to constructing from request info for incoming requests
|
|
17
|
+
const protocol = req.protocol || (req.secure ? 'https' : 'http');
|
|
18
|
+
const host = req.get('host') || req.get('x-forwarded-host') || 'localhost';
|
|
19
|
+
return `${protocol}://${host}${url}`;
|
|
21
20
|
};
|
|
22
|
-
const buildIncomingHttpPayload = (req, res) => ({
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
},
|
|
33
|
-
response: res
|
|
34
|
-
? {
|
|
35
|
-
headers: res.headers,
|
|
36
|
-
status: res.status,
|
|
37
|
-
body: (0, utils_1.safeJsonParse)(res.body),
|
|
38
|
-
}
|
|
39
|
-
: undefined,
|
|
21
|
+
const buildIncomingHttpPayload = (req, res, body) => ({
|
|
22
|
+
type: 'http',
|
|
23
|
+
http: {
|
|
24
|
+
url: getFullUrl(req),
|
|
25
|
+
method: req.method.toLowerCase(),
|
|
26
|
+
ip: (0, utils_1.normalizeIp)(req.ip),
|
|
27
|
+
incoming: true,
|
|
28
|
+
request: {
|
|
29
|
+
headers: req.headers,
|
|
30
|
+
body: (0, utils_1.safeJsonParse)(req.body),
|
|
40
31
|
},
|
|
32
|
+
response: res
|
|
33
|
+
? {
|
|
34
|
+
headers: res?.headers,
|
|
35
|
+
status: res.statusCode,
|
|
36
|
+
body: (0, utils_1.safeJsonParse)(body),
|
|
37
|
+
}
|
|
38
|
+
: undefined,
|
|
39
|
+
},
|
|
41
40
|
});
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
const traceMiddleware =
|
|
42
|
+
(
|
|
43
|
+
{
|
|
44
|
+
ignoreTraceRoutes = types_1.defaultIgnoreTraceRoutes,
|
|
45
|
+
traceHeaderKey = types_1.defaultTraceHeaderKey,
|
|
46
|
+
} = {
|
|
47
|
+
ignoreTraceRoutes: types_1.defaultIgnoreTraceRoutes,
|
|
48
|
+
traceHeaderKey: types_1.defaultTraceHeaderKey,
|
|
49
|
+
}
|
|
50
|
+
) =>
|
|
51
|
+
async (req, res, next) => {
|
|
52
|
+
if ((0, utils_1.shouldIgnorePath)(req.path, ignoreTraceRoutes)) return next();
|
|
50
53
|
const traceId = req.header(traceHeaderKey) || (0, trace_1.getTraceId)();
|
|
51
54
|
res.setHeader(traceHeaderKey, traceId);
|
|
52
|
-
return await (0, trace_1.withTrace)(
|
|
53
|
-
|
|
55
|
+
return await (0, trace_1.withTrace)(
|
|
56
|
+
async () => {
|
|
57
|
+
return await (0, span_1.startSpan)(
|
|
58
|
+
'Incoming HTTP request',
|
|
59
|
+
async () => {
|
|
54
60
|
return new Promise((resolve) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
// Capture response body for logging
|
|
62
|
+
const send = res.send.bind(res);
|
|
63
|
+
res.send = (body) => {
|
|
64
|
+
res.locals.body = body;
|
|
65
|
+
return send(body);
|
|
66
|
+
};
|
|
67
|
+
res.on('finish', () => resolve());
|
|
68
|
+
return next();
|
|
63
69
|
});
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
},
|
|
71
|
+
(o) => {
|
|
72
|
+
return buildIncomingHttpPayload(
|
|
73
|
+
req,
|
|
74
|
+
o
|
|
66
75
|
? {
|
|
67
|
-
|
|
76
|
+
statusCode: res.statusCode,
|
|
68
77
|
headers: res.getHeaders(),
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
78
|
+
}
|
|
79
|
+
: undefined,
|
|
80
|
+
res.locals.body
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
},
|
|
85
|
+
{ traceId }
|
|
86
|
+
);
|
|
87
|
+
};
|
|
76
88
|
exports.traceMiddleware = traceMiddleware;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
type LogPayloadGetterOptions<T> =
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
type LogPayloadGetterOptions<T> =
|
|
2
|
+
| {
|
|
3
|
+
error: unknown;
|
|
4
|
+
result?: never;
|
|
5
|
+
}
|
|
6
|
+
| {
|
|
7
|
+
error?: never;
|
|
8
|
+
result: T;
|
|
9
|
+
};
|
|
8
10
|
type LogPayloadGetter<T> = object | ((o?: LogPayloadGetterOptions<T>) => object);
|
|
9
11
|
/**
|
|
10
12
|
* Starts a span that tracks the duration of a callback
|
|
@@ -12,5 +14,9 @@ type LogPayloadGetter<T> = object | ((o?: LogPayloadGetterOptions<T>) => object)
|
|
|
12
14
|
* @param callback - The async callback to execute
|
|
13
15
|
* @returns The result of the callback
|
|
14
16
|
*/
|
|
15
|
-
export declare const startSpan: <T>(
|
|
17
|
+
export declare const startSpan: <T>(
|
|
18
|
+
spanName: string,
|
|
19
|
+
callback: () => Promise<T>,
|
|
20
|
+
getter?: LogPayloadGetter<T>
|
|
21
|
+
) => Promise<T>;
|
|
16
22
|
export {};
|
package/dist/logger/src/span.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
3
|
exports.startSpan = void 0;
|
|
4
|
-
const uuid_1 = require(
|
|
5
|
-
const storage_1 = require(
|
|
6
|
-
const trace_1 = require(
|
|
7
|
-
const logger_1 = require(
|
|
4
|
+
const uuid_1 = require('uuid');
|
|
5
|
+
const storage_1 = require('./storage');
|
|
6
|
+
const trace_1 = require('./trace');
|
|
7
|
+
const logger_1 = require('./logger');
|
|
8
8
|
/**
|
|
9
9
|
* Starts a span that tracks the duration of a callback
|
|
10
10
|
* @param spanName - The span name to use for logging
|
|
@@ -12,30 +12,37 @@ const logger_1 = require("./logger");
|
|
|
12
12
|
* @returns The result of the callback
|
|
13
13
|
*/
|
|
14
14
|
const startSpan = async (spanName, callback, getter) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
15
|
+
const spanId = (0, uuid_1.v4)();
|
|
16
|
+
const start = performance.now();
|
|
17
|
+
const previous = storage_1.storage.getStore();
|
|
18
|
+
return storage_1.storage.run(
|
|
19
|
+
{
|
|
20
|
+
...previous,
|
|
21
|
+
traceId: previous?.traceId ?? (0, trace_1.getTraceId)(),
|
|
22
|
+
spanId: previous?.spanId ? `${spanId} ${previous?.spanId}` : spanId,
|
|
23
|
+
},
|
|
24
|
+
async () => {
|
|
25
|
+
logger_1.logger.info({ ...getLogPayload(getter) }, `${spanName} started.`);
|
|
26
|
+
try {
|
|
27
|
+
const result = await callback();
|
|
28
|
+
logger_1.logger.info(
|
|
29
|
+
{ ...getLogPayload(getter, { result }), duration: getDuration(start) },
|
|
30
|
+
`${spanName} completed.`
|
|
31
|
+
);
|
|
32
|
+
return result;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
logger_1.logger.error(
|
|
35
|
+
{ ...getLogPayload(getter, { error }), err: error, duration: getDuration(start) },
|
|
36
|
+
`${spanName} failed.`
|
|
37
|
+
);
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
);
|
|
34
42
|
};
|
|
35
43
|
exports.startSpan = startSpan;
|
|
36
44
|
const getLogPayload = (getter, o) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return getter(o);
|
|
45
|
+
if (typeof getter !== 'function') return getter;
|
|
46
|
+
return getter(o);
|
|
40
47
|
};
|
|
41
48
|
const getDuration = (start) => Math.round(performance.now() - start);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
3
|
exports.storage = void 0;
|
|
4
|
-
const async_hooks_1 = require(
|
|
4
|
+
const async_hooks_1 = require('async_hooks');
|
|
5
5
|
exports.storage = new async_hooks_1.AsyncLocalStorage();
|
|
@@ -9,6 +9,12 @@ export declare const getTraceId: () => string;
|
|
|
9
9
|
* @param extra - Extra context to add to the trace
|
|
10
10
|
* @returns The result of the callback
|
|
11
11
|
*/
|
|
12
|
-
export declare const withTrace: <
|
|
12
|
+
export declare const withTrace: <
|
|
13
|
+
T,
|
|
14
|
+
E extends {
|
|
13
15
|
traceId?: string;
|
|
14
|
-
}
|
|
16
|
+
},
|
|
17
|
+
>(
|
|
18
|
+
callback: () => T,
|
|
19
|
+
extra?: E
|
|
20
|
+
) => T;
|
package/dist/logger/src/trace.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
3
|
exports.withTrace = exports.getTraceId = void 0;
|
|
4
|
-
const uuid_1 = require(
|
|
5
|
-
const storage_1 = require(
|
|
4
|
+
const uuid_1 = require('uuid');
|
|
5
|
+
const storage_1 = require('./storage');
|
|
6
6
|
/**
|
|
7
7
|
* Generates a trace ID
|
|
8
8
|
* @returns A trace ID
|
|
@@ -16,6 +16,13 @@ exports.getTraceId = getTraceId;
|
|
|
16
16
|
* @returns The result of the callback
|
|
17
17
|
*/
|
|
18
18
|
const withTrace = (callback, extra) => {
|
|
19
|
-
|
|
19
|
+
return storage_1.storage.run(
|
|
20
|
+
{
|
|
21
|
+
...storage_1.storage.getStore(),
|
|
22
|
+
...extra,
|
|
23
|
+
traceId: extra?.traceId ?? (0, exports.getTraceId)(),
|
|
24
|
+
},
|
|
25
|
+
callback
|
|
26
|
+
);
|
|
20
27
|
};
|
|
21
28
|
exports.withTrace = withTrace;
|
|
@@ -14,49 +14,67 @@ export type LogType = 'general' | 'http' | 'sftp';
|
|
|
14
14
|
*/
|
|
15
15
|
export type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
|
|
16
16
|
export interface Log<T extends LogType = 'general'> {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
17
|
+
logId: string;
|
|
18
|
+
level: LogLevel;
|
|
19
|
+
message: string;
|
|
20
|
+
type: T;
|
|
21
|
+
traceId?: string;
|
|
22
|
+
spanId?: string;
|
|
23
|
+
serviceId?: string;
|
|
24
|
+
deploymentId?: string;
|
|
25
|
+
workflowId?: string;
|
|
26
|
+
http: T extends 'http' ? HttpPayload : never;
|
|
27
|
+
sftp: T extends 'sftp' ? SftpPayload : never;
|
|
28
|
+
duration?: number;
|
|
29
|
+
err?: unknown;
|
|
30
30
|
}
|
|
31
31
|
export interface HttpPayload {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
url: string;
|
|
33
|
+
method: HttpMethod;
|
|
34
|
+
ip?: string;
|
|
35
|
+
request: {
|
|
36
|
+
headers: Record<string, string | string[]>;
|
|
37
|
+
body?: unknown;
|
|
38
|
+
};
|
|
39
|
+
response?: {
|
|
40
|
+
headers: Record<string, string | string[]>;
|
|
41
|
+
status: number;
|
|
42
|
+
body?: unknown;
|
|
43
|
+
};
|
|
44
44
|
}
|
|
45
|
-
export type SftpOperation =
|
|
45
|
+
export type SftpOperation =
|
|
46
|
+
| 'connect'
|
|
47
|
+
| 'upload'
|
|
48
|
+
| 'download'
|
|
49
|
+
| 'list'
|
|
50
|
+
| 'delete'
|
|
51
|
+
| 'rename'
|
|
52
|
+
| 'stat'
|
|
53
|
+
| 'exists'
|
|
54
|
+
| 'realPath'
|
|
55
|
+
| 'get'
|
|
56
|
+
| 'put'
|
|
57
|
+
| 'cwd'
|
|
58
|
+
| 'mkdir'
|
|
59
|
+
| 'rmdir'
|
|
60
|
+
| 'chmod'
|
|
61
|
+
| 'append'
|
|
62
|
+
| 'uploadDir'
|
|
63
|
+
| 'downloadDir'
|
|
64
|
+
| 'close';
|
|
46
65
|
export interface SftpPayload {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
66
|
+
host: string;
|
|
67
|
+
operation: SftpOperation;
|
|
68
|
+
path?: string;
|
|
69
|
+
bytes?: number;
|
|
70
|
+
destinationPath?: string;
|
|
71
|
+
files?: string[];
|
|
72
|
+
content?: string;
|
|
73
|
+
exists?: string | false;
|
|
55
74
|
}
|
|
56
|
-
export interface HttpOptions
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
getPayload?: G;
|
|
75
|
+
export interface HttpOptions {
|
|
76
|
+
ignoreTraceRoutes?: string[];
|
|
77
|
+
traceHeaderKey?: string;
|
|
60
78
|
}
|
|
61
79
|
export declare const defaultIgnoreTraceRoutes: string[];
|
|
62
|
-
export declare const defaultTraceHeaderKey =
|
|
80
|
+
export declare const defaultTraceHeaderKey = 'x-unnbound-trace-id';
|
package/dist/logger/src/types.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
/**
|
|
3
3
|
* Type definitions for structured logging library
|
|
4
4
|
*/
|
|
5
|
-
Object.defineProperty(exports,
|
|
5
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
6
6
|
exports.defaultTraceHeaderKey = exports.defaultIgnoreTraceRoutes = void 0;
|
|
7
7
|
exports.defaultIgnoreTraceRoutes = ['/health', '/healthcheck'];
|
|
8
8
|
exports.defaultTraceHeaderKey = 'x-unnbound-trace-id';
|