@lark-apaas/nestjs-logger 1.0.12 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +20 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +21 -20
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -9497,16 +9497,6 @@ var import_config2 = require("@nestjs/config");
|
|
|
9497
9497
|
var import_operators = __toESM(require_operators(), 1);
|
|
9498
9498
|
var import_util = require("util");
|
|
9499
9499
|
var import_nestjs_common2 = require("@lark-apaas/nestjs-common");
|
|
9500
|
-
|
|
9501
|
-
// src/utils/formatDuration.ts
|
|
9502
|
-
var formatDuration = /* @__PURE__ */ __name((ms) => {
|
|
9503
|
-
if (ms < 0.01) {
|
|
9504
|
-
return Number(ms.toPrecision(1));
|
|
9505
|
-
}
|
|
9506
|
-
return Number(ms.toFixed(2));
|
|
9507
|
-
}, "formatDuration");
|
|
9508
|
-
|
|
9509
|
-
// src/interceptor/logging.interceptor.ts
|
|
9510
9500
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
9511
9501
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
9512
9502
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -9556,9 +9546,11 @@ var LoggingInterceptor = class {
|
|
|
9556
9546
|
method,
|
|
9557
9547
|
path
|
|
9558
9548
|
});
|
|
9559
|
-
const
|
|
9560
|
-
const
|
|
9561
|
-
const pageRoute =
|
|
9549
|
+
const elapsed = (0, import_nestjs_common2.createTimer)();
|
|
9550
|
+
const contextState = this.requestContext.getContext();
|
|
9551
|
+
const pageRoute = contextState?.pageRoute ?? null;
|
|
9552
|
+
const refererPath = contextState?.refererPath ?? null;
|
|
9553
|
+
const api = contextState?.observabilityApi ?? null;
|
|
9562
9554
|
const baseMeta = {
|
|
9563
9555
|
method,
|
|
9564
9556
|
path,
|
|
@@ -9568,6 +9560,8 @@ var LoggingInterceptor = class {
|
|
|
9568
9560
|
app_id: req.userContext?.appId ?? null,
|
|
9569
9561
|
ip: req.ip ?? null,
|
|
9570
9562
|
page_route: pageRoute,
|
|
9563
|
+
referer_path: refererPath,
|
|
9564
|
+
api,
|
|
9571
9565
|
pid: process.pid
|
|
9572
9566
|
};
|
|
9573
9567
|
const originalJson = res.json.bind(res);
|
|
@@ -9600,12 +9594,12 @@ url=${req.url}`, "HTTPTraceInterceptor");
|
|
|
9600
9594
|
return;
|
|
9601
9595
|
}
|
|
9602
9596
|
logged = true;
|
|
9603
|
-
const durationMs =
|
|
9597
|
+
const durationMs = elapsed();
|
|
9604
9598
|
const statusCode = res.statusCode;
|
|
9605
9599
|
const responseMeta = {
|
|
9606
9600
|
...baseMeta,
|
|
9607
9601
|
status_code: statusCode,
|
|
9608
|
-
duration_ms:
|
|
9602
|
+
duration_ms: durationMs
|
|
9609
9603
|
};
|
|
9610
9604
|
const finalResponseBody = res.__finalResponseBody;
|
|
9611
9605
|
const contentType = res.getHeader("content-type");
|
|
@@ -9649,13 +9643,13 @@ duration_ms=${durationMs}`, "HTTPTraceInterceptor");
|
|
|
9649
9643
|
return next.handle().pipe((0, import_operators.tap)({
|
|
9650
9644
|
next: /* @__PURE__ */ __name((data) => {
|
|
9651
9645
|
const statusCode = res.statusCode;
|
|
9652
|
-
const durationMs =
|
|
9646
|
+
const durationMs = elapsed();
|
|
9653
9647
|
const isError = statusCode > 400;
|
|
9654
9648
|
const responseData = {
|
|
9655
9649
|
method,
|
|
9656
9650
|
path,
|
|
9657
9651
|
url: fullUrl,
|
|
9658
|
-
duration_ms:
|
|
9652
|
+
duration_ms: durationMs,
|
|
9659
9653
|
error_message: isError ? data?.message ?? "" : ""
|
|
9660
9654
|
};
|
|
9661
9655
|
if (req.body) responseData.request_body = req.body;
|
|
@@ -9664,14 +9658,21 @@ duration_ms=${durationMs}`, "HTTPTraceInterceptor");
|
|
|
9664
9658
|
if (!isDev) {
|
|
9665
9659
|
this.appLogger.log(reportData, {
|
|
9666
9660
|
paas_attributes_module: "app_server",
|
|
9667
|
-
source_type: "platform"
|
|
9661
|
+
source_type: "platform",
|
|
9662
|
+
referer_path: refererPath ?? "",
|
|
9663
|
+
api,
|
|
9664
|
+
duration_ms: durationMs
|
|
9668
9665
|
}, "HTTPTraceInterceptor");
|
|
9669
9666
|
}
|
|
9670
9667
|
}, "next")
|
|
9671
9668
|
}), (0, import_operators.catchError)((error) => {
|
|
9669
|
+
const durationMs = elapsed();
|
|
9672
9670
|
this.appLogger.error((0, import_util.format)("HTTP request exception\nmethod=%s url=%s\nerror=%o", req.method, req.url, error), {
|
|
9673
9671
|
paas_attributes_module: "app_server",
|
|
9674
|
-
source_type: "platform"
|
|
9672
|
+
source_type: "platform",
|
|
9673
|
+
referer_path: refererPath ?? "",
|
|
9674
|
+
api,
|
|
9675
|
+
duration_ms: durationMs
|
|
9675
9676
|
}, "HTTPTraceInterceptor");
|
|
9676
9677
|
throw error;
|
|
9677
9678
|
}));
|