unnbound-logger-sdk 3.0.13 → 3.0.15

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/index.d.ts CHANGED
@@ -11,3 +11,4 @@ export { withTrace, getTraceId } from './trace';
11
11
  export { startSpan } from './span';
12
12
  export { traceAxios } from './axios';
13
13
  export { traceMiddleware } from './middleware';
14
+ export { sanitizeLogContent } from './utils';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.traceMiddleware = exports.traceAxios = exports.startSpan = exports.getTraceId = exports.withTrace = exports.logger = void 0;
3
+ exports.sanitizeLogContent = exports.traceMiddleware = exports.traceAxios = exports.startSpan = exports.getTraceId = exports.withTrace = exports.logger = void 0;
4
4
  var logger_1 = require("./logger");
5
5
  Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return logger_1.logger; } });
6
6
  var trace_1 = require("./trace");
@@ -12,3 +12,5 @@ var axios_1 = require("./axios");
12
12
  Object.defineProperty(exports, "traceAxios", { enumerable: true, get: function () { return axios_1.traceAxios; } });
13
13
  var middleware_1 = require("./middleware");
14
14
  Object.defineProperty(exports, "traceMiddleware", { enumerable: true, get: function () { return middleware_1.traceMiddleware; } });
15
+ var utils_1 = require("./utils");
16
+ Object.defineProperty(exports, "sanitizeLogContent", { enumerable: true, get: function () { return utils_1.sanitizeLogContent; } });
package/dist/logger.js CHANGED
@@ -7,6 +7,7 @@ exports.logger = void 0;
7
7
  const pino_1 = __importDefault(require("pino"));
8
8
  const uuid_1 = require("uuid");
9
9
  const storage_1 = require("./storage");
10
+ const utils_1 = require("./utils");
10
11
  const levels = new Set(['debug', 'info', 'warn', 'error']);
11
12
  const hidden = (data) => '_hide' in data && data._hide;
12
13
  exports.logger = (0, pino_1.default)({
@@ -44,7 +45,9 @@ exports.logger = (0, pino_1.default)({
44
45
  firstArg.level = undefined;
45
46
  }
46
47
  }
47
- method.apply(this, args);
48
+ // Sanitize all arguments to prevent CloudWatch log splitting
49
+ const sanitizedArgs = args.map((arg) => (0, utils_1.sanitizeLogContent)(arg));
50
+ method.apply(this, sanitizedArgs);
48
51
  },
49
52
  },
