unnbound-logger-sdk 3.0.24 → 3.0.25
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/axios.js +5 -3
- package/dist/index.d.ts +1 -1
- package/dist/logger.d.ts +3 -1
- package/dist/logger.js +43 -9
- package/package.json +1 -1
package/dist/axios.js
CHANGED
|
@@ -6,6 +6,9 @@ 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 buildUrl = (baseUrl, url) => {
|
|
10
|
+
return url?.startsWith('http') ? url : [baseUrl, url].filter(Boolean).join('');
|
|
11
|
+
};
|
|
9
12
|
const extractQueryParams = (url, config) => {
|
|
10
13
|
const object = new URL(url);
|
|
11
14
|
const query = { ...Object.fromEntries(object.searchParams.entries()), ...config.params };
|
|
@@ -16,7 +19,7 @@ const extractQueryParams = (url, config) => {
|
|
|
16
19
|
const buildOutgoingHttpPayload = (config, res) => ({
|
|
17
20
|
type: 'http',
|
|
18
21
|
http: {
|
|
19
|
-
...extractQueryParams(
|
|
22
|
+
...extractQueryParams(buildUrl(config.baseURL, config.url), config),
|
|
20
23
|
method: config.method?.toLowerCase() ?? 'get',
|
|
21
24
|
incoming: false,
|
|
22
25
|
request: {
|
|
@@ -50,8 +53,7 @@ const traceAxios = (client, { ignoreTraceRoutes = types_1.defaultIgnoreTraceRout
|
|
|
50
53
|
const defaultConfig = { ...partialDefaultConfig, headers };
|
|
51
54
|
return async (config) => {
|
|
52
55
|
config = (0, axios_1.mergeConfig)(defaultConfig, config);
|
|
53
|
-
|
|
54
|
-
const url = [config.baseURL, config.url].filter(Boolean).join('');
|
|
56
|
+
const url = buildUrl(config.baseURL, config.url);
|
|
55
57
|
// Check if this request should be ignored
|
|
56
58
|
if ((0, utils_1.shouldIgnorePath)(url, ignoreTraceRoutes))
|
|
57
59
|
return originalMethod(config);
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Provides consistent, well-typed logging across different operational contexts.
|
|
6
6
|
*/
|
|
7
7
|
export type { LogLevel, LogType, HttpMethod, Maybe, EventSource, Log, HttpPayload, SftpPayload, EdiPayload, EdiOperation, EdiFormat, EdiX12Payload, EdiX12Operation, } from './types';
|
|
8
|
-
export type { UnnboundLogger } from './logger';
|
|
8
|
+
export type { ILogger, UnnboundLogger } from './logger';
|
|
9
9
|
export { logger } from './logger';
|
|
10
10
|
export { encode, decode } from './encode';
|
|
11
11
|
export { withTrace, getTraceId } from './trace';
|
package/dist/logger.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import pino from 'pino';
|
|
2
|
-
export interface
|
|
2
|
+
export interface ILogger {
|
|
3
3
|
trace(object: {}, message: string): void;
|
|
4
4
|
trace(message: string): void;
|
|
5
5
|
debug(object: {}, message: string): void;
|
|
@@ -12,4 +12,6 @@ export interface UnnboundLogger extends Omit<pino.Logger, 'trace' | 'debug' | 'e
|
|
|
12
12
|
err: unknown;
|
|
13
13
|
}>(object: O, message: string): void;
|
|
14
14
|
}
|
|
15
|
+
export interface UnnboundLogger extends ILogger, Omit<pino.Logger, keyof ILogger> {
|
|
16
|
+
}
|
|
15
17
|
export declare const logger: UnnboundLogger;
|
package/dist/logger.js
CHANGED
|
@@ -11,17 +11,38 @@ const encode_1 = require("./encode");
|
|
|
11
11
|
const internal_1 = require("./internal");
|
|
12
12
|
const levels = new Set(['debug', 'info', 'warn', 'error']);
|
|
13
13
|
const formatLevel = (level) => ({ level });
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
// TODO: Check if there is a better way to encode the log object.
|
|
15
|
+
const formatLog = (log, visited = new WeakSet()) => {
|
|
16
|
+
// Prevent infinite loops from circular references
|
|
17
|
+
if (visited.has(log))
|
|
18
|
+
return log;
|
|
19
|
+
visited.add(log);
|
|
20
|
+
// We can't encode frozen objects.
|
|
21
|
+
if (Object.isFrozen(log))
|
|
22
|
+
return log;
|
|
23
|
+
// We don't use Object.entries() for performance reasons
|
|
24
|
+
for (const key in log) {
|
|
25
|
+
const value = log[key];
|
|
26
|
+
// We don't want to encode undefined values.
|
|
27
|
+
if (value == undefined)
|
|
28
|
+
continue;
|
|
29
|
+
// We can't encode immutable properties.
|
|
30
|
+
if (!Object.getOwnPropertyDescriptor(log, key)?.writable)
|
|
31
|
+
continue;
|
|
20
32
|
if (typeof value === 'string') {
|
|
21
33
|
log[key] = (0, encode_1.encode)(value);
|
|
22
|
-
return;
|
|
23
34
|
}
|
|
24
|
-
|
|
35
|
+
else if (Array.isArray(value)) {
|
|
36
|
+
log[key] = value.map((item) => typeof item === 'string'
|
|
37
|
+
? (0, encode_1.encode)(item)
|
|
38
|
+
: item && typeof item === 'object'
|
|
39
|
+
? formatLog(item, visited)
|
|
40
|
+
: item);
|
|
41
|
+
}
|
|
42
|
+
else if (typeof value === 'object') {
|
|
43
|
+
log[key] = formatLog(value, visited);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
25
46
|
return log;
|
|
26
47
|
};
|
|
27
48
|
exports.logger = (0, pino_1.default)({
|
|
@@ -74,5 +95,18 @@ exports.logger = (0, pino_1.default)({
|
|
|
74
95
|
},
|
|
75
96
|
});
|
|
76
97
|
process.on('uncaughtException', (err, origin) => {
|
|
77
|
-
|
|
98
|
+
try {
|
|
99
|
+
exports.logger.error({ err, origin }, `Uncaught exception.`);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
// noop
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
process.on('unhandledRejection', (err, origin) => {
|
|
106
|
+
try {
|
|
107
|
+
exports.logger.error({ err, origin }, `Unhandled rejection.`);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
// noop
|
|
111
|
+
}
|
|
78
112
|
});
|
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.25",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"keywords": [
|