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
package/dist/index.mjs
CHANGED
|
@@ -1,368 +1,16 @@
|
|
|
1
|
-
import { n as internalLog, r as internalWarn
|
|
1
|
+
import { n as internalLog, r as internalWarn } from "./internal-log-Cm8SOWSV.mjs";
|
|
2
2
|
import { i as stringifyForLog, n as retrocycle, r as safeStringify, t as decycleValue } from "./safe-stringify-DJ66tW5I.mjs";
|
|
3
3
|
import { i as HttpError, n as DEFAULT_MAX_BUFFER_SIZE, r as DEFAULT_REQUEST_TIMEOUT_MS, t as BatchBuffer } from "./batch-buffer-PGvSgbmd.mjs";
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import { t as
|
|
7
|
-
import "./
|
|
8
|
-
import {
|
|
4
|
+
import "./entry-fields-BJkuPnIg.mjs";
|
|
5
|
+
import { a as _setActiveContextKey, c as getCurrentTraceId, d as sanitizeIncomingId, f as setTraceId, i as TraceContext, l as getTraceContextKey, n as MAX_INCOMING_ID_LENGTH, o as createTraceMiddleware, p as traceStorage, r as TRACE_CONTEXT_KEY, s as extractTraceId, t as DEFAULT_TRACE_HEADERS, u as runWithTraceId } from "./trace.utils-CvXgaiQT.mjs";
|
|
6
|
+
import { n as createExpressContextMiddleware, r as createFastifyContextHook, t as LogixiaContext } from "./async-context-BzJrbfQs.mjs";
|
|
7
|
+
import { C as globalPluginRegistry, D as DEFAULT_LOG_LEVELS, E as DEFAULT_LOG_COLORS, O as LogLevel, S as PluginRegistry, T as DEFAULT_CONFIG, _ as getOtelMetaFields, a as isLogixiaException, b as normalizeError, c as _shutdownRegistrySize, d as registerForShutdown, f as resetShutdownHandlers, g as getActiveOtelContext, h as disableOtelBridge, i as LogixiaException, l as deregisterFromShutdown, m as redactObject, n as generateRequestId, o as LogixiaLogger, p as applyRedaction, r as generateTraceId, s as createLogger$1, t as ErrorResponseBuilder, u as flushOnExit, v as initOtelBridge, w as usePlugin, x as serializeError, y as isError } from "./builder-0gEzRopq.mjs";
|
|
8
|
+
import { t as safeToString } from "./coerce.utils-Cu6IUTgX.mjs";
|
|
9
|
+
import { d as stripControlChars } from "./transport.manager-BiuCAJd2.mjs";
|
|
10
|
+
import { n as DiscordTransport, t as SlackTransport } from "./slack.transport-Bzw7sucI.mjs";
|
|
11
|
+
import { a as BasicSearchEngine, i as CorrelationEngine, n as PatternRecognitionEngine, o as BasicLogIndexer, r as NLPSearchEngine, t as SearchManager } from "./search-BFbu_oVn.mjs";
|
|
9
12
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
10
|
-
import { Catch, Inject, Optional } from "@nestjs/common";
|
|
11
13
|
|
|
12
|
-
//#region src/exceptions/exception.ts
|
|
13
|
-
var LogixiaException = class extends Error {
|
|
14
|
-
constructor(options) {
|
|
15
|
-
super(options.message, { cause: options.cause });
|
|
16
|
-
this.name = "LogixiaException";
|
|
17
|
-
this.errorCode = options.code;
|
|
18
|
-
this.errorType = options.type;
|
|
19
|
-
this.httpStatus = options.httpStatus;
|
|
20
|
-
this.param = options.param;
|
|
21
|
-
this.details = options.details;
|
|
22
|
-
this.docUrl = options.docUrl;
|
|
23
|
-
this.metadata = options.metadata;
|
|
24
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Returns `true` when `value` is a `LogixiaException` instance.
|
|
29
|
-
*
|
|
30
|
-
* Useful in exception filters or middleware that need to distinguish a
|
|
31
|
-
* `LogixiaException` from a plain `Error` or a framework `HttpException`.
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```ts
|
|
35
|
-
* if (isLogixiaException(err)) {
|
|
36
|
-
* console.log(err.errorCode, err.httpStatus);
|
|
37
|
-
* }
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
function isLogixiaException(value) {
|
|
41
|
-
return value instanceof LogixiaException;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
//#endregion
|
|
45
|
-
//#region src/exceptions/builder.ts
|
|
46
|
-
/**
|
|
47
|
-
* Generates a trace ID via the shared {@link TraceContext} generator.
|
|
48
|
-
*
|
|
49
|
-
* Delegates to `TraceContext.instance.generate()` so any custom generator
|
|
50
|
-
* configured on `TraceIdConfig.generator` is respected — avoids the silent
|
|
51
|
-
* "builder has its own UUID source" divergence this module had previously.
|
|
52
|
-
*
|
|
53
|
-
* @example `'550e8400-e29b-41d4-a716-446655440000'`
|
|
54
|
-
*/
|
|
55
|
-
function generateTraceId() {
|
|
56
|
-
return TraceContext.instance.generate();
|
|
57
|
-
}
|
|
58
|
-
/** @deprecated Use `generateTraceId` instead. */
|
|
59
|
-
const generateRequestId = generateTraceId;
|
|
60
|
-
/**
|
|
61
|
-
* Maps an HTTP status code to a human-friendly error type string.
|
|
62
|
-
* Used as a fallback when the exception is a generic `HttpException`.
|
|
63
|
-
*/
|
|
64
|
-
function httpStatusToType(status) {
|
|
65
|
-
if (status === 400) return "api_error";
|
|
66
|
-
if (status === 401) return "authentication_error";
|
|
67
|
-
if (status === 402) return "payment_error";
|
|
68
|
-
if (status === 403) return "authorization_error";
|
|
69
|
-
if (status === 404) return "not_found_error";
|
|
70
|
-
if (status === 408) return "timeout_error";
|
|
71
|
-
if (status === 409) return "conflict_error";
|
|
72
|
-
if (status === 422) return "validation_error";
|
|
73
|
-
if (status === 429) return "rate_limit_error";
|
|
74
|
-
if (status >= 500) return "server_error";
|
|
75
|
-
if (status >= 400) return "api_error";
|
|
76
|
-
return "server_error";
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Duck-type check for NestJS `HttpException`.
|
|
80
|
-
* Avoids a hard import on `@nestjs/common` so the builder is usable outside NestJS.
|
|
81
|
-
*/
|
|
82
|
-
function isHttpException(value) {
|
|
83
|
-
return typeof value === "object" && value !== null && typeof value["getStatus"] === "function" && typeof value["getResponse"] === "function";
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Builds the optional `debug` block from an error.
|
|
87
|
-
* Returns `undefined` when there is nothing useful to include.
|
|
88
|
-
*/
|
|
89
|
-
function buildDebug(error, service, durationMs) {
|
|
90
|
-
const stack = error instanceof Error ? error.stack : void 0;
|
|
91
|
-
const causeRaw = error instanceof Error ? error.cause : void 0;
|
|
92
|
-
let cause;
|
|
93
|
-
if (causeRaw instanceof Error) cause = causeRaw.message;
|
|
94
|
-
else if (causeRaw !== void 0 && causeRaw !== null) cause = String(causeRaw);
|
|
95
|
-
if (!stack && !cause && !service && durationMs === void 0) return void 0;
|
|
96
|
-
return {
|
|
97
|
-
...stack !== void 0 ? { stack } : {},
|
|
98
|
-
...cause !== void 0 ? { cause } : {},
|
|
99
|
-
...service !== void 0 ? { service } : {},
|
|
100
|
-
...durationMs !== void 0 ? { duration_ms: durationMs } : {}
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
var ErrorResponseBuilder = class {
|
|
104
|
-
/**
|
|
105
|
-
* Build a `LogixiaErrorResponse` from any thrown value.
|
|
106
|
-
*
|
|
107
|
-
* @param params - See `BuildParams`.
|
|
108
|
-
* @returns The unified error response and the HTTP status code to send.
|
|
109
|
-
*
|
|
110
|
-
* @remarks
|
|
111
|
-
* `traceId` does not need to be supplied by the caller in most cases — the
|
|
112
|
-
* builder reads `TraceContext.instance.getCurrentTraceId()` internally and
|
|
113
|
-
* falls back to the explicit `traceId` argument only when AsyncLocalStorage
|
|
114
|
-
* is empty. If neither source yields a value, `meta.trace_id` is omitted.
|
|
115
|
-
*
|
|
116
|
-
* @example In a NestJS exception filter
|
|
117
|
-
* ```ts
|
|
118
|
-
* const { response, httpStatus } = ErrorResponseBuilder.build<AppCode, AppType>({
|
|
119
|
-
* exception,
|
|
120
|
-
* // Omit traceId — it will be picked up from ALS automatically.
|
|
121
|
-
* path: request.url,
|
|
122
|
-
* service: process.env.SERVICE_NAME,
|
|
123
|
-
* startTime: request.startTime,
|
|
124
|
-
* });
|
|
125
|
-
*
|
|
126
|
-
* if (process.env.NODE_ENV === 'production') delete response.debug;
|
|
127
|
-
* // Echo the resolved traceId back on whatever header your TraceIdConfig says —
|
|
128
|
-
* // do NOT hardcode 'X-Trace-Id', use `resolveResponseHeader(config)` instead.
|
|
129
|
-
* if (response.meta.trace_id) {
|
|
130
|
-
* response.setHeader(resolveResponseHeader(config) ?? 'X-Trace-Id', response.meta.trace_id);
|
|
131
|
-
* }
|
|
132
|
-
* response.status(httpStatus).json(response);
|
|
133
|
-
* ```
|
|
134
|
-
*/
|
|
135
|
-
static build(params) {
|
|
136
|
-
const { exception, path, service, startTime, traceId: rawTraceId } = params;
|
|
137
|
-
const traceId = TraceContext.instance.getCurrentTraceId() ?? rawTraceId;
|
|
138
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
139
|
-
const durationMs = startTime !== void 0 ? Date.now() - startTime : void 0;
|
|
140
|
-
if (isLogixiaException(exception)) {
|
|
141
|
-
const debug$1 = buildDebug(exception, service, durationMs);
|
|
142
|
-
const errorBlock = {
|
|
143
|
-
type: exception.errorType,
|
|
144
|
-
code: exception.errorCode,
|
|
145
|
-
message: exception.message
|
|
146
|
-
};
|
|
147
|
-
if (exception.param !== void 0) errorBlock.param = exception.param;
|
|
148
|
-
if (exception.details !== void 0 && exception.details.length > 0) errorBlock.details = exception.details;
|
|
149
|
-
if (exception.docUrl !== void 0) errorBlock.doc_url = exception.docUrl;
|
|
150
|
-
return {
|
|
151
|
-
response: {
|
|
152
|
-
success: false,
|
|
153
|
-
error: errorBlock,
|
|
154
|
-
meta: {
|
|
155
|
-
...traceId !== void 0 ? { trace_id: traceId } : {},
|
|
156
|
-
timestamp,
|
|
157
|
-
path,
|
|
158
|
-
status: exception.httpStatus
|
|
159
|
-
},
|
|
160
|
-
...debug$1 !== void 0 ? { debug: debug$1 } : {}
|
|
161
|
-
},
|
|
162
|
-
httpStatus: exception.httpStatus
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
if (isHttpException(exception)) {
|
|
166
|
-
const status = exception.getStatus();
|
|
167
|
-
const exResponse = exception.getResponse();
|
|
168
|
-
let message;
|
|
169
|
-
if (typeof exResponse === "string") message = exResponse;
|
|
170
|
-
else if (typeof exResponse === "object" && exResponse !== null && "message" in exResponse) {
|
|
171
|
-
const raw = exResponse.message;
|
|
172
|
-
message = Array.isArray(raw) ? raw.join(", ") : String(raw);
|
|
173
|
-
} else message = exception.message;
|
|
174
|
-
const type = httpStatusToType(status);
|
|
175
|
-
const code = `HTTP_${status}`;
|
|
176
|
-
const debug$1 = buildDebug(exception, service, durationMs);
|
|
177
|
-
return {
|
|
178
|
-
response: {
|
|
179
|
-
success: false,
|
|
180
|
-
error: {
|
|
181
|
-
type,
|
|
182
|
-
code,
|
|
183
|
-
message
|
|
184
|
-
},
|
|
185
|
-
meta: {
|
|
186
|
-
...traceId !== void 0 ? { trace_id: traceId } : {},
|
|
187
|
-
timestamp,
|
|
188
|
-
path,
|
|
189
|
-
status
|
|
190
|
-
},
|
|
191
|
-
...debug$1 !== void 0 ? { debug: debug$1 } : {}
|
|
192
|
-
},
|
|
193
|
-
httpStatus: status
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
const debug = buildDebug(exception instanceof Error ? exception : new Error(String(exception)), service, durationMs);
|
|
197
|
-
return {
|
|
198
|
-
response: {
|
|
199
|
-
success: false,
|
|
200
|
-
error: {
|
|
201
|
-
type: "server_error",
|
|
202
|
-
code: "INTERNAL_SERVER_ERROR",
|
|
203
|
-
message: "An unexpected error occurred."
|
|
204
|
-
},
|
|
205
|
-
meta: {
|
|
206
|
-
...traceId !== void 0 ? { trace_id: traceId } : {},
|
|
207
|
-
timestamp,
|
|
208
|
-
path,
|
|
209
|
-
status: 500
|
|
210
|
-
},
|
|
211
|
-
...debug !== void 0 ? { debug } : {}
|
|
212
|
-
},
|
|
213
|
-
httpStatus: 500
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
//#endregion
|
|
219
|
-
//#region src/core/nestjs-extras.ts
|
|
220
|
-
var _ref;
|
|
221
|
-
/**
|
|
222
|
-
* Inject the Logixia logger registered in the current NestJS DI container.
|
|
223
|
-
*
|
|
224
|
-
* Equivalent to `@Inject(LOGIXIA_LOGGER_TOKEN)` but without needing to import
|
|
225
|
-
* the internal token constant yourself.
|
|
226
|
-
*
|
|
227
|
-
* @example
|
|
228
|
-
* ```ts
|
|
229
|
-
* constructor(@InjectLogger() private readonly logger: LogixiaLoggerService) {}
|
|
230
|
-
* ```
|
|
231
|
-
*/
|
|
232
|
-
const InjectLogger = () => Inject(`${LOGIXIA_LOGGER_PREFIX}SERVICE`);
|
|
233
|
-
/**
|
|
234
|
-
* Method decorator that auto-logs entry, exit, duration, and errors.
|
|
235
|
-
*
|
|
236
|
-
* Preserves the original method's sync/async contract: a synchronous method
|
|
237
|
-
* stays synchronous (returns its value directly, with logs emitted
|
|
238
|
-
* fire-and-forget), and an async method is awaited so exit/error logs reflect
|
|
239
|
-
* the resolved result. Attaches to the logger found on the class instance via a
|
|
240
|
-
* `logger` property (the conventional NestJS name).
|
|
241
|
-
*
|
|
242
|
-
* @example
|
|
243
|
-
* ```ts
|
|
244
|
-
* @LogMethod({ level: 'info', logArgs: true })
|
|
245
|
-
* async processPayment(orderId: string): Promise<void> { … }
|
|
246
|
-
* ```
|
|
247
|
-
*/
|
|
248
|
-
function LogMethod(options = {}) {
|
|
249
|
-
const { level = "debug", logArgs = true, logResult = false, logErrors = true } = options;
|
|
250
|
-
return function(target, propertyKey, descriptor) {
|
|
251
|
-
var _constructor;
|
|
252
|
-
const originalMethod = descriptor.value;
|
|
253
|
-
if (typeof originalMethod !== "function") return descriptor;
|
|
254
|
-
const methodName = String(propertyKey);
|
|
255
|
-
const className = ((_constructor = target.constructor) === null || _constructor === void 0 ? void 0 : _constructor.name) ?? "Unknown";
|
|
256
|
-
const label = options.label ?? `${className}.${methodName}`;
|
|
257
|
-
let _warnedNoLogger = false;
|
|
258
|
-
const reportLogFailure = (phase, err) => {
|
|
259
|
-
internalError(`@LogMethod(${label}) ${phase} log failed: ${String(err)}`);
|
|
260
|
-
};
|
|
261
|
-
const emit$1 = (logger$1, phase, message, data) => {
|
|
262
|
-
const logFnRaw = logger$1[level];
|
|
263
|
-
const p = (typeof logFnRaw === "function" ? logFnRaw : logger$1.debug).bind(logger$1)(message, data);
|
|
264
|
-
if (p && typeof p.catch === "function") p.catch((e) => reportLogFailure(phase, e));
|
|
265
|
-
};
|
|
266
|
-
const emitError = (logger$1, error, start) => {
|
|
267
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
268
|
-
const errLog = logger$1.error(err, {
|
|
269
|
-
method: label,
|
|
270
|
-
durationMs: Date.now() - start
|
|
271
|
-
});
|
|
272
|
-
if (errLog && typeof errLog.catch === "function") errLog.catch((e) => reportLogFailure("error", e));
|
|
273
|
-
};
|
|
274
|
-
descriptor.value = function(...args) {
|
|
275
|
-
const logger$1 = this.logger ?? LogixiaLoggerModule._globalLogger ?? void 0;
|
|
276
|
-
if (!logger$1 && !_warnedNoLogger) {
|
|
277
|
-
_warnedNoLogger = true;
|
|
278
|
-
internalWarn(`@LogMethod on ${label}: no logger available. Either inject LogixiaLoggerService as this.logger or ensure LogixiaLoggerModule is initialised.`);
|
|
279
|
-
}
|
|
280
|
-
const start = Date.now();
|
|
281
|
-
const entry = { method: label };
|
|
282
|
-
if (logArgs && args.length > 0) entry["args"] = args;
|
|
283
|
-
if (logger$1) emit$1(logger$1, "entry", `→ ${label}`, entry);
|
|
284
|
-
const buildExit = (result$1) => {
|
|
285
|
-
const exit = {
|
|
286
|
-
method: label,
|
|
287
|
-
durationMs: Date.now() - start
|
|
288
|
-
};
|
|
289
|
-
if (logResult) exit["result"] = result$1;
|
|
290
|
-
return exit;
|
|
291
|
-
};
|
|
292
|
-
let result;
|
|
293
|
-
try {
|
|
294
|
-
result = originalMethod.apply(this, args);
|
|
295
|
-
} catch (error) {
|
|
296
|
-
if (logger$1 && logErrors) emitError(logger$1, error, start);
|
|
297
|
-
throw error;
|
|
298
|
-
}
|
|
299
|
-
if (result && typeof result.then === "function") return result.then((resolved) => {
|
|
300
|
-
if (logger$1) emit$1(logger$1, "exit", `← ${label}`, buildExit(resolved));
|
|
301
|
-
return resolved;
|
|
302
|
-
}, (error) => {
|
|
303
|
-
if (logger$1 && logErrors) emitError(logger$1, error, start);
|
|
304
|
-
throw error;
|
|
305
|
-
});
|
|
306
|
-
if (logger$1) emit$1(logger$1, "exit", `← ${label}`, buildExit(result));
|
|
307
|
-
return result;
|
|
308
|
-
};
|
|
309
|
-
return descriptor;
|
|
310
|
-
};
|
|
311
|
-
}
|
|
312
|
-
let LogixiaExceptionFilter = class LogixiaExceptionFilter$1 {
|
|
313
|
-
constructor(logger$1, loggerConfig) {
|
|
314
|
-
this._logger = logger$1 ?? LogixiaLoggerModule._globalLogger ?? void 0;
|
|
315
|
-
this._traceConfig = typeof (loggerConfig === null || loggerConfig === void 0 ? void 0 : loggerConfig.traceId) === "object" ? loggerConfig.traceId : void 0;
|
|
316
|
-
}
|
|
317
|
-
catch(exception, host) {
|
|
318
|
-
var _request$headers;
|
|
319
|
-
const ctx = host.switchToHttp();
|
|
320
|
-
const request = ctx.getRequest();
|
|
321
|
-
const response = ctx.getResponse();
|
|
322
|
-
const traceId = TraceContext.instance.getCurrentTraceId() ?? ((_request$headers = request.headers) === null || _request$headers === void 0 ? void 0 : _request$headers["x-trace-id"]) ?? request.id ?? void 0;
|
|
323
|
-
const { response: errorResponse, httpStatus } = ErrorResponseBuilder.build({
|
|
324
|
-
exception,
|
|
325
|
-
traceId,
|
|
326
|
-
path: request.url ?? "/",
|
|
327
|
-
startTime: request.startTime
|
|
328
|
-
});
|
|
329
|
-
if (this._logger) {
|
|
330
|
-
const requestMeta = {
|
|
331
|
-
method: request.method ?? "",
|
|
332
|
-
url: request.url ?? "",
|
|
333
|
-
status: httpStatus,
|
|
334
|
-
...errorResponse.meta.trace_id !== void 0 ? { trace_id: errorResponse.meta.trace_id } : {}
|
|
335
|
-
};
|
|
336
|
-
const onLogFailure = (err) => {
|
|
337
|
-
internalError(`ExceptionFilter failed to write log entry: ${String(err)}`);
|
|
338
|
-
};
|
|
339
|
-
let logPromise;
|
|
340
|
-
if (httpStatus >= 500) {
|
|
341
|
-
const err = exception instanceof Error ? exception : new Error(String(exception));
|
|
342
|
-
logPromise = this._logger.error(err, requestMeta);
|
|
343
|
-
} else if (isLogixiaException(exception)) logPromise = this._logger.warn(`[${errorResponse.error.code}] ${errorResponse.error.message}`, requestMeta);
|
|
344
|
-
else logPromise = this._logger.warn(`[${httpStatus}] ${errorResponse.error.message}`, requestMeta);
|
|
345
|
-
if (logPromise && typeof logPromise.catch === "function") logPromise.catch(onLogFailure);
|
|
346
|
-
}
|
|
347
|
-
if (process.env["NODE_ENV"] === "production") delete errorResponse.debug;
|
|
348
|
-
if (errorResponse.meta.trace_id) {
|
|
349
|
-
const traceHeader = resolveResponseHeader(this._traceConfig);
|
|
350
|
-
if (traceHeader) response.setHeader(traceHeader, errorResponse.meta.trace_id);
|
|
351
|
-
}
|
|
352
|
-
if (httpStatus === 429) response.setHeader("Retry-After", "60");
|
|
353
|
-
response.status(httpStatus).json(errorResponse);
|
|
354
|
-
}
|
|
355
|
-
};
|
|
356
|
-
LogixiaExceptionFilter = __decorate([
|
|
357
|
-
Catch(),
|
|
358
|
-
__decorateParam(0, Optional()),
|
|
359
|
-
__decorateParam(0, Inject(`${LOGIXIA_LOGGER_PREFIX}SERVICE`)),
|
|
360
|
-
__decorateParam(1, Optional()),
|
|
361
|
-
__decorateParam(1, Inject(LOGIXIA_LOGGER_CONFIG)),
|
|
362
|
-
__decorateMetadata("design:paramtypes", [Object, typeof (_ref = typeof Partial !== "undefined" && Partial) === "function" ? _ref : Object])
|
|
363
|
-
], LogixiaExceptionFilter);
|
|
364
|
-
|
|
365
|
-
//#endregion
|
|
366
14
|
//#region src/formatters/json.formatter.ts
|
|
367
15
|
/**
|
|
368
16
|
* Build a JSON.stringify replacer that replaces circular references with the
|
|
@@ -430,8 +78,7 @@ var JsonFormatter = class {
|
|
|
430
78
|
|
|
431
79
|
//#endregion
|
|
432
80
|
//#region src/formatters/text.formatter.ts
|
|
433
|
-
const
|
|
434
|
-
const stripControls = (value) => safeToString(value).replace(CONTROL_CHARS_RE, "");
|
|
81
|
+
const stripControls = (value) => stripControlChars(safeToString(value));
|
|
435
82
|
var TextFormatter = class TextFormatter {
|
|
436
83
|
constructor(options = {}) {
|
|
437
84
|
this.colorize = options.colorize ?? true;
|
|
@@ -583,6 +230,15 @@ function registerLevelSignal(logger$1, options = {}) {
|
|
|
583
230
|
process.removeListener(signal, handler);
|
|
584
231
|
};
|
|
585
232
|
}
|
|
233
|
+
/** Maximum accepted request body size for the level control handler. */
|
|
234
|
+
const MAX_BODY_BYTES = 16 * 1024;
|
|
235
|
+
function isJsonContentType(req) {
|
|
236
|
+
var _req$headers;
|
|
237
|
+
const raw = (_req$headers = req.headers) === null || _req$headers === void 0 ? void 0 : _req$headers["content-type"];
|
|
238
|
+
const value = Array.isArray(raw) ? raw[0] : raw;
|
|
239
|
+
if (typeof value !== "string") return false;
|
|
240
|
+
return value.split(";")[0].trim().toLowerCase() === "application/json";
|
|
241
|
+
}
|
|
586
242
|
const VALID_LEVELS = new Set([
|
|
587
243
|
"error",
|
|
588
244
|
"warn",
|
|
@@ -601,7 +257,16 @@ const VALID_LEVELS = new Set([
|
|
|
601
257
|
*
|
|
602
258
|
* Custom levels are accepted too: any level the logger already knows passes
|
|
603
259
|
* through. Unknown levels are rejected with 400 so a typo can't silently mute
|
|
604
|
-
* logging.
|
|
260
|
+
* logging.
|
|
261
|
+
*
|
|
262
|
+
* **SECURITY: this handler has NO authentication or authorization.** Anyone who
|
|
263
|
+
* can reach it can silence logging or turn on verbose output. Always mount it
|
|
264
|
+
* behind your own auth (and on an internal-only route/port), never on a public
|
|
265
|
+
* listener.
|
|
266
|
+
*
|
|
267
|
+
* Mutating requests must send `Content-Type: application/json` (otherwise 415,
|
|
268
|
+
* which also keeps cross-site form posts out) and a body of at most 16 KB
|
|
269
|
+
* (otherwise 413).
|
|
605
270
|
*/
|
|
606
271
|
function createLevelControlHandler(logger$1, options = {}) {
|
|
607
272
|
const allowed = options.allowedLevels && options.allowedLevels.length > 0 ? new Set(options.allowedLevels.map((l) => l.toLowerCase())) : VALID_LEVELS;
|
|
@@ -648,8 +313,7 @@ function createLevelControlHandler(logger$1, options = {}) {
|
|
|
648
313
|
return;
|
|
649
314
|
}
|
|
650
315
|
if (logger$1.setNamespaceLevels) {
|
|
651
|
-
const coerced =
|
|
652
|
-
for (const [pat, lvl] of Object.entries(nl)) coerced[pat] = String(lvl).toLowerCase();
|
|
316
|
+
const coerced = Object.fromEntries(Object.entries(nl).map(([pat, lvl]) => [pat, String(lvl).toLowerCase()]));
|
|
653
317
|
logger$1.setNamespaceLevels(coerced);
|
|
654
318
|
} else internalWarn("level control: logger does not support setNamespaceLevels — ignored");
|
|
655
319
|
}
|
|
@@ -662,17 +326,48 @@ function createLevelControlHandler(logger$1, options = {}) {
|
|
|
662
326
|
return;
|
|
663
327
|
}
|
|
664
328
|
if (method === "POST" || method === "PUT" || method === "PATCH") {
|
|
329
|
+
var _req$headers2;
|
|
330
|
+
if (!isJsonContentType(req)) {
|
|
331
|
+
send(res, 415, { error: "Content-Type must be application/json" });
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const declared = Number((_req$headers2 = req.headers) === null || _req$headers2 === void 0 ? void 0 : _req$headers2["content-length"]);
|
|
335
|
+
if (Number.isFinite(declared) && declared > MAX_BODY_BYTES) {
|
|
336
|
+
send(res, 413, { error: "request body too large" });
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
665
339
|
const maybeBody = req.body;
|
|
666
|
-
if (maybeBody !== void 0
|
|
667
|
-
|
|
340
|
+
if (maybeBody !== void 0) {
|
|
341
|
+
let text;
|
|
342
|
+
if (typeof maybeBody === "string") text = maybeBody;
|
|
343
|
+
else if (Buffer.isBuffer(maybeBody)) text = maybeBody.toString("utf8");
|
|
344
|
+
else text = JSON.stringify(maybeBody);
|
|
345
|
+
if (Buffer.byteLength(text) > MAX_BODY_BYTES) {
|
|
346
|
+
send(res, 413, { error: "request body too large" });
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
applyBody(res, text);
|
|
668
350
|
return;
|
|
669
351
|
}
|
|
670
352
|
if (typeof req.on === "function") {
|
|
671
353
|
let raw = "";
|
|
354
|
+
let size = 0;
|
|
355
|
+
let rejected = false;
|
|
672
356
|
req.on("data", (chunk) => {
|
|
673
|
-
|
|
357
|
+
if (rejected) return;
|
|
358
|
+
const piece = Buffer.isBuffer(chunk) ? chunk.toString("utf8") : String(chunk ?? "");
|
|
359
|
+
size += Buffer.byteLength(piece);
|
|
360
|
+
if (size > MAX_BODY_BYTES) {
|
|
361
|
+
rejected = true;
|
|
362
|
+
raw = "";
|
|
363
|
+
send(res, 413, { error: "request body too large" });
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
raw += piece;
|
|
367
|
+
});
|
|
368
|
+
req.on("end", () => {
|
|
369
|
+
if (!rejected) applyBody(res, raw);
|
|
674
370
|
});
|
|
675
|
-
req.on("end", () => applyBody(res, raw));
|
|
676
371
|
return;
|
|
677
372
|
}
|
|
678
373
|
applyBody(res, "");
|
|
@@ -1037,6 +732,10 @@ const DEFAULT_BUCKETS = [
|
|
|
1037
732
|
5e3,
|
|
1038
733
|
1e4
|
|
1039
734
|
];
|
|
735
|
+
const MAX_LABEL_VALUE_LENGTH = 256;
|
|
736
|
+
const DEFAULT_MAX_LABEL_SETS = 1e3;
|
|
737
|
+
/** Label value used for the series that absorbs label sets beyond the cardinality cap. */
|
|
738
|
+
const OVERFLOW_LABEL_VALUE = "__overflow__";
|
|
1040
739
|
function buildLabelKey(config, entry) {
|
|
1041
740
|
const labelNames = config.labels ?? [];
|
|
1042
741
|
if (labelNames.length === 0) return "{}";
|
|
@@ -1044,10 +743,16 @@ function buildLabelKey(config, entry) {
|
|
|
1044
743
|
const payload = entry.payload ?? {};
|
|
1045
744
|
for (const name of labelNames) {
|
|
1046
745
|
const raw = name === "level" ? entry.level : payload[name];
|
|
1047
|
-
pairs[sanitizePromName(name)] = raw !== void 0 && raw !== null ? String(raw) : "";
|
|
746
|
+
pairs[sanitizePromName(name)] = raw !== void 0 && raw !== null ? String(raw).slice(0, MAX_LABEL_VALUE_LENGTH) : "";
|
|
1048
747
|
}
|
|
1049
748
|
return JSON.stringify(pairs);
|
|
1050
749
|
}
|
|
750
|
+
/** Label key of the shared overflow series for a metric (all label values `__overflow__`). */
|
|
751
|
+
function buildOverflowKey(config) {
|
|
752
|
+
const names = config.labels ?? [];
|
|
753
|
+
if (names.length === 0) return "{}";
|
|
754
|
+
return JSON.stringify(Object.fromEntries(names.map((n) => [sanitizePromName(n), OVERFLOW_LABEL_VALUE])));
|
|
755
|
+
}
|
|
1051
756
|
function renderLabels(labelKey) {
|
|
1052
757
|
if (labelKey === "{}") return "";
|
|
1053
758
|
const obj = JSON.parse(labelKey);
|
|
@@ -1084,10 +789,13 @@ function sanitizePromName(name) {
|
|
|
1084
789
|
* ```
|
|
1085
790
|
*/
|
|
1086
791
|
var MetricsPlugin = class {
|
|
1087
|
-
constructor(map) {
|
|
792
|
+
constructor(map, options = {}) {
|
|
1088
793
|
this.name = "logixia-metrics";
|
|
1089
794
|
this.metricState = /* @__PURE__ */ new Map();
|
|
795
|
+
this.overflowKeys = /* @__PURE__ */ new Map();
|
|
1090
796
|
this.map = map;
|
|
797
|
+
const max = options.maxLabelSets;
|
|
798
|
+
this.maxLabelSets = typeof max === "number" && Number.isFinite(max) && max >= 1 ? Math.floor(max) : DEFAULT_MAX_LABEL_SETS;
|
|
1091
799
|
this.initAllState();
|
|
1092
800
|
}
|
|
1093
801
|
onInit() {}
|
|
@@ -1096,16 +804,19 @@ var MetricsPlugin = class {
|
|
|
1096
804
|
for (const [rawName, config] of Object.entries(this.map)) {
|
|
1097
805
|
const state = this.metricState.get(rawName);
|
|
1098
806
|
if (!state) continue;
|
|
1099
|
-
const
|
|
807
|
+
const rawLabelKey = buildLabelKey(config, entry);
|
|
808
|
+
const overflowKey = this.overflowKeys.get(rawName) ?? "{}";
|
|
1100
809
|
if (config.type === "counter" && state.type === "counter") {
|
|
1101
810
|
if (config.levelFilter && entry.level !== config.levelFilter) continue;
|
|
1102
811
|
if (config.field !== void 0 && payload[config.field] !== config.value) continue;
|
|
812
|
+
const labelKey = this.capLabelKey(state.values, rawLabelKey, overflowKey);
|
|
1103
813
|
state.values.set(labelKey, (state.values.get(labelKey) ?? 0) + 1);
|
|
1104
814
|
} else if (config.type === "histogram" && state.type === "histogram") {
|
|
1105
815
|
const raw = payload[config.field];
|
|
1106
816
|
if (raw === void 0 || raw === null) continue;
|
|
1107
817
|
const val = Number(raw);
|
|
1108
818
|
if (Number.isNaN(val)) continue;
|
|
819
|
+
const labelKey = this.capLabelKey(state.counts, rawLabelKey, overflowKey);
|
|
1109
820
|
if (!state.counts.has(labelKey)) {
|
|
1110
821
|
state.counts.set(labelKey, Array.from({ length: state.buckets.length + 1 }).fill(0));
|
|
1111
822
|
state.sums.set(labelKey, 0);
|
|
@@ -1121,7 +832,7 @@ var MetricsPlugin = class {
|
|
|
1121
832
|
if (raw === void 0 || raw === null) continue;
|
|
1122
833
|
const val = Number(raw);
|
|
1123
834
|
if (Number.isNaN(val)) continue;
|
|
1124
|
-
state.values.set(
|
|
835
|
+
state.values.set(this.capLabelKey(state.values, rawLabelKey, overflowKey), val);
|
|
1125
836
|
}
|
|
1126
837
|
}
|
|
1127
838
|
return entry;
|
|
@@ -1222,10 +933,19 @@ var MetricsPlugin = class {
|
|
|
1222
933
|
res.end(body);
|
|
1223
934
|
};
|
|
1224
935
|
}
|
|
936
|
+
/**
|
|
937
|
+
* Return `labelKey` when it is already tracked or there is room for it;
|
|
938
|
+
* otherwise the shared overflow series key.
|
|
939
|
+
*/
|
|
940
|
+
capLabelKey(series, labelKey, overflowKey) {
|
|
941
|
+
if (series.has(labelKey) || series.size < this.maxLabelSets) return labelKey;
|
|
942
|
+
return overflowKey;
|
|
943
|
+
}
|
|
1225
944
|
initAllState() {
|
|
1226
945
|
for (const [rawName, config] of Object.entries(this.map)) this.initSingleState(rawName, config);
|
|
1227
946
|
}
|
|
1228
947
|
initSingleState(rawName, config) {
|
|
948
|
+
this.overflowKeys.set(rawName, buildOverflowKey(config));
|
|
1229
949
|
if (config.type === "counter") this.metricState.set(rawName, {
|
|
1230
950
|
type: "counter",
|
|
1231
951
|
values: /* @__PURE__ */ new Map()
|
|
@@ -1271,74 +991,22 @@ var MetricsPlugin = class {
|
|
|
1271
991
|
* logger.use(metrics);
|
|
1272
992
|
* app.get('/metrics', metrics.expressHandler());
|
|
1273
993
|
* ```
|
|
994
|
+
*
|
|
995
|
+
* Pass `{ maxLabelSets }` to change the per-metric label cardinality cap (default 1000).
|
|
1274
996
|
*/
|
|
1275
|
-
function createMetricsPlugin(map) {
|
|
1276
|
-
return new MetricsPlugin(map);
|
|
997
|
+
function createMetricsPlugin(map, options) {
|
|
998
|
+
return new MetricsPlugin(map, options);
|
|
1277
999
|
}
|
|
1278
1000
|
|
|
1279
1001
|
//#endregion
|
|
1280
1002
|
//#region src/index.ts
|
|
1281
1003
|
/**
|
|
1282
|
-
* Default configuration for Logixia logger
|
|
1283
|
-
*/
|
|
1284
|
-
const DEFAULT_CONFIG = {
|
|
1285
|
-
appName: "App",
|
|
1286
|
-
environment: "development",
|
|
1287
|
-
traceId: true,
|
|
1288
|
-
format: {
|
|
1289
|
-
timestamp: true,
|
|
1290
|
-
colorize: true,
|
|
1291
|
-
json: false
|
|
1292
|
-
},
|
|
1293
|
-
silent: false,
|
|
1294
|
-
levelOptions: {
|
|
1295
|
-
level: LogLevel.INFO,
|
|
1296
|
-
levels: {
|
|
1297
|
-
[LogLevel.ERROR]: 0,
|
|
1298
|
-
[LogLevel.WARN]: 1,
|
|
1299
|
-
[LogLevel.INFO]: 2,
|
|
1300
|
-
[LogLevel.DEBUG]: 3,
|
|
1301
|
-
[LogLevel.TRACE]: 4,
|
|
1302
|
-
[LogLevel.VERBOSE]: 5
|
|
1303
|
-
},
|
|
1304
|
-
colors: {
|
|
1305
|
-
[LogLevel.ERROR]: "red",
|
|
1306
|
-
[LogLevel.WARN]: "yellow",
|
|
1307
|
-
[LogLevel.INFO]: "blue",
|
|
1308
|
-
[LogLevel.DEBUG]: "green",
|
|
1309
|
-
[LogLevel.TRACE]: "gray",
|
|
1310
|
-
[LogLevel.VERBOSE]: "cyan"
|
|
1311
|
-
}
|
|
1312
|
-
},
|
|
1313
|
-
fields: {
|
|
1314
|
-
timestamp: true,
|
|
1315
|
-
level: true,
|
|
1316
|
-
appName: true,
|
|
1317
|
-
traceId: true,
|
|
1318
|
-
message: true,
|
|
1319
|
-
payload: true,
|
|
1320
|
-
timeTaken: true
|
|
1321
|
-
},
|
|
1322
|
-
outputs: ["console"]
|
|
1323
|
-
};
|
|
1324
|
-
/**
|
|
1325
1004
|
* Create a new Logixia logger instance with TypeScript support for custom levels
|
|
1326
1005
|
* @param config - Logger configuration
|
|
1327
1006
|
* @returns Typed logger instance
|
|
1328
1007
|
*/
|
|
1329
1008
|
const createLogger = createLogger$1;
|
|
1330
1009
|
/**
|
|
1331
|
-
* Create a new Logixia logger service for NestJS
|
|
1332
|
-
* @param config - Logger configuration
|
|
1333
|
-
* @returns LogixiaLoggerService instance
|
|
1334
|
-
*/
|
|
1335
|
-
function createLoggerService(config) {
|
|
1336
|
-
return new LogixiaLoggerService({
|
|
1337
|
-
...DEFAULT_CONFIG,
|
|
1338
|
-
...config
|
|
1339
|
-
});
|
|
1340
|
-
}
|
|
1341
|
-
/**
|
|
1342
1010
|
* Default logger instance
|
|
1343
1011
|
*/
|
|
1344
1012
|
const logger = new LogixiaLogger(DEFAULT_CONFIG);
|
|
@@ -1347,5 +1015,5 @@ const logger = new LogixiaLogger(DEFAULT_CONFIG);
|
|
|
1347
1015
|
*/
|
|
1348
1016
|
|
|
1349
1017
|
//#endregion
|
|
1350
|
-
export { BasicLogIndexer, BasicSearchEngine, CorrelationEngine, DEFAULT_CONFIG, DEFAULT_LOG_COLORS, DEFAULT_LOG_LEVELS, DEFAULT_TRACE_HEADERS,
|
|
1018
|
+
export { BasicLogIndexer, BasicSearchEngine, CorrelationEngine, DEFAULT_CONFIG, DEFAULT_LOG_COLORS, DEFAULT_LOG_LEVELS, DEFAULT_TRACE_HEADERS, DiscordTransport, ErrorResponseBuilder, JsonFormatter, LogLevel, LogixiaContext, LogixiaException, LogixiaLogger, MAX_INCOMING_ID_LENGTH, MetricsPlugin, NLPSearchEngine, OVERFLOW_LABEL_VALUE, OtlpLogTransport, PatternRecognitionEngine, PluginRegistry, SearchManager, SlackTransport, TRACE_CONTEXT_KEY, TextFormatter, TraceContext, _setActiveContextKey, _shutdownRegistrySize, addEventFields, applyRedaction, createExpressContextMiddleware, createFastifyContextHook, createLevelControlHandler, createLogger, createMetricsPlugin, createTraceMiddleware, createTypedLogger, decycleValue, defineLogSchema, deregisterFromShutdown, disableOtelBridge, extractTraceId, flushOnExit, generateRequestId, generateTraceId, getActiveOtelContext, getCurrentTraceId, getEventFields, getOtelMetaFields, getTraceContextKey, globalPluginRegistry, initOtelBridge, isError, isLogixiaException, logger, normalizeError, redactObject, registerForShutdown, registerLevelSignal, resetShutdownHandlers, retrocycle, runWithTraceId, safeStringify, sanitizeIncomingId, serializeError, setEventField, setTraceId, stringifyForLog, toOtelSeverity, traceStorage, usePlugin, wideEventMiddleware, withWideEvent };
|
|
1351
1019
|
//# sourceMappingURL=index.mjs.map
|