50
53
  redact: {
package/dist/storage.d.ts CHANGED
@@ -2,5 +2,6 @@ import { AsyncLocalStorage } from 'async_hooks';
2
2
  export interface Context {
3
3
  traceId?: string;
4
4
  spanId?: string;
5
+ messageId?: string;
5
6
  }
6
7
  export declare const storage: AsyncLocalStorage<Context>;
package/dist/trace.d.ts CHANGED
@@ -11,4 +11,5 @@ export declare const getTraceId: () => string;
11
11
  */
12
12
  export declare const withTrace: <T, E extends {
13
13
  traceId?: string;
14
+ messageId?: string;
14
15
  }>(callback: () => T, extra?: E) => T;
package/dist/trace.js CHANGED
@@ -16,6 +16,8 @@ exports.getTraceId = getTraceId;
16
16
  * @returns The result of the callback
17
17
  */
18
18
  const withTrace = (callback, extra) => {
19
- return storage_1.storage.run({ ...storage_1.storage.getStore(), ...extra, traceId: extra?.traceId ?? (0, exports.getTraceId)() }, callback);
19
+ const previous = storage_1.storage.getStore();
20
+ const traceId = extra?.traceId ?? previous?.traceId ?? (0, exports.getTraceId)();
21
+ return storage_1.storage.run({ ...previous, ...extra, traceId }, callback);
20
22
  };
21
23
  exports.withTrace = withTrace;
package/dist/utils.d.ts CHANGED
@@ -11,6 +11,13 @@ export declare const shouldIgnorePath: (path: string, patterns: string[]) => boo
11
11
  * @returns Parsed JSON object or the original data.
12
12
  */
13
13
  export declare function safeJsonParse(data: any): any;
14
+ /**
15
+ * Sanitizes log content by replacing newlines with carriage returns to prevent
16
+ * CloudWatch from splitting logs into multiple entries.
17
+ * @param obj The object to sanitize
18
+ * @returns Sanitized object with newlines replaced
19
+ */
20
+ export declare function sanitizeLogContent(obj: any): any;
14
21
  /**
15
22
  * Normalizes IP addresses by removing IPv6 mapping prefix for IPv4 addresses.
16
23
  * @param ip The IP address to normalize.
package/dist/utils.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.shouldIgnorePath = void 0;
4
4
  exports.safeJsonParse = safeJsonParse;
5
+ exports.sanitizeLogContent = sanitizeLogContent;
5
6
  exports.normalizeIp = normalizeIp;
6
7
  /**
7
8
  * Checks if a path matches any of the ignore patterns
@@ -37,6 +38,33 @@ function safeJsonParse(data) {
37
38
  }
38
39
  return data;
39
40
  }
41
+ /**
42
+ * Sanitizes log content by replacing newlines with carriage returns to prevent
43
+ * CloudWatch from splitting logs into multiple entries.
44
+ * @param obj The object to sanitize
45
+ * @returns Sanitized object with newlines replaced
46
+ */
47
+ function sanitizeLogContent(obj) {
48
+ if (obj === null || obj === undefined) {
49
+ return obj;
50
+ }
51
+ if (typeof obj === 'string') {
52
+ // Replace \n and \r\n with \r to prevent CloudWatch log splitting
53
+ return obj.replace(/\r?\n/g, '\r');
54
+ }
55
+ if (Array.isArray(obj)) {
56
+ return obj.map(sanitizeLogContent);
57
+ }
58
+ if (typeof obj === 'object') {
59
+ const sanitized = {};
60
+ for (const [key, value] of Object.entries(obj)) {
61
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
62
+ sanitized[key] = sanitizeLogContent(value);
63
+ }
64
+ return sanitized;
65
+ }
66
+ return obj;
67
+ }
40
68
  /**
41
69
  * Normalizes IP addresses by removing IPv6 mapping prefix for IPv4 addresses.
42
70
  * @param ip The IP address to normalize.
package/package.json CHANGED
@@ -1,9 +1,23 @@
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.13",
4
+ "version": "3.0.15",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "test": "jest",
10
+ "test:coverage": "jest --coverage",
11
+ "test:watch": "jest --watch",
12
+ "typecheck": "tsc -noEmit",
13
+ "lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .",
14
+ "lint:fix": "pnpm lint --fix",
15
+ "format": "prettier --write .",
16
+ "format:check": "prettier --check .",
17
+ "prepublishOnly": "pnpm build",
18
+ "start:example": "npx --yes tsx --watch examples/node-express.ts",
19
+ "version:bump": "npm version patch"
20
+ },
7
21
  "keywords": [
8
22
  "logging",
9
23
  "typescript",
@@ -57,18 +71,5 @@
57
71
  "engines": {
58
72
  "node": ">=22"
59
73
  },
60
- "sideEffects": false,
61
- "scripts": {
62
- "build": "tsc",
63
- "test": "jest",
64
- "test:coverage": "jest --coverage",
65
- "test:watch": "jest --watch",
66
- "typecheck": "tsc -noEmit",
67
- "lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .",
68
- "lint:fix": "pnpm lint --fix",
69
- "format": "prettier --write .",
70
- "format:check": "prettier --check .",
71
- "start:example": "npx --yes tsx --watch examples/node-express.ts",
72
- "version:bump": "npm version patch"
73
- }
74
- }
74
+ "sideEffects": false
75
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Unnbound Team
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.