@cryptexlabs/codex-nodejs-common 0.12.12 → 0.14.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/lib/package.json +1 -1
- package/lib/src/context/context.d.ts +2 -1
- package/lib/src/filter/app-http-exception-filter.js +1 -0
- package/lib/src/filter/app-http-exception-filter.js.map +1 -1
- package/lib/src/filter/index.d.ts +1 -0
- package/lib/src/filter/index.js +1 -0
- package/lib/src/filter/index.js.map +1 -1
- package/lib/src/filter/log-watching.interceptor.d.ts +6 -0
- package/lib/src/filter/log-watching.interceptor.js +25 -0
- package/lib/src/filter/log-watching.interceptor.js.map +1 -0
- package/lib/src/logger/context.logger.d.ts +7 -2
- package/lib/src/logger/context.logger.js +106 -2
- package/lib/src/logger/context.logger.js.map +1 -1
- package/lib/src/logger/index.d.ts +1 -0
- package/lib/src/logger/index.js +1 -0
- package/lib/src/logger/index.js.map +1 -1
- package/lib/src/logger/log-watcher.interface.d.ts +6 -0
- package/lib/src/logger/log-watcher.interface.js +3 -0
- package/lib/src/logger/log-watcher.interface.js.map +1 -0
- package/lib/src/service/healthz/healthz.service.js +4 -2
- package/lib/src/service/healthz/healthz.service.js.map +1 -1
- package/package.json +1 -1
- package/src/context/context.ts +1 -1
- package/src/filter/app-http-exception-filter.ts +2 -1
- package/src/filter/index.ts +1 -0
- package/src/filter/log-watching.interceptor.ts +26 -0
- package/src/logger/context.logger.ts +112 -4
- package/src/logger/index.ts +1 -0
- package/src/logger/log-watcher.interface.ts +7 -0
- package/src/service/healthz/healthz.service.spec.ts +2 -2
- package/src/service/healthz/healthz.service.ts +5 -4
package/lib/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ClientInterface, LocaleI18nInterface, MessageContextInterface, MessageMetaInterface } from "@cryptexlabs/codex-data-model";
|
|
2
2
|
import { LoggerService } from "@nestjs/common";
|
|
3
3
|
import { DefaultConfig } from "../config";
|
|
4
|
+
import { ContextLogger } from "../logger";
|
|
4
5
|
import { I18n } from "i18n";
|
|
5
6
|
export declare class Context {
|
|
6
7
|
correlationId: string;
|
|
@@ -10,7 +11,7 @@ export declare class Context {
|
|
|
10
11
|
readonly messageContext: MessageContextInterface;
|
|
11
12
|
readonly i18n?: I18n;
|
|
12
13
|
readonly path?: string;
|
|
13
|
-
readonly logger:
|
|
14
|
+
readonly logger: ContextLogger;
|
|
14
15
|
started: Date;
|
|
15
16
|
private _now;
|
|
16
17
|
constructor(correlationId: string, logger: LoggerService, config: DefaultConfig, client: ClientInterface, locale: LocaleI18nInterface, messageContext: MessageContextInterface, started?: Date, i18n?: I18n, path?: string);
|
|
@@ -146,6 +146,7 @@ let AppHttpExceptionFilter = class AppHttpExceptionFilter extends core_1.BaseExc
|
|
|
146
146
|
errorHttpResponse.meta.context.category = request.headers["x-context-category"];
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
+
logger_1.ContextLogger.deregisterWatchers(correlationId);
|
|
149
150
|
response.status(status).json(errorHttpResponse);
|
|
150
151
|
}
|
|
151
152
|
getDeveloperText(exception, locale) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-http-exception-filter.js","sourceRoot":"","sources":["../../../src/filter/app-http-exception-filter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CASwB;AACxB,uCAAmD;AAEnD,0CAA8D;AAC9D,4CAAqD;AACrD,oEAAuD;AACvD,gDAA8C;AAC9C,0CAA8C;AAC9C,sCAA0C;AAC1C,4CAAuD;AACvD,sCAA0C;AAC1C,kCAAqC;AAI9B,IAAM,sBAAsB,GAA5B,MAAM,sBAAuB,SAAQ,0BAAmB;IAC7D,YACmB,cAAsB,EACJ,cAA6B,EAC/C,MAAqB,EACtC,cAA2B;QAE3B,KAAK,CAAC,cAAc,CAAC,CAAC;QALL,mBAAc,GAAd,cAAc,CAAQ;QACJ,mBAAc,GAAd,cAAc,CAAe;QAC/C,WAAM,GAAN,MAAM,CAAe;IAIxC,CAAC;IAEO,YAAY;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAC/B,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,OAAO,CAC3C,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,SAAc,EAAE,IAAmB;QACvC,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAChC,MAAM,OAAO,GAAG,GAAG,CAAC,UAAU,EAAW,CAAC;QAC1C,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QAEnC,IAAI,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;QACzC,IAAI,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;QAEzC,IAAI,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC;YACvC,IAAI,CAAC;gBACH,cAAc,GAAG,iBAAU,CAAC,iCAAiC,CAC3D,IAAI,EACJ,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAuB,CACzD,CAAC;YACJ,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,IAAI,CAAC,cAAc,CAAC,KAAK,CACvB,8CAA8C,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC,GAAG,CACpF,CAAC;YACJ,CAAC;QACH,CAAC;QAED,IAAI,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAC,EAAE,CAAC;YACxC,cAAc,GAAG,IAAI,sBAAa,CAChC,OAAO,CAAC,OAAO,CAAC,kBAAkB,
|
|
1
|
+
{"version":3,"file":"app-http-exception-filter.js","sourceRoot":"","sources":["../../../src/filter/app-http-exception-filter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CASwB;AACxB,uCAAmD;AAEnD,0CAA8D;AAC9D,4CAAqD;AACrD,oEAAuD;AACvD,gDAA8C;AAC9C,0CAA8C;AAC9C,sCAA0C;AAC1C,4CAAuD;AACvD,sCAA0C;AAC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CAAC,KAAK,CAAC,CAAC;oBACzD,CAAC;yBAAM,CAAC;wBACN,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC;oBAC7C,CAAC;gBACH,CAAC;qBAAM,IAAI,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;oBACrC,aAAa,GAAG,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC;gBAC5C,CAAC;qBAAM,IAAI,SAAS,CAAC,WAAW,EAAE,CAAC;oBACjC,aAAa,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;gBAC1C,CAAC;qBAAM,CAAC;oBACN,aAAa,GAAG,SAAS,CAAC,OAAO,CAAC;gBACpC,CAAC;YACH,CAAC;iBAAM,IAAI,SAAS,CAAC,OAAO,EAAE,CAAC;gBAC7B,aAAa,GAAG,SAAS,CAAC,OAAO,CAAC;YACpC,CAAC;QACH,CAAC;QACD,OAAO,aAAa,CAAC;IACvB,CAAC;CACF,CAAA;AAxNY,wDAAsB;iCAAtB,sBAAsB;IAFlC,IAAA,cAAK,GAAE;IACP,IAAA,mBAAU,GAAE;IAIR,WAAA,IAAA,eAAM,EAAC,QAAQ,CAAC,CAAA;qCADgB,yBAAM,UAEd,sBAAa;GAJ7B,sBAAsB,CAwNlC"}
|
package/lib/src/filter/index.js
CHANGED
|
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./app-http-exception-filter"), exports);
|
|
18
18
|
__exportStar(require("./http-status.interceptor"), exports);
|
|
19
|
+
__exportStar(require("./log-watching.interceptor"), exports);
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/filter/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA4C;AAC5C,4DAA0C"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/filter/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA4C;AAC5C,4DAA0C;AAC1C,6DAA2C"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CallHandler, ExecutionContext, NestInterceptor } from "@nestjs/common";
|
|
2
|
+
import { Observable } from "rxjs";
|
|
3
|
+
import { HttpResponse } from "../response";
|
|
4
|
+
export declare class LogWatchingInterceptor implements NestInterceptor {
|
|
5
|
+
intercept(context: ExecutionContext, next: CallHandler<any>): Observable<HttpResponse<any>>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.LogWatchingInterceptor = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const logger_1 = require("../logger");
|
|
12
|
+
let LogWatchingInterceptor = class LogWatchingInterceptor {
|
|
13
|
+
intercept(context, next) {
|
|
14
|
+
const request = context.switchToHttp().getRequest();
|
|
15
|
+
if (request.headers["x-correlation-id"]) {
|
|
16
|
+
logger_1.ContextLogger.deregisterWatchers(request.headers["x-correlation-id"]);
|
|
17
|
+
}
|
|
18
|
+
return next.handle();
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.LogWatchingInterceptor = LogWatchingInterceptor;
|
|
22
|
+
exports.LogWatchingInterceptor = LogWatchingInterceptor = __decorate([
|
|
23
|
+
(0, common_1.Injectable)()
|
|
24
|
+
], LogWatchingInterceptor);
|
|
25
|
+
//# sourceMappingURL=log-watching.interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-watching.interceptor.js","sourceRoot":"","sources":["../../../src/filter/log-watching.interceptor.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAKwB;AAIxB,sCAA0C;AAGnC,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IACjC,SAAS,CACP,OAAyB,EACzB,IAAsB;QAEtB,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QAEpD,IAAI,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAC,EAAE,CAAC;YACxC,sBAAa,CAAC,kBAAkB,CAAC,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC;QACxE,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;CACF,CAAA;AAbY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,mBAAU,GAAE;GACA,sBAAsB,CAalC"}
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import { LoggerService } from "@nestjs/common";
|
|
2
2
|
import { DefaultConfig } from "../config";
|
|
3
3
|
import { ClientInterface } from "@cryptexlabs/codex-data-model";
|
|
4
|
+
import { LogWatcherInterface } from "./log-watcher.interface";
|
|
4
5
|
export declare class ContextLogger implements LoggerService {
|
|
5
6
|
private readonly correlationId;
|
|
6
7
|
private readonly config;
|
|
7
8
|
private readonly client;
|
|
8
9
|
private readonly logger;
|
|
9
|
-
private readonly
|
|
10
|
-
|
|
10
|
+
private readonly _stackTraceId;
|
|
11
|
+
private static _contextWatchers;
|
|
12
|
+
private _watchers;
|
|
13
|
+
constructor(correlationId: string, config: DefaultConfig, client: ClientInterface, logger: LoggerService);
|
|
11
14
|
debug(message: any, data?: any): any;
|
|
12
15
|
error(message: any, data?: any): any;
|
|
13
16
|
log(message: any, data?: any): any;
|
|
14
17
|
verbose(message: any, data?: any): any;
|
|
15
18
|
warn(message: any, data?: any): any;
|
|
19
|
+
static deregisterWatchers(correlationId: string): void;
|
|
20
|
+
registerWatcher(watcher: LogWatcherInterface): void;
|
|
16
21
|
private _getData;
|
|
17
22
|
}
|
|
@@ -8,26 +8,129 @@ class ContextLogger {
|
|
|
8
8
|
this.config = config;
|
|
9
9
|
this.client = client;
|
|
10
10
|
this.logger = logger;
|
|
11
|
-
this.
|
|
11
|
+
this._watchers = new Map();
|
|
12
|
+
this._stackTraceId = (0, uuid_1.v4)();
|
|
12
13
|
}
|
|
13
14
|
debug(message, data) {
|
|
14
15
|
this.logger.debug(message, this._getData(data));
|
|
16
|
+
if (ContextLogger._contextWatchers.has(this.correlationId)) {
|
|
17
|
+
ContextLogger._contextWatchers
|
|
18
|
+
.get(this.correlationId)
|
|
19
|
+
.debug(message, this._getData(data));
|
|
20
|
+
for (const watcher of this._watchers.values()) {
|
|
21
|
+
if (watcher.correlationId !== this.correlationId) {
|
|
22
|
+
watcher.debug(message, this._getData(data));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
for (const watcher of this._watchers.values()) {
|
|
28
|
+
watcher.debug(message, this._getData(data));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
15
31
|
}
|
|
16
32
|
error(message, data) {
|
|
17
33
|
this.logger.error(message, this._getData(data));
|
|
34
|
+
if (ContextLogger._contextWatchers.has(this.correlationId)) {
|
|
35
|
+
ContextLogger._contextWatchers
|
|
36
|
+
.get(this.correlationId)
|
|
37
|
+
.error(message, this._getData(data));
|
|
38
|
+
for (const watcher of this._watchers.values()) {
|
|
39
|
+
if (watcher.correlationId !== this.correlationId) {
|
|
40
|
+
watcher.error(message, this._getData(data));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
for (const watcher of this._watchers.values()) {
|
|
46
|
+
watcher.error(message, this._getData(data));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
18
49
|
}
|
|
19
50
|
log(message, data) {
|
|
20
51
|
this.logger.log(message, this._getData(data));
|
|
52
|
+
if (ContextLogger._contextWatchers.has(this.correlationId)) {
|
|
53
|
+
ContextLogger._contextWatchers
|
|
54
|
+
.get(this.correlationId)
|
|
55
|
+
.log(message, this._getData(data));
|
|
56
|
+
for (const watcher of this._watchers.values()) {
|
|
57
|
+
if (watcher.correlationId !== this.correlationId) {
|
|
58
|
+
watcher.log(message, this._getData(data));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
for (const watcher of this._watchers.values()) {
|
|
64
|
+
watcher.log(message, this._getData(data));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
21
67
|
}
|
|
22
68
|
verbose(message, data) {
|
|
23
69
|
this.logger.verbose(message, this._getData(data));
|
|
70
|
+
if (ContextLogger._contextWatchers.has(this.correlationId)) {
|
|
71
|
+
ContextLogger._contextWatchers
|
|
72
|
+
.get(this.correlationId)
|
|
73
|
+
.verbose(message, this._getData(data));
|
|
74
|
+
for (const watcher of this._watchers.values()) {
|
|
75
|
+
if (watcher.correlationId !== this.correlationId) {
|
|
76
|
+
watcher.verbose(message, this._getData(data));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
for (const watcher of this._watchers.values()) {
|
|
82
|
+
watcher.verbose(message, this._getData(data));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
24
85
|
}
|
|
25
86
|
warn(message, data) {
|
|
26
87
|
this.logger.warn(message, this._getData(data));
|
|
88
|
+
if (ContextLogger._contextWatchers.has(this.correlationId)) {
|
|
89
|
+
ContextLogger._contextWatchers
|
|
90
|
+
.get(this.correlationId)
|
|
91
|
+
.warn(message, this._getData(data));
|
|
92
|
+
for (const watcher of this._watchers.values()) {
|
|
93
|
+
if (watcher.correlationId !== this.correlationId) {
|
|
94
|
+
watcher.warn(message, this._getData(data));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
for (const watcher of this._watchers.values()) {
|
|
100
|
+
watcher.warn(message, this._getData(data));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
static deregisterWatchers(correlationId) {
|
|
105
|
+
if (ContextLogger._contextWatchers.has(correlationId)) {
|
|
106
|
+
ContextLogger._contextWatchers.delete(correlationId);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
registerWatcher(watcher) {
|
|
110
|
+
if (!watcher)
|
|
111
|
+
throw new Error("Cannot register a watcher with a null or undefined value");
|
|
112
|
+
if (!watcher.name) {
|
|
113
|
+
this.logger.warn("Watcher has no name. Skipping registration.", {
|
|
114
|
+
id: watcher.id,
|
|
115
|
+
name: watcher.name,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
if (!watcher.id) {
|
|
119
|
+
this.logger.warn("Watcher has no id. Skipping registration.", {
|
|
120
|
+
id: watcher.id,
|
|
121
|
+
name: watcher.name,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
if (!this._watchers.has(`${watcher.name}:${watcher.id}`)) {
|
|
125
|
+
this._watchers.set(`${watcher.name}:${watcher.id}`, watcher);
|
|
126
|
+
}
|
|
127
|
+
if (!ContextLogger._contextWatchers.has(this.correlationId)) {
|
|
128
|
+
ContextLogger._contextWatchers.set(this.correlationId, watcher);
|
|
129
|
+
}
|
|
27
130
|
}
|
|
28
131
|
_getData(data) {
|
|
29
132
|
let logData = {
|
|
30
|
-
stackTraceId: this.
|
|
133
|
+
stackTraceId: this._stackTraceId,
|
|
31
134
|
correlationId: this.correlationId,
|
|
32
135
|
appVersion: this.config.appVersion,
|
|
33
136
|
appName: this.config.appName,
|
|
@@ -42,4 +145,5 @@ class ContextLogger {
|
|
|
42
145
|
}
|
|
43
146
|
}
|
|
44
147
|
exports.ContextLogger = ContextLogger;
|
|
148
|
+
ContextLogger._contextWatchers = new Map();
|
|
45
149
|
//# sourceMappingURL=context.logger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.logger.js","sourceRoot":"","sources":["../../../src/logger/context.logger.ts"],"names":[],"mappings":";;;AACA,+BAAoC;
|
|
1
|
+
{"version":3,"file":"context.logger.js","sourceRoot":"","sources":["../../../src/logger/context.logger.ts"],"names":[],"mappings":";;;AACA,+BAAoC;AAMpC,MAAa,aAAa;IAMxB,YACmB,aAAqB,EACrB,MAAqB,EACrB,MAAuB,EACvB,MAAqB;QAHrB,kBAAa,GAAb,aAAa,CAAQ;QACrB,WAAM,GAAN,MAAM,CAAe;QACrB,WAAM,GAAN,MAAM,CAAiB;QACvB,WAAM,GAAN,MAAM,CAAe;QANhC,cAAS,GAAqC,IAAI,GAAG,EAAE,CAAC;QAQ9D,IAAI,CAAC,aAAa,GAAG,IAAA,SAAM,GAAE,CAAC;IAChC,CAAC;IAEM,KAAK,CAAC,OAAY,EAAE,IAAU;QACnC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;QAEhD,IAAI,aAAa,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;YAC3D,aAAa,CAAC,gBAAgB;iBAC3B,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC;iBACvB,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;YACvC,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC;gBAC9C,IAAI,OAAO,CAAC,aAAa,KAAK,IAAI,CAAC,aAAa,EAAE,CAAC;oBACjD,OAAO,CAAC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AAI,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;IAEO,QAAQ,CAAC,IAAU;QACzB,IAAI,OAAO,GAAQ;YACjB,YAAY,EAAE,IAAI,CAAC,aAAa;YAChC,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU;YAClC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;YAC5B,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;YAC5B,aAAa,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;YAClC,aAAa,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;SACnC,CAAC;QAEF,IAAI,IAAI,EAAE,CAAC;YACT,OAAO,mCACF,OAAO,KACV,IAAI,GACL,CAAC;QACJ,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;;AA7JH,sCA8JC;AA3JgB,8BAAgB,GAAqC,IAAI,GAAG,EAAE,AAA9C,CAA+C"}
|
package/lib/src/logger/index.js
CHANGED
|
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./custom.logger"), exports);
|
|
18
18
|
__exportStar(require("./context.logger"), exports);
|
|
19
19
|
__exportStar(require("./custom-console.logger"), exports);
|
|
20
|
+
__exportStar(require("./log-watcher.interface"), exports);
|
|
20
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/logger/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,mDAAiC;AACjC,0DAAwC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/logger/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,mDAAiC;AACjC,0DAAwC;AACxC,0DAAwC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-watcher.interface.js","sourceRoot":"","sources":["../../../src/logger/log-watcher.interface.ts"],"names":[],"mappings":""}
|
|
@@ -24,8 +24,10 @@ let HealthzService = class HealthzService {
|
|
|
24
24
|
this._isHealthy = false;
|
|
25
25
|
}
|
|
26
26
|
async isHealthy() {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
if (Object.keys(this.componentHealth).length === 0) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return this._allComponentsAreHealthy();
|
|
29
31
|
}
|
|
30
32
|
async makeHealthy(component) {
|
|
31
33
|
this.componentHealth[component] = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"healthz.service.js","sourceRoot":"","sources":["../../../../src/service/healthz/healthz.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAmE;AACnE,yBAAyB;AACzB,yCAA6C;AAItC,IAAM,cAAc,GAApB,MAAM,cAAc;IAQzB,YACqC,MAAqB,EACrB,MAAqB;QADrB,WAAM,GAAN,MAAM,CAAe;QACrB,WAAM,GAAN,MAAM,CAAe;QAExD,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;QAC1B,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,SAAS;QACb,
|
|
1
|
+
{"version":3,"file":"healthz.service.js","sourceRoot":"","sources":["../../../../src/service/healthz/healthz.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAmE;AACnE,yBAAyB;AACzB,yCAA6C;AAItC,IAAM,cAAc,GAApB,MAAM,cAAc;IAQzB,YACqC,MAAqB,EACrB,MAAqB;QADrB,WAAM,GAAN,MAAM,CAAe;QACrB,WAAM,GAAN,MAAM,CAAe;QAExD,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;QAC1B,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,SAAS;Q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AC;oBACpB,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;oBACxB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;gBAChD,CAAC;gBACD,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,GAAG,EAAE;oBAC1C,OAAO,EAAE,CAAC;gBACZ,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAEO,wBAAwB;QAC9B,KAAK,MAAM,aAAa,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACjD,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;YACpD,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,aAAa,qBAAqB,CAAC,CAAC;gBACzD,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAxEY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;IAUR,WAAA,IAAA,eAAM,EAAC,QAAQ,CAAC,CAAA;IAChB,WAAA,IAAA,eAAM,EAAC,QAAQ,CAAC,CAAA;qCAD0B,sBAAa;GAT/C,cAAc,CAwE1B"}
|
package/package.json
CHANGED
package/src/context/context.ts
CHANGED
|
@@ -61,7 +61,7 @@ export class AppHttpExceptionFilter extends BaseExceptionFilter {
|
|
|
61
61
|
|
|
62
62
|
if (request.headers["x-correlation-id"]) {
|
|
63
63
|
fallbackLogger = new ContextLogger(
|
|
64
|
-
request.headers["x-correlation-id"],
|
|
64
|
+
request.headers["x-correlation-id"] as string,
|
|
65
65
|
this.config,
|
|
66
66
|
{
|
|
67
67
|
id: request.headers["x-client-id"] as string | undefined,
|
|
@@ -207,6 +207,7 @@ export class AppHttpExceptionFilter extends BaseExceptionFilter {
|
|
|
207
207
|
] as string;
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
|
+
ContextLogger.deregisterWatchers(correlationId);
|
|
210
211
|
|
|
211
212
|
response.status(status).json(errorHttpResponse);
|
|
212
213
|
}
|
package/src/filter/index.ts
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CallHandler,
|
|
3
|
+
ExecutionContext,
|
|
4
|
+
Injectable,
|
|
5
|
+
NestInterceptor,
|
|
6
|
+
} from "@nestjs/common";
|
|
7
|
+
import { Observable } from "rxjs";
|
|
8
|
+
import { HttpResponse } from "../response";
|
|
9
|
+
import { tap } from "rxjs/operators";
|
|
10
|
+
import { ContextLogger } from "../logger";
|
|
11
|
+
|
|
12
|
+
@Injectable()
|
|
13
|
+
export class LogWatchingInterceptor implements NestInterceptor {
|
|
14
|
+
intercept(
|
|
15
|
+
context: ExecutionContext,
|
|
16
|
+
next: CallHandler<any>
|
|
17
|
+
): Observable<HttpResponse<any>> {
|
|
18
|
+
const request = context.switchToHttp().getRequest();
|
|
19
|
+
|
|
20
|
+
if (request.headers["x-correlation-id"]) {
|
|
21
|
+
ContextLogger.deregisterWatchers(request.headers["x-correlation-id"]);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return next.handle();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -3,42 +3,150 @@ import { v4 as uuidV4 } from "uuid";
|
|
|
3
3
|
import { DefaultConfig } from "../config";
|
|
4
4
|
import { ClientInterface } from "@cryptexlabs/codex-data-model";
|
|
5
5
|
import { CustomLogger } from "./custom.logger";
|
|
6
|
+
import { LogWatcherInterface } from "./log-watcher.interface";
|
|
6
7
|
|
|
7
8
|
export class ContextLogger implements LoggerService {
|
|
8
|
-
private readonly
|
|
9
|
+
private readonly _stackTraceId: string;
|
|
10
|
+
|
|
11
|
+
private static _contextWatchers: Map<string, LogWatcherInterface> = new Map();
|
|
12
|
+
private _watchers: Map<string, LogWatcherInterface> = new Map();
|
|
9
13
|
|
|
10
14
|
constructor(
|
|
11
|
-
private readonly correlationId,
|
|
15
|
+
private readonly correlationId: string,
|
|
12
16
|
private readonly config: DefaultConfig,
|
|
13
17
|
private readonly client: ClientInterface,
|
|
14
18
|
private readonly logger: LoggerService
|
|
15
19
|
) {
|
|
16
|
-
this.
|
|
20
|
+
this._stackTraceId = uuidV4();
|
|
17
21
|
}
|
|
18
22
|
|
|
19
23
|
public debug(message: any, data?: any): any {
|
|
20
24
|
this.logger.debug(message, this._getData(data));
|
|
25
|
+
|
|
26
|
+
if (ContextLogger._contextWatchers.has(this.correlationId)) {
|
|
27
|
+
ContextLogger._contextWatchers
|
|
28
|
+
.get(this.correlationId)
|
|
29
|
+
.debug(message, this._getData(data));
|
|
30
|
+
for (const watcher of this._watchers.values()) {
|
|
31
|
+
if (watcher.correlationId !== this.correlationId) {
|
|
32
|
+
watcher.debug(message, this._getData(data));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
for (const watcher of this._watchers.values()) {
|
|
37
|
+
watcher.debug(message, this._getData(data));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
21
40
|
}
|
|
22
41
|
|
|
23
42
|
public error(message: any, data?: any): any {
|
|
24
43
|
this.logger.error(message, this._getData(data));
|
|
44
|
+
if (ContextLogger._contextWatchers.has(this.correlationId)) {
|
|
45
|
+
ContextLogger._contextWatchers
|
|
46
|
+
.get(this.correlationId)
|
|
47
|
+
.error(message, this._getData(data));
|
|
48
|
+
for (const watcher of this._watchers.values()) {
|
|
49
|
+
if (watcher.correlationId !== this.correlationId) {
|
|
50
|
+
watcher.error(message, this._getData(data));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
for (const watcher of this._watchers.values()) {
|
|
55
|
+
watcher.error(message, this._getData(data));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
25
58
|
}
|
|
26
59
|
|
|
27
60
|
public log(message: any, data?: any): any {
|
|
28
61
|
this.logger.log(message, this._getData(data));
|
|
62
|
+
if (ContextLogger._contextWatchers.has(this.correlationId)) {
|
|
63
|
+
ContextLogger._contextWatchers
|
|
64
|
+
.get(this.correlationId)
|
|
65
|
+
.log(message, this._getData(data));
|
|
66
|
+
for (const watcher of this._watchers.values()) {
|
|
67
|
+
if (watcher.correlationId !== this.correlationId) {
|
|
68
|
+
watcher.log(message, this._getData(data));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
for (const watcher of this._watchers.values()) {
|
|
73
|
+
watcher.log(message, this._getData(data));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
29
76
|
}
|
|
30
77
|
|
|
31
78
|
public verbose(message: any, data?: any): any {
|
|
32
79
|
this.logger.verbose(message, this._getData(data));
|
|
80
|
+
if (ContextLogger._contextWatchers.has(this.correlationId)) {
|
|
81
|
+
ContextLogger._contextWatchers
|
|
82
|
+
.get(this.correlationId)
|
|
83
|
+
.verbose(message, this._getData(data));
|
|
84
|
+
for (const watcher of this._watchers.values()) {
|
|
85
|
+
if (watcher.correlationId !== this.correlationId) {
|
|
86
|
+
watcher.verbose(message, this._getData(data));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
for (const watcher of this._watchers.values()) {
|
|
91
|
+
watcher.verbose(message, this._getData(data));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
33
94
|
}
|
|
34
95
|
|
|
35
96
|
public warn(message: any, data?: any): any {
|
|
36
97
|
this.logger.warn(message, this._getData(data));
|
|
98
|
+
if (ContextLogger._contextWatchers.has(this.correlationId)) {
|
|
99
|
+
ContextLogger._contextWatchers
|
|
100
|
+
.get(this.correlationId)
|
|
101
|
+
.warn(message, this._getData(data));
|
|
102
|
+
for (const watcher of this._watchers.values()) {
|
|
103
|
+
if (watcher.correlationId !== this.correlationId) {
|
|
104
|
+
watcher.warn(message, this._getData(data));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
for (const watcher of this._watchers.values()) {
|
|
109
|
+
watcher.warn(message, this._getData(data));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
static deregisterWatchers(correlationId: string): void {
|
|
115
|
+
if (ContextLogger._contextWatchers.has(correlationId)) {
|
|
116
|
+
ContextLogger._contextWatchers.delete(correlationId);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public registerWatcher(watcher: LogWatcherInterface): void {
|
|
121
|
+
if (!watcher)
|
|
122
|
+
throw new Error(
|
|
123
|
+
"Cannot register a watcher with a null or undefined value"
|
|
124
|
+
);
|
|
125
|
+
if (!watcher.name) {
|
|
126
|
+
this.logger.warn("Watcher has no name. Skipping registration.", {
|
|
127
|
+
id: watcher.id,
|
|
128
|
+
name: watcher.name,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
if (!watcher.id) {
|
|
132
|
+
this.logger.warn("Watcher has no id. Skipping registration.", {
|
|
133
|
+
id: watcher.id,
|
|
134
|
+
name: watcher.name,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (!this._watchers.has(`${watcher.name}:${watcher.id}`)) {
|
|
139
|
+
this._watchers.set(`${watcher.name}:${watcher.id}`, watcher);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (!ContextLogger._contextWatchers.has(this.correlationId)) {
|
|
143
|
+
ContextLogger._contextWatchers.set(this.correlationId, watcher);
|
|
144
|
+
}
|
|
37
145
|
}
|
|
38
146
|
|
|
39
147
|
private _getData(data?: any) {
|
|
40
148
|
let logData: any = {
|
|
41
|
-
stackTraceId: this.
|
|
149
|
+
stackTraceId: this._stackTraceId,
|
|
42
150
|
correlationId: this.correlationId,
|
|
43
151
|
appVersion: this.config.appVersion,
|
|
44
152
|
appName: this.config.appName,
|
package/src/logger/index.ts
CHANGED
|
@@ -45,8 +45,8 @@ describe("HealthzService", () => {
|
|
|
45
45
|
jest.resetModules();
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
it("Should be
|
|
49
|
-
expect(await service.isHealthy()).toBe(
|
|
48
|
+
it("Should be healthy when no components were made healthy or unhealthy", async () => {
|
|
49
|
+
expect(await service.isHealthy()).toBe(true);
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
it("Should be healthy when all components are healthy", async () => {
|
|
@@ -21,10 +21,11 @@ export class HealthzService {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
async isHealthy(): Promise<boolean> {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
if (Object.keys(this.componentHealth).length === 0) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return this._allComponentsAreHealthy();
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
async makeHealthy(component: HealthzComponentEnum | string): Promise<void> {
|