logixia 1.13.0 → 2.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/README.md +81 -16
- package/dist/{async-context-CwBNMm2E.mjs → async-context-BzJrbfQs.mjs} +8 -4
- package/dist/async-context-BzJrbfQs.mjs.map +1 -0
- package/dist/{async-context-CSHWoHMB.js → async-context-DyQQYq3I.js} +8 -4
- package/dist/async-context-DyQQYq3I.js.map +1 -0
- package/dist/{azure-monitor.transport-CG7ClkYj.d.ts → azure-monitor.transport-Cn_3Usvu.d.ts} +2 -2
- package/dist/{azure-monitor.transport-CG7ClkYj.d.ts.map → azure-monitor.transport-Cn_3Usvu.d.ts.map} +1 -1
- package/dist/{azure-monitor.transport-Cm74kXZS.d.mts → azure-monitor.transport-D7Da4RAb.d.mts} +2 -2
- package/dist/{azure-monitor.transport-Cm74kXZS.d.mts.map → azure-monitor.transport-D7Da4RAb.d.mts.map} +1 -1
- package/dist/azure.d.mts +2 -2
- package/dist/azure.d.ts +2 -2
- package/dist/browser.d.mts +9 -0
- package/dist/browser.d.mts.map +1 -1
- package/dist/browser.d.ts +9 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +43 -12
- package/dist/browser.js.map +1 -1
- package/dist/browser.mjs +43 -12
- package/dist/browser.mjs.map +1 -1
- package/dist/{logitron-logger.module-Bs3XYZgF.mjs → builder-0gEzRopq.mjs} +383 -1021
- package/dist/builder-0gEzRopq.mjs.map +1 -0
- package/dist/{logitron-logger.module-BsDZR5BH.js → builder-D44QktIo.js} +411 -1155
- package/dist/builder-D44QktIo.js.map +1 -0
- package/dist/cli/index.js +130 -65
- package/dist/cloudwatch.d.mts +2 -2
- package/dist/cloudwatch.d.ts +2 -2
- package/dist/cloudwatch.js +2 -1
- package/dist/cloudwatch.mjs +2 -1
- package/dist/{cloudwatch.transport-pNBNWJLt.js → cloudwatch.transport-BO1ahxw-.js} +26 -19
- package/dist/cloudwatch.transport-BO1ahxw-.js.map +1 -0
- package/dist/{cloudwatch.transport-yBwm4OeO.mjs → cloudwatch.transport-DZ6ies7g.mjs} +26 -19
- package/dist/cloudwatch.transport-DZ6ies7g.mjs.map +1 -0
- package/dist/{cloudwatch.transport-CGHY4buE.d.mts → cloudwatch.transport-DsEq633o.d.ts} +9 -2
- package/dist/cloudwatch.transport-DsEq633o.d.ts.map +1 -0
- package/dist/{cloudwatch.transport-DK_8cKd3.d.ts → cloudwatch.transport-UlyZFWMn.d.mts} +9 -2
- package/dist/cloudwatch.transport-UlyZFWMn.d.mts.map +1 -0
- package/dist/{coerce.utils-BN980Y9V.js → coerce.utils-B-LilukN.js} +1 -1
- package/dist/{coerce.utils-BN980Y9V.js.map → coerce.utils-B-LilukN.js.map} +1 -1
- package/dist/{coerce.utils-Dxv4_ikC.mjs → coerce.utils-Cu6IUTgX.mjs} +1 -1
- package/dist/{coerce.utils-Dxv4_ikC.mjs.map → coerce.utils-Cu6IUTgX.mjs.map} +1 -1
- package/dist/correlation.d.mts +24 -6
- package/dist/correlation.d.mts.map +1 -1
- package/dist/correlation.d.ts +24 -6
- package/dist/correlation.d.ts.map +1 -1
- package/dist/correlation.js +41 -16
- package/dist/correlation.js.map +1 -1
- package/dist/correlation.mjs +41 -16
- package/dist/correlation.mjs.map +1 -1
- package/dist/entry-fields-BJkuPnIg.mjs +30 -0
- package/dist/entry-fields-BJkuPnIg.mjs.map +1 -0
- package/dist/entry-fields-BvOLFlJ4.js +36 -0
- package/dist/entry-fields-BvOLFlJ4.js.map +1 -0
- package/dist/gcp.d.mts +2 -2
- package/dist/gcp.d.ts +2 -2
- package/dist/gcp.js +2 -1
- package/dist/gcp.mjs +2 -1
- package/dist/{gcp.transport-BOhkVKlI.d.ts → gcp.transport-B7oc97sG.d.ts} +2 -2
- package/dist/gcp.transport-B7oc97sG.d.ts.map +1 -0
- package/dist/{gcp.transport-SHdtc1n0.js → gcp.transport-CHV8MGgz.js} +5 -5
- package/dist/gcp.transport-CHV8MGgz.js.map +1 -0
- package/dist/{gcp.transport-BJuNRFe_.mjs → gcp.transport-DBX5TPIy.mjs} +5 -5
- package/dist/gcp.transport-DBX5TPIy.mjs.map +1 -0
- package/dist/{gcp.transport-Bi6CUqZR.d.mts → gcp.transport-GrJurKo8.d.mts} +2 -2
- package/dist/gcp.transport-GrJurKo8.d.mts.map +1 -0
- package/dist/{index-BPKwwERo.d.mts → index-3mw5gaCw.d.mts} +2 -2
- package/dist/{index-BPKwwERo.d.mts.map → index-3mw5gaCw.d.mts.map} +1 -1
- package/dist/{index-C1X-TE5I.d.ts → index-DhIoploR.d.ts} +2 -2
- package/dist/{index-C1X-TE5I.d.ts.map → index-DhIoploR.d.ts.map} +1 -1
- package/dist/index.d.mts +99 -137
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +99 -137
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +146 -510
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +99 -431
- package/dist/index.mjs.map +1 -1
- package/dist/logitron-logger-BFDSO8Io.d.mts +257 -0
- package/dist/logitron-logger-BFDSO8Io.d.mts.map +1 -0
- package/dist/logitron-logger-UVeN-mQm.d.ts +257 -0
- package/dist/logitron-logger-UVeN-mQm.d.ts.map +1 -0
- package/dist/middleware.d.mts +11 -4
- package/dist/middleware.d.mts.map +1 -1
- package/dist/middleware.d.ts +11 -4
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +148 -24
- package/dist/middleware.js.map +1 -1
- package/dist/middleware.mjs +148 -24
- package/dist/middleware.mjs.map +1 -1
- package/dist/nest.d.mts +481 -6
- package/dist/nest.d.mts.map +1 -1
- package/dist/nest.d.ts +481 -6
- package/dist/nest.d.ts.map +1 -1
- package/dist/nest.js +884 -13
- package/dist/nest.js.map +1 -0
- package/dist/nest.mjs +863 -6
- package/dist/nest.mjs.map +1 -0
- package/dist/{search-CFQRISUv.mjs → search-BFbu_oVn.mjs} +35 -12
- package/dist/search-BFbu_oVn.mjs.map +1 -0
- package/dist/{search-njTI2hdo.js → search-C4V0OMEn.js} +35 -12
- package/dist/search-C4V0OMEn.js.map +1 -0
- package/dist/{search-DujhR94O.d.ts → search-CNh9uVwR.d.ts} +2 -3
- package/dist/search-CNh9uVwR.d.ts.map +1 -0
- package/dist/{search-CQOo-Iq6.d.mts → search-DXANsQ2n.d.mts} +2 -3
- package/dist/search-DXANsQ2n.d.mts.map +1 -0
- package/dist/search.d.mts +3 -3
- package/dist/search.d.ts +3 -3
- package/dist/search.js +2 -2
- package/dist/search.mjs +2 -2
- package/dist/slack.transport-BZzoXDPn.d.mts +112 -0
- package/dist/slack.transport-BZzoXDPn.d.mts.map +1 -0
- package/dist/slack.transport-BfJRouB2.js +654 -0
- package/dist/slack.transport-BfJRouB2.js.map +1 -0
- package/dist/slack.transport-Bzw7sucI.mjs +643 -0
- package/dist/slack.transport-Bzw7sucI.mjs.map +1 -0
- package/dist/slack.transport-CXjQYOes.d.ts +112 -0
- package/dist/slack.transport-CXjQYOes.d.ts.map +1 -0
- package/dist/testing.d.mts +2 -2
- package/dist/testing.d.ts +2 -2
- package/dist/trace.utils-CvXgaiQT.mjs +278 -0
- package/dist/trace.utils-CvXgaiQT.mjs.map +1 -0
- package/dist/trace.utils-DpBOLDtq.js +358 -0
- package/dist/trace.utils-DpBOLDtq.js.map +1 -0
- package/dist/{transport.manager-D6KL3t9V.mjs → transport.manager-BiuCAJd2.mjs} +526 -160
- package/dist/transport.manager-BiuCAJd2.mjs.map +1 -0
- package/dist/{transport.manager-BivyUTtU.js → transport.manager-CXbKKdVE.js} +537 -159
- package/dist/transport.manager-CXbKKdVE.js.map +1 -0
- package/dist/{transport.types-B5vcyv2k.d.mts → transport.types-BMnurPcc.d.mts} +23 -3
- package/dist/transport.types-BMnurPcc.d.mts.map +1 -0
- package/dist/{transport.types-BuY84TwO.d.ts → transport.types-CGoHpWQR.d.ts} +23 -3
- package/dist/transport.types-CGoHpWQR.d.ts.map +1 -0
- package/dist/transports.d.mts +50 -20
- package/dist/transports.d.mts.map +1 -1
- package/dist/transports.d.ts +50 -20
- package/dist/transports.d.ts.map +1 -1
- package/dist/transports.js +9 -5
- package/dist/transports.mjs +8 -6
- package/dist/worker-entry.js +307 -55
- package/dist/worker.d.mts +2 -2
- package/dist/worker.d.ts +2 -2
- package/dist/worker.js +1 -1
- package/dist/worker.mjs +1 -1
- package/dist/{worker.transport-CfH6z37Z.js → worker.transport-BdPxu3PN.js} +1 -1
- package/dist/{worker.transport-CfH6z37Z.js.map → worker.transport-BdPxu3PN.js.map} +1 -1
- package/dist/{worker.transport-mKXgNK0L.d.ts → worker.transport-CdzSZJmw.d.ts} +2 -2
- package/dist/{worker.transport-mKXgNK0L.d.ts.map → worker.transport-CdzSZJmw.d.ts.map} +1 -1
- package/dist/{worker.transport-BP8Q28Z2.d.mts → worker.transport-JvGPog3C.d.mts} +2 -2
- package/dist/{worker.transport-BP8Q28Z2.d.mts.map → worker.transport-JvGPog3C.d.mts.map} +1 -1
- package/dist/{worker.transport-BhMyvqQ2.mjs → worker.transport-lPxO2MVL.mjs} +1 -1
- package/dist/{worker.transport-BhMyvqQ2.mjs.map → worker.transport-lPxO2MVL.mjs.map} +1 -1
- package/package.json +27 -14
- package/dist/.tsbuildinfo +0 -1
- package/dist/async-context-CSHWoHMB.js.map +0 -1
- package/dist/async-context-CwBNMm2E.mjs.map +0 -1
- package/dist/cloudwatch.transport-CGHY4buE.d.mts.map +0 -1
- package/dist/cloudwatch.transport-DK_8cKd3.d.ts.map +0 -1
- package/dist/cloudwatch.transport-pNBNWJLt.js.map +0 -1
- package/dist/cloudwatch.transport-yBwm4OeO.mjs.map +0 -1
- package/dist/gcp.transport-BJuNRFe_.mjs.map +0 -1
- package/dist/gcp.transport-BOhkVKlI.d.ts.map +0 -1
- package/dist/gcp.transport-Bi6CUqZR.d.mts.map +0 -1
- package/dist/gcp.transport-SHdtc1n0.js.map +0 -1
- package/dist/logitron-logger.module-BdG1Jnpk.d.mts +0 -618
- package/dist/logitron-logger.module-BdG1Jnpk.d.mts.map +0 -1
- package/dist/logitron-logger.module-Bs3XYZgF.mjs.map +0 -1
- package/dist/logitron-logger.module-BsDZR5BH.js.map +0 -1
- package/dist/logitron-logger.module-CbXy2gfW.d.ts +0 -618
- package/dist/logitron-logger.module-CbXy2gfW.d.ts.map +0 -1
- package/dist/search-CFQRISUv.mjs.map +0 -1
- package/dist/search-CQOo-Iq6.d.mts.map +0 -1
- package/dist/search-DujhR94O.d.ts.map +0 -1
- package/dist/search-njTI2hdo.js.map +0 -1
- package/dist/transport.manager-BivyUTtU.js.map +0 -1
- package/dist/transport.manager-D6KL3t9V.mjs.map +0 -1
- package/dist/transport.types-B5vcyv2k.d.mts.map +0 -1
- package/dist/transport.types-BuY84TwO.d.ts.map +0 -1
- package/scripts/postinstall.js +0 -61
|
@@ -1,22 +1,88 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-nOFOJqeH.js');
|
|
2
2
|
const require_internal_log = require('./internal-log-BUJYMZbE.js');
|
|
3
3
|
const require_safe_stringify = require('./safe-stringify-DWo3aZp_.js');
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
4
|
+
const require_trace_utils = require('./trace.utils-DpBOLDtq.js');
|
|
5
|
+
const require_async_context = require('./async-context-DyQQYq3I.js');
|
|
6
|
+
const require_coerce_utils = require('./coerce.utils-B-LilukN.js');
|
|
7
|
+
const require_transport_manager = require('./transport.manager-CXbKKdVE.js');
|
|
7
8
|
let node_os = require("node:os");
|
|
8
9
|
node_os = require_chunk.__toESM(node_os);
|
|
9
|
-
let node_async_hooks = require("node:async_hooks");
|
|
10
|
-
node_async_hooks = require_chunk.__toESM(node_async_hooks);
|
|
11
10
|
let fast_json_stringify = require("fast-json-stringify");
|
|
12
11
|
fast_json_stringify = require_chunk.__toESM(fast_json_stringify);
|
|
13
|
-
let crypto = require("crypto");
|
|
14
|
-
crypto = require_chunk.__toESM(crypto);
|
|
15
|
-
let __nestjs_common = require("@nestjs/common");
|
|
16
|
-
__nestjs_common = require_chunk.__toESM(__nestjs_common);
|
|
17
|
-
let rxjs = require("rxjs");
|
|
18
|
-
rxjs = require_chunk.__toESM(rxjs);
|
|
19
12
|
|
|
13
|
+
//#region src/types/index.ts
|
|
14
|
+
const LogLevel = {
|
|
15
|
+
ERROR: "error",
|
|
16
|
+
WARN: "warn",
|
|
17
|
+
INFO: "info",
|
|
18
|
+
DEBUG: "debug",
|
|
19
|
+
TRACE: "trace",
|
|
20
|
+
VERBOSE: "verbose"
|
|
21
|
+
};
|
|
22
|
+
const DEFAULT_LOG_LEVELS = {
|
|
23
|
+
error: 0,
|
|
24
|
+
warn: 1,
|
|
25
|
+
info: 2,
|
|
26
|
+
debug: 3,
|
|
27
|
+
trace: 4,
|
|
28
|
+
verbose: 5
|
|
29
|
+
};
|
|
30
|
+
const DEFAULT_LOG_COLORS = {
|
|
31
|
+
error: "red",
|
|
32
|
+
warn: "yellow",
|
|
33
|
+
info: "green",
|
|
34
|
+
debug: "blue",
|
|
35
|
+
trace: "magenta",
|
|
36
|
+
verbose: "cyan"
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/core/default-config.ts
|
|
41
|
+
/**
|
|
42
|
+
* Default configuration for Logixia logger
|
|
43
|
+
*/
|
|
44
|
+
const DEFAULT_CONFIG = {
|
|
45
|
+
appName: "App",
|
|
46
|
+
environment: "development",
|
|
47
|
+
traceId: true,
|
|
48
|
+
format: {
|
|
49
|
+
timestamp: true,
|
|
50
|
+
colorize: true,
|
|
51
|
+
json: false
|
|
52
|
+
},
|
|
53
|
+
silent: false,
|
|
54
|
+
levelOptions: {
|
|
55
|
+
level: LogLevel.INFO,
|
|
56
|
+
levels: {
|
|
57
|
+
[LogLevel.ERROR]: 0,
|
|
58
|
+
[LogLevel.WARN]: 1,
|
|
59
|
+
[LogLevel.INFO]: 2,
|
|
60
|
+
[LogLevel.DEBUG]: 3,
|
|
61
|
+
[LogLevel.TRACE]: 4,
|
|
62
|
+
[LogLevel.VERBOSE]: 5
|
|
63
|
+
},
|
|
64
|
+
colors: {
|
|
65
|
+
[LogLevel.ERROR]: "red",
|
|
66
|
+
[LogLevel.WARN]: "yellow",
|
|
67
|
+
[LogLevel.INFO]: "blue",
|
|
68
|
+
[LogLevel.DEBUG]: "green",
|
|
69
|
+
[LogLevel.TRACE]: "gray",
|
|
70
|
+
[LogLevel.VERBOSE]: "cyan"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
fields: {
|
|
74
|
+
timestamp: true,
|
|
75
|
+
level: true,
|
|
76
|
+
appName: true,
|
|
77
|
+
traceId: true,
|
|
78
|
+
message: true,
|
|
79
|
+
payload: true,
|
|
80
|
+
timeTaken: true
|
|
81
|
+
},
|
|
82
|
+
outputs: ["console"]
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
//#endregion
|
|
20
86
|
//#region src/plugin.ts
|
|
21
87
|
/**
|
|
22
88
|
* Holds an ordered list of `LogixiaPlugin` instances and dispatches lifecycle
|
|
@@ -123,33 +189,6 @@ function usePlugin(plugin) {
|
|
|
123
189
|
globalPluginRegistry.register(plugin);
|
|
124
190
|
}
|
|
125
191
|
|
|
126
|
-
//#endregion
|
|
127
|
-
//#region src/types/index.ts
|
|
128
|
-
const LogLevel = {
|
|
129
|
-
ERROR: "error",
|
|
130
|
-
WARN: "warn",
|
|
131
|
-
INFO: "info",
|
|
132
|
-
DEBUG: "debug",
|
|
133
|
-
TRACE: "trace",
|
|
134
|
-
VERBOSE: "verbose"
|
|
135
|
-
};
|
|
136
|
-
const DEFAULT_LOG_LEVELS = {
|
|
137
|
-
error: 0,
|
|
138
|
-
warn: 1,
|
|
139
|
-
info: 2,
|
|
140
|
-
debug: 3,
|
|
141
|
-
trace: 4,
|
|
142
|
-
verbose: 5
|
|
143
|
-
};
|
|
144
|
-
const DEFAULT_LOG_COLORS = {
|
|
145
|
-
error: "red",
|
|
146
|
-
warn: "yellow",
|
|
147
|
-
info: "green",
|
|
148
|
-
debug: "blue",
|
|
149
|
-
trace: "magenta",
|
|
150
|
-
verbose: "cyan"
|
|
151
|
-
};
|
|
152
|
-
|
|
153
192
|
//#endregion
|
|
154
193
|
//#region src/utils/error.utils.ts
|
|
155
194
|
const EXTRA_FIELDS = [
|
|
@@ -392,16 +431,29 @@ function disableOtelBridge() {
|
|
|
392
431
|
//#endregion
|
|
393
432
|
//#region src/utils/redact.utils.ts
|
|
394
433
|
const DEFAULT_CENSOR = "[REDACTED]";
|
|
434
|
+
/** Maximum nesting depth walked; deeper values are replaced with a marker. */
|
|
435
|
+
const MAX_DEPTH = 32;
|
|
436
|
+
/** Maximum number of objects/arrays visited per redaction pass. */
|
|
437
|
+
const MAX_NODES = 1e4;
|
|
438
|
+
/**
|
|
439
|
+
* Strings longer than this are truncated before pattern scanning. The tail is
|
|
440
|
+
* dropped rather than emitted unscanned, so oversized input can never carry an
|
|
441
|
+
* unredacted secret past the patterns.
|
|
442
|
+
*/
|
|
443
|
+
const MAX_SCAN_LENGTH = 16384;
|
|
444
|
+
const MAX_DEPTH_MARKER = "[MaxDepth]";
|
|
445
|
+
const MAX_NODES_MARKER = "[MaxNodes]";
|
|
446
|
+
const REDACTION_FAILED = "[RedactionFailed]";
|
|
395
447
|
/**
|
|
396
448
|
* Conservative patterns: tokens and secrets that should NEVER appear in logs.
|
|
397
449
|
* Applied when `autoDetect: true` or `autoDetect: 'conservative'`.
|
|
398
450
|
*/
|
|
399
451
|
const PII_CONSERVATIVE_PATTERNS = [
|
|
400
|
-
/eyJ[A-Za-z0-9_-]
|
|
452
|
+
/eyJ[A-Za-z0-9_-]{1,1024}\.[A-Za-z0-9_-]{1,16384}\.[A-Za-z0-9_-]{0,1024}/g,
|
|
401
453
|
/Bearer\s+[A-Za-z0-9._~+/-]+=*/gi,
|
|
402
454
|
/\b(?:sk|pk|api|key|secret|token)-[A-Za-z0-9_-]{16,}/gi,
|
|
403
455
|
/\bAKIA[0-9A-Z]{16}\b/g,
|
|
404
|
-
|
|
456
|
+
/secret[_-]?(?:access[_-]?)?key["'\s:=]{1,6}[A-Za-z0-9/+]{40}(?![A-Za-z0-9/+])/gi
|
|
405
457
|
];
|
|
406
458
|
/**
|
|
407
459
|
* Conservative field-name paths auto-redacted by name regardless of value.
|
|
@@ -422,14 +474,24 @@ const PII_CONSERVATIVE_PATHS = [
|
|
|
422
474
|
"**.privateKey",
|
|
423
475
|
"**.private_key",
|
|
424
476
|
"**.clientSecret",
|
|
425
|
-
"**.client_secret"
|
|
477
|
+
"**.client_secret",
|
|
478
|
+
"**.cookie",
|
|
479
|
+
"**.set-cookie",
|
|
480
|
+
"**.x-api-key",
|
|
481
|
+
"**.session",
|
|
482
|
+
"**.proxy-authorization",
|
|
483
|
+
"**.x-auth-token",
|
|
484
|
+
"**.x-access-token",
|
|
485
|
+
"**.aws_secret_access_key",
|
|
486
|
+
"**.awsSecretAccessKey",
|
|
487
|
+
"**.secretAccessKey"
|
|
426
488
|
];
|
|
427
489
|
/**
|
|
428
490
|
* Aggressive patterns: also catch personal data that could identify a person.
|
|
429
491
|
* Applied when `autoDetect: 'aggressive'`.
|
|
430
492
|
*/
|
|
431
493
|
const PII_AGGRESSIVE_PATTERNS = [
|
|
432
|
-
/\b[A-Za-z0-9._%+-]
|
|
494
|
+
/\b[A-Za-z0-9._%+-]{1,64}@[A-Za-z0-9.-]{1,255}\.[A-Za-z]{2,24}\b/g,
|
|
433
495
|
/\b\d{3}-?\d{2}-?\d{4}\b/g,
|
|
434
496
|
/\b(?:\d[ -]?){13,19}\b/g,
|
|
435
497
|
/\b(?:\+?1[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}\b/g,
|
|
@@ -526,32 +588,54 @@ function matchesPath(fullPath, pattern) {
|
|
|
526
588
|
}
|
|
527
589
|
return re.test(fullPath);
|
|
528
590
|
}
|
|
591
|
+
function isTokenChar(code) {
|
|
592
|
+
return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 46 || code === 95 || code === 126 || code === 43 || code === 47 || code === 61 || code === 45;
|
|
593
|
+
}
|
|
529
594
|
function applyPatterns(value, patterns, censor) {
|
|
530
595
|
let redacted = value;
|
|
596
|
+
let suffix = "";
|
|
597
|
+
if (redacted.length > MAX_SCAN_LENGTH) {
|
|
598
|
+
let end = MAX_SCAN_LENGTH;
|
|
599
|
+
while (end > 0 && isTokenChar(redacted.charCodeAt(end - 1))) end--;
|
|
600
|
+
suffix = `…[truncated ${value.length - end} unscanned chars]`;
|
|
601
|
+
redacted = redacted.slice(0, end);
|
|
602
|
+
}
|
|
531
603
|
for (const pattern of patterns) redacted = redacted.replace(pattern, censor);
|
|
532
|
-
return redacted;
|
|
604
|
+
return redacted + suffix;
|
|
533
605
|
}
|
|
534
606
|
const CIRCULAR = "[Circular]";
|
|
535
607
|
function joinPath(parent, key) {
|
|
536
608
|
return parent ? `${parent}.${key}` : key;
|
|
537
609
|
}
|
|
538
|
-
function walkValue(value, state, fullPath, bare) {
|
|
610
|
+
function walkValue(value, state, fullPath, bare, depth) {
|
|
539
611
|
const { paths = [], excludePaths = [], patterns = [], censor = DEFAULT_CENSOR } = state.config;
|
|
540
612
|
if (paths.some((p) => matchesPath(fullPath, p) || matchesPath(bare, p))) return censor;
|
|
613
|
+
if (typeof value === "object" && value !== null) {
|
|
614
|
+
if (depth >= MAX_DEPTH) return MAX_DEPTH_MARKER;
|
|
615
|
+
if (++state.nodes > MAX_NODES) return MAX_NODES_MARKER;
|
|
616
|
+
}
|
|
541
617
|
if (typeof value === "string") {
|
|
542
618
|
if (patterns.length === 0) return value;
|
|
543
619
|
if (excludePaths.some((p) => matchesPath(fullPath, p) || matchesPath(bare, p))) return value;
|
|
544
620
|
return applyPatterns(value, patterns, censor);
|
|
545
621
|
}
|
|
546
|
-
if (Array.isArray(value)) return walkContainer(value, state, fullPath, bare, walkArray);
|
|
547
|
-
if (
|
|
622
|
+
if (Array.isArray(value)) return walkContainer(value, state, fullPath, bare, depth, walkArray);
|
|
623
|
+
if (value instanceof Error) return walkContainer(value, state, fullPath, bare, depth, walkError);
|
|
624
|
+
if (value instanceof URL) {
|
|
625
|
+
const url = new URL(value.href);
|
|
626
|
+
url.username = "";
|
|
627
|
+
url.password = "";
|
|
628
|
+
const redacted = walkValue(url.href, state, fullPath, bare, depth);
|
|
629
|
+
return redacted === value.href ? value : redacted;
|
|
630
|
+
}
|
|
631
|
+
if (isPlainObject(value)) return walkContainer(value, state, fullPath, bare, depth, typeof value.toJSON === "function" ? walkToJSON : walkRecord);
|
|
548
632
|
return value;
|
|
549
633
|
}
|
|
550
|
-
function walkContainer(value, state, fullPath, bare, walk) {
|
|
634
|
+
function walkContainer(value, state, fullPath, bare, depth, walk) {
|
|
551
635
|
if (state.ancestors.has(value)) return CIRCULAR;
|
|
552
636
|
state.ancestors.add(value);
|
|
553
637
|
try {
|
|
554
|
-
return walk(value, state, fullPath, bare);
|
|
638
|
+
return walk(value, state, fullPath, bare, depth + 1);
|
|
555
639
|
} finally {
|
|
556
640
|
state.ancestors.delete(value);
|
|
557
641
|
}
|
|
@@ -560,26 +644,51 @@ function walkContainer(value, state, fullPath, bare, walk) {
|
|
|
560
644
|
* Array elements are matched by their indexed path (`users.0.password`) and by
|
|
561
645
|
* the index-free path (`users.password`) that earlier versions used.
|
|
562
646
|
*/
|
|
563
|
-
function walkArray(arr, state, fullPath, bare) {
|
|
647
|
+
function walkArray(arr, state, fullPath, bare, depth) {
|
|
564
648
|
let result;
|
|
565
649
|
for (const [i, item] of arr.entries()) {
|
|
566
|
-
const next = walkValue(item, state, joinPath(fullPath, String(i)), bare);
|
|
650
|
+
const next = walkValue(item, state, joinPath(fullPath, String(i)), bare, depth);
|
|
567
651
|
if (next !== item && !result) result = arr.slice(0, i);
|
|
568
652
|
if (result) result.push(next);
|
|
569
653
|
}
|
|
570
654
|
return result ?? arr;
|
|
571
655
|
}
|
|
572
|
-
function walkRecord(obj, state, fullPath, bare) {
|
|
656
|
+
function walkRecord(obj, state, fullPath, bare, depth) {
|
|
573
657
|
let result;
|
|
574
658
|
const entries = Object.entries(obj);
|
|
575
659
|
for (const [index, [key, value]] of entries.entries()) {
|
|
576
660
|
const forbidden = key === "__proto__" || key === "constructor" || key === "prototype";
|
|
577
|
-
const next = forbidden ? void 0 : walkValue(value, state, joinPath(fullPath, key), joinPath(bare, key));
|
|
661
|
+
const next = forbidden ? void 0 : walkValue(value, state, joinPath(fullPath, key), joinPath(bare, key), depth);
|
|
578
662
|
if ((forbidden || next !== value) && !result) result = Object.fromEntries(entries.slice(0, index));
|
|
579
663
|
if (result && !forbidden) result[key] = next;
|
|
580
664
|
}
|
|
581
665
|
return result ?? obj;
|
|
582
666
|
}
|
|
667
|
+
/** Errors are serialized (own props + cause chain) and the result is walked. */
|
|
668
|
+
function walkError(err, state, fullPath, bare, depth) {
|
|
669
|
+
let serialized;
|
|
670
|
+
try {
|
|
671
|
+
serialized = serializeError(err);
|
|
672
|
+
} catch {
|
|
673
|
+
return {
|
|
674
|
+
name: err.name,
|
|
675
|
+
message: REDACTION_FAILED
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
const result = walkRecord(serialized, state, fullPath, bare, depth);
|
|
679
|
+
return result === serialized ? { ...serialized } : result;
|
|
680
|
+
}
|
|
681
|
+
/** Objects with `toJSON()` are redacted via the value they would serialize to. */
|
|
682
|
+
function walkToJSON(obj, state, fullPath, bare, depth) {
|
|
683
|
+
let json;
|
|
684
|
+
try {
|
|
685
|
+
json = obj.toJSON();
|
|
686
|
+
} catch {
|
|
687
|
+
return REDACTION_FAILED;
|
|
688
|
+
}
|
|
689
|
+
if (json === obj) return walkRecord(obj, state, fullPath, bare, depth);
|
|
690
|
+
return walkValue(json, state, fullPath, bare, depth);
|
|
691
|
+
}
|
|
583
692
|
/**
|
|
584
693
|
* Redact an object according to the given RedactConfig and return a new
|
|
585
694
|
* top-level object. Subtrees with nothing to redact are shared with the input,
|
|
@@ -588,8 +697,9 @@ function walkRecord(obj, state, fullPath, bare) {
|
|
|
588
697
|
function redactObject(obj, config, _currentPath = "") {
|
|
589
698
|
const result = walkRecord(obj, {
|
|
590
699
|
config,
|
|
591
|
-
ancestors: new Set([obj])
|
|
592
|
-
|
|
700
|
+
ancestors: new Set([obj]),
|
|
701
|
+
nodes: 0
|
|
702
|
+
}, _currentPath, _currentPath, 0);
|
|
593
703
|
return result === obj ? { ...obj } : result;
|
|
594
704
|
}
|
|
595
705
|
/**
|
|
@@ -600,12 +710,11 @@ function redactObject(obj, config, _currentPath = "") {
|
|
|
600
710
|
* stays allocation-free for the common no-redact case.
|
|
601
711
|
*/
|
|
602
712
|
function applyRedactionToString(value, config) {
|
|
603
|
-
|
|
713
|
+
const text = typeof value === "string" ? value : require_coerce_utils.safeToString(value);
|
|
714
|
+
if (!config) return text;
|
|
604
715
|
const resolved = resolveConfig(config);
|
|
605
|
-
if (!resolved.patterns || resolved.patterns.length === 0) return
|
|
606
|
-
|
|
607
|
-
for (const pattern of resolved.patterns) redacted = redacted.replace(pattern, resolved.censor ?? DEFAULT_CENSOR);
|
|
608
|
-
return redacted;
|
|
716
|
+
if (!resolved.patterns || resolved.patterns.length === 0) return text;
|
|
717
|
+
return applyPatterns(text, resolved.patterns, resolved.censor ?? DEFAULT_CENSOR);
|
|
609
718
|
}
|
|
610
719
|
/**
|
|
611
720
|
* Apply redaction to a log payload (top-level call convenience wrapper).
|
|
@@ -645,11 +754,21 @@ const ALWAYS_EMIT_LEVELS = new Set([
|
|
|
645
754
|
"warn",
|
|
646
755
|
"fatal"
|
|
647
756
|
]);
|
|
757
|
+
const MAX_CACHED_TRACE_ID_LENGTH = 256;
|
|
758
|
+
function isCacheableTraceId(id) {
|
|
759
|
+
if (typeof id !== "string" || id.length === 0 || id.length > MAX_CACHED_TRACE_ID_LENGTH) return false;
|
|
760
|
+
for (let i = 0; i < id.length; i++) {
|
|
761
|
+
const c = id.charCodeAt(i);
|
|
762
|
+
if (c < 32 || c >= 127 && c <= 159) return false;
|
|
763
|
+
}
|
|
764
|
+
return true;
|
|
765
|
+
}
|
|
648
766
|
var Sampler = class {
|
|
649
767
|
constructor(config, onStats) {
|
|
650
768
|
this.traceDecisions = /* @__PURE__ */ new Map();
|
|
651
769
|
this.maxTrackedTraces = 1e5;
|
|
652
770
|
this.traceTtlMs = 5 * 6e4;
|
|
771
|
+
this.traceMaxLifetimeMs = 60 * 6e4;
|
|
653
772
|
this._tokenBucket = 0;
|
|
654
773
|
this._lastRefillMs = Date.now();
|
|
655
774
|
this._adaptiveWindow = [];
|
|
@@ -769,13 +888,15 @@ var Sampler = class {
|
|
|
769
888
|
}
|
|
770
889
|
/**
|
|
771
890
|
* Return the cached decision for a trace, or make and cache a new one. Entries
|
|
772
|
-
* idle past the TTL are re-decided; the least
|
|
773
|
-
* once the cap is reached.
|
|
891
|
+
* idle past the TTL, or older than the hard lifetime, are re-decided; the least
|
|
892
|
+
* recently used entry is evicted once the cap is reached. IDs that are empty,
|
|
893
|
+
* too long or contain control characters are sampled independently and never cached.
|
|
774
894
|
*/
|
|
775
895
|
_decideForTrace(traceId, level) {
|
|
896
|
+
if (!isCacheableTraceId(traceId)) return this._sampleByRate(level);
|
|
776
897
|
const now = Date.now();
|
|
777
898
|
const known = this.traceDecisions.get(traceId);
|
|
778
|
-
if (known && now - known.seenAt <= this.traceTtlMs) {
|
|
899
|
+
if (known && now - known.seenAt <= this.traceTtlMs && now - known.firstAt <= this.traceMaxLifetimeMs) {
|
|
779
900
|
this.traceDecisions.delete(traceId);
|
|
780
901
|
known.seenAt = now;
|
|
781
902
|
this.traceDecisions.set(traceId, known);
|
|
@@ -785,6 +906,7 @@ var Sampler = class {
|
|
|
785
906
|
this.traceDecisions.delete(traceId);
|
|
786
907
|
this.traceDecisions.set(traceId, {
|
|
787
908
|
emit,
|
|
909
|
+
firstAt: now,
|
|
788
910
|
seenAt: now
|
|
789
911
|
});
|
|
790
912
|
if (this.traceDecisions.size > this.maxTrackedTraces) {
|
|
@@ -948,318 +1070,6 @@ function resetShutdownHandlers() {
|
|
|
948
1070
|
shutdownInProgress = false;
|
|
949
1071
|
}
|
|
950
1072
|
|
|
951
|
-
//#endregion
|
|
952
|
-
//#region node_modules/uuid/dist/esm-node/rng.js
|
|
953
|
-
const rnds8Pool = new Uint8Array(256);
|
|
954
|
-
let poolPtr = rnds8Pool.length;
|
|
955
|
-
function rng() {
|
|
956
|
-
if (poolPtr > rnds8Pool.length - 16) {
|
|
957
|
-
crypto.default.randomFillSync(rnds8Pool);
|
|
958
|
-
poolPtr = 0;
|
|
959
|
-
}
|
|
960
|
-
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
//#endregion
|
|
964
|
-
//#region node_modules/uuid/dist/esm-node/stringify.js
|
|
965
|
-
/**
|
|
966
|
-
* Convert array of 16 byte values to UUID string format of the form:
|
|
967
|
-
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
|
968
|
-
*/
|
|
969
|
-
const byteToHex = [];
|
|
970
|
-
for (let i = 0; i < 256; ++i) byteToHex.push((i + 256).toString(16).slice(1));
|
|
971
|
-
function unsafeStringify(arr, offset = 0) {
|
|
972
|
-
return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
//#endregion
|
|
976
|
-
//#region node_modules/uuid/dist/esm-node/native.js
|
|
977
|
-
var native_default = { randomUUID: crypto.default.randomUUID };
|
|
978
|
-
|
|
979
|
-
//#endregion
|
|
980
|
-
//#region node_modules/uuid/dist/esm-node/v4.js
|
|
981
|
-
function v4(options, buf, offset) {
|
|
982
|
-
if (native_default.randomUUID && !buf && !options) return native_default.randomUUID();
|
|
983
|
-
options = options || {};
|
|
984
|
-
const rnds = options.random || (options.rng || rng)();
|
|
985
|
-
rnds[6] = rnds[6] & 15 | 64;
|
|
986
|
-
rnds[8] = rnds[8] & 63 | 128;
|
|
987
|
-
if (buf) {
|
|
988
|
-
offset = offset || 0;
|
|
989
|
-
for (let i = 0; i < 16; ++i) buf[offset + i] = rnds[i];
|
|
990
|
-
return buf;
|
|
991
|
-
}
|
|
992
|
-
return unsafeStringify(rnds);
|
|
993
|
-
}
|
|
994
|
-
var v4_default = v4;
|
|
995
|
-
|
|
996
|
-
//#endregion
|
|
997
|
-
//#region src/utils/trace.utils.ts
|
|
998
|
-
/** Default key used to store the trace ID in AsyncLocalStorage. */
|
|
999
|
-
const TRACE_CONTEXT_KEY = "traceId";
|
|
1000
|
-
/**
|
|
1001
|
-
* Singleton that owns the AsyncLocalStorage and the active contextKey.
|
|
1002
|
-
*
|
|
1003
|
-
* Why a class instead of bare module-level variables?
|
|
1004
|
-
* - The contextKey is user-configurable; encapsulating it here means there is
|
|
1005
|
-
* exactly one place that reads and writes it.
|
|
1006
|
-
* - All helpers (getCurrentTraceId, runWithTraceId, etc.) delegate to this
|
|
1007
|
-
* instance, so the key is always in sync without hidden global state.
|
|
1008
|
-
* - Easier to test: you can reset the singleton between test cases.
|
|
1009
|
-
*
|
|
1010
|
-
* Usage (advanced):
|
|
1011
|
-
* import { TraceContext } from 'logixia';
|
|
1012
|
-
* TraceContext.instance.contextKey // → 'traceId' (or custom)
|
|
1013
|
-
* TraceContext.instance.getCurrentTraceId() // same as standalone fn
|
|
1014
|
-
*/
|
|
1015
|
-
var TraceContext = class TraceContext {
|
|
1016
|
-
static #_ = this._instance = null;
|
|
1017
|
-
constructor() {
|
|
1018
|
-
this.storage = new node_async_hooks.AsyncLocalStorage();
|
|
1019
|
-
this._contextKey = TRACE_CONTEXT_KEY;
|
|
1020
|
-
}
|
|
1021
|
-
/** The process-wide singleton. */
|
|
1022
|
-
static get instance() {
|
|
1023
|
-
if (!TraceContext._instance) TraceContext._instance = new TraceContext();
|
|
1024
|
-
return TraceContext._instance;
|
|
1025
|
-
}
|
|
1026
|
-
/** @internal Reset the singleton (useful in tests). */
|
|
1027
|
-
static _reset() {
|
|
1028
|
-
TraceContext._instance = null;
|
|
1029
|
-
}
|
|
1030
|
-
/** The AsyncLocalStorage key that holds the trace ID value. */
|
|
1031
|
-
get contextKey() {
|
|
1032
|
-
return this._contextKey;
|
|
1033
|
-
}
|
|
1034
|
-
/** @internal Called by TraceMiddleware when it boots to register the user's key. */
|
|
1035
|
-
setContextKey(key) {
|
|
1036
|
-
this._contextKey = key;
|
|
1037
|
-
}
|
|
1038
|
-
/** UUID v4 generator (default). */
|
|
1039
|
-
generate() {
|
|
1040
|
-
return v4_default();
|
|
1041
|
-
}
|
|
1042
|
-
/** Read the trace ID from the current async context. */
|
|
1043
|
-
getCurrentTraceId() {
|
|
1044
|
-
var _this$storage$getStor;
|
|
1045
|
-
return (_this$storage$getStor = this.storage.getStore()) === null || _this$storage$getStor === void 0 ? void 0 : _this$storage$getStor[this._contextKey];
|
|
1046
|
-
}
|
|
1047
|
-
/**
|
|
1048
|
-
* Mutate the CURRENT async context in-place.
|
|
1049
|
-
*
|
|
1050
|
-
* ⚠️ DEPRECATED — unsafe for concurrent requests.
|
|
1051
|
-
*
|
|
1052
|
-
* Uses `AsyncLocalStorage.enterWith()`, which mutates the current async
|
|
1053
|
-
* execution context and every Promise chain spawned from it. In a server
|
|
1054
|
-
* processing overlapping requests this can cause a trace ID set for one
|
|
1055
|
-
* request to bleed into *other* in-flight requests that share the same
|
|
1056
|
-
* async parent (e.g. a module-level setup function or a cached handler).
|
|
1057
|
-
*
|
|
1058
|
-
* Use {@link run} instead — it scopes the context to a callback so there
|
|
1059
|
-
* is no risk of cross-request leakage.
|
|
1060
|
-
*
|
|
1061
|
-
* @deprecated Use `TraceContext.instance.run(traceId, fn)` — do not call
|
|
1062
|
-
* `setTraceId` from request-handling code.
|
|
1063
|
-
*/
|
|
1064
|
-
setTraceId(traceId, data) {
|
|
1065
|
-
const current = this.storage.getStore() ?? {};
|
|
1066
|
-
this.storage.enterWith({
|
|
1067
|
-
...current,
|
|
1068
|
-
[this._contextKey]: traceId,
|
|
1069
|
-
...data
|
|
1070
|
-
});
|
|
1071
|
-
}
|
|
1072
|
-
/** Run `fn` inside a new async context that carries `traceId`. */
|
|
1073
|
-
run(traceId, fn, data) {
|
|
1074
|
-
return this.storage.run({
|
|
1075
|
-
[this._contextKey]: traceId,
|
|
1076
|
-
...data
|
|
1077
|
-
}, fn);
|
|
1078
|
-
}
|
|
1079
|
-
};
|
|
1080
|
-
/**
|
|
1081
|
-
* The shared AsyncLocalStorage instance.
|
|
1082
|
-
* @deprecated Prefer `TraceContext.instance.storage` for new code.
|
|
1083
|
-
*/
|
|
1084
|
-
const traceStorage = TraceContext.instance.storage;
|
|
1085
|
-
/** Returns the key currently used to store the trace ID in AsyncLocalStorage. */
|
|
1086
|
-
function getTraceContextKey() {
|
|
1087
|
-
return TraceContext.instance.contextKey;
|
|
1088
|
-
}
|
|
1089
|
-
/** @internal Called by TraceMiddleware / traceMiddleware() when they boot. */
|
|
1090
|
-
function _setActiveContextKey(key) {
|
|
1091
|
-
TraceContext.instance.setContextKey(key);
|
|
1092
|
-
}
|
|
1093
|
-
/** Generate a UUID v4 trace ID. */
|
|
1094
|
-
function generateTraceId() {
|
|
1095
|
-
return TraceContext.instance.generate();
|
|
1096
|
-
}
|
|
1097
|
-
/**
|
|
1098
|
-
* Get the current trace ID from async context.
|
|
1099
|
-
* Returns `undefined` when called outside a traced request.
|
|
1100
|
-
*/
|
|
1101
|
-
function getCurrentTraceId() {
|
|
1102
|
-
return TraceContext.instance.getCurrentTraceId();
|
|
1103
|
-
}
|
|
1104
|
-
/**
|
|
1105
|
-
* Set trace ID in the CURRENT async context without starting a new one.
|
|
1106
|
-
*
|
|
1107
|
-
* ⚠️ DEPRECATED — unsafe for concurrent requests.
|
|
1108
|
-
*
|
|
1109
|
-
* Uses `AsyncLocalStorage.enterWith()`, which mutates the current async
|
|
1110
|
-
* execution context and every Promise chain spawned from it. Under load this
|
|
1111
|
-
* can cause a trace ID from one request to bleed into others sharing the same
|
|
1112
|
-
* async parent.
|
|
1113
|
-
*
|
|
1114
|
-
* Use {@link runWithTraceId} instead. Migration patterns:
|
|
1115
|
-
*
|
|
1116
|
-
* **Express / Fastify middleware — before:**
|
|
1117
|
-
* ```ts
|
|
1118
|
-
* app.use((req, _res, next) => {
|
|
1119
|
-
* setTraceId(req.headers['x-trace-id'] ?? generateTraceId());
|
|
1120
|
-
* next();
|
|
1121
|
-
* });
|
|
1122
|
-
* ```
|
|
1123
|
-
* **after:**
|
|
1124
|
-
* ```ts
|
|
1125
|
-
* app.use((req, _res, next) => {
|
|
1126
|
-
* runWithTraceId(req.headers['x-trace-id'] ?? generateTraceId(), () => next());
|
|
1127
|
-
* });
|
|
1128
|
-
* ```
|
|
1129
|
-
*
|
|
1130
|
-
* **Kafka / queue consumer — before:**
|
|
1131
|
-
* ```ts
|
|
1132
|
-
* async function handle(msg) {
|
|
1133
|
-
* setTraceId(msg.headers['x-trace-id']);
|
|
1134
|
-
* await processMessage(msg);
|
|
1135
|
-
* }
|
|
1136
|
-
* ```
|
|
1137
|
-
* **after:**
|
|
1138
|
-
* ```ts
|
|
1139
|
-
* async function handle(msg) {
|
|
1140
|
-
* await runWithTraceId(msg.headers['x-trace-id'], () => processMessage(msg));
|
|
1141
|
-
* }
|
|
1142
|
-
* ```
|
|
1143
|
-
*
|
|
1144
|
-
* **Background job — before:**
|
|
1145
|
-
* ```ts
|
|
1146
|
-
* setTraceId(generateTraceId(), { jobId: job.id });
|
|
1147
|
-
* await job.run();
|
|
1148
|
-
* ```
|
|
1149
|
-
* **after:**
|
|
1150
|
-
* ```ts
|
|
1151
|
-
* await runWithTraceId(generateTraceId(), () => job.run(), { jobId: job.id });
|
|
1152
|
-
* ```
|
|
1153
|
-
*
|
|
1154
|
-
* @deprecated Use `runWithTraceId(traceId, fn)` — do not call `setTraceId`
|
|
1155
|
-
* from request-handling code.
|
|
1156
|
-
*/
|
|
1157
|
-
function setTraceId(traceId, data) {
|
|
1158
|
-
TraceContext.instance.setTraceId(traceId, data);
|
|
1159
|
-
}
|
|
1160
|
-
/** Run `fn` inside a new async context carrying `traceId`. */
|
|
1161
|
-
function runWithTraceId(traceId, fn, data) {
|
|
1162
|
-
return TraceContext.instance.run(traceId, fn, data);
|
|
1163
|
-
}
|
|
1164
|
-
/**
|
|
1165
|
-
* Coerce an arbitrary value to a non-empty trace ID string, or `undefined`.
|
|
1166
|
-
* Rejects empty/whitespace-only strings, non-strings, and non-first array elements.
|
|
1167
|
-
*/
|
|
1168
|
-
function toValidTraceId(value) {
|
|
1169
|
-
const first = Array.isArray(value) ? value[0] : value;
|
|
1170
|
-
if (typeof first !== "string") return void 0;
|
|
1171
|
-
const trimmed = first.trim();
|
|
1172
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
1173
|
-
}
|
|
1174
|
-
/** W3C trace-context: `version-traceId(32hex)-spanId(16hex)-flags(2hex)`. */
|
|
1175
|
-
const W3C_TRACEPARENT_RE = /^[\da-f]{2}-([\da-f]{32})-[\da-f]{16}-[\da-f]{2}$/i;
|
|
1176
|
-
/**
|
|
1177
|
-
* Extract the 32-hex trace-id segment from a W3C `traceparent` header value.
|
|
1178
|
-
* Returns the parsed trace ID, or the original value unchanged when it is not a
|
|
1179
|
-
* well-formed traceparent (so non-W3C propagation still works).
|
|
1180
|
-
*/
|
|
1181
|
-
function parseTraceparent(value) {
|
|
1182
|
-
const m = W3C_TRACEPARENT_RE.exec(value);
|
|
1183
|
-
return m ? m[1] : value;
|
|
1184
|
-
}
|
|
1185
|
-
/** Extract trace ID from request using configuration (header → query → body → params). */
|
|
1186
|
-
function extractTraceId(request, config) {
|
|
1187
|
-
const req = request;
|
|
1188
|
-
if (config.header) {
|
|
1189
|
-
const headers = Array.isArray(config.header) ? config.header : [config.header];
|
|
1190
|
-
for (const header of headers) {
|
|
1191
|
-
var _req$headers;
|
|
1192
|
-
const lower = header.toLowerCase();
|
|
1193
|
-
const value = toValidTraceId((_req$headers = req.headers) === null || _req$headers === void 0 ? void 0 : _req$headers[lower]);
|
|
1194
|
-
if (value) return lower === "traceparent" ? parseTraceparent(value) : value;
|
|
1195
|
-
}
|
|
1196
|
-
}
|
|
1197
|
-
if (config.query) {
|
|
1198
|
-
const queries = Array.isArray(config.query) ? config.query : [config.query];
|
|
1199
|
-
for (const query of queries) {
|
|
1200
|
-
var _req$query;
|
|
1201
|
-
const value = toValidTraceId((_req$query = req.query) === null || _req$query === void 0 ? void 0 : _req$query[query]);
|
|
1202
|
-
if (value) return value;
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
if (config.body) {
|
|
1206
|
-
const bodyFields = Array.isArray(config.body) ? config.body : [config.body];
|
|
1207
|
-
for (const field of bodyFields) {
|
|
1208
|
-
var _req$body;
|
|
1209
|
-
const value = toValidTraceId((_req$body = req.body) === null || _req$body === void 0 ? void 0 : _req$body[field]);
|
|
1210
|
-
if (value) return value;
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
if (config.params) {
|
|
1214
|
-
const paramFields = Array.isArray(config.params) ? config.params : [config.params];
|
|
1215
|
-
for (const param of paramFields) {
|
|
1216
|
-
var _req$params;
|
|
1217
|
-
const value = toValidTraceId((_req$params = req.params) === null || _req$params === void 0 ? void 0 : _req$params[param]);
|
|
1218
|
-
if (value) return value;
|
|
1219
|
-
}
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1222
|
-
/**
|
|
1223
|
-
* Default headers checked for incoming trace ID propagation, in priority order:
|
|
1224
|
-
* traceparent (W3C/OTel) → x-trace-id → x-request-id → x-correlation-id → trace-id
|
|
1225
|
-
*/
|
|
1226
|
-
const DEFAULT_TRACE_HEADERS = [
|
|
1227
|
-
"traceparent",
|
|
1228
|
-
"x-trace-id",
|
|
1229
|
-
"x-request-id",
|
|
1230
|
-
"x-correlation-id",
|
|
1231
|
-
"trace-id"
|
|
1232
|
-
];
|
|
1233
|
-
/**
|
|
1234
|
-
* Create trace ID middleware for Express/NestJS
|
|
1235
|
-
*/
|
|
1236
|
-
function createTraceMiddleware(config) {
|
|
1237
|
-
const defaultExtractor = {
|
|
1238
|
-
header: DEFAULT_TRACE_HEADERS,
|
|
1239
|
-
query: ["traceId", "trace_id"]
|
|
1240
|
-
};
|
|
1241
|
-
const resolvedConfig = {
|
|
1242
|
-
...config,
|
|
1243
|
-
extractor: (config === null || config === void 0 ? void 0 : config.extractor) ? {
|
|
1244
|
-
...defaultExtractor,
|
|
1245
|
-
...config.extractor
|
|
1246
|
-
} : defaultExtractor
|
|
1247
|
-
};
|
|
1248
|
-
_setActiveContextKey(resolvedConfig.contextKey ?? TRACE_CONTEXT_KEY);
|
|
1249
|
-
return (req, res, next) => {
|
|
1250
|
-
let traceId;
|
|
1251
|
-
if (resolvedConfig.extractor) traceId = extractTraceId(req, resolvedConfig.extractor);
|
|
1252
|
-
if (!traceId) traceId = resolvedConfig.generator ? resolvedConfig.generator() : generateTraceId();
|
|
1253
|
-
req.traceId = traceId;
|
|
1254
|
-
const resObj = res;
|
|
1255
|
-
if (!resObj.headersSent) try {
|
|
1256
|
-
if (typeof resObj.setHeader === "function") resObj.setHeader("X-Trace-Id", traceId);
|
|
1257
|
-
else if (typeof resObj.header === "function") resObj.header("X-Trace-Id", traceId);
|
|
1258
|
-
} catch {}
|
|
1259
|
-
runWithTraceId(traceId, () => next());
|
|
1260
|
-
};
|
|
1261
|
-
}
|
|
1262
|
-
|
|
1263
1073
|
//#endregion
|
|
1264
1074
|
//#region src/core/logitron-logger.ts
|
|
1265
1075
|
const _fastStringifyEntry = (0, fast_json_stringify.default)({
|
|
@@ -1348,7 +1158,7 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1348
1158
|
this.timers = /* @__PURE__ */ new Map();
|
|
1349
1159
|
this.contextData = {};
|
|
1350
1160
|
this.fieldState = /* @__PURE__ */ new Map();
|
|
1351
|
-
this.fallbackTraceId = TraceContext.instance.generate();
|
|
1161
|
+
this.fallbackTraceId = require_trace_utils.TraceContext.instance.generate();
|
|
1352
1162
|
this._levelValues = /* @__PURE__ */ new Map();
|
|
1353
1163
|
this._minLevelValue = 2;
|
|
1354
1164
|
this._warnedInvalidLevels = /* @__PURE__ */ new Set();
|
|
@@ -1799,7 +1609,7 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1799
1609
|
if (this.config.silent) return;
|
|
1800
1610
|
if (!this.shouldLog(level)) return;
|
|
1801
1611
|
if (this._sampler) {
|
|
1802
|
-
const traceId$1 = this.config.traceId ? TraceContext.instance.getCurrentTraceId() : void 0;
|
|
1612
|
+
const traceId$1 = this.config.traceId ? require_trace_utils.TraceContext.instance.getCurrentTraceId() : void 0;
|
|
1803
1613
|
if (!this._sampler.shouldEmit(level, traceId$1)) return;
|
|
1804
1614
|
}
|
|
1805
1615
|
const alsContext = require_async_context.LogixiaContext.get();
|
|
@@ -1822,9 +1632,21 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1822
1632
|
...mergedData
|
|
1823
1633
|
} : mergedData;
|
|
1824
1634
|
let payload;
|
|
1825
|
-
if (rawPayload !== void 0 && rawPayload !== null)
|
|
1826
|
-
|
|
1827
|
-
|
|
1635
|
+
if (rawPayload !== void 0 && rawPayload !== null) if (this._hasRedact) try {
|
|
1636
|
+
payload = applyRedaction(rawPayload, this.config.redact) ?? rawPayload;
|
|
1637
|
+
} catch (error) {
|
|
1638
|
+
require_internal_log.internalError("Redaction failed", error);
|
|
1639
|
+
payload = { redaction: REDACTION_FAILED };
|
|
1640
|
+
}
|
|
1641
|
+
else payload = rawPayload;
|
|
1642
|
+
const traceId = this.config.traceId ? require_trace_utils.TraceContext.instance.getCurrentTraceId() ?? this.fallbackTraceId : void 0;
|
|
1643
|
+
let safeMessage = message;
|
|
1644
|
+
if (this._hasRedact) try {
|
|
1645
|
+
safeMessage = applyRedactionToString(message, this.config.redact);
|
|
1646
|
+
} catch (error) {
|
|
1647
|
+
require_internal_log.internalError("Redaction failed", error);
|
|
1648
|
+
safeMessage = REDACTION_FAILED;
|
|
1649
|
+
}
|
|
1828
1650
|
const entry = {
|
|
1829
1651
|
timestamp: nowIso(),
|
|
1830
1652
|
level,
|
|
@@ -1895,9 +1717,9 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1895
1717
|
if (((_this$config$format4 = this.config.format) === null || _this$config$format4 === void 0 ? void 0 : _this$config$format4.timestamp) !== false && this._fieldCache.get("timestamp") !== false) formatted += `${gray}[${entry.timestamp}]${reset} `;
|
|
1896
1718
|
if (this._fieldCache.get("level") !== false) formatted += this._formattedLevels.get(entry.level) ?? `[${entry.level.toUpperCase()}] `;
|
|
1897
1719
|
formatted += this._formattedAppName;
|
|
1898
|
-
if (entry.traceId && this._fieldCache.get("traceId") !== false) formatted += `${cyan}[${entry.traceId}]${reset} `;
|
|
1899
|
-
if (entry.context && this._fieldCache.get("context") !== false) formatted += `${yellow}[${entry.context}]${reset} `;
|
|
1900
|
-
if (this._fieldCache.get("message") !== false) formatted += entry.message;
|
|
1720
|
+
if (entry.traceId && this._fieldCache.get("traceId") !== false) formatted += `${cyan}[${require_transport_manager.stripControlChars(String(entry.traceId))}]${reset} `;
|
|
1721
|
+
if (entry.context && this._fieldCache.get("context") !== false) formatted += `${yellow}[${require_transport_manager.stripControlChars(String(entry.context))}]${reset} `;
|
|
1722
|
+
if (this._fieldCache.get("message") !== false) formatted += require_transport_manager.stripControlChars(require_coerce_utils.safeToString(entry.message));
|
|
1901
1723
|
if (entry.payload !== void 0 && this._fieldCache.get("payload") !== false) formatted += ` ${require_safe_stringify.stringifyForLog(entry.payload)}`;
|
|
1902
1724
|
return formatted;
|
|
1903
1725
|
}
|
|
@@ -1947,723 +1769,241 @@ function createLogger(config, context) {
|
|
|
1947
1769
|
}
|
|
1948
1770
|
|
|
1949
1771
|
//#endregion
|
|
1950
|
-
//#region
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
}
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
//#endregion
|
|
1965
|
-
//#region src/core/logitron-nestjs.service.ts
|
|
1966
|
-
var _LogixiaLoggerService;
|
|
1967
|
-
let LogixiaLoggerService = _LogixiaLoggerService = class LogixiaLoggerService$1 {
|
|
1968
|
-
constructor(config) {
|
|
1969
|
-
this._mergedConfig = {
|
|
1970
|
-
appName: "NestJS-App",
|
|
1971
|
-
environment: "development",
|
|
1972
|
-
traceId: true,
|
|
1973
|
-
format: {
|
|
1974
|
-
timestamp: true,
|
|
1975
|
-
colorize: true,
|
|
1976
|
-
json: false
|
|
1977
|
-
},
|
|
1978
|
-
silent: false,
|
|
1979
|
-
levelOptions: {
|
|
1980
|
-
level: LogLevel.INFO,
|
|
1981
|
-
levels: {
|
|
1982
|
-
error: 0,
|
|
1983
|
-
warn: 1,
|
|
1984
|
-
log: 2,
|
|
1985
|
-
debug: 3,
|
|
1986
|
-
verbose: 4
|
|
1987
|
-
},
|
|
1988
|
-
colors: {
|
|
1989
|
-
error: "red",
|
|
1990
|
-
warn: "yellow",
|
|
1991
|
-
log: "green",
|
|
1992
|
-
debug: "blue",
|
|
1993
|
-
verbose: "cyan"
|
|
1994
|
-
}
|
|
1995
|
-
},
|
|
1996
|
-
fields: {
|
|
1997
|
-
timestamp: "[yyyy-mm-dd HH:MM:ss.MS]",
|
|
1998
|
-
level: "[log_level]",
|
|
1999
|
-
appName: "[app_name]",
|
|
2000
|
-
traceId: "[trace_id]",
|
|
2001
|
-
message: "[message]",
|
|
2002
|
-
payload: "[payload]",
|
|
2003
|
-
timeTaken: "[time_taken_MS]"
|
|
2004
|
-
},
|
|
2005
|
-
...config
|
|
2006
|
-
};
|
|
2007
|
-
this.logger = new LogixiaLogger(this._mergedConfig);
|
|
2008
|
-
this._createCustomLevelMethods();
|
|
2009
|
-
}
|
|
2010
|
-
_createCustomLevelMethods() {
|
|
2011
|
-
var _this$_mergedConfig$l;
|
|
2012
|
-
const levels = (_this$_mergedConfig$l = this._mergedConfig.levelOptions) === null || _this$_mergedConfig$l === void 0 ? void 0 : _this$_mergedConfig$l.levels;
|
|
2013
|
-
if (!levels) return;
|
|
2014
|
-
for (const levelName of Object.keys(levels)) {
|
|
2015
|
-
const lower = levelName.toLowerCase();
|
|
2016
|
-
if (typeof this[lower] !== "undefined") continue;
|
|
2017
|
-
this[lower] = async (message, data) => {
|
|
2018
|
-
return this.logger.logLevel(lower, message, data);
|
|
2019
|
-
};
|
|
2020
|
-
}
|
|
2021
|
-
}
|
|
2022
|
-
/**
|
|
2023
|
-
* NestJS `LoggerService.log` — void, string context.
|
|
2024
|
-
* Maps internally to `info`.
|
|
2025
|
-
*
|
|
2026
|
-
* @example `logger.log('User signed up', 'AuthService')`
|
|
2027
|
-
*/
|
|
2028
|
-
log(message, context) {
|
|
2029
|
-
this.setContextIfProvided(context);
|
|
2030
|
-
this.logger.info(this.formatMessage(message)).catch((err) => require_internal_log.internalError("LogixiaLoggerService.log failed", err));
|
|
2031
|
-
}
|
|
2032
|
-
/**
|
|
2033
|
-
* Native async `info` — structured data, returns `Promise<void>`.
|
|
2034
|
-
*
|
|
2035
|
-
* @example `await logger.info('User signed up', { userId: 'u_abc' })`
|
|
2036
|
-
*/
|
|
2037
|
-
async info(message, data) {
|
|
2038
|
-
return this.logger.info(message, data);
|
|
2039
|
-
}
|
|
2040
|
-
error(message, dataOrTrace, context) {
|
|
2041
|
-
if (typeof dataOrTrace === "object" && dataOrTrace !== null) return message instanceof Error ? this.logger.error(message, dataOrTrace) : this.logger.error(this.formatMessage(message), dataOrTrace);
|
|
2042
|
-
this.setContextIfProvided(context);
|
|
2043
|
-
const errorData = {};
|
|
2044
|
-
if (typeof dataOrTrace === "string" && dataOrTrace) errorData.stack = dataOrTrace;
|
|
2045
|
-
(message instanceof Error ? this.logger.error(message, errorData) : this.logger.error(this.formatMessage(message), errorData)).catch((err) => require_internal_log.internalError("LogixiaLoggerService.error failed", err));
|
|
2046
|
-
}
|
|
2047
|
-
warn(message, dataOrContext) {
|
|
2048
|
-
if (typeof dataOrContext === "object" && dataOrContext !== null) return this.logger.warn(this.formatMessage(message), dataOrContext);
|
|
2049
|
-
this.setContextIfProvided(typeof dataOrContext === "string" ? dataOrContext : void 0);
|
|
2050
|
-
this.logger.warn(this.formatMessage(message)).catch((err) => require_internal_log.internalError("LogixiaLoggerService.warn failed", err));
|
|
2051
|
-
}
|
|
2052
|
-
debug(message, dataOrContext) {
|
|
2053
|
-
if (typeof dataOrContext === "object" && dataOrContext !== null) return this.logger.debug(this.formatMessage(message), dataOrContext);
|
|
2054
|
-
this.setContextIfProvided(typeof dataOrContext === "string" ? dataOrContext : void 0);
|
|
2055
|
-
this.logger.debug(this.formatMessage(message)).catch((err) => require_internal_log.internalError("LogixiaLoggerService.debug failed", err));
|
|
2056
|
-
}
|
|
2057
|
-
verbose(message, dataOrContext) {
|
|
2058
|
-
if (typeof dataOrContext === "object" && dataOrContext !== null) return this.logger.trace(this.formatMessage(message), dataOrContext);
|
|
2059
|
-
this.setContextIfProvided(typeof dataOrContext === "string" ? dataOrContext : void 0);
|
|
2060
|
-
this.logger.trace(this.formatMessage(message)).catch((err) => require_internal_log.internalError("LogixiaLoggerService.verbose failed", err));
|
|
2061
|
-
}
|
|
2062
|
-
/**
|
|
2063
|
-
* Native async `trace` — lowest verbosity level, structured data.
|
|
2064
|
-
*/
|
|
2065
|
-
async trace(message, data) {
|
|
2066
|
-
return this.logger.trace(message, data);
|
|
2067
|
-
}
|
|
2068
|
-
/**
|
|
2069
|
-
* Log at any named level with structured data.
|
|
2070
|
-
*/
|
|
2071
|
-
logLevel(level, message, data) {
|
|
2072
|
-
return this.logger.logLevel(level, message, data);
|
|
2073
|
-
}
|
|
2074
|
-
time(label) {
|
|
2075
|
-
this.logger.time(label);
|
|
2076
|
-
}
|
|
2077
|
-
async timeEnd(label) {
|
|
2078
|
-
return this.logger.timeEnd(label);
|
|
2079
|
-
}
|
|
2080
|
-
async timeAsync(label, fn) {
|
|
2081
|
-
return this.logger.timeAsync(label, fn);
|
|
2082
|
-
}
|
|
2083
|
-
setContext(context) {
|
|
2084
|
-
const coerced = typeof context === "string" ? context : require_coerce_utils.safeToString(context);
|
|
2085
|
-
this.context = coerced;
|
|
2086
|
-
this.logger.setContext(coerced);
|
|
2087
|
-
}
|
|
2088
|
-
getContext() {
|
|
2089
|
-
return this.context;
|
|
2090
|
-
}
|
|
2091
|
-
setLevel(level) {
|
|
2092
|
-
this.logger.setLevel(level);
|
|
2093
|
-
}
|
|
2094
|
-
getLevel() {
|
|
2095
|
-
return this.logger.getLevel();
|
|
2096
|
-
}
|
|
2097
|
-
child(context, data) {
|
|
2098
|
-
const childService = new _LogixiaLoggerService(this._mergedConfig);
|
|
2099
|
-
childService.logger = this.logger.child(context, data);
|
|
2100
|
-
childService.context = context;
|
|
2101
|
-
return childService;
|
|
2102
|
-
}
|
|
2103
|
-
getCurrentTraceId() {
|
|
2104
|
-
return TraceContext.instance.getCurrentTraceId();
|
|
2105
|
-
}
|
|
2106
|
-
/** Returns the AsyncLocalStorage key currently used to store the trace ID. */
|
|
2107
|
-
get traceContextKey() {
|
|
2108
|
-
return getTraceContextKey();
|
|
2109
|
-
}
|
|
2110
|
-
async close() {
|
|
2111
|
-
return this.logger.close();
|
|
2112
|
-
}
|
|
2113
|
-
static create(config) {
|
|
2114
|
-
return new _LogixiaLoggerService(config);
|
|
2115
|
-
}
|
|
2116
|
-
getLogger() {
|
|
2117
|
-
return this.logger;
|
|
2118
|
-
}
|
|
2119
|
-
setContextIfProvided(context) {
|
|
2120
|
-
if (typeof context !== "string" || context.length === 0) return;
|
|
2121
|
-
if (context !== this.context) this.setContext(context);
|
|
2122
|
-
}
|
|
2123
|
-
formatMessage(message) {
|
|
2124
|
-
if (typeof message === "string") return message;
|
|
2125
|
-
return require_coerce_utils.safeToString(message);
|
|
2126
|
-
}
|
|
2127
|
-
};
|
|
2128
|
-
LogixiaLoggerService = _LogixiaLoggerService = __decorate([(0, __nestjs_common.Injectable)({ scope: __nestjs_common.Scope.TRANSIENT }), __decorateMetadata("design:paramtypes", [Object])], LogixiaLoggerService);
|
|
2129
|
-
|
|
2130
|
-
//#endregion
|
|
2131
|
-
//#region src/core/kafka-trace.interceptor.ts
|
|
2132
|
-
var _KafkaTraceInterceptor;
|
|
2133
|
-
let KafkaTraceInterceptor = class KafkaTraceInterceptor$1 {
|
|
2134
|
-
static {
|
|
2135
|
-
_KafkaTraceInterceptor = this;
|
|
2136
|
-
}
|
|
2137
|
-
static #_ = this.metrics = {
|
|
2138
|
-
accepted: 0,
|
|
2139
|
-
acceptedWithoutTrace: 0,
|
|
2140
|
-
dropped: 0
|
|
2141
|
-
};
|
|
2142
|
-
/** Reset counters (tests). */
|
|
2143
|
-
static resetMetrics() {
|
|
2144
|
-
_KafkaTraceInterceptor.metrics.accepted = 0;
|
|
2145
|
-
_KafkaTraceInterceptor.metrics.acceptedWithoutTrace = 0;
|
|
2146
|
-
_KafkaTraceInterceptor.metrics.dropped = 0;
|
|
2147
|
-
}
|
|
2148
|
-
/**
|
|
2149
|
-
* @param config - TraceIdConfig options (extractor keys, contextKey, etc.)
|
|
2150
|
-
* @param requireTraceId - When true, messages with no traceId are silently skipped
|
|
2151
|
-
* (EMPTY Observable — message is ack'd, consumer stays alive).
|
|
2152
|
-
* A WARN is logged AND `KafkaTraceInterceptor.metrics.dropped`
|
|
2153
|
-
* increments so the missing traceId is observable end-to-end.
|
|
2154
|
-
* Default: false (handler runs without trace context).
|
|
2155
|
-
*/
|
|
2156
|
-
constructor(config, requireTraceId = false) {
|
|
2157
|
-
this.config = config;
|
|
2158
|
-
this.requireTraceId = requireTraceId;
|
|
2159
|
-
this.ctx = TraceContext.instance;
|
|
2160
|
-
this.config = {
|
|
2161
|
-
enabled: true,
|
|
2162
|
-
contextKey: "traceId",
|
|
2163
|
-
extractor: {
|
|
2164
|
-
body: [
|
|
2165
|
-
"traceId",
|
|
2166
|
-
"trace_id",
|
|
2167
|
-
"x-trace-id"
|
|
2168
|
-
],
|
|
2169
|
-
header: ["x-trace-id", "trace-id"]
|
|
2170
|
-
},
|
|
2171
|
-
...config
|
|
2172
|
-
};
|
|
2173
|
-
}
|
|
2174
|
-
intercept(context, next) {
|
|
2175
|
-
var _this$config;
|
|
2176
|
-
if (!((_this$config = this.config) === null || _this$config === void 0 ? void 0 : _this$config.enabled)) return next.handle();
|
|
2177
|
-
const rpcContext = context.switchToRpc();
|
|
2178
|
-
const data = rpcContext.getData();
|
|
2179
|
-
const rpcData = rpcContext.getContext();
|
|
2180
|
-
let traceId;
|
|
2181
|
-
if (this.config.extractor) traceId = extractTraceId({
|
|
2182
|
-
body: data,
|
|
2183
|
-
headers: (rpcData === null || rpcData === void 0 ? void 0 : rpcData.headers) ?? {},
|
|
2184
|
-
query: {},
|
|
2185
|
-
params: {}
|
|
2186
|
-
}, this.config.extractor);
|
|
2187
|
-
if (!traceId) traceId = this.ctx.getCurrentTraceId();
|
|
2188
|
-
if (!traceId) {
|
|
2189
|
-
if (this.requireTraceId) {
|
|
2190
|
-
var _LogixiaLoggerModule$;
|
|
2191
|
-
_KafkaTraceInterceptor.metrics.dropped++;
|
|
2192
|
-
(_LogixiaLoggerModule$ = LogixiaLoggerModule.getGlobalLogger()) === null || _LogixiaLoggerModule$ === void 0 || _LogixiaLoggerModule$.warn(`[KafkaTraceInterceptor] Missing traceId on topic "${rpcData === null || rpcData === void 0 ? void 0 : rpcData.topic}" — message skipped.`);
|
|
2193
|
-
return rxjs.EMPTY;
|
|
2194
|
-
}
|
|
2195
|
-
_KafkaTraceInterceptor.metrics.acceptedWithoutTrace++;
|
|
2196
|
-
return next.handle();
|
|
2197
|
-
}
|
|
2198
|
-
_KafkaTraceInterceptor.metrics.accepted++;
|
|
2199
|
-
const kafkaContext = {
|
|
2200
|
-
messageType: "kafka",
|
|
2201
|
-
topic: rpcData === null || rpcData === void 0 ? void 0 : rpcData.topic,
|
|
2202
|
-
partition: rpcData === null || rpcData === void 0 ? void 0 : rpcData.partition,
|
|
2203
|
-
offset: rpcData === null || rpcData === void 0 ? void 0 : rpcData.offset,
|
|
2204
|
-
key: rpcData === null || rpcData === void 0 ? void 0 : rpcData.key,
|
|
2205
|
-
timestamp: rpcData === null || rpcData === void 0 ? void 0 : rpcData.timestamp
|
|
2206
|
-
};
|
|
2207
|
-
return new rxjs.Observable((subscriber) => {
|
|
2208
|
-
let inner;
|
|
2209
|
-
this.ctx.run(traceId, () => {
|
|
2210
|
-
inner = next.handle().subscribe({
|
|
2211
|
-
next: (value) => subscriber.next(value),
|
|
2212
|
-
error: (err) => subscriber.error(err),
|
|
2213
|
-
complete: () => subscriber.complete()
|
|
2214
|
-
});
|
|
2215
|
-
}, kafkaContext);
|
|
2216
|
-
return () => inner === null || inner === void 0 ? void 0 : inner.unsubscribe();
|
|
2217
|
-
});
|
|
1772
|
+
//#region src/exceptions/exception.ts
|
|
1773
|
+
var LogixiaException = class extends Error {
|
|
1774
|
+
constructor(options) {
|
|
1775
|
+
super(options.message, { cause: options.cause });
|
|
1776
|
+
this.name = "LogixiaException";
|
|
1777
|
+
this.errorCode = options.code;
|
|
1778
|
+
this.errorType = options.type;
|
|
1779
|
+
this.httpStatus = options.httpStatus;
|
|
1780
|
+
this.param = options.param;
|
|
1781
|
+
this.details = options.details;
|
|
1782
|
+
this.docUrl = options.docUrl;
|
|
1783
|
+
this.metadata = options.metadata;
|
|
1784
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
2218
1785
|
}
|
|
2219
1786
|
};
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
1787
|
+
/**
|
|
1788
|
+
* Returns `true` when `value` is a `LogixiaException` instance.
|
|
1789
|
+
*
|
|
1790
|
+
* Useful in exception filters or middleware that need to distinguish a
|
|
1791
|
+
* `LogixiaException` from a plain `Error` or a framework `HttpException`.
|
|
1792
|
+
*
|
|
1793
|
+
* @example
|
|
1794
|
+
* ```ts
|
|
1795
|
+
* if (isLogixiaException(err)) {
|
|
1796
|
+
* console.log(err.errorCode, err.httpStatus);
|
|
1797
|
+
* }
|
|
1798
|
+
* ```
|
|
1799
|
+
*/
|
|
1800
|
+
function isLogixiaException(value) {
|
|
1801
|
+
return value instanceof LogixiaException;
|
|
2228
1802
|
}
|
|
2229
1803
|
|
|
2230
1804
|
//#endregion
|
|
2231
|
-
//#region src/
|
|
2232
|
-
/**
|
|
2233
|
-
|
|
1805
|
+
//#region src/exceptions/builder.ts
|
|
1806
|
+
/**
|
|
1807
|
+
* Generates a trace ID via the shared {@link TraceContext} generator.
|
|
1808
|
+
*
|
|
1809
|
+
* Delegates to `TraceContext.instance.generate()` so any custom generator
|
|
1810
|
+
* configured on `TraceIdConfig.generator` is respected — avoids the silent
|
|
1811
|
+
* "builder has its own UUID source" divergence this module had previously.
|
|
1812
|
+
*
|
|
1813
|
+
* @example `'550e8400-e29b-41d4-a716-446655440000'`
|
|
1814
|
+
*/
|
|
1815
|
+
function generateTraceId() {
|
|
1816
|
+
return require_trace_utils.TraceContext.instance.generate();
|
|
1817
|
+
}
|
|
1818
|
+
/** @deprecated Use `generateTraceId` instead. */
|
|
1819
|
+
const generateRequestId = generateTraceId;
|
|
2234
1820
|
/**
|
|
2235
|
-
*
|
|
2236
|
-
*
|
|
2237
|
-
* - `string` → user's custom header
|
|
2238
|
-
* - `false` → `null` (suppress entirely)
|
|
1821
|
+
* Maps an HTTP status code to a human-friendly error type string.
|
|
1822
|
+
* Used as a fallback when the exception is a generic `HttpException`.
|
|
2239
1823
|
*/
|
|
2240
|
-
function
|
|
2241
|
-
if (
|
|
2242
|
-
|
|
1824
|
+
function httpStatusToType(status) {
|
|
1825
|
+
if (status === 400) return "api_error";
|
|
1826
|
+
if (status === 401) return "authentication_error";
|
|
1827
|
+
if (status === 402) return "payment_error";
|
|
1828
|
+
if (status === 403) return "authorization_error";
|
|
1829
|
+
if (status === 404) return "not_found_error";
|
|
1830
|
+
if (status === 408) return "timeout_error";
|
|
1831
|
+
if (status === 409) return "conflict_error";
|
|
1832
|
+
if (status === 422) return "validation_error";
|
|
1833
|
+
if (status === 429) return "rate_limit_error";
|
|
1834
|
+
if (status >= 500) return "server_error";
|
|
1835
|
+
if (status >= 400) return "api_error";
|
|
1836
|
+
return "server_error";
|
|
2243
1837
|
}
|
|
2244
1838
|
/**
|
|
2245
|
-
*
|
|
2246
|
-
*
|
|
2247
|
-
* res.setHeader()), and on a closed/sent response setHeader throws — neither
|
|
2248
|
-
* should crash the request. The trace ID is still propagated via async context.
|
|
1839
|
+
* Duck-type check for NestJS `HttpException`.
|
|
1840
|
+
* Avoids a hard import on `@nestjs/common` so the builder is usable outside NestJS.
|
|
2249
1841
|
*/
|
|
2250
|
-
function
|
|
2251
|
-
|
|
2252
|
-
if (r.headersSent) return;
|
|
2253
|
-
try {
|
|
2254
|
-
if (typeof r.setHeader === "function") r.setHeader(header, traceId);
|
|
2255
|
-
else if (typeof r.header === "function") r.header(header, traceId);
|
|
2256
|
-
} catch {}
|
|
1842
|
+
function isHttpException(value) {
|
|
1843
|
+
return typeof value === "object" && value !== null && typeof value["getStatus"] === "function" && typeof value["getResponse"] === "function";
|
|
2257
1844
|
}
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
}
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
var _this$config, _req$socket, _req$connection;
|
|
2280
|
-
if (!((_this$config = this.config) === null || _this$config === void 0 ? void 0 : _this$config.enabled)) return next();
|
|
2281
|
-
let traceId;
|
|
2282
|
-
if (this.config.extractor) traceId = extractTraceId(req, this.config.extractor);
|
|
2283
|
-
if (!traceId && this.config.generator) {
|
|
2284
|
-
const candidate = this.config.generator();
|
|
2285
|
-
if (typeof candidate === "string" && candidate.trim().length > 0) traceId = candidate;
|
|
2286
|
-
else require_internal_log.internalWarn("TraceIdConfig.generator returned a non-string/empty value — using built-in generator.");
|
|
2287
|
-
}
|
|
2288
|
-
if (!traceId) traceId = this.ctx.generate();
|
|
2289
|
-
req.traceId = traceId;
|
|
2290
|
-
const header = resolveResponseHeader(this.config);
|
|
2291
|
-
if (header) writeTraceHeader(res, header, traceId);
|
|
2292
|
-
this.ctx.run(traceId, () => next(), {
|
|
2293
|
-
method: req.method,
|
|
2294
|
-
url: req.url,
|
|
2295
|
-
userAgent: req.get("User-Agent"),
|
|
2296
|
-
ip: req.ip || ((_req$socket = req.socket) === null || _req$socket === void 0 ? void 0 : _req$socket.remoteAddress) || ((_req$connection = req.connection) === null || _req$connection === void 0 ? void 0 : _req$connection.remoteAddress)
|
|
2297
|
-
});
|
|
2298
|
-
}
|
|
2299
|
-
};
|
|
2300
|
-
TraceMiddleware = __decorate([
|
|
2301
|
-
(0, __nestjs_common.Injectable)(),
|
|
2302
|
-
__decorateParam(0, (0, __nestjs_common.Optional)()),
|
|
2303
|
-
__decorateMetadata("design:paramtypes", [Object])
|
|
2304
|
-
], TraceMiddleware);
|
|
2305
|
-
|
|
2306
|
-
//#endregion
|
|
2307
|
-
//#region src/core/websocket-trace.interceptor.ts
|
|
2308
|
-
let WebSocketTraceInterceptor = class WebSocketTraceInterceptor$1 {
|
|
2309
|
-
constructor(config) {
|
|
2310
|
-
this.config = config;
|
|
2311
|
-
this.ctx = TraceContext.instance;
|
|
2312
|
-
this.config = {
|
|
2313
|
-
enabled: true,
|
|
2314
|
-
contextKey: "traceId",
|
|
2315
|
-
extractor: {
|
|
2316
|
-
body: [
|
|
2317
|
-
"traceId",
|
|
2318
|
-
"trace_id",
|
|
2319
|
-
"x-trace-id"
|
|
2320
|
-
],
|
|
2321
|
-
header: ["x-trace-id", "trace-id"],
|
|
2322
|
-
query: ["traceId", "trace_id"]
|
|
2323
|
-
},
|
|
2324
|
-
...config
|
|
2325
|
-
};
|
|
2326
|
-
}
|
|
2327
|
-
intercept(context, next) {
|
|
2328
|
-
var _this$config, _client$handshake3;
|
|
2329
|
-
if (!((_this$config = this.config) === null || _this$config === void 0 ? void 0 : _this$config.enabled)) return next.handle();
|
|
2330
|
-
const wsContext = context.switchToWs();
|
|
2331
|
-
const data = wsContext.getData();
|
|
2332
|
-
const client = wsContext.getClient();
|
|
2333
|
-
let traceId;
|
|
2334
|
-
if (this.config.extractor) {
|
|
2335
|
-
var _client$handshake, _client$handshake2;
|
|
2336
|
-
traceId = extractTraceId({
|
|
2337
|
-
body: data,
|
|
2338
|
-
headers: (client === null || client === void 0 || (_client$handshake = client.handshake) === null || _client$handshake === void 0 ? void 0 : _client$handshake.headers) || {},
|
|
2339
|
-
query: (client === null || client === void 0 || (_client$handshake2 = client.handshake) === null || _client$handshake2 === void 0 ? void 0 : _client$handshake2.query) || {},
|
|
2340
|
-
params: {}
|
|
2341
|
-
}, this.config.extractor);
|
|
2342
|
-
}
|
|
2343
|
-
if (!traceId) traceId = this.ctx.getCurrentTraceId();
|
|
2344
|
-
if (!traceId) return next.handle();
|
|
2345
|
-
const wsContextData = {
|
|
2346
|
-
messageType: "websocket",
|
|
2347
|
-
event: data === null || data === void 0 ? void 0 : data.event,
|
|
2348
|
-
socketId: client === null || client === void 0 ? void 0 : client.id,
|
|
2349
|
-
rooms: (client === null || client === void 0 ? void 0 : client.rooms) ? Array.from(client.rooms) : [],
|
|
2350
|
-
clientAddress: client === null || client === void 0 || (_client$handshake3 = client.handshake) === null || _client$handshake3 === void 0 ? void 0 : _client$handshake3.address
|
|
2351
|
-
};
|
|
2352
|
-
return new rxjs.Observable((observer) => {
|
|
2353
|
-
let inner;
|
|
2354
|
-
this.ctx.run(traceId, () => {
|
|
2355
|
-
inner = next.handle().subscribe({
|
|
2356
|
-
next: (value) => observer.next(value),
|
|
2357
|
-
error: (err) => observer.error(err),
|
|
2358
|
-
complete: () => observer.complete()
|
|
2359
|
-
});
|
|
2360
|
-
}, wsContextData);
|
|
2361
|
-
return () => inner === null || inner === void 0 ? void 0 : inner.unsubscribe();
|
|
2362
|
-
});
|
|
2363
|
-
}
|
|
2364
|
-
};
|
|
2365
|
-
WebSocketTraceInterceptor = __decorate([(0, __nestjs_common.Injectable)(), __decorateMetadata("design:paramtypes", [Object])], WebSocketTraceInterceptor);
|
|
2366
|
-
|
|
2367
|
-
//#endregion
|
|
2368
|
-
//#region src/core/logitron-logger.module.ts
|
|
2369
|
-
var _LogixiaLoggerModule;
|
|
2370
|
-
const DEFAULT_ROUTES = [{
|
|
2371
|
-
path: "*",
|
|
2372
|
-
method: __nestjs_common.RequestMethod.ALL
|
|
2373
|
-
}];
|
|
2374
|
-
const LOGIXIA_LOGGER_CONFIG = "LOGIXIA_LOGGER_CONFIG";
|
|
2375
|
-
const LOGIXIA_TRACE_CONFIG = "TRACE_CONFIG";
|
|
2376
|
-
const LOGIXIA_LOGGER_PREFIX = "LOGIXIA_LOGGER_";
|
|
2377
|
-
let LogixiaLoggerModule = class LogixiaLoggerModule$1 {
|
|
2378
|
-
static {
|
|
2379
|
-
_LogixiaLoggerModule = this;
|
|
2380
|
-
}
|
|
2381
|
-
constructor() {
|
|
2382
|
-
this.config = {};
|
|
2383
|
-
}
|
|
2384
|
-
static #_ = this.loggerConfig = {};
|
|
2385
|
-
static #_2 = this._globalLogger = null;
|
|
1845
|
+
/**
|
|
1846
|
+
* Builds the optional `debug` block from an error.
|
|
1847
|
+
* Returns `undefined` when there is nothing useful to include.
|
|
1848
|
+
*/
|
|
1849
|
+
function buildDebug(error, service, durationMs, expose) {
|
|
1850
|
+
if (expose.debug !== true) return void 0;
|
|
1851
|
+
const stack = error instanceof Error ? error.stack : void 0;
|
|
1852
|
+
const causeRaw = error instanceof Error ? error.cause : void 0;
|
|
1853
|
+
let cause;
|
|
1854
|
+
if (expose.cause !== true) cause = void 0;
|
|
1855
|
+
else if (causeRaw instanceof Error) cause = causeRaw.message;
|
|
1856
|
+
else if (causeRaw !== void 0 && causeRaw !== null) cause = String(causeRaw);
|
|
1857
|
+
if (!stack && !cause && !service && durationMs === void 0) return void 0;
|
|
1858
|
+
return {
|
|
1859
|
+
...stack !== void 0 ? { stack } : {},
|
|
1860
|
+
...cause !== void 0 ? { cause } : {},
|
|
1861
|
+
...service !== void 0 ? { service } : {},
|
|
1862
|
+
...durationMs !== void 0 ? { duration_ms: durationMs } : {}
|
|
1863
|
+
};
|
|
1864
|
+
}
|
|
1865
|
+
var ErrorResponseBuilder = class {
|
|
2386
1866
|
/**
|
|
2387
|
-
*
|
|
2388
|
-
*
|
|
2389
|
-
* Called from the module's forRoot / forRootAsync factory. If the module is
|
|
2390
|
-
* initialised more than once in the same process (nested DI context, test
|
|
2391
|
-
* harness creating multiple apps, hot reload, etc.) a warning is written to
|
|
2392
|
-
* stderr and the first logger wins — silently overwriting would allow the
|
|
2393
|
-
* newer instance's transport config to replace the live one while the old
|
|
2394
|
-
* one is still being used by registered shutdown hooks, decorators, etc.
|
|
1867
|
+
* Build a `LogixiaErrorResponse` from any thrown value.
|
|
2395
1868
|
*
|
|
2396
|
-
*
|
|
2397
|
-
|
|
2398
|
-
static _setGlobalLogger(service) {
|
|
2399
|
-
if (_LogixiaLoggerModule._globalLogger !== null) {
|
|
2400
|
-
require_internal_log.internalWarn("LogixiaLoggerModule.forRoot() was called more than once — ignoring the second init. If this is intentional (e.g. in tests), call LogixiaLoggerModule._resetGlobalLogger() first.");
|
|
2401
|
-
return;
|
|
2402
|
-
}
|
|
2403
|
-
_LogixiaLoggerModule._globalLogger = service;
|
|
2404
|
-
}
|
|
2405
|
-
/** @internal Clear the global logger. Tests only. */
|
|
2406
|
-
static _resetGlobalLogger() {
|
|
2407
|
-
_LogixiaLoggerModule._globalLogger = null;
|
|
2408
|
-
}
|
|
2409
|
-
/**
|
|
2410
|
-
* Returns the global LogixiaLoggerService instance that was created when the
|
|
2411
|
-
* module booted. Useful for logging outside of NestJS DI — utility functions,
|
|
2412
|
-
* plain scripts, decorators — without injecting the service everywhere.
|
|
1869
|
+
* @param params - See `BuildParams`.
|
|
1870
|
+
* @returns The unified error response and the HTTP status code to send.
|
|
2413
1871
|
*
|
|
2414
|
-
*
|
|
2415
|
-
*
|
|
1872
|
+
* @remarks
|
|
1873
|
+
* `traceId` does not need to be supplied by the caller in most cases — the
|
|
1874
|
+
* builder reads `TraceContext.instance.getCurrentTraceId()` internally and
|
|
1875
|
+
* falls back to the explicit `traceId` argument only when AsyncLocalStorage
|
|
1876
|
+
* is empty. If neither source yields a value, `meta.trace_id` is omitted.
|
|
2416
1877
|
*
|
|
2417
|
-
* @example
|
|
1878
|
+
* @example In a NestJS exception filter
|
|
2418
1879
|
* ```ts
|
|
2419
|
-
*
|
|
2420
|
-
*
|
|
1880
|
+
* const { response, httpStatus } = ErrorResponseBuilder.build<AppCode, AppType>({
|
|
1881
|
+
* exception,
|
|
1882
|
+
* // Omit traceId — it will be picked up from ALS automatically.
|
|
1883
|
+
* path: request.url,
|
|
1884
|
+
* service: process.env.SERVICE_NAME,
|
|
1885
|
+
* startTime: request.startTime,
|
|
1886
|
+
* });
|
|
2421
1887
|
*
|
|
2422
|
-
*
|
|
2423
|
-
*
|
|
1888
|
+
* if (process.env.NODE_ENV === 'production') delete response.debug;
|
|
1889
|
+
* // Echo the resolved traceId back on whatever header your TraceIdConfig says —
|
|
1890
|
+
* // do NOT hardcode 'X-Trace-Id', use `resolveResponseHeader(config)` instead.
|
|
1891
|
+
* if (response.meta.trace_id) {
|
|
1892
|
+
* response.setHeader(resolveResponseHeader(config) ?? 'X-Trace-Id', response.meta.trace_id);
|
|
2424
1893
|
* }
|
|
1894
|
+
* response.status(httpStatus).json(response);
|
|
2425
1895
|
* ```
|
|
2426
1896
|
*/
|
|
2427
|
-
static
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
let resolvedTraceConfig;
|
|
2433
|
-
if (typeof _LogixiaLoggerModule.loggerConfig.traceId === "object") resolvedTraceConfig = _LogixiaLoggerModule.loggerConfig.traceId;
|
|
2434
|
-
else if (_LogixiaLoggerModule.loggerConfig.traceId === true) resolvedTraceConfig = {
|
|
2435
|
-
enabled: true,
|
|
2436
|
-
contextKey: "traceId",
|
|
2437
|
-
generator: () => TraceContext.instance.generate()
|
|
1897
|
+
static build(params) {
|
|
1898
|
+
const { exception, path, service, startTime, traceId: rawTraceId, exposeDebug, exposeCause } = params;
|
|
1899
|
+
const expose = {
|
|
1900
|
+
debug: exposeDebug,
|
|
1901
|
+
cause: exposeCause
|
|
2438
1902
|
};
|
|
2439
|
-
const
|
|
2440
|
-
const
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
{
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
{
|
|
2462
|
-
provide: LogixiaLoggerService,
|
|
2463
|
-
useFactory: (loggerConfig) => {
|
|
2464
|
-
const service = new LogixiaLoggerService({
|
|
2465
|
-
level: "info",
|
|
2466
|
-
service: "NestJSApp",
|
|
2467
|
-
environment: "development",
|
|
2468
|
-
fields: {},
|
|
2469
|
-
formatters: ["text"],
|
|
2470
|
-
outputs: ["console"],
|
|
2471
|
-
levelOptions: {
|
|
2472
|
-
level: "info",
|
|
2473
|
-
levels: {
|
|
2474
|
-
error: 0,
|
|
2475
|
-
warn: 1,
|
|
2476
|
-
info: 2,
|
|
2477
|
-
debug: 3,
|
|
2478
|
-
verbose: 4
|
|
2479
|
-
},
|
|
2480
|
-
colors: {
|
|
2481
|
-
error: "red",
|
|
2482
|
-
warn: "yellow",
|
|
2483
|
-
info: "green",
|
|
2484
|
-
debug: "blue",
|
|
2485
|
-
verbose: "cyan"
|
|
2486
|
-
}
|
|
2487
|
-
},
|
|
2488
|
-
...loggerConfig
|
|
2489
|
-
});
|
|
2490
|
-
_LogixiaLoggerModule._setGlobalLogger(service);
|
|
2491
|
-
return service;
|
|
1903
|
+
const traceId = require_trace_utils.TraceContext.instance.getCurrentTraceId() ?? rawTraceId;
|
|
1904
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
1905
|
+
const durationMs = startTime !== void 0 ? Date.now() - startTime : void 0;
|
|
1906
|
+
if (isLogixiaException(exception)) {
|
|
1907
|
+
const debug$1 = buildDebug(exception, service, durationMs, expose);
|
|
1908
|
+
const errorBlock = {
|
|
1909
|
+
type: exception.errorType,
|
|
1910
|
+
code: exception.errorCode,
|
|
1911
|
+
message: exception.message
|
|
1912
|
+
};
|
|
1913
|
+
if (exception.param !== void 0) errorBlock.param = exception.param;
|
|
1914
|
+
if (exception.details !== void 0 && exception.details.length > 0) errorBlock.details = exception.details;
|
|
1915
|
+
if (exception.docUrl !== void 0) errorBlock.doc_url = exception.docUrl;
|
|
1916
|
+
return {
|
|
1917
|
+
response: {
|
|
1918
|
+
success: false,
|
|
1919
|
+
error: errorBlock,
|
|
1920
|
+
meta: {
|
|
1921
|
+
...traceId !== void 0 ? { trace_id: traceId } : {},
|
|
1922
|
+
timestamp,
|
|
1923
|
+
path,
|
|
1924
|
+
status: exception.httpStatus
|
|
2492
1925
|
},
|
|
2493
|
-
|
|
2494
|
-
},
|
|
2495
|
-
{
|
|
2496
|
-
provide: KafkaTraceInterceptor,
|
|
2497
|
-
useFactory: (traceConfig$1) => new KafkaTraceInterceptor(traceConfig$1),
|
|
2498
|
-
inject: [LOGIXIA_TRACE_CONFIG]
|
|
1926
|
+
...debug$1 !== void 0 ? { debug: debug$1 } : {}
|
|
2499
1927
|
},
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
providers: [
|
|
2523
|
-
...this.createAsyncProviders(options),
|
|
2524
|
-
{
|
|
2525
|
-
provide: LOGIXIA_TRACE_CONFIG,
|
|
2526
|
-
useFactory: (loggerConfig) => {
|
|
2527
|
-
return typeof (loggerConfig === null || loggerConfig === void 0 ? void 0 : loggerConfig.traceId) === "object" ? loggerConfig.traceId : { enabled: !!(loggerConfig === null || loggerConfig === void 0 ? void 0 : loggerConfig.traceId) };
|
|
1928
|
+
httpStatus: exception.httpStatus
|
|
1929
|
+
};
|
|
1930
|
+
}
|
|
1931
|
+
if (isHttpException(exception)) {
|
|
1932
|
+
const status = exception.getStatus();
|
|
1933
|
+
const exResponse = exception.getResponse();
|
|
1934
|
+
let message;
|
|
1935
|
+
if (typeof exResponse === "string") message = exResponse;
|
|
1936
|
+
else if (typeof exResponse === "object" && exResponse !== null && "message" in exResponse) {
|
|
1937
|
+
const raw = exResponse.message;
|
|
1938
|
+
message = Array.isArray(raw) ? raw.join(", ") : String(raw);
|
|
1939
|
+
} else message = exception.message;
|
|
1940
|
+
const type = httpStatusToType(status);
|
|
1941
|
+
const code = `HTTP_${status}`;
|
|
1942
|
+
const debug$1 = buildDebug(exception, service, durationMs, expose);
|
|
1943
|
+
return {
|
|
1944
|
+
response: {
|
|
1945
|
+
success: false,
|
|
1946
|
+
error: {
|
|
1947
|
+
type,
|
|
1948
|
+
code,
|
|
1949
|
+
message
|
|
2528
1950
|
},
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
const defaultConfig = {
|
|
2535
|
-
level: "info",
|
|
2536
|
-
service: "NestJSApp",
|
|
2537
|
-
environment: "development",
|
|
2538
|
-
fields: {},
|
|
2539
|
-
formatters: ["text"],
|
|
2540
|
-
outputs: ["console"],
|
|
2541
|
-
levelOptions: {
|
|
2542
|
-
level: "info",
|
|
2543
|
-
levels: {
|
|
2544
|
-
error: 0,
|
|
2545
|
-
warn: 1,
|
|
2546
|
-
info: 2,
|
|
2547
|
-
debug: 3,
|
|
2548
|
-
verbose: 4
|
|
2549
|
-
},
|
|
2550
|
-
colors: {
|
|
2551
|
-
error: "red",
|
|
2552
|
-
warn: "yellow",
|
|
2553
|
-
info: "green",
|
|
2554
|
-
debug: "blue",
|
|
2555
|
-
verbose: "cyan"
|
|
2556
|
-
}
|
|
2557
|
-
},
|
|
2558
|
-
...loggerConfig
|
|
2559
|
-
};
|
|
2560
|
-
_LogixiaLoggerModule.loggerConfig = defaultConfig;
|
|
2561
|
-
const service = new LogixiaLoggerService(defaultConfig);
|
|
2562
|
-
_LogixiaLoggerModule._setGlobalLogger(service);
|
|
2563
|
-
return service;
|
|
1951
|
+
meta: {
|
|
1952
|
+
...traceId !== void 0 ? { trace_id: traceId } : {},
|
|
1953
|
+
timestamp,
|
|
1954
|
+
path,
|
|
1955
|
+
status
|
|
2564
1956
|
},
|
|
2565
|
-
|
|
1957
|
+
...debug$1 !== void 0 ? { debug: debug$1 } : {}
|
|
2566
1958
|
},
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
},
|
|
2572
|
-
{
|
|
2573
|
-
provide: WebSocketTraceInterceptor,
|
|
2574
|
-
useFactory: (traceConfig) => new WebSocketTraceInterceptor(traceConfig),
|
|
2575
|
-
inject: [LOGIXIA_TRACE_CONFIG]
|
|
2576
|
-
}
|
|
2577
|
-
],
|
|
2578
|
-
exports: [
|
|
2579
|
-
LogixiaLoggerService,
|
|
2580
|
-
LOGIXIA_LOGGER_CONFIG,
|
|
2581
|
-
KafkaTraceInterceptor,
|
|
2582
|
-
WebSocketTraceInterceptor
|
|
2583
|
-
],
|
|
2584
|
-
global: true
|
|
2585
|
-
};
|
|
2586
|
-
}
|
|
2587
|
-
/**
|
|
2588
|
-
* Create feature-specific logger instances
|
|
2589
|
-
*/
|
|
2590
|
-
static forFeature(context) {
|
|
2591
|
-
const providerToken = `${LOGIXIA_LOGGER_PREFIX}${context.toUpperCase()}`;
|
|
1959
|
+
httpStatus: status
|
|
1960
|
+
};
|
|
1961
|
+
}
|
|
1962
|
+
const debug = buildDebug(exception instanceof Error ? exception : new Error(String(exception)), service, durationMs, expose);
|
|
2592
1963
|
return {
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
1964
|
+
response: {
|
|
1965
|
+
success: false,
|
|
1966
|
+
error: {
|
|
1967
|
+
type: "server_error",
|
|
1968
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
1969
|
+
message: "An unexpected error occurred."
|
|
2598
1970
|
},
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
useClass: options.useClass
|
|
2609
|
-
}];
|
|
2610
|
-
}
|
|
2611
|
-
static createAsyncOptionsProvider(options) {
|
|
2612
|
-
if (options.useFactory) return {
|
|
2613
|
-
provide: LOGIXIA_LOGGER_CONFIG,
|
|
2614
|
-
useFactory: options.useFactory,
|
|
2615
|
-
inject: options.inject || []
|
|
2616
|
-
};
|
|
2617
|
-
return {
|
|
2618
|
-
provide: LOGIXIA_LOGGER_CONFIG,
|
|
2619
|
-
useFactory: async (optionsFactory) => await optionsFactory.createLogixiaOptions(),
|
|
2620
|
-
inject: [options.useExisting || options.useClass]
|
|
1971
|
+
meta: {
|
|
1972
|
+
...traceId !== void 0 ? { trace_id: traceId } : {},
|
|
1973
|
+
timestamp,
|
|
1974
|
+
path,
|
|
1975
|
+
status: 500
|
|
1976
|
+
},
|
|
1977
|
+
...debug !== void 0 ? { debug } : {}
|
|
1978
|
+
},
|
|
1979
|
+
httpStatus: 500
|
|
2621
1980
|
};
|
|
2622
1981
|
}
|
|
2623
1982
|
};
|
|
2624
|
-
LogixiaLoggerModule = _LogixiaLoggerModule = __decorate([(0, __nestjs_common.Module)({})], LogixiaLoggerModule);
|
|
2625
1983
|
|
|
2626
1984
|
//#endregion
|
|
2627
|
-
Object.defineProperty(exports, '
|
|
2628
|
-
enumerable: true,
|
|
2629
|
-
get: function () {
|
|
2630
|
-
return DEFAULT_LOG_COLORS;
|
|
2631
|
-
}
|
|
2632
|
-
});
|
|
2633
|
-
Object.defineProperty(exports, 'DEFAULT_LOG_LEVELS', {
|
|
1985
|
+
Object.defineProperty(exports, 'DEFAULT_CONFIG', {
|
|
2634
1986
|
enumerable: true,
|
|
2635
1987
|
get: function () {
|
|
2636
|
-
return
|
|
1988
|
+
return DEFAULT_CONFIG;
|
|
2637
1989
|
}
|
|
2638
1990
|
});
|
|
2639
|
-
Object.defineProperty(exports, '
|
|
2640
|
-
enumerable: true,
|
|
2641
|
-
get: function () {
|
|
2642
|
-
return DEFAULT_TRACE_HEADERS;
|
|
2643
|
-
}
|
|
2644
|
-
});
|
|
2645
|
-
Object.defineProperty(exports, 'KafkaTraceInterceptor', {
|
|
2646
|
-
enumerable: true,
|
|
2647
|
-
get: function () {
|
|
2648
|
-
return KafkaTraceInterceptor;
|
|
2649
|
-
}
|
|
2650
|
-
});
|
|
2651
|
-
Object.defineProperty(exports, 'LOGIXIA_LOGGER_CONFIG', {
|
|
1991
|
+
Object.defineProperty(exports, 'DEFAULT_LOG_COLORS', {
|
|
2652
1992
|
enumerable: true,
|
|
2653
1993
|
get: function () {
|
|
2654
|
-
return
|
|
1994
|
+
return DEFAULT_LOG_COLORS;
|
|
2655
1995
|
}
|
|
2656
1996
|
});
|
|
2657
|
-
Object.defineProperty(exports, '
|
|
1997
|
+
Object.defineProperty(exports, 'DEFAULT_LOG_LEVELS', {
|
|
2658
1998
|
enumerable: true,
|
|
2659
1999
|
get: function () {
|
|
2660
|
-
return
|
|
2000
|
+
return DEFAULT_LOG_LEVELS;
|
|
2661
2001
|
}
|
|
2662
2002
|
});
|
|
2663
|
-
Object.defineProperty(exports, '
|
|
2003
|
+
Object.defineProperty(exports, 'ErrorResponseBuilder', {
|
|
2664
2004
|
enumerable: true,
|
|
2665
2005
|
get: function () {
|
|
2666
|
-
return
|
|
2006
|
+
return ErrorResponseBuilder;
|
|
2667
2007
|
}
|
|
2668
2008
|
});
|
|
2669
2009
|
Object.defineProperty(exports, 'LogLevel', {
|
|
@@ -2672,22 +2012,16 @@ Object.defineProperty(exports, 'LogLevel', {
|
|
|
2672
2012
|
return LogLevel;
|
|
2673
2013
|
}
|
|
2674
2014
|
});
|
|
2675
|
-
Object.defineProperty(exports, '
|
|
2676
|
-
enumerable: true,
|
|
2677
|
-
get: function () {
|
|
2678
|
-
return LogixiaLogger;
|
|
2679
|
-
}
|
|
2680
|
-
});
|
|
2681
|
-
Object.defineProperty(exports, 'LogixiaLoggerModule', {
|
|
2015
|
+
Object.defineProperty(exports, 'LogixiaException', {
|
|
2682
2016
|
enumerable: true,
|
|
2683
2017
|
get: function () {
|
|
2684
|
-
return
|
|
2018
|
+
return LogixiaException;
|
|
2685
2019
|
}
|
|
2686
2020
|
});
|
|
2687
|
-
Object.defineProperty(exports, '
|
|
2021
|
+
Object.defineProperty(exports, 'LogixiaLogger', {
|
|
2688
2022
|
enumerable: true,
|
|
2689
2023
|
get: function () {
|
|
2690
|
-
return
|
|
2024
|
+
return LogixiaLogger;
|
|
2691
2025
|
}
|
|
2692
2026
|
});
|
|
2693
2027
|
Object.defineProperty(exports, 'PluginRegistry', {
|
|
@@ -2696,54 +2030,6 @@ Object.defineProperty(exports, 'PluginRegistry', {
|
|
|
2696
2030
|
return PluginRegistry;
|
|
2697
2031
|
}
|
|
2698
2032
|
});
|
|
2699
|
-
Object.defineProperty(exports, 'TRACE_CONTEXT_KEY', {
|
|
2700
|
-
enumerable: true,
|
|
2701
|
-
get: function () {
|
|
2702
|
-
return TRACE_CONTEXT_KEY;
|
|
2703
|
-
}
|
|
2704
|
-
});
|
|
2705
|
-
Object.defineProperty(exports, 'TraceContext', {
|
|
2706
|
-
enumerable: true,
|
|
2707
|
-
get: function () {
|
|
2708
|
-
return TraceContext;
|
|
2709
|
-
}
|
|
2710
|
-
});
|
|
2711
|
-
Object.defineProperty(exports, 'TraceMiddleware', {
|
|
2712
|
-
enumerable: true,
|
|
2713
|
-
get: function () {
|
|
2714
|
-
return TraceMiddleware;
|
|
2715
|
-
}
|
|
2716
|
-
});
|
|
2717
|
-
Object.defineProperty(exports, 'WebSocketTraceInterceptor', {
|
|
2718
|
-
enumerable: true,
|
|
2719
|
-
get: function () {
|
|
2720
|
-
return WebSocketTraceInterceptor;
|
|
2721
|
-
}
|
|
2722
|
-
});
|
|
2723
|
-
Object.defineProperty(exports, '__decorate', {
|
|
2724
|
-
enumerable: true,
|
|
2725
|
-
get: function () {
|
|
2726
|
-
return __decorate;
|
|
2727
|
-
}
|
|
2728
|
-
});
|
|
2729
|
-
Object.defineProperty(exports, '__decorateMetadata', {
|
|
2730
|
-
enumerable: true,
|
|
2731
|
-
get: function () {
|
|
2732
|
-
return __decorateMetadata;
|
|
2733
|
-
}
|
|
2734
|
-
});
|
|
2735
|
-
Object.defineProperty(exports, '__decorateParam', {
|
|
2736
|
-
enumerable: true,
|
|
2737
|
-
get: function () {
|
|
2738
|
-
return __decorateParam;
|
|
2739
|
-
}
|
|
2740
|
-
});
|
|
2741
|
-
Object.defineProperty(exports, '_setActiveContextKey', {
|
|
2742
|
-
enumerable: true,
|
|
2743
|
-
get: function () {
|
|
2744
|
-
return _setActiveContextKey;
|
|
2745
|
-
}
|
|
2746
|
-
});
|
|
2747
2033
|
Object.defineProperty(exports, '_shutdownRegistrySize', {
|
|
2748
2034
|
enumerable: true,
|
|
2749
2035
|
get: function () {
|
|
@@ -2762,12 +2048,6 @@ Object.defineProperty(exports, 'createLogger', {
|
|
|
2762
2048
|
return createLogger;
|
|
2763
2049
|
}
|
|
2764
2050
|
});
|
|
2765
|
-
Object.defineProperty(exports, 'createTraceMiddleware', {
|
|
2766
|
-
enumerable: true,
|
|
2767
|
-
get: function () {
|
|
2768
|
-
return createTraceMiddleware;
|
|
2769
|
-
}
|
|
2770
|
-
});
|
|
2771
2051
|
Object.defineProperty(exports, 'deregisterFromShutdown', {
|
|
2772
2052
|
enumerable: true,
|
|
2773
2053
|
get: function () {
|
|
@@ -2780,40 +2060,34 @@ Object.defineProperty(exports, 'disableOtelBridge', {
|
|
|
2780
2060
|
return disableOtelBridge;
|
|
2781
2061
|
}
|
|
2782
2062
|
});
|
|
2783
|
-
Object.defineProperty(exports, 'extractTraceId', {
|
|
2784
|
-
enumerable: true,
|
|
2785
|
-
get: function () {
|
|
2786
|
-
return extractTraceId;
|
|
2787
|
-
}
|
|
2788
|
-
});
|
|
2789
2063
|
Object.defineProperty(exports, 'flushOnExit', {
|
|
2790
2064
|
enumerable: true,
|
|
2791
2065
|
get: function () {
|
|
2792
2066
|
return flushOnExit;
|
|
2793
2067
|
}
|
|
2794
2068
|
});
|
|
2795
|
-
Object.defineProperty(exports, '
|
|
2069
|
+
Object.defineProperty(exports, 'generateRequestId', {
|
|
2796
2070
|
enumerable: true,
|
|
2797
2071
|
get: function () {
|
|
2798
|
-
return
|
|
2072
|
+
return generateRequestId;
|
|
2799
2073
|
}
|
|
2800
2074
|
});
|
|
2801
|
-
Object.defineProperty(exports, '
|
|
2075
|
+
Object.defineProperty(exports, 'generateTraceId', {
|
|
2802
2076
|
enumerable: true,
|
|
2803
2077
|
get: function () {
|
|
2804
|
-
return
|
|
2078
|
+
return generateTraceId;
|
|
2805
2079
|
}
|
|
2806
2080
|
});
|
|
2807
|
-
Object.defineProperty(exports, '
|
|
2081
|
+
Object.defineProperty(exports, 'getActiveOtelContext', {
|
|
2808
2082
|
enumerable: true,
|
|
2809
2083
|
get: function () {
|
|
2810
|
-
return
|
|
2084
|
+
return getActiveOtelContext;
|
|
2811
2085
|
}
|
|
2812
2086
|
});
|
|
2813
|
-
Object.defineProperty(exports, '
|
|
2087
|
+
Object.defineProperty(exports, 'getOtelMetaFields', {
|
|
2814
2088
|
enumerable: true,
|
|
2815
2089
|
get: function () {
|
|
2816
|
-
return
|
|
2090
|
+
return getOtelMetaFields;
|
|
2817
2091
|
}
|
|
2818
2092
|
});
|
|
2819
2093
|
Object.defineProperty(exports, 'globalPluginRegistry', {
|
|
@@ -2834,6 +2108,12 @@ Object.defineProperty(exports, 'isError', {
|
|
|
2834
2108
|
return isError;
|
|
2835
2109
|
}
|
|
2836
2110
|
});
|
|
2111
|
+
Object.defineProperty(exports, 'isLogixiaException', {
|
|
2112
|
+
enumerable: true,
|
|
2113
|
+
get: function () {
|
|
2114
|
+
return isLogixiaException;
|
|
2115
|
+
}
|
|
2116
|
+
});
|
|
2837
2117
|
Object.defineProperty(exports, 'normalizeError', {
|
|
2838
2118
|
enumerable: true,
|
|
2839
2119
|
get: function () {
|
|
@@ -2858,40 +2138,16 @@ Object.defineProperty(exports, 'resetShutdownHandlers', {
|
|
|
2858
2138
|
return resetShutdownHandlers;
|
|
2859
2139
|
}
|
|
2860
2140
|
});
|
|
2861
|
-
Object.defineProperty(exports, 'resolveResponseHeader', {
|
|
2862
|
-
enumerable: true,
|
|
2863
|
-
get: function () {
|
|
2864
|
-
return resolveResponseHeader;
|
|
2865
|
-
}
|
|
2866
|
-
});
|
|
2867
|
-
Object.defineProperty(exports, 'runWithTraceId', {
|
|
2868
|
-
enumerable: true,
|
|
2869
|
-
get: function () {
|
|
2870
|
-
return runWithTraceId;
|
|
2871
|
-
}
|
|
2872
|
-
});
|
|
2873
2141
|
Object.defineProperty(exports, 'serializeError', {
|
|
2874
2142
|
enumerable: true,
|
|
2875
2143
|
get: function () {
|
|
2876
2144
|
return serializeError;
|
|
2877
2145
|
}
|
|
2878
2146
|
});
|
|
2879
|
-
Object.defineProperty(exports, 'setTraceId', {
|
|
2880
|
-
enumerable: true,
|
|
2881
|
-
get: function () {
|
|
2882
|
-
return setTraceId;
|
|
2883
|
-
}
|
|
2884
|
-
});
|
|
2885
|
-
Object.defineProperty(exports, 'traceStorage', {
|
|
2886
|
-
enumerable: true,
|
|
2887
|
-
get: function () {
|
|
2888
|
-
return traceStorage;
|
|
2889
|
-
}
|
|
2890
|
-
});
|
|
2891
2147
|
Object.defineProperty(exports, 'usePlugin', {
|
|
2892
2148
|
enumerable: true,
|
|
2893
2149
|
get: function () {
|
|
2894
2150
|
return usePlugin;
|
|
2895
2151
|
}
|
|
2896
2152
|
});
|
|
2897
|
-
//# sourceMappingURL=
|
|
2153
|
+
//# sourceMappingURL=builder-D44QktIo.js.map
|