logixia 1.13.0 → 1.13.3
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 +9 -0
- 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-BDFO4F-i.d.ts} +2 -2
- package/dist/{azure-monitor.transport-CG7ClkYj.d.ts.map → azure-monitor.transport-BDFO4F-i.d.ts.map} +1 -1
- package/dist/{azure-monitor.transport-Cm74kXZS.d.mts → azure-monitor.transport-D5wQEH04.d.mts} +2 -2
- package/dist/{azure-monitor.transport-Cm74kXZS.d.mts.map → azure-monitor.transport-D5wQEH04.d.mts.map} +1 -1
- package/dist/azure.d.mts +2 -2
- package/dist/azure.d.ts +2 -2
- package/dist/cli/index.js +98 -52
- 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-CGHY4buE.d.mts → cloudwatch.transport-B00st6Xv.d.ts} +9 -2
- package/dist/cloudwatch.transport-B00st6Xv.d.ts.map +1 -0
- 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-DK_8cKd3.d.ts → cloudwatch.transport-Blc7Gtxt.d.mts} +9 -2
- package/dist/cloudwatch.transport-Blc7Gtxt.d.mts.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/{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-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-BOhkVKlI.d.ts → gcp.transport-m4fVw0b1.d.ts} +2 -2
- package/dist/gcp.transport-m4fVw0b1.d.ts.map +1 -0
- package/dist/{gcp.transport-Bi6CUqZR.d.mts → gcp.transport-zzNyIoih.d.mts} +2 -2
- package/dist/gcp.transport-zzNyIoih.d.mts.map +1 -0
- package/dist/{index-BPKwwERo.d.mts → index-BPwEisy4.d.mts} +2 -2
- package/dist/{index-BPKwwERo.d.mts.map → index-BPwEisy4.d.mts.map} +1 -1
- package/dist/{index-C1X-TE5I.d.ts → index-nZEeCr3X.d.ts} +2 -2
- package/dist/{index-C1X-TE5I.d.ts.map → index-nZEeCr3X.d.ts.map} +1 -1
- package/dist/index.d.mts +63 -98
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +63 -98
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +167 -443
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +98 -377
- package/dist/index.mjs.map +1 -1
- 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 +4 -4
- package/dist/nest.d.ts +4 -4
- package/dist/nest.js +20 -11
- package/dist/nest.mjs +7 -5
- package/dist/{logitron-logger.module-BsDZR5BH.js → nestjs-extras-DnJ6vrIC.js} +562 -444
- package/dist/nestjs-extras-DnJ6vrIC.js.map +1 -0
- package/dist/{logitron-logger.module-Bs3XYZgF.mjs → nestjs-extras-ImbuDhs1.mjs} +505 -349
- package/dist/nestjs-extras-ImbuDhs1.mjs.map +1 -0
- package/dist/{logitron-logger.module-CbXy2gfW.d.ts → nestjs-extras-OkC796py.d.mts} +111 -4
- package/dist/nestjs-extras-OkC796py.d.mts.map +1 -0
- package/dist/{logitron-logger.module-BdG1Jnpk.d.mts → nestjs-extras-mKrHE9S6.d.ts} +111 -4
- package/dist/nestjs-extras-mKrHE9S6.d.ts.map +1 -0
- package/dist/{search-njTI2hdo.js → search-B0MH1SJJ.js} +23 -10
- package/dist/search-B0MH1SJJ.js.map +1 -0
- package/dist/{search-DujhR94O.d.ts → search-BfBzDIT9.d.mts} +2 -3
- package/dist/search-BfBzDIT9.d.mts.map +1 -0
- package/dist/{search-CQOo-Iq6.d.mts → search-CHUZPl0h.d.ts} +2 -3
- package/dist/search-CHUZPl0h.d.ts.map +1 -0
- package/dist/{search-CFQRISUv.mjs → search-DjXSn6v5.mjs} +23 -10
- package/dist/search-DjXSn6v5.mjs.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/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-CpdVHEGP.mjs} +365 -86
- package/dist/transport.manager-CpdVHEGP.mjs.map +1 -0
- package/dist/{transport.manager-BivyUTtU.js → transport.manager-Crau3Rle.js} +370 -85
- package/dist/transport.manager-Crau3Rle.js.map +1 -0
- package/dist/{transport.types-B5vcyv2k.d.mts → transport.types-CtNr3D7S.d.mts} +19 -2
- package/dist/transport.types-CtNr3D7S.d.mts.map +1 -0
- package/dist/{transport.types-BuY84TwO.d.ts → transport.types-DqVLZTyf.d.ts} +19 -2
- package/dist/transport.types-DqVLZTyf.d.ts.map +1 -0
- package/dist/transports.d.mts +38 -13
- package/dist/transports.d.mts.map +1 -1
- package/dist/transports.d.ts +38 -13
- package/dist/transports.d.ts.map +1 -1
- package/dist/transports.js +6 -5
- package/dist/transports.mjs +6 -5
- 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-BP8Q28Z2.d.mts → worker.transport-Bgv9heDI.d.mts} +2 -2
- package/dist/{worker.transport-BP8Q28Z2.d.mts.map → worker.transport-Bgv9heDI.d.mts.map} +1 -1
- package/dist/{worker.transport-mKXgNK0L.d.ts → worker.transport-Bj-i0P9V.d.ts} +2 -2
- package/dist/{worker.transport-mKXgNK0L.d.ts.map → worker.transport-Bj-i0P9V.d.ts.map} +1 -1
- package/dist/{worker.transport-CfH6z37Z.js → worker.transport-JP8YHBuU.js} +1 -1
- package/dist/{worker.transport-CfH6z37Z.js.map → worker.transport-JP8YHBuU.js.map} +1 -1
- package/dist/{worker.transport-BhMyvqQ2.mjs → worker.transport-otwhJ_Et.mjs} +1 -1
- package/dist/{worker.transport-BhMyvqQ2.mjs.map → worker.transport-otwhJ_Et.mjs.map} +1 -1
- package/package.json +10 -6
- 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.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.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
package/dist/index.js
CHANGED
|
@@ -2,370 +2,16 @@ 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
4
|
const require_batch_buffer = require('./batch-buffer-BY-mRWIK.js');
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
require('./
|
|
9
|
-
const
|
|
5
|
+
require('./entry-fields-BvOLFlJ4.js');
|
|
6
|
+
const require_trace_utils = require('./trace.utils-DpBOLDtq.js');
|
|
7
|
+
const require_async_context = require('./async-context-DyQQYq3I.js');
|
|
8
|
+
const require_nestjs_extras = require('./nestjs-extras-DnJ6vrIC.js');
|
|
9
|
+
const require_coerce_utils = require('./coerce.utils-B-LilukN.js');
|
|
10
|
+
const require_transport_manager = require('./transport.manager-Crau3Rle.js');
|
|
11
|
+
const require_search = require('./search-B0MH1SJJ.js');
|
|
10
12
|
let node_async_hooks = require("node:async_hooks");
|
|
11
13
|
node_async_hooks = require_chunk.__toESM(node_async_hooks);
|
|
12
|
-
let __nestjs_common = require("@nestjs/common");
|
|
13
|
-
__nestjs_common = require_chunk.__toESM(__nestjs_common);
|
|
14
14
|
|
|
15
|
-
//#region src/exceptions/exception.ts
|
|
16
|
-
var LogixiaException = class extends Error {
|
|
17
|
-
constructor(options) {
|
|
18
|
-
super(options.message, { cause: options.cause });
|
|
19
|
-
this.name = "LogixiaException";
|
|
20
|
-
this.errorCode = options.code;
|
|
21
|
-
this.errorType = options.type;
|
|
22
|
-
this.httpStatus = options.httpStatus;
|
|
23
|
-
this.param = options.param;
|
|
24
|
-
this.details = options.details;
|
|
25
|
-
this.docUrl = options.docUrl;
|
|
26
|
-
this.metadata = options.metadata;
|
|
27
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* Returns `true` when `value` is a `LogixiaException` instance.
|
|
32
|
-
*
|
|
33
|
-
* Useful in exception filters or middleware that need to distinguish a
|
|
34
|
-
* `LogixiaException` from a plain `Error` or a framework `HttpException`.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```ts
|
|
38
|
-
* if (isLogixiaException(err)) {
|
|
39
|
-
* console.log(err.errorCode, err.httpStatus);
|
|
40
|
-
* }
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
function isLogixiaException(value) {
|
|
44
|
-
return value instanceof LogixiaException;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
//#endregion
|
|
48
|
-
//#region src/exceptions/builder.ts
|
|
49
|
-
/**
|
|
50
|
-
* Generates a trace ID via the shared {@link TraceContext} generator.
|
|
51
|
-
*
|
|
52
|
-
* Delegates to `TraceContext.instance.generate()` so any custom generator
|
|
53
|
-
* configured on `TraceIdConfig.generator` is respected — avoids the silent
|
|
54
|
-
* "builder has its own UUID source" divergence this module had previously.
|
|
55
|
-
*
|
|
56
|
-
* @example `'550e8400-e29b-41d4-a716-446655440000'`
|
|
57
|
-
*/
|
|
58
|
-
function generateTraceId() {
|
|
59
|
-
return require_logitron_logger_module.TraceContext.instance.generate();
|
|
60
|
-
}
|
|
61
|
-
/** @deprecated Use `generateTraceId` instead. */
|
|
62
|
-
const generateRequestId = generateTraceId;
|
|
63
|
-
/**
|
|
64
|
-
* Maps an HTTP status code to a human-friendly error type string.
|
|
65
|
-
* Used as a fallback when the exception is a generic `HttpException`.
|
|
66
|
-
*/
|
|
67
|
-
function httpStatusToType(status) {
|
|
68
|
-
if (status === 400) return "api_error";
|
|
69
|
-
if (status === 401) return "authentication_error";
|
|
70
|
-
if (status === 402) return "payment_error";
|
|
71
|
-
if (status === 403) return "authorization_error";
|
|
72
|
-
if (status === 404) return "not_found_error";
|
|
73
|
-
if (status === 408) return "timeout_error";
|
|
74
|
-
if (status === 409) return "conflict_error";
|
|
75
|
-
if (status === 422) return "validation_error";
|
|
76
|
-
if (status === 429) return "rate_limit_error";
|
|
77
|
-
if (status >= 500) return "server_error";
|
|
78
|
-
if (status >= 400) return "api_error";
|
|
79
|
-
return "server_error";
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Duck-type check for NestJS `HttpException`.
|
|
83
|
-
* Avoids a hard import on `@nestjs/common` so the builder is usable outside NestJS.
|
|
84
|
-
*/
|
|
85
|
-
function isHttpException(value) {
|
|
86
|
-
return typeof value === "object" && value !== null && typeof value["getStatus"] === "function" && typeof value["getResponse"] === "function";
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Builds the optional `debug` block from an error.
|
|
90
|
-
* Returns `undefined` when there is nothing useful to include.
|
|
91
|
-
*/
|
|
92
|
-
function buildDebug(error, service, durationMs) {
|
|
93
|
-
const stack = error instanceof Error ? error.stack : void 0;
|
|
94
|
-
const causeRaw = error instanceof Error ? error.cause : void 0;
|
|
95
|
-
let cause;
|
|
96
|
-
if (causeRaw instanceof Error) cause = causeRaw.message;
|
|
97
|
-
else if (causeRaw !== void 0 && causeRaw !== null) cause = String(causeRaw);
|
|
98
|
-
if (!stack && !cause && !service && durationMs === void 0) return void 0;
|
|
99
|
-
return {
|
|
100
|
-
...stack !== void 0 ? { stack } : {},
|
|
101
|
-
...cause !== void 0 ? { cause } : {},
|
|
102
|
-
...service !== void 0 ? { service } : {},
|
|
103
|
-
...durationMs !== void 0 ? { duration_ms: durationMs } : {}
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
var ErrorResponseBuilder = class {
|
|
107
|
-
/**
|
|
108
|
-
* Build a `LogixiaErrorResponse` from any thrown value.
|
|
109
|
-
*
|
|
110
|
-
* @param params - See `BuildParams`.
|
|
111
|
-
* @returns The unified error response and the HTTP status code to send.
|
|
112
|
-
*
|
|
113
|
-
* @remarks
|
|
114
|
-
* `traceId` does not need to be supplied by the caller in most cases — the
|
|
115
|
-
* builder reads `TraceContext.instance.getCurrentTraceId()` internally and
|
|
116
|
-
* falls back to the explicit `traceId` argument only when AsyncLocalStorage
|
|
117
|
-
* is empty. If neither source yields a value, `meta.trace_id` is omitted.
|
|
118
|
-
*
|
|
119
|
-
* @example In a NestJS exception filter
|
|
120
|
-
* ```ts
|
|
121
|
-
* const { response, httpStatus } = ErrorResponseBuilder.build<AppCode, AppType>({
|
|
122
|
-
* exception,
|
|
123
|
-
* // Omit traceId — it will be picked up from ALS automatically.
|
|
124
|
-
* path: request.url,
|
|
125
|
-
* service: process.env.SERVICE_NAME,
|
|
126
|
-
* startTime: request.startTime,
|
|
127
|
-
* });
|
|
128
|
-
*
|
|
129
|
-
* if (process.env.NODE_ENV === 'production') delete response.debug;
|
|
130
|
-
* // Echo the resolved traceId back on whatever header your TraceIdConfig says —
|
|
131
|
-
* // do NOT hardcode 'X-Trace-Id', use `resolveResponseHeader(config)` instead.
|
|
132
|
-
* if (response.meta.trace_id) {
|
|
133
|
-
* response.setHeader(resolveResponseHeader(config) ?? 'X-Trace-Id', response.meta.trace_id);
|
|
134
|
-
* }
|
|
135
|
-
* response.status(httpStatus).json(response);
|
|
136
|
-
* ```
|
|
137
|
-
*/
|
|
138
|
-
static build(params) {
|
|
139
|
-
const { exception, path, service, startTime, traceId: rawTraceId } = params;
|
|
140
|
-
const traceId = require_logitron_logger_module.TraceContext.instance.getCurrentTraceId() ?? rawTraceId;
|
|
141
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
142
|
-
const durationMs = startTime !== void 0 ? Date.now() - startTime : void 0;
|
|
143
|
-
if (isLogixiaException(exception)) {
|
|
144
|
-
const debug$1 = buildDebug(exception, service, durationMs);
|
|
145
|
-
const errorBlock = {
|
|
146
|
-
type: exception.errorType,
|
|
147
|
-
code: exception.errorCode,
|
|
148
|
-
message: exception.message
|
|
149
|
-
};
|
|
150
|
-
if (exception.param !== void 0) errorBlock.param = exception.param;
|
|
151
|
-
if (exception.details !== void 0 && exception.details.length > 0) errorBlock.details = exception.details;
|
|
152
|
-
if (exception.docUrl !== void 0) errorBlock.doc_url = exception.docUrl;
|
|
153
|
-
return {
|
|
154
|
-
response: {
|
|
155
|
-
success: false,
|
|
156
|
-
error: errorBlock,
|
|
157
|
-
meta: {
|
|
158
|
-
...traceId !== void 0 ? { trace_id: traceId } : {},
|
|
159
|
-
timestamp,
|
|
160
|
-
path,
|
|
161
|
-
status: exception.httpStatus
|
|
162
|
-
},
|
|
163
|
-
...debug$1 !== void 0 ? { debug: debug$1 } : {}
|
|
164
|
-
},
|
|
165
|
-
httpStatus: exception.httpStatus
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
if (isHttpException(exception)) {
|
|
169
|
-
const status = exception.getStatus();
|
|
170
|
-
const exResponse = exception.getResponse();
|
|
171
|
-
let message;
|
|
172
|
-
if (typeof exResponse === "string") message = exResponse;
|
|
173
|
-
else if (typeof exResponse === "object" && exResponse !== null && "message" in exResponse) {
|
|
174
|
-
const raw = exResponse.message;
|
|
175
|
-
message = Array.isArray(raw) ? raw.join(", ") : String(raw);
|
|
176
|
-
} else message = exception.message;
|
|
177
|
-
const type = httpStatusToType(status);
|
|
178
|
-
const code = `HTTP_${status}`;
|
|
179
|
-
const debug$1 = buildDebug(exception, service, durationMs);
|
|
180
|
-
return {
|
|
181
|
-
response: {
|
|
182
|
-
success: false,
|
|
183
|
-
error: {
|
|
184
|
-
type,
|
|
185
|
-
code,
|
|
186
|
-
message
|
|
187
|
-
},
|
|
188
|
-
meta: {
|
|
189
|
-
...traceId !== void 0 ? { trace_id: traceId } : {},
|
|
190
|
-
timestamp,
|
|
191
|
-
path,
|
|
192
|
-
status
|
|
193
|
-
},
|
|
194
|
-
...debug$1 !== void 0 ? { debug: debug$1 } : {}
|
|
195
|
-
},
|
|
196
|
-
httpStatus: status
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
const debug = buildDebug(exception instanceof Error ? exception : new Error(String(exception)), service, durationMs);
|
|
200
|
-
return {
|
|
201
|
-
response: {
|
|
202
|
-
success: false,
|
|
203
|
-
error: {
|
|
204
|
-
type: "server_error",
|
|
205
|
-
code: "INTERNAL_SERVER_ERROR",
|
|
206
|
-
message: "An unexpected error occurred."
|
|
207
|
-
},
|
|
208
|
-
meta: {
|
|
209
|
-
...traceId !== void 0 ? { trace_id: traceId } : {},
|
|
210
|
-
timestamp,
|
|
211
|
-
path,
|
|
212
|
-
status: 500
|
|
213
|
-
},
|
|
214
|
-
...debug !== void 0 ? { debug } : {}
|
|
215
|
-
},
|
|
216
|
-
httpStatus: 500
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
//#endregion
|
|
222
|
-
//#region src/core/nestjs-extras.ts
|
|
223
|
-
var _ref;
|
|
224
|
-
/**
|
|
225
|
-
* Inject the Logixia logger registered in the current NestJS DI container.
|
|
226
|
-
*
|
|
227
|
-
* Equivalent to `@Inject(LOGIXIA_LOGGER_TOKEN)` but without needing to import
|
|
228
|
-
* the internal token constant yourself.
|
|
229
|
-
*
|
|
230
|
-
* @example
|
|
231
|
-
* ```ts
|
|
232
|
-
* constructor(@InjectLogger() private readonly logger: LogixiaLoggerService) {}
|
|
233
|
-
* ```
|
|
234
|
-
*/
|
|
235
|
-
const InjectLogger = () => (0, __nestjs_common.Inject)(`${require_logitron_logger_module.LOGIXIA_LOGGER_PREFIX}SERVICE`);
|
|
236
|
-
/**
|
|
237
|
-
* Method decorator that auto-logs entry, exit, duration, and errors.
|
|
238
|
-
*
|
|
239
|
-
* Preserves the original method's sync/async contract: a synchronous method
|
|
240
|
-
* stays synchronous (returns its value directly, with logs emitted
|
|
241
|
-
* fire-and-forget), and an async method is awaited so exit/error logs reflect
|
|
242
|
-
* the resolved result. Attaches to the logger found on the class instance via a
|
|
243
|
-
* `logger` property (the conventional NestJS name).
|
|
244
|
-
*
|
|
245
|
-
* @example
|
|
246
|
-
* ```ts
|
|
247
|
-
* @LogMethod({ level: 'info', logArgs: true })
|
|
248
|
-
* async processPayment(orderId: string): Promise<void> { … }
|
|
249
|
-
* ```
|
|
250
|
-
*/
|
|
251
|
-
function LogMethod(options = {}) {
|
|
252
|
-
const { level = "debug", logArgs = true, logResult = false, logErrors = true } = options;
|
|
253
|
-
return function(target, propertyKey, descriptor) {
|
|
254
|
-
var _constructor;
|
|
255
|
-
const originalMethod = descriptor.value;
|
|
256
|
-
if (typeof originalMethod !== "function") return descriptor;
|
|
257
|
-
const methodName = String(propertyKey);
|
|
258
|
-
const className = ((_constructor = target.constructor) === null || _constructor === void 0 ? void 0 : _constructor.name) ?? "Unknown";
|
|
259
|
-
const label = options.label ?? `${className}.${methodName}`;
|
|
260
|
-
let _warnedNoLogger = false;
|
|
261
|
-
const reportLogFailure = (phase, err) => {
|
|
262
|
-
require_internal_log.internalError(`@LogMethod(${label}) ${phase} log failed: ${String(err)}`);
|
|
263
|
-
};
|
|
264
|
-
const emit$1 = (logger$1, phase, message, data) => {
|
|
265
|
-
const logFnRaw = logger$1[level];
|
|
266
|
-
const p = (typeof logFnRaw === "function" ? logFnRaw : logger$1.debug).bind(logger$1)(message, data);
|
|
267
|
-
if (p && typeof p.catch === "function") p.catch((e) => reportLogFailure(phase, e));
|
|
268
|
-
};
|
|
269
|
-
const emitError = (logger$1, error, start) => {
|
|
270
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
271
|
-
const errLog = logger$1.error(err, {
|
|
272
|
-
method: label,
|
|
273
|
-
durationMs: Date.now() - start
|
|
274
|
-
});
|
|
275
|
-
if (errLog && typeof errLog.catch === "function") errLog.catch((e) => reportLogFailure("error", e));
|
|
276
|
-
};
|
|
277
|
-
descriptor.value = function(...args) {
|
|
278
|
-
const logger$1 = this.logger ?? require_logitron_logger_module.LogixiaLoggerModule._globalLogger ?? void 0;
|
|
279
|
-
if (!logger$1 && !_warnedNoLogger) {
|
|
280
|
-
_warnedNoLogger = true;
|
|
281
|
-
require_internal_log.internalWarn(`@LogMethod on ${label}: no logger available. Either inject LogixiaLoggerService as this.logger or ensure LogixiaLoggerModule is initialised.`);
|
|
282
|
-
}
|
|
283
|
-
const start = Date.now();
|
|
284
|
-
const entry = { method: label };
|
|
285
|
-
if (logArgs && args.length > 0) entry["args"] = args;
|
|
286
|
-
if (logger$1) emit$1(logger$1, "entry", `→ ${label}`, entry);
|
|
287
|
-
const buildExit = (result$1) => {
|
|
288
|
-
const exit = {
|
|
289
|
-
method: label,
|
|
290
|
-
durationMs: Date.now() - start
|
|
291
|
-
};
|
|
292
|
-
if (logResult) exit["result"] = result$1;
|
|
293
|
-
return exit;
|
|
294
|
-
};
|
|
295
|
-
let result;
|
|
296
|
-
try {
|
|
297
|
-
result = originalMethod.apply(this, args);
|
|
298
|
-
} catch (error) {
|
|
299
|
-
if (logger$1 && logErrors) emitError(logger$1, error, start);
|
|
300
|
-
throw error;
|
|
301
|
-
}
|
|
302
|
-
if (result && typeof result.then === "function") return result.then((resolved) => {
|
|
303
|
-
if (logger$1) emit$1(logger$1, "exit", `← ${label}`, buildExit(resolved));
|
|
304
|
-
return resolved;
|
|
305
|
-
}, (error) => {
|
|
306
|
-
if (logger$1 && logErrors) emitError(logger$1, error, start);
|
|
307
|
-
throw error;
|
|
308
|
-
});
|
|
309
|
-
if (logger$1) emit$1(logger$1, "exit", `← ${label}`, buildExit(result));
|
|
310
|
-
return result;
|
|
311
|
-
};
|
|
312
|
-
return descriptor;
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
let LogixiaExceptionFilter = class LogixiaExceptionFilter$1 {
|
|
316
|
-
constructor(logger$1, loggerConfig) {
|
|
317
|
-
this._logger = logger$1 ?? require_logitron_logger_module.LogixiaLoggerModule._globalLogger ?? void 0;
|
|
318
|
-
this._traceConfig = typeof (loggerConfig === null || loggerConfig === void 0 ? void 0 : loggerConfig.traceId) === "object" ? loggerConfig.traceId : void 0;
|
|
319
|
-
}
|
|
320
|
-
catch(exception, host) {
|
|
321
|
-
var _request$headers;
|
|
322
|
-
const ctx = host.switchToHttp();
|
|
323
|
-
const request = ctx.getRequest();
|
|
324
|
-
const response = ctx.getResponse();
|
|
325
|
-
const traceId = require_logitron_logger_module.TraceContext.instance.getCurrentTraceId() ?? ((_request$headers = request.headers) === null || _request$headers === void 0 ? void 0 : _request$headers["x-trace-id"]) ?? request.id ?? void 0;
|
|
326
|
-
const { response: errorResponse, httpStatus } = ErrorResponseBuilder.build({
|
|
327
|
-
exception,
|
|
328
|
-
traceId,
|
|
329
|
-
path: request.url ?? "/",
|
|
330
|
-
startTime: request.startTime
|
|
331
|
-
});
|
|
332
|
-
if (this._logger) {
|
|
333
|
-
const requestMeta = {
|
|
334
|
-
method: request.method ?? "",
|
|
335
|
-
url: request.url ?? "",
|
|
336
|
-
status: httpStatus,
|
|
337
|
-
...errorResponse.meta.trace_id !== void 0 ? { trace_id: errorResponse.meta.trace_id } : {}
|
|
338
|
-
};
|
|
339
|
-
const onLogFailure = (err) => {
|
|
340
|
-
require_internal_log.internalError(`ExceptionFilter failed to write log entry: ${String(err)}`);
|
|
341
|
-
};
|
|
342
|
-
let logPromise;
|
|
343
|
-
if (httpStatus >= 500) {
|
|
344
|
-
const err = exception instanceof Error ? exception : new Error(String(exception));
|
|
345
|
-
logPromise = this._logger.error(err, requestMeta);
|
|
346
|
-
} else if (isLogixiaException(exception)) logPromise = this._logger.warn(`[${errorResponse.error.code}] ${errorResponse.error.message}`, requestMeta);
|
|
347
|
-
else logPromise = this._logger.warn(`[${httpStatus}] ${errorResponse.error.message}`, requestMeta);
|
|
348
|
-
if (logPromise && typeof logPromise.catch === "function") logPromise.catch(onLogFailure);
|
|
349
|
-
}
|
|
350
|
-
if (process.env["NODE_ENV"] === "production") delete errorResponse.debug;
|
|
351
|
-
if (errorResponse.meta.trace_id) {
|
|
352
|
-
const traceHeader = require_logitron_logger_module.resolveResponseHeader(this._traceConfig);
|
|
353
|
-
if (traceHeader) response.setHeader(traceHeader, errorResponse.meta.trace_id);
|
|
354
|
-
}
|
|
355
|
-
if (httpStatus === 429) response.setHeader("Retry-After", "60");
|
|
356
|
-
response.status(httpStatus).json(errorResponse);
|
|
357
|
-
}
|
|
358
|
-
};
|
|
359
|
-
LogixiaExceptionFilter = require_logitron_logger_module.__decorate([
|
|
360
|
-
(0, __nestjs_common.Catch)(),
|
|
361
|
-
require_logitron_logger_module.__decorateParam(0, (0, __nestjs_common.Optional)()),
|
|
362
|
-
require_logitron_logger_module.__decorateParam(0, (0, __nestjs_common.Inject)(`${require_logitron_logger_module.LOGIXIA_LOGGER_PREFIX}SERVICE`)),
|
|
363
|
-
require_logitron_logger_module.__decorateParam(1, (0, __nestjs_common.Optional)()),
|
|
364
|
-
require_logitron_logger_module.__decorateParam(1, (0, __nestjs_common.Inject)(require_logitron_logger_module.LOGIXIA_LOGGER_CONFIG)),
|
|
365
|
-
require_logitron_logger_module.__decorateMetadata("design:paramtypes", [Object, typeof (_ref = typeof Partial !== "undefined" && Partial) === "function" ? _ref : Object])
|
|
366
|
-
], LogixiaExceptionFilter);
|
|
367
|
-
|
|
368
|
-
//#endregion
|
|
369
15
|
//#region src/formatters/json.formatter.ts
|
|
370
16
|
/**
|
|
371
17
|
* Build a JSON.stringify replacer that replaces circular references with the
|
|
@@ -403,7 +49,7 @@ var JsonFormatter = class {
|
|
|
403
49
|
if (this.includeContext && entry.context) formatted.context = entry.context;
|
|
404
50
|
formatted.message = entry.message;
|
|
405
51
|
if (entry.payload && Object.keys(entry.payload).length > 0) formatted.payload = this.serializePayload(entry.payload);
|
|
406
|
-
if (entry.error) formatted.error =
|
|
52
|
+
if (entry.error) formatted.error = require_nestjs_extras.serializeError(entry.error);
|
|
407
53
|
formatted.meta = {
|
|
408
54
|
pid: process.pid,
|
|
409
55
|
hostname: process.env.HOSTNAME || "unknown",
|
|
@@ -417,7 +63,7 @@ var JsonFormatter = class {
|
|
|
417
63
|
for (const [key, value] of Object.entries(payload)) {
|
|
418
64
|
if (key === "__proto__" || key === "constructor" || key === "prototype") continue;
|
|
419
65
|
try {
|
|
420
|
-
if (value instanceof Error) serialized[key] =
|
|
66
|
+
if (value instanceof Error) serialized[key] = require_nestjs_extras.serializeError(value);
|
|
421
67
|
else if (value instanceof Date) serialized[key] = value.toISOString();
|
|
422
68
|
else if (typeof value === "function") serialized[key] = "[Function]";
|
|
423
69
|
else if (typeof value === "symbol") serialized[key] = value.toString();
|
|
@@ -433,8 +79,7 @@ var JsonFormatter = class {
|
|
|
433
79
|
|
|
434
80
|
//#endregion
|
|
435
81
|
//#region src/formatters/text.formatter.ts
|
|
436
|
-
const
|
|
437
|
-
const stripControls = (value) => require_coerce_utils.safeToString(value).replace(CONTROL_CHARS_RE, "");
|
|
82
|
+
const stripControls = (value) => require_transport_manager.stripControlChars(require_coerce_utils.safeToString(value));
|
|
438
83
|
var TextFormatter = class TextFormatter {
|
|
439
84
|
constructor(options = {}) {
|
|
440
85
|
this.colorize = options.colorize ?? true;
|
|
@@ -482,7 +127,7 @@ var TextFormatter = class TextFormatter {
|
|
|
482
127
|
parts.push(`[${context}]`);
|
|
483
128
|
}
|
|
484
129
|
const safeMessage = stripControls(entry.message);
|
|
485
|
-
const message = this.colorize && entry.level ===
|
|
130
|
+
const message = this.colorize && entry.level === require_nestjs_extras.LogLevel.ERROR ? `${this.colors.error}${safeMessage}${this.colors.reset}` : safeMessage;
|
|
486
131
|
parts.push(message);
|
|
487
132
|
if (entry.payload && Object.keys(entry.payload).length > 0) {
|
|
488
133
|
const payload = this.formatPayload(entry.payload);
|
|
@@ -586,6 +231,15 @@ function registerLevelSignal(logger$1, options = {}) {
|
|
|
586
231
|
process.removeListener(signal, handler);
|
|
587
232
|
};
|
|
588
233
|
}
|
|
234
|
+
/** Maximum accepted request body size for the level control handler. */
|
|
235
|
+
const MAX_BODY_BYTES = 16 * 1024;
|
|
236
|
+
function isJsonContentType(req) {
|
|
237
|
+
var _req$headers;
|
|
238
|
+
const raw = (_req$headers = req.headers) === null || _req$headers === void 0 ? void 0 : _req$headers["content-type"];
|
|
239
|
+
const value = Array.isArray(raw) ? raw[0] : raw;
|
|
240
|
+
if (typeof value !== "string") return false;
|
|
241
|
+
return value.split(";")[0].trim().toLowerCase() === "application/json";
|
|
242
|
+
}
|
|
589
243
|
const VALID_LEVELS = new Set([
|
|
590
244
|
"error",
|
|
591
245
|
"warn",
|
|
@@ -604,7 +258,16 @@ const VALID_LEVELS = new Set([
|
|
|
604
258
|
*
|
|
605
259
|
* Custom levels are accepted too: any level the logger already knows passes
|
|
606
260
|
* through. Unknown levels are rejected with 400 so a typo can't silently mute
|
|
607
|
-
* logging.
|
|
261
|
+
* logging.
|
|
262
|
+
*
|
|
263
|
+
* **SECURITY: this handler has NO authentication or authorization.** Anyone who
|
|
264
|
+
* can reach it can silence logging or turn on verbose output. Always mount it
|
|
265
|
+
* behind your own auth (and on an internal-only route/port), never on a public
|
|
266
|
+
* listener.
|
|
267
|
+
*
|
|
268
|
+
* Mutating requests must send `Content-Type: application/json` (otherwise 415,
|
|
269
|
+
* which also keeps cross-site form posts out) and a body of at most 16 KB
|
|
270
|
+
* (otherwise 413).
|
|
608
271
|
*/
|
|
609
272
|
function createLevelControlHandler(logger$1, options = {}) {
|
|
610
273
|
const allowed = options.allowedLevels && options.allowedLevels.length > 0 ? new Set(options.allowedLevels.map((l) => l.toLowerCase())) : VALID_LEVELS;
|
|
@@ -651,8 +314,7 @@ function createLevelControlHandler(logger$1, options = {}) {
|
|
|
651
314
|
return;
|
|
652
315
|
}
|
|
653
316
|
if (logger$1.setNamespaceLevels) {
|
|
654
|
-
const coerced =
|
|
655
|
-
for (const [pat, lvl] of Object.entries(nl)) coerced[pat] = String(lvl).toLowerCase();
|
|
317
|
+
const coerced = Object.fromEntries(Object.entries(nl).map(([pat, lvl]) => [pat, String(lvl).toLowerCase()]));
|
|
656
318
|
logger$1.setNamespaceLevels(coerced);
|
|
657
319
|
} else require_internal_log.internalWarn("level control: logger does not support setNamespaceLevels — ignored");
|
|
658
320
|
}
|
|
@@ -665,17 +327,48 @@ function createLevelControlHandler(logger$1, options = {}) {
|
|
|
665
327
|
return;
|
|
666
328
|
}
|
|
667
329
|
if (method === "POST" || method === "PUT" || method === "PATCH") {
|
|
330
|
+
var _req$headers2;
|
|
331
|
+
if (!isJsonContentType(req)) {
|
|
332
|
+
send(res, 415, { error: "Content-Type must be application/json" });
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
const declared = Number((_req$headers2 = req.headers) === null || _req$headers2 === void 0 ? void 0 : _req$headers2["content-length"]);
|
|
336
|
+
if (Number.isFinite(declared) && declared > MAX_BODY_BYTES) {
|
|
337
|
+
send(res, 413, { error: "request body too large" });
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
668
340
|
const maybeBody = req.body;
|
|
669
|
-
if (maybeBody !== void 0
|
|
670
|
-
|
|
341
|
+
if (maybeBody !== void 0) {
|
|
342
|
+
let text;
|
|
343
|
+
if (typeof maybeBody === "string") text = maybeBody;
|
|
344
|
+
else if (Buffer.isBuffer(maybeBody)) text = maybeBody.toString("utf8");
|
|
345
|
+
else text = JSON.stringify(maybeBody);
|
|
346
|
+
if (Buffer.byteLength(text) > MAX_BODY_BYTES) {
|
|
347
|
+
send(res, 413, { error: "request body too large" });
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
applyBody(res, text);
|
|
671
351
|
return;
|
|
672
352
|
}
|
|
673
353
|
if (typeof req.on === "function") {
|
|
674
354
|
let raw = "";
|
|
355
|
+
let size = 0;
|
|
356
|
+
let rejected = false;
|
|
675
357
|
req.on("data", (chunk) => {
|
|
676
|
-
|
|
358
|
+
if (rejected) return;
|
|
359
|
+
const piece = Buffer.isBuffer(chunk) ? chunk.toString("utf8") : String(chunk ?? "");
|
|
360
|
+
size += Buffer.byteLength(piece);
|
|
361
|
+
if (size > MAX_BODY_BYTES) {
|
|
362
|
+
rejected = true;
|
|
363
|
+
raw = "";
|
|
364
|
+
send(res, 413, { error: "request body too large" });
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
raw += piece;
|
|
368
|
+
});
|
|
369
|
+
req.on("end", () => {
|
|
370
|
+
if (!rejected) applyBody(res, raw);
|
|
677
371
|
});
|
|
678
|
-
req.on("end", () => applyBody(res, raw));
|
|
679
372
|
return;
|
|
680
373
|
}
|
|
681
374
|
applyBody(res, "");
|
|
@@ -783,7 +476,7 @@ function emit(logger$1, state, options, extra) {
|
|
|
783
476
|
if (extra) Object.assign(payload, extra);
|
|
784
477
|
payload[durationField] = Date.now() - state.startMs;
|
|
785
478
|
if (includeTrace) {
|
|
786
|
-
const traceId =
|
|
479
|
+
const traceId = require_trace_utils.getCurrentTraceId();
|
|
787
480
|
if (traceId !== void 0 && payload["traceId"] === void 0) payload["traceId"] = traceId;
|
|
788
481
|
}
|
|
789
482
|
const p = logger$1.logLevel(level, message, payload);
|
|
@@ -1040,6 +733,10 @@ const DEFAULT_BUCKETS = [
|
|
|
1040
733
|
5e3,
|
|
1041
734
|
1e4
|
|
1042
735
|
];
|
|
736
|
+
const MAX_LABEL_VALUE_LENGTH = 256;
|
|
737
|
+
const DEFAULT_MAX_LABEL_SETS = 1e3;
|
|
738
|
+
/** Label value used for the series that absorbs label sets beyond the cardinality cap. */
|
|
739
|
+
const OVERFLOW_LABEL_VALUE = "__overflow__";
|
|
1043
740
|
function buildLabelKey(config, entry) {
|
|
1044
741
|
const labelNames = config.labels ?? [];
|
|
1045
742
|
if (labelNames.length === 0) return "{}";
|
|
@@ -1047,10 +744,16 @@ function buildLabelKey(config, entry) {
|
|
|
1047
744
|
const payload = entry.payload ?? {};
|
|
1048
745
|
for (const name of labelNames) {
|
|
1049
746
|
const raw = name === "level" ? entry.level : payload[name];
|
|
1050
|
-
pairs[sanitizePromName(name)] = raw !== void 0 && raw !== null ? String(raw) : "";
|
|
747
|
+
pairs[sanitizePromName(name)] = raw !== void 0 && raw !== null ? String(raw).slice(0, MAX_LABEL_VALUE_LENGTH) : "";
|
|
1051
748
|
}
|
|
1052
749
|
return JSON.stringify(pairs);
|
|
1053
750
|
}
|
|
751
|
+
/** Label key of the shared overflow series for a metric (all label values `__overflow__`). */
|
|
752
|
+
function buildOverflowKey(config) {
|
|
753
|
+
const names = config.labels ?? [];
|
|
754
|
+
if (names.length === 0) return "{}";
|
|
755
|
+
return JSON.stringify(Object.fromEntries(names.map((n) => [sanitizePromName(n), OVERFLOW_LABEL_VALUE])));
|
|
756
|
+
}
|
|
1054
757
|
function renderLabels(labelKey) {
|
|
1055
758
|
if (labelKey === "{}") return "";
|
|
1056
759
|
const obj = JSON.parse(labelKey);
|
|
@@ -1087,10 +790,13 @@ function sanitizePromName(name) {
|
|
|
1087
790
|
* ```
|
|
1088
791
|
*/
|
|
1089
792
|
var MetricsPlugin = class {
|
|
1090
|
-
constructor(map) {
|
|
793
|
+
constructor(map, options = {}) {
|
|
1091
794
|
this.name = "logixia-metrics";
|
|
1092
795
|
this.metricState = /* @__PURE__ */ new Map();
|
|
796
|
+
this.overflowKeys = /* @__PURE__ */ new Map();
|
|
1093
797
|
this.map = map;
|
|
798
|
+
const max = options.maxLabelSets;
|
|
799
|
+
this.maxLabelSets = typeof max === "number" && Number.isFinite(max) && max >= 1 ? Math.floor(max) : DEFAULT_MAX_LABEL_SETS;
|
|
1094
800
|
this.initAllState();
|
|
1095
801
|
}
|
|
1096
802
|
onInit() {}
|
|
@@ -1099,16 +805,19 @@ var MetricsPlugin = class {
|
|
|
1099
805
|
for (const [rawName, config] of Object.entries(this.map)) {
|
|
1100
806
|
const state = this.metricState.get(rawName);
|
|
1101
807
|
if (!state) continue;
|
|
1102
|
-
const
|
|
808
|
+
const rawLabelKey = buildLabelKey(config, entry);
|
|
809
|
+
const overflowKey = this.overflowKeys.get(rawName) ?? "{}";
|
|
1103
810
|
if (config.type === "counter" && state.type === "counter") {
|
|
1104
811
|
if (config.levelFilter && entry.level !== config.levelFilter) continue;
|
|
1105
812
|
if (config.field !== void 0 && payload[config.field] !== config.value) continue;
|
|
813
|
+
const labelKey = this.capLabelKey(state.values, rawLabelKey, overflowKey);
|
|
1106
814
|
state.values.set(labelKey, (state.values.get(labelKey) ?? 0) + 1);
|
|
1107
815
|
} else if (config.type === "histogram" && state.type === "histogram") {
|
|
1108
816
|
const raw = payload[config.field];
|
|
1109
817
|
if (raw === void 0 || raw === null) continue;
|
|
1110
818
|
const val = Number(raw);
|
|
1111
819
|
if (Number.isNaN(val)) continue;
|
|
820
|
+
const labelKey = this.capLabelKey(state.counts, rawLabelKey, overflowKey);
|
|
1112
821
|
if (!state.counts.has(labelKey)) {
|
|
1113
822
|
state.counts.set(labelKey, Array.from({ length: state.buckets.length + 1 }).fill(0));
|
|
1114
823
|
state.sums.set(labelKey, 0);
|
|
@@ -1124,7 +833,7 @@ var MetricsPlugin = class {
|
|
|
1124
833
|
if (raw === void 0 || raw === null) continue;
|
|
1125
834
|
const val = Number(raw);
|
|
1126
835
|
if (Number.isNaN(val)) continue;
|
|
1127
|
-
state.values.set(
|
|
836
|
+
state.values.set(this.capLabelKey(state.values, rawLabelKey, overflowKey), val);
|
|
1128
837
|
}
|
|
1129
838
|
}
|
|
1130
839
|
return entry;
|
|
@@ -1225,10 +934,19 @@ var MetricsPlugin = class {
|
|
|
1225
934
|
res.end(body);
|
|
1226
935
|
};
|
|
1227
936
|
}
|
|
937
|
+
/**
|
|
938
|
+
* Return `labelKey` when it is already tracked or there is room for it;
|
|
939
|
+
* otherwise the shared overflow series key.
|
|
940
|
+
*/
|
|
941
|
+
capLabelKey(series, labelKey, overflowKey) {
|
|
942
|
+
if (series.has(labelKey) || series.size < this.maxLabelSets) return labelKey;
|
|
943
|
+
return overflowKey;
|
|
944
|
+
}
|
|
1228
945
|
initAllState() {
|
|
1229
946
|
for (const [rawName, config] of Object.entries(this.map)) this.initSingleState(rawName, config);
|
|
1230
947
|
}
|
|
1231
948
|
initSingleState(rawName, config) {
|
|
949
|
+
this.overflowKeys.set(rawName, buildOverflowKey(config));
|
|
1232
950
|
if (config.type === "counter") this.metricState.set(rawName, {
|
|
1233
951
|
type: "counter",
|
|
1234
952
|
values: /* @__PURE__ */ new Map()
|
|
@@ -1274,9 +992,11 @@ var MetricsPlugin = class {
|
|
|
1274
992
|
* logger.use(metrics);
|
|
1275
993
|
* app.get('/metrics', metrics.expressHandler());
|
|
1276
994
|
* ```
|
|
995
|
+
*
|
|
996
|
+
* Pass `{ maxLabelSets }` to change the per-metric label cardinality cap (default 1000).
|
|
1277
997
|
*/
|
|
1278
|
-
function createMetricsPlugin(map) {
|
|
1279
|
-
return new MetricsPlugin(map);
|
|
998
|
+
function createMetricsPlugin(map, options) {
|
|
999
|
+
return new MetricsPlugin(map, options);
|
|
1280
1000
|
}
|
|
1281
1001
|
|
|
1282
1002
|
//#endregion
|
|
@@ -1295,22 +1015,22 @@ const DEFAULT_CONFIG = {
|
|
|
1295
1015
|
},
|
|
1296
1016
|
silent: false,
|
|
1297
1017
|
levelOptions: {
|
|
1298
|
-
level:
|
|
1018
|
+
level: require_nestjs_extras.LogLevel.INFO,
|
|
1299
1019
|
levels: {
|
|
1300
|
-
[
|
|
1301
|
-
[
|
|
1302
|
-
[
|
|
1303
|
-
[
|
|
1304
|
-
[
|
|
1305
|
-
[
|
|
1020
|
+
[require_nestjs_extras.LogLevel.ERROR]: 0,
|
|
1021
|
+
[require_nestjs_extras.LogLevel.WARN]: 1,
|
|
1022
|
+
[require_nestjs_extras.LogLevel.INFO]: 2,
|
|
1023
|
+
[require_nestjs_extras.LogLevel.DEBUG]: 3,
|
|
1024
|
+
[require_nestjs_extras.LogLevel.TRACE]: 4,
|
|
1025
|
+
[require_nestjs_extras.LogLevel.VERBOSE]: 5
|
|
1306
1026
|
},
|
|
1307
1027
|
colors: {
|
|
1308
|
-
[
|
|
1309
|
-
[
|
|
1310
|
-
[
|
|
1311
|
-
[
|
|
1312
|
-
[
|
|
1313
|
-
[
|
|
1028
|
+
[require_nestjs_extras.LogLevel.ERROR]: "red",
|
|
1029
|
+
[require_nestjs_extras.LogLevel.WARN]: "yellow",
|
|
1030
|
+
[require_nestjs_extras.LogLevel.INFO]: "blue",
|
|
1031
|
+
[require_nestjs_extras.LogLevel.DEBUG]: "green",
|
|
1032
|
+
[require_nestjs_extras.LogLevel.TRACE]: "gray",
|
|
1033
|
+
[require_nestjs_extras.LogLevel.VERBOSE]: "cyan"
|
|
1314
1034
|
}
|
|
1315
1035
|
},
|
|
1316
1036
|
fields: {
|
|
@@ -1329,14 +1049,14 @@ const DEFAULT_CONFIG = {
|
|
|
1329
1049
|
* @param config - Logger configuration
|
|
1330
1050
|
* @returns Typed logger instance
|
|
1331
1051
|
*/
|
|
1332
|
-
const createLogger =
|
|
1052
|
+
const createLogger = require_nestjs_extras.createLogger;
|
|
1333
1053
|
/**
|
|
1334
1054
|
* Create a new Logixia logger service for NestJS
|
|
1335
1055
|
* @param config - Logger configuration
|
|
1336
1056
|
* @returns LogixiaLoggerService instance
|
|
1337
1057
|
*/
|
|
1338
1058
|
function createLoggerService(config) {
|
|
1339
|
-
return new
|
|
1059
|
+
return new require_nestjs_extras.LogixiaLoggerService({
|
|
1340
1060
|
...DEFAULT_CONFIG,
|
|
1341
1061
|
...config
|
|
1342
1062
|
});
|
|
@@ -1344,7 +1064,7 @@ function createLoggerService(config) {
|
|
|
1344
1064
|
/**
|
|
1345
1065
|
* Default logger instance
|
|
1346
1066
|
*/
|
|
1347
|
-
const logger = new
|
|
1067
|
+
const logger = new require_nestjs_extras.LogixiaLogger(DEFAULT_CONFIG);
|
|
1348
1068
|
/**
|
|
1349
1069
|
* Export default configuration for reference
|
|
1350
1070
|
*/
|
|
@@ -1354,104 +1074,108 @@ exports.BasicLogIndexer = require_search.BasicLogIndexer;
|
|
|
1354
1074
|
exports.BasicSearchEngine = require_search.BasicSearchEngine;
|
|
1355
1075
|
exports.CorrelationEngine = require_search.CorrelationEngine;
|
|
1356
1076
|
exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
|
|
1357
|
-
exports.DEFAULT_LOG_COLORS =
|
|
1358
|
-
exports.DEFAULT_LOG_LEVELS =
|
|
1359
|
-
exports.DEFAULT_TRACE_HEADERS =
|
|
1360
|
-
exports.ErrorResponseBuilder = ErrorResponseBuilder;
|
|
1361
|
-
exports.InjectLogger = InjectLogger;
|
|
1077
|
+
exports.DEFAULT_LOG_COLORS = require_nestjs_extras.DEFAULT_LOG_COLORS;
|
|
1078
|
+
exports.DEFAULT_LOG_LEVELS = require_nestjs_extras.DEFAULT_LOG_LEVELS;
|
|
1079
|
+
exports.DEFAULT_TRACE_HEADERS = require_trace_utils.DEFAULT_TRACE_HEADERS;
|
|
1080
|
+
exports.ErrorResponseBuilder = require_nestjs_extras.ErrorResponseBuilder;
|
|
1081
|
+
exports.InjectLogger = require_nestjs_extras.InjectLogger;
|
|
1362
1082
|
exports.JsonFormatter = JsonFormatter;
|
|
1363
1083
|
Object.defineProperty(exports, 'KafkaTraceInterceptor', {
|
|
1364
1084
|
enumerable: true,
|
|
1365
1085
|
get: function () {
|
|
1366
|
-
return
|
|
1086
|
+
return require_nestjs_extras.KafkaTraceInterceptor;
|
|
1367
1087
|
}
|
|
1368
1088
|
});
|
|
1369
|
-
exports.
|
|
1370
|
-
exports.
|
|
1371
|
-
exports.
|
|
1372
|
-
exports.
|
|
1373
|
-
exports.
|
|
1089
|
+
exports.LOGIXIA_EXCEPTION_FILTER_OPTIONS = require_nestjs_extras.LOGIXIA_EXCEPTION_FILTER_OPTIONS;
|
|
1090
|
+
exports.LOGIXIA_LOGGER_CONFIG = require_nestjs_extras.LOGIXIA_LOGGER_CONFIG;
|
|
1091
|
+
exports.LOGIXIA_LOGGER_PREFIX = require_nestjs_extras.LOGIXIA_LOGGER_PREFIX;
|
|
1092
|
+
exports.LOGIXIA_TRACE_CONFIG = require_nestjs_extras.LOGIXIA_TRACE_CONFIG;
|
|
1093
|
+
exports.LogLevel = require_nestjs_extras.LogLevel;
|
|
1094
|
+
exports.LogMethod = require_nestjs_extras.LogMethod;
|
|
1374
1095
|
exports.LogixiaContext = require_async_context.LogixiaContext;
|
|
1375
|
-
exports.LogixiaException = LogixiaException;
|
|
1096
|
+
exports.LogixiaException = require_nestjs_extras.LogixiaException;
|
|
1376
1097
|
Object.defineProperty(exports, 'LogixiaExceptionFilter', {
|
|
1377
1098
|
enumerable: true,
|
|
1378
1099
|
get: function () {
|
|
1379
|
-
return LogixiaExceptionFilter;
|
|
1100
|
+
return require_nestjs_extras.LogixiaExceptionFilter;
|
|
1380
1101
|
}
|
|
1381
1102
|
});
|
|
1382
|
-
exports.LogixiaLogger =
|
|
1103
|
+
exports.LogixiaLogger = require_nestjs_extras.LogixiaLogger;
|
|
1383
1104
|
Object.defineProperty(exports, 'LogixiaLoggerModule', {
|
|
1384
1105
|
enumerable: true,
|
|
1385
1106
|
get: function () {
|
|
1386
|
-
return
|
|
1107
|
+
return require_nestjs_extras.LogixiaLoggerModule;
|
|
1387
1108
|
}
|
|
1388
1109
|
});
|
|
1389
1110
|
Object.defineProperty(exports, 'LogixiaLoggerService', {
|
|
1390
1111
|
enumerable: true,
|
|
1391
1112
|
get: function () {
|
|
1392
|
-
return
|
|
1113
|
+
return require_nestjs_extras.LogixiaLoggerService;
|
|
1393
1114
|
}
|
|
1394
1115
|
});
|
|
1116
|
+
exports.MAX_INCOMING_ID_LENGTH = require_trace_utils.MAX_INCOMING_ID_LENGTH;
|
|
1395
1117
|
exports.MetricsPlugin = MetricsPlugin;
|
|
1396
1118
|
exports.NLPSearchEngine = require_search.NLPSearchEngine;
|
|
1119
|
+
exports.OVERFLOW_LABEL_VALUE = OVERFLOW_LABEL_VALUE;
|
|
1397
1120
|
exports.OtlpLogTransport = OtlpLogTransport;
|
|
1398
1121
|
exports.PatternRecognitionEngine = require_search.PatternRecognitionEngine;
|
|
1399
|
-
exports.PluginRegistry =
|
|
1122
|
+
exports.PluginRegistry = require_nestjs_extras.PluginRegistry;
|
|
1400
1123
|
exports.SearchManager = require_search.SearchManager;
|
|
1401
|
-
exports.TRACE_CONTEXT_KEY =
|
|
1124
|
+
exports.TRACE_CONTEXT_KEY = require_trace_utils.TRACE_CONTEXT_KEY;
|
|
1402
1125
|
exports.TextFormatter = TextFormatter;
|
|
1403
|
-
exports.TraceContext =
|
|
1126
|
+
exports.TraceContext = require_trace_utils.TraceContext;
|
|
1404
1127
|
Object.defineProperty(exports, 'WebSocketTraceInterceptor', {
|
|
1405
1128
|
enumerable: true,
|
|
1406
1129
|
get: function () {
|
|
1407
|
-
return
|
|
1130
|
+
return require_nestjs_extras.WebSocketTraceInterceptor;
|
|
1408
1131
|
}
|
|
1409
1132
|
});
|
|
1410
|
-
exports._setActiveContextKey =
|
|
1411
|
-
exports._shutdownRegistrySize =
|
|
1133
|
+
exports._setActiveContextKey = require_trace_utils._setActiveContextKey;
|
|
1134
|
+
exports._shutdownRegistrySize = require_nestjs_extras._shutdownRegistrySize;
|
|
1412
1135
|
exports.addEventFields = addEventFields;
|
|
1413
|
-
exports.applyRedaction =
|
|
1136
|
+
exports.applyRedaction = require_nestjs_extras.applyRedaction;
|
|
1414
1137
|
exports.createExpressContextMiddleware = require_async_context.createExpressContextMiddleware;
|
|
1415
1138
|
exports.createFastifyContextHook = require_async_context.createFastifyContextHook;
|
|
1416
1139
|
exports.createLevelControlHandler = createLevelControlHandler;
|
|
1417
1140
|
exports.createLogger = createLogger;
|
|
1418
1141
|
exports.createLoggerService = createLoggerService;
|
|
1419
1142
|
exports.createMetricsPlugin = createMetricsPlugin;
|
|
1420
|
-
exports.createTraceMiddleware =
|
|
1143
|
+
exports.createTraceMiddleware = require_trace_utils.createTraceMiddleware;
|
|
1421
1144
|
exports.createTypedLogger = createTypedLogger;
|
|
1422
1145
|
exports.decycleValue = require_safe_stringify.decycleValue;
|
|
1423
1146
|
exports.defineLogSchema = defineLogSchema;
|
|
1424
|
-
exports.deregisterFromShutdown =
|
|
1425
|
-
exports.disableOtelBridge =
|
|
1426
|
-
exports.extractTraceId =
|
|
1427
|
-
exports.flushOnExit =
|
|
1428
|
-
exports.generateRequestId = generateRequestId;
|
|
1429
|
-
exports.generateTraceId = generateTraceId;
|
|
1430
|
-
exports.getActiveOtelContext =
|
|
1431
|
-
exports.getCurrentTraceId =
|
|
1147
|
+
exports.deregisterFromShutdown = require_nestjs_extras.deregisterFromShutdown;
|
|
1148
|
+
exports.disableOtelBridge = require_nestjs_extras.disableOtelBridge;
|
|
1149
|
+
exports.extractTraceId = require_trace_utils.extractTraceId;
|
|
1150
|
+
exports.flushOnExit = require_nestjs_extras.flushOnExit;
|
|
1151
|
+
exports.generateRequestId = require_nestjs_extras.generateRequestId;
|
|
1152
|
+
exports.generateTraceId = require_nestjs_extras.generateTraceId;
|
|
1153
|
+
exports.getActiveOtelContext = require_nestjs_extras.getActiveOtelContext;
|
|
1154
|
+
exports.getCurrentTraceId = require_trace_utils.getCurrentTraceId;
|
|
1432
1155
|
exports.getEventFields = getEventFields;
|
|
1433
|
-
exports.getOtelMetaFields =
|
|
1434
|
-
exports.getTraceContextKey =
|
|
1435
|
-
exports.globalPluginRegistry =
|
|
1436
|
-
exports.initOtelBridge =
|
|
1437
|
-
exports.isError =
|
|
1438
|
-
exports.isLogixiaException = isLogixiaException;
|
|
1156
|
+
exports.getOtelMetaFields = require_nestjs_extras.getOtelMetaFields;
|
|
1157
|
+
exports.getTraceContextKey = require_trace_utils.getTraceContextKey;
|
|
1158
|
+
exports.globalPluginRegistry = require_nestjs_extras.globalPluginRegistry;
|
|
1159
|
+
exports.initOtelBridge = require_nestjs_extras.initOtelBridge;
|
|
1160
|
+
exports.isError = require_nestjs_extras.isError;
|
|
1161
|
+
exports.isLogixiaException = require_nestjs_extras.isLogixiaException;
|
|
1439
1162
|
exports.logger = logger;
|
|
1440
|
-
exports.normalizeError =
|
|
1441
|
-
exports.redactObject =
|
|
1442
|
-
exports.registerForShutdown =
|
|
1163
|
+
exports.normalizeError = require_nestjs_extras.normalizeError;
|
|
1164
|
+
exports.redactObject = require_nestjs_extras.redactObject;
|
|
1165
|
+
exports.registerForShutdown = require_nestjs_extras.registerForShutdown;
|
|
1443
1166
|
exports.registerLevelSignal = registerLevelSignal;
|
|
1444
|
-
exports.resetShutdownHandlers =
|
|
1167
|
+
exports.resetShutdownHandlers = require_nestjs_extras.resetShutdownHandlers;
|
|
1445
1168
|
exports.retrocycle = require_safe_stringify.retrocycle;
|
|
1446
|
-
exports.runWithTraceId =
|
|
1169
|
+
exports.runWithTraceId = require_trace_utils.runWithTraceId;
|
|
1447
1170
|
exports.safeStringify = require_safe_stringify.safeStringify;
|
|
1448
|
-
exports.
|
|
1171
|
+
exports.sanitizeIncomingId = require_trace_utils.sanitizeIncomingId;
|
|
1172
|
+
exports.serializeError = require_nestjs_extras.serializeError;
|
|
1449
1173
|
exports.setEventField = setEventField;
|
|
1450
|
-
exports.setTraceId =
|
|
1174
|
+
exports.setTraceId = require_trace_utils.setTraceId;
|
|
1451
1175
|
exports.stringifyForLog = require_safe_stringify.stringifyForLog;
|
|
1452
1176
|
exports.toOtelSeverity = toOtelSeverity;
|
|
1453
|
-
exports.traceStorage =
|
|
1454
|
-
exports.usePlugin =
|
|
1177
|
+
exports.traceStorage = require_trace_utils.traceStorage;
|
|
1178
|
+
exports.usePlugin = require_nestjs_extras.usePlugin;
|
|
1455
1179
|
exports.wideEventMiddleware = wideEventMiddleware;
|
|
1456
1180
|
exports.withWideEvent = withWideEvent;
|
|
1457
1181
|
//# sourceMappingURL=index.js.map
|