unnbound-logger-sdk 1.0.0
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 +312 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +29 -0
- package/dist/src/index.d.ts +38 -0
- package/dist/src/index.js +29 -0
- package/dist/src/types.d.ts +134 -0
- package/dist/src/types.js +5 -0
- package/dist/src/unnbound-logger.d.ts +105 -0
- package/dist/src/unnbound-logger.js +292 -0
- package/dist/src/utils/id-generator.d.ts +21 -0
- package/dist/src/utils/id-generator.js +46 -0
- package/dist/src/utils/logger-utils.d.ts +21 -0
- package/dist/src/utils/logger-utils.js +63 -0
- package/dist/src/utils/trace-context.d.ts +10 -0
- package/dist/src/utils/trace-context.js +23 -0
- package/dist/src/utils/with-trace.d.ts +7 -0
- package/dist/src/utils/with-trace.js +17 -0
- package/dist/types.d.ts +134 -0
- package/dist/types.js +5 -0
- package/dist/unnbound-logger.d.ts +105 -0
- package/dist/unnbound-logger.js +292 -0
- package/dist/utils/id-generator.d.ts +21 -0
- package/dist/utils/id-generator.js +46 -0
- package/dist/utils/logger-utils.d.ts +21 -0
- package/dist/utils/logger-utils.js +63 -0
- package/dist/utils/trace-context.d.ts +10 -0
- package/dist/utils/trace-context.js +23 -0
- package/dist/utils/with-trace.d.ts +7 -0
- package/dist/utils/with-trace.js +17 -0
- package/package.json +90 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare class TraceContextManager {
|
|
2
|
+
private static instance;
|
|
3
|
+
private storage;
|
|
4
|
+
private constructor();
|
|
5
|
+
static getInstance(): TraceContextManager;
|
|
6
|
+
run<T>(traceId: string, callback: () => T): T;
|
|
7
|
+
getTraceId(): string | undefined;
|
|
8
|
+
}
|
|
9
|
+
export declare const traceContext: TraceContextManager;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.traceContext = void 0;
|
|
4
|
+
const async_hooks_1 = require("async_hooks");
|
|
5
|
+
class TraceContextManager {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.storage = new async_hooks_1.AsyncLocalStorage();
|
|
8
|
+
}
|
|
9
|
+
static getInstance() {
|
|
10
|
+
if (!TraceContextManager.instance) {
|
|
11
|
+
TraceContextManager.instance = new TraceContextManager();
|
|
12
|
+
}
|
|
13
|
+
return TraceContextManager.instance;
|
|
14
|
+
}
|
|
15
|
+
run(traceId, callback) {
|
|
16
|
+
return this.storage.run({ traceId }, callback);
|
|
17
|
+
}
|
|
18
|
+
getTraceId() {
|
|
19
|
+
const context = this.storage.getStore();
|
|
20
|
+
return context?.traceId;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.traceContext = TraceContextManager.getInstance();
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Higher-order function that wraps a function with trace context
|
|
3
|
+
* @param fn - Function to wrap with trace context
|
|
4
|
+
* @param traceId - Optional trace ID to use (will generate new one if not provided)
|
|
5
|
+
* @returns Wrapped function that maintains trace context
|
|
6
|
+
*/
|
|
7
|
+
export declare function withTrace<T extends (...args: any[]) => any>(fn: T, traceId?: string): T;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withTrace = withTrace;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
const trace_context_1 = require("./trace-context");
|
|
6
|
+
/**
|
|
7
|
+
* Higher-order function that wraps a function with trace context
|
|
8
|
+
* @param fn - Function to wrap with trace context
|
|
9
|
+
* @param traceId - Optional trace ID to use (will generate new one if not provided)
|
|
10
|
+
* @returns Wrapped function that maintains trace context
|
|
11
|
+
*/
|
|
12
|
+
function withTrace(fn, traceId) {
|
|
13
|
+
const id = traceId || (0, uuid_1.v4)();
|
|
14
|
+
return ((...args) => {
|
|
15
|
+
return trace_context_1.traceContext.run(id, () => fn(...args));
|
|
16
|
+
});
|
|
17
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "unnbound-logger-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A structured logging library with TypeScript support using Pino. Provides consistent, well-typed logging across different operational contexts with automatic trace ID propagation.",
|
|
5
|
+
"main": "dist/index.js",
|
|
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
|
+
"lint": "eslint src/**/*.ts",
|
|
13
|
+
"lint:fix": "eslint . --ext .ts --fix",
|
|
14
|
+
"format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
15
|
+
"format:check": "prettier --check \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
16
|
+
"prepublishOnly": "npm run build && npm test",
|
|
17
|
+
"check-coverage": "ts-node scripts/check-coverage.ts",
|
|
18
|
+
"start:example:node-app": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' examples/node-app.ts",
|
|
19
|
+
"start:example:basic-usage": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' examples/basic-usage.ts"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"logging",
|
|
23
|
+
"typescript",
|
|
24
|
+
"structured-logging",
|
|
25
|
+
"pino",
|
|
26
|
+
"tracing",
|
|
27
|
+
"http-logging",
|
|
28
|
+
"express-middleware",
|
|
29
|
+
"axios-interceptor",
|
|
30
|
+
"observability"
|
|
31
|
+
],
|
|
32
|
+
"author": "Unnbound Team",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/unnbound/logger.git"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/unnbound/logger#readme",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/unnbound/logger/issues"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"axios": "^1.9.0",
|
|
44
|
+
"express": "^5.1.0",
|
|
45
|
+
"pino": "^8.17.2",
|
|
46
|
+
"uuid": "^11.1.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/express": "^4.17.21",
|
|
50
|
+
"@types/jest": "^29.5.12",
|
|
51
|
+
"@types/node": "^20.11.24",
|
|
52
|
+
"@types/uuid": "^9.0.8",
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "^7.1.0",
|
|
54
|
+
"@typescript-eslint/parser": "^7.1.0",
|
|
55
|
+
"cors": "^2.8.5",
|
|
56
|
+
"dotenv": "^16.5.0",
|
|
57
|
+
"eslint": "^8.57.0",
|
|
58
|
+
"eslint-config-prettier": "^10.1.5",
|
|
59
|
+
"jest": "^29.7.0",
|
|
60
|
+
"nodemon": "^3.1.10",
|
|
61
|
+
"prettier": "^3.2.5",
|
|
62
|
+
"ts-jest": "^29.1.2",
|
|
63
|
+
"ts-node": "^10.9.2",
|
|
64
|
+
"typescript": "^5.3.3"
|
|
65
|
+
},
|
|
66
|
+
"peerDependencies": {
|
|
67
|
+
"express": "^4.0.0 || ^5.0.0",
|
|
68
|
+
"axios": "^1.0.0"
|
|
69
|
+
},
|
|
70
|
+
"peerDependenciesMeta": {
|
|
71
|
+
"express": {
|
|
72
|
+
"optional": true
|
|
73
|
+
},
|
|
74
|
+
"axios": {
|
|
75
|
+
"optional": true
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"files": [
|
|
79
|
+
"dist/src/**/*",
|
|
80
|
+
"dist/index.*",
|
|
81
|
+
"dist/types.*",
|
|
82
|
+
"dist/unnbound-logger.*",
|
|
83
|
+
"dist/utils/**/*",
|
|
84
|
+
"README.md",
|
|
85
|
+
"LICENSE"
|
|
86
|
+
],
|
|
87
|
+
"engines": {
|
|
88
|
+
"node": ">=14.0.0"
|
|
89
|
+
}
|
|
90
|
+
}
|