unnbound-logger-sdk 3.0.18 → 3.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/axios.js +8 -1
- package/dist/middleware.d.ts +1 -1
- package/dist/middleware.js +13 -4
- package/dist/types.d.ts +2 -0
- package/dist/types.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -395,6 +395,7 @@ app.use(traceMiddleware(options?: HttpOptions));
|
|
|
395
395
|
**HttpOptions:**
|
|
396
396
|
|
|
397
397
|
- `traceHeaderKey?: string` - Custom trace header name (default: 'x-unnbound-trace-id')
|
|
398
|
+
- `messageHeaderKey?: string` - Custom message header name (default: 'x-message-id')
|
|
398
399
|
- `ignoreTraceRoutes?: string[]` - Routes to ignore in middleware (default: ['/health', '/healthcheck'])
|
|
399
400
|
|
|
400
401
|
### traceAxios
|
package/dist/axios.js
CHANGED
|
@@ -6,10 +6,17 @@ const types_1 = require("./types");
|
|
|
6
6
|
const storage_1 = require("./storage");
|
|
7
7
|
const utils_1 = require("./utils");
|
|
8
8
|
const span_1 = require("./span");
|
|
9
|
+
const extractQueryParams = (url, config) => {
|
|
10
|
+
const object = new URL(url);
|
|
11
|
+
const query = { ...Object.fromEntries(object.searchParams.entries()), ...config.params };
|
|
12
|
+
const keys = Object.keys(query);
|
|
13
|
+
keys.forEach((key) => object.searchParams.delete(key));
|
|
14
|
+
return { url: object.toString(), query: keys.length > 0 ? query : undefined };
|
|
15
|
+
};
|
|
9
16
|
const buildOutgoingHttpPayload = (config, res) => ({
|
|
10
17
|
type: 'http',
|
|
11
18
|
http: {
|
|
12
|
-
|
|
19
|
+
...extractQueryParams([config.baseURL, config.url].filter(Boolean).join(''), config),
|
|
13
20
|
method: config.method?.toLowerCase() ?? 'get',
|
|
14
21
|
incoming: false,
|
|
15
22
|
request: {
|
package/dist/middleware.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ interface Response {
|
|
|
6
6
|
body?: unknown;
|
|
7
7
|
}
|
|
8
8
|
type GetPayload = (config: Request, res?: Response) => object;
|
|
9
|
-
export declare const traceMiddleware: ({ ignoreTraceRoutes, traceHeaderKey, getPayload, }?: HttpOptions<GetPayload>) => RequestHandler;
|
|
9
|
+
export declare const traceMiddleware: ({ ignoreTraceRoutes, traceHeaderKey, messageHeaderKey, getPayload, }?: HttpOptions<GetPayload>) => RequestHandler;
|
|
10
10
|
export {};
|
package/dist/middleware.js
CHANGED
|
@@ -5,6 +5,13 @@ const span_1 = require("./span");
|
|
|
5
5
|
const types_1 = require("./types");
|
|
6
6
|
const utils_1 = require("./utils");
|
|
7
7
|
const trace_1 = require("./trace");
|
|
8
|
+
const extractQueryParams = (url) => {
|
|
9
|
+
const object = new URL(url);
|
|
10
|
+
const query = Object.fromEntries(object.searchParams.entries());
|
|
11
|
+
const keys = Object.keys(query);
|
|
12
|
+
keys.forEach((key) => object.searchParams.delete(key));
|
|
13
|
+
return { url: object.toString(), query: keys.length > 0 ? query : undefined };
|
|
14
|
+
};
|
|
8
15
|
const getFullUrl = (req) => {
|
|
9
16
|
const url = req.originalUrl || req.url;
|
|
10
17
|
if (url?.startsWith('http://') || url?.startsWith('https://'))
|
|
@@ -12,7 +19,7 @@ const getFullUrl = (req) => {
|
|
|
12
19
|
// Check if we have a workflow URL configured (preferred method)
|
|
13
20
|
if (process.env.UNNBOUND_WORKFLOW_URL) {
|
|
14
21
|
// Use workflow URL as the base URL
|
|
15
|
-
return
|
|
22
|
+
return `https://${process.env.UNNBOUND_WORKFLOW_URL.replace(/\/$/, '')}${url}`;
|
|
16
23
|
}
|
|
17
24
|
// Fallback to constructing from request info for incoming requests
|
|
18
25
|
const protocol = req.protocol || (req.secure ? 'https' : 'http');
|
|
@@ -22,7 +29,7 @@ const getFullUrl = (req) => {
|
|
|
22
29
|
const buildIncomingHttpPayload = (req, res) => ({
|
|
23
30
|
type: 'http',
|
|
24
31
|
http: {
|
|
25
|
-
|
|
32
|
+
...extractQueryParams(getFullUrl(req)),
|
|
26
33
|
method: req.method.toLowerCase(),
|
|
27
34
|
ip: (0, utils_1.normalizeIp)(req.ip),
|
|
28
35
|
incoming: true,
|
|
@@ -40,14 +47,16 @@ const buildIncomingHttpPayload = (req, res) => ({
|
|
|
40
47
|
},
|
|
41
48
|
});
|
|
42
49
|
const getNoopPayload = () => ({});
|
|
43
|
-
const traceMiddleware = ({ ignoreTraceRoutes = types_1.defaultIgnoreTraceRoutes, traceHeaderKey = types_1.defaultTraceHeaderKey, getPayload = getNoopPayload, } = {
|
|
50
|
+
const traceMiddleware = ({ ignoreTraceRoutes = types_1.defaultIgnoreTraceRoutes, traceHeaderKey = types_1.defaultTraceHeaderKey, messageHeaderKey = types_1.defaultMessageHeaderKey, getPayload = getNoopPayload, } = {
|
|
44
51
|
ignoreTraceRoutes: types_1.defaultIgnoreTraceRoutes,
|
|
45
52
|
traceHeaderKey: types_1.defaultTraceHeaderKey,
|
|
53
|
+
messageHeaderKey: types_1.defaultMessageHeaderKey,
|
|
46
54
|
getPayload: getNoopPayload,
|
|
47
55
|
}) => async (req, res, next) => {
|
|
48
56
|
if ((0, utils_1.shouldIgnorePath)(req.path, ignoreTraceRoutes))
|
|
49
57
|
return next();
|
|
50
58
|
const traceId = req.header(traceHeaderKey) || (0, trace_1.getTraceId)();
|
|
59
|
+
const messageId = req.header(messageHeaderKey) || undefined;
|
|
51
60
|
res.setHeader(traceHeaderKey, traceId);
|
|
52
61
|
return await (0, trace_1.withTrace)(async () => {
|
|
53
62
|
return await (0, span_1.startSpan)('Incoming HTTP request', async () => {
|
|
@@ -71,6 +80,6 @@ const traceMiddleware = ({ ignoreTraceRoutes = types_1.defaultIgnoreTraceRoutes,
|
|
|
71
80
|
: undefined;
|
|
72
81
|
return { ...buildIncomingHttpPayload(req, response), ...getPayload(req, response) };
|
|
73
82
|
});
|
|
74
|
-
}, { traceId });
|
|
83
|
+
}, messageId ? { traceId, messageId } : { traceId });
|
|
75
84
|
};
|
|
76
85
|
exports.traceMiddleware = traceMiddleware;
|
package/dist/types.d.ts
CHANGED
|
@@ -69,7 +69,9 @@ export interface EdiPayload {
|
|
|
69
69
|
export interface HttpOptions<G extends Function> {
|
|
70
70
|
ignoreTraceRoutes?: string[];
|
|
71
71
|
traceHeaderKey?: string;
|
|
72
|
+
messageHeaderKey?: string;
|
|
72
73
|
getPayload?: G;
|
|
73
74
|
}
|
|
74
75
|
export declare const defaultIgnoreTraceRoutes: string[];
|
|
75
76
|
export declare const defaultTraceHeaderKey = "x-unnbound-trace-id";
|
|
77
|
+
export declare const defaultMessageHeaderKey = "x-message-id";
|
package/dist/types.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Type definitions for structured logging library
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.defaultTraceHeaderKey = exports.defaultIgnoreTraceRoutes = void 0;
|
|
6
|
+
exports.defaultMessageHeaderKey = exports.defaultTraceHeaderKey = exports.defaultIgnoreTraceRoutes = void 0;
|
|
7
7
|
exports.defaultIgnoreTraceRoutes = ['/health', '/healthcheck'];
|
|
8
8
|
exports.defaultTraceHeaderKey = 'x-unnbound-trace-id';
|
|
9
|
+
exports.defaultMessageHeaderKey = 'x-message-id';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unnbound-logger-sdk",
|
|
3
3
|
"description": "A structured logging library with TypeScript support using Pino. Provides consistent, well-typed logging with automatic logId, workflowId, traceId, and deploymentId tracking across operational contexts.",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.20",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|