@dex-monit/observability-sdk-node 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.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/lib/console-capture.d.ts +7 -2
- package/dist/lib/console-capture.d.ts.map +1 -1
- package/dist/lib/console-capture.js +49 -4
- package/dist/lib/dex-logger.service.d.ts +1 -1
- package/dist/lib/dex-logger.service.d.ts.map +1 -1
- package/dist/lib/dex-logger.service.js +12 -9
- package/dist/lib/error-capture.interceptor.d.ts +1 -1
- package/dist/lib/error-capture.interceptor.d.ts.map +1 -1
- package/dist/lib/error-capture.interceptor.js +14 -11
- package/dist/lib/global-exception.filter.d.ts +1 -1
- package/dist/lib/global-exception.filter.d.ts.map +1 -1
- package/dist/lib/global-exception.filter.js +13 -10
- package/dist/lib/http-interceptor.d.ts +1 -1
- package/dist/lib/http-interceptor.d.ts.map +1 -1
- package/dist/lib/http-interceptor.js +29 -21
- package/dist/lib/monitoring-client.js +34 -23
- package/dist/lib/nest-logger-capture.d.ts +1 -1
- package/dist/lib/nest-logger-capture.d.ts.map +1 -1
- package/dist/lib/nest-logger-capture.js +23 -18
- package/dist/lib/remote-logger.d.ts +1 -1
- package/dist/lib/remote-logger.d.ts.map +1 -1
- package/dist/lib/remote-logger.js +8 -3
- package/dist/lib/request-id.middleware.js +18 -15
- package/dist/lib/sdk-node.d.ts +10 -10
- package/dist/lib/sdk-node.d.ts.map +1 -1
- package/dist/lib/sdk-node.js +13 -10
- package/dist/lib/sdk-node.module.d.ts +1 -1
- package/dist/lib/sdk-node.module.d.ts.map +1 -1
- package/dist/lib/sdk-node.module.js +63 -56
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +2 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './lib/sdk-node
|
|
1
|
+
export * from './lib/sdk-node';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import { MonitoringClient } from './monitoring-client
|
|
1
|
+
import { MonitoringClient } from './monitoring-client';
|
|
2
2
|
/**
|
|
3
3
|
* Start capturing console output and sending to monitoring
|
|
4
|
+
* @param monitoringClient - The monitoring client to send logs to
|
|
5
|
+
* @param options - Options for console capture
|
|
6
|
+
* @param options.skipNestJsLogs - Skip logs that appear to come from NestJS Logger (to avoid duplicates)
|
|
4
7
|
*/
|
|
5
|
-
export declare function startConsoleCapture(monitoringClient: MonitoringClient
|
|
8
|
+
export declare function startConsoleCapture(monitoringClient: MonitoringClient, options?: {
|
|
9
|
+
skipNestJsLogs?: boolean;
|
|
10
|
+
}): void;
|
|
6
11
|
/**
|
|
7
12
|
* Stop capturing console output
|
|
8
13
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console-capture.d.ts","sourceRoot":"","sources":["../../src/lib/console-capture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"console-capture.d.ts","sourceRoot":"","sources":["../../src/lib/console-capture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAyBvD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,gBAAgB,EAAE,gBAAgB,EAClC,OAAO,GAAE;IAAE,cAAc,CAAC,EAAE,OAAO,CAAA;CAAO,GACzC,IAAI,CA2CN;AAyCD;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAczC;AAqBD;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,OAAO,CAEhD"}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startConsoleCapture = startConsoleCapture;
|
|
4
|
+
exports.stopConsoleCapture = stopConsoleCapture;
|
|
5
|
+
exports.isConsoleCaptureActive = isConsoleCaptureActive;
|
|
1
6
|
const CONSOLE_TO_SEVERITY = {
|
|
2
7
|
debug: 'debug',
|
|
3
8
|
log: 'info',
|
|
@@ -7,13 +12,18 @@ const CONSOLE_TO_SEVERITY = {
|
|
|
7
12
|
};
|
|
8
13
|
let originalMethods = null;
|
|
9
14
|
let isCapturing = false;
|
|
15
|
+
let skipNestLogs = false;
|
|
10
16
|
/**
|
|
11
17
|
* Start capturing console output and sending to monitoring
|
|
18
|
+
* @param monitoringClient - The monitoring client to send logs to
|
|
19
|
+
* @param options - Options for console capture
|
|
20
|
+
* @param options.skipNestJsLogs - Skip logs that appear to come from NestJS Logger (to avoid duplicates)
|
|
12
21
|
*/
|
|
13
|
-
|
|
22
|
+
function startConsoleCapture(monitoringClient, options = {}) {
|
|
14
23
|
if (isCapturing) {
|
|
15
24
|
return;
|
|
16
25
|
}
|
|
26
|
+
skipNestLogs = options.skipNestJsLogs ?? false;
|
|
17
27
|
// Store original methods
|
|
18
28
|
originalMethods = {
|
|
19
29
|
log: console.log.bind(console),
|
|
@@ -31,7 +41,7 @@ export function startConsoleCapture(monitoringClient) {
|
|
|
31
41
|
original(...args);
|
|
32
42
|
// Skip if it's our own SDK log to avoid infinite loops
|
|
33
43
|
const message = formatConsoleArgs(args);
|
|
34
|
-
if (
|
|
44
|
+
if (shouldSkipLog(message)) {
|
|
35
45
|
return;
|
|
36
46
|
}
|
|
37
47
|
// Send to monitoring (fire and forget)
|
|
@@ -45,10 +55,44 @@ export function startConsoleCapture(monitoringClient) {
|
|
|
45
55
|
}
|
|
46
56
|
isCapturing = true;
|
|
47
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Check if a log message should be skipped
|
|
60
|
+
*/
|
|
61
|
+
function shouldSkipLog(message) {
|
|
62
|
+
// Skip SDK internal logs
|
|
63
|
+
if (message.startsWith('[DEX SDK]') ||
|
|
64
|
+
message.startsWith('[MonitoringClient]') ||
|
|
65
|
+
message.startsWith('[RemoteLogger]')) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
// Skip NestJS Logger output if configured
|
|
69
|
+
// NestJS Logger format: "[Nest] PID - DATE LEVEL [Context] Message"
|
|
70
|
+
// or just colored output with ANSI codes
|
|
71
|
+
if (skipNestLogs) {
|
|
72
|
+
// Check for NestJS log patterns
|
|
73
|
+
// Pattern 1: [Nest] prefix
|
|
74
|
+
if (message.includes('[Nest]')) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
// Pattern 2: ANSI color codes followed by LOG/WARN/ERROR/DEBUG
|
|
78
|
+
if (/\x1b\[\d+m\s*(LOG|WARN|ERROR|DEBUG|VERBOSE)\s*\x1b/.test(message)) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
// Pattern 3: Timestamp pattern from NestJS "MM/DD/YYYY, HH:MM:SS"
|
|
82
|
+
if (/\d{1,2}\/\d{1,2}\/\d{4},\s+\d{1,2}:\d{2}:\d{2}\s+(AM|PM)?\s*(LOG|WARN|ERROR|DEBUG|VERBOSE)?/.test(message)) {
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
// Pattern 4: Context in brackets [ContextName]
|
|
86
|
+
if (/^\s*\[[\w-]+\]\s+/.test(message)) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
48
92
|
/**
|
|
49
93
|
* Stop capturing console output
|
|
50
94
|
*/
|
|
51
|
-
|
|
95
|
+
function stopConsoleCapture() {
|
|
52
96
|
if (!isCapturing || !originalMethods) {
|
|
53
97
|
return;
|
|
54
98
|
}
|
|
@@ -59,6 +103,7 @@ export function stopConsoleCapture() {
|
|
|
59
103
|
console.debug = originalMethods.debug;
|
|
60
104
|
originalMethods = null;
|
|
61
105
|
isCapturing = false;
|
|
106
|
+
skipNestLogs = false;
|
|
62
107
|
}
|
|
63
108
|
/**
|
|
64
109
|
* Format console arguments into a single message string
|
|
@@ -82,6 +127,6 @@ function formatConsoleArgs(args) {
|
|
|
82
127
|
/**
|
|
83
128
|
* Check if console capture is active
|
|
84
129
|
*/
|
|
85
|
-
|
|
130
|
+
function isConsoleCaptureActive() {
|
|
86
131
|
return isCapturing;
|
|
87
132
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dex-logger.service.d.ts","sourceRoot":"","sources":["../../src/lib/dex-logger.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,aAAa,EAAS,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"dex-logger.service.d.ts","sourceRoot":"","sources":["../../src/lib/dex-logger.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,aAAa,EAAS,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAIvD;;GAEG;AACH,eAAO,MAAM,gBAAgB,uBAAuB,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBACa,gBAAiB,YAAW,aAAa;IACpD,OAAO,CAAC,OAAO,CAAC,CAAS;IACzB,OAAO,CAAC,gBAAgB,CAAC,CAAmB;IAE5C;;OAEG;IACH,mBAAmB,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,IAAI;IAIpD;;OAEG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAKjC;;OAEG;IACH,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,O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|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DexLoggerService = exports.DEX_LOGGER_TOKEN = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const observability_request_context_1 = require("@dex-monit/observability-request-context");
|
|
4
7
|
/**
|
|
5
8
|
* Token for injecting DexLoggerService
|
|
6
9
|
*/
|
|
7
|
-
|
|
10
|
+
exports.DEX_LOGGER_TOKEN = 'DEX_LOGGER_SERVICE';
|
|
8
11
|
/**
|
|
9
12
|
* DexLoggerService - NestJS compatible logger that sends logs to monitoring
|
|
10
13
|
*
|
|
@@ -29,7 +32,7 @@ export const DEX_LOGGER_TOKEN = 'DEX_LOGGER_SERVICE';
|
|
|
29
32
|
* ```
|
|
30
33
|
*/
|
|
31
34
|
let DexLoggerService = (() => {
|
|
32
|
-
let _classDecorators = [Injectable({ scope: Scope.TRANSIENT })];
|
|
35
|
+
let _classDecorators = [(0, common_1.Injectable)({ scope: common_1.Scope.TRANSIENT })];
|
|
33
36
|
let _classDescriptor;
|
|
34
37
|
let _classExtraInitializers = [];
|
|
35
38
|
let _classThis;
|
|
@@ -37,10 +40,10 @@ let DexLoggerService = (() => {
|
|
|
37
40
|
static { _classThis = this; }
|
|
38
41
|
static {
|
|
39
42
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
40
|
-
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
43
|
+
tslib_1.__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
41
44
|
DexLoggerService = _classThis = _classDescriptor.value;
|
|
42
45
|
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
43
|
-
__runInitializers(_classThis, _classExtraInitializers);
|
|
46
|
+
tslib_1.__runInitializers(_classThis, _classExtraInitializers);
|
|
44
47
|
}
|
|
45
48
|
context;
|
|
46
49
|
monitoringClient;
|
|
@@ -86,7 +89,7 @@ let DexLoggerService = (() => {
|
|
|
86
89
|
*/
|
|
87
90
|
writeLog(level, message, context, extra) {
|
|
88
91
|
const ctx = context || this.context || 'Application';
|
|
89
|
-
const requestContext = RequestContextService.get();
|
|
92
|
+
const requestContext = observability_request_context_1.RequestContextService.get();
|
|
90
93
|
const timestamp = new Date().toISOString();
|
|
91
94
|
// Format for console output
|
|
92
95
|
const logData = {
|
|
@@ -169,4 +172,4 @@ let DexLoggerService = (() => {
|
|
|
169
172
|
};
|
|
170
173
|
return DexLoggerService = _classThis;
|
|
171
174
|
})();
|
|
172
|
-
|
|
175
|
+
exports.DexLoggerService = DexLoggerService;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
|
-
import { MonitoringClient } from './monitoring-client
|
|
3
|
+
import { MonitoringClient } from './monitoring-client';
|
|
4
4
|
/**
|
|
5
5
|
* Error Capture Interceptor
|
|
6
6
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-capture.interceptor.d.ts","sourceRoot":"","sources":["../../src/lib/error-capture.interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EACf,gBAAgB,EAChB,WAAW,EACZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAc,MAAM,MAAM,CAAC;AAI9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"error-capture.interceptor.d.ts","sourceRoot":"","sources":["../../src/lib/error-capture.interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EACf,gBAAgB,EAChB,WAAW,EACZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAc,MAAM,MAAM,CAAC;AAI9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;;;;GAMG;AACH,qBACa,uBAAwB,YAAW,eAAe;IAE3D,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC;gBAAjB,gBAAgB,CAAC,EAAE,gBAAgB,YAAA;IAGtD,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC;IAY5E,OAAO,CAAC,YAAY;IAkEpB,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,eAAe;IAevB,OAAO,CAAC,YAAY;IAiBpB,OAAO,CAAC,eAAe;CASxB"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorCaptureInterceptor = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const rxjs_1 = require("rxjs");
|
|
7
|
+
const operators_1 = require("rxjs/operators");
|
|
8
|
+
const os = tslib_1.__importStar(require("os"));
|
|
6
9
|
/**
|
|
7
10
|
* Error Capture Interceptor
|
|
8
11
|
*
|
|
@@ -11,7 +14,7 @@ import * as os from 'os';
|
|
|
11
14
|
* so this will capture errors even if another filter handles them.
|
|
12
15
|
*/
|
|
13
16
|
let ErrorCaptureInterceptor = (() => {
|
|
14
|
-
let _classDecorators = [Injectable()];
|
|
17
|
+
let _classDecorators = [(0, common_1.Injectable)()];
|
|
15
18
|
let _classDescriptor;
|
|
16
19
|
let _classExtraInitializers = [];
|
|
17
20
|
let _classThis;
|
|
@@ -19,21 +22,21 @@ let ErrorCaptureInterceptor = (() => {
|
|
|
19
22
|
static { _classThis = this; }
|
|
20
23
|
static {
|
|
21
24
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
22
|
-
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
25
|
+
tslib_1.__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
23
26
|
ErrorCaptureInterceptor = _classThis = _classDescriptor.value;
|
|
24
27
|
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
25
|
-
__runInitializers(_classThis, _classExtraInitializers);
|
|
28
|
+
tslib_1.__runInitializers(_classThis, _classExtraInitializers);
|
|
26
29
|
}
|
|
27
30
|
monitoringClient;
|
|
28
31
|
constructor(monitoringClient) {
|
|
29
32
|
this.monitoringClient = monitoringClient;
|
|
30
33
|
}
|
|
31
34
|
intercept(context, next) {
|
|
32
|
-
return next.handle().pipe(catchError((error) => {
|
|
35
|
+
return next.handle().pipe((0, operators_1.catchError)((error) => {
|
|
33
36
|
// Capture the error
|
|
34
37
|
this.captureError(error, context);
|
|
35
38
|
// Re-throw so other handlers can process it
|
|
36
|
-
return throwError(() => error);
|
|
39
|
+
return (0, rxjs_1.throwError)(() => error);
|
|
37
40
|
}));
|
|
38
41
|
}
|
|
39
42
|
captureError(error, context) {
|
|
@@ -146,4 +149,4 @@ let ErrorCaptureInterceptor = (() => {
|
|
|
146
149
|
};
|
|
147
150
|
return ErrorCaptureInterceptor = _classThis;
|
|
148
151
|
})();
|
|
149
|
-
|
|
152
|
+
exports.ErrorCaptureInterceptor = ErrorCaptureInterceptor;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ExceptionFilter, ArgumentsHost } from '@nestjs/common';
|
|
2
2
|
import { Logger } from '@dex-monit/observability-logger';
|
|
3
|
-
import { MonitoringClient } from './monitoring-client
|
|
3
|
+
import { MonitoringClient } from './monitoring-client';
|
|
4
4
|
/**
|
|
5
5
|
* Global Exception Filter
|
|
6
6
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-exception.filter.d.ts","sourceRoot":"","sources":["../../src/lib/global-exception.filter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAEf,aAAa,EAId,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"global-exception.filter.d.ts","sourceRoot":"","sources":["../../src/lib/global-exception.filter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAEf,aAAa,EAId,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAavD;;;;;GAKG;AACH,qBAEa,qBAAsB,YAAW,eAAe;IAEzD,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC;gBADjB,MAAM,EAAE,MAAM,EACd,gBAAgB,CAAC,EAAE,gBAAgB,YAAA;IAGtD,KAAK,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI;IAiFpD;;OAEG;IACH,OAAO,CAAC,eAAe;CAcxB"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GlobalExceptionFilter = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const observability_request_context_1 = require("@dex-monit/observability-request-context");
|
|
4
7
|
/**
|
|
5
8
|
* Global Exception Filter
|
|
6
9
|
*
|
|
@@ -8,7 +11,7 @@ import { RequestContextService } from '@dex-monit/observability-request-context'
|
|
|
8
11
|
* Returns a standardized error response with request ID for correlation.
|
|
9
12
|
*/
|
|
10
13
|
let GlobalExceptionFilter = (() => {
|
|
11
|
-
let _classDecorators = [Catch(), Injectable()];
|
|
14
|
+
let _classDecorators = [(0, common_1.Catch)(), (0, common_1.Injectable)()];
|
|
12
15
|
let _classDescriptor;
|
|
13
16
|
let _classExtraInitializers = [];
|
|
14
17
|
let _classThis;
|
|
@@ -16,10 +19,10 @@ let GlobalExceptionFilter = (() => {
|
|
|
16
19
|
static { _classThis = this; }
|
|
17
20
|
static {
|
|
18
21
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
19
|
-
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
22
|
+
tslib_1.__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
20
23
|
GlobalExceptionFilter = _classThis = _classDescriptor.value;
|
|
21
24
|
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
22
|
-
__runInitializers(_classThis, _classExtraInitializers);
|
|
25
|
+
tslib_1.__runInitializers(_classThis, _classExtraInitializers);
|
|
23
26
|
}
|
|
24
27
|
logger;
|
|
25
28
|
monitoringClient;
|
|
@@ -33,14 +36,14 @@ let GlobalExceptionFilter = (() => {
|
|
|
33
36
|
const response = ctx.getResponse();
|
|
34
37
|
const request = ctx.getRequest();
|
|
35
38
|
// Get request context
|
|
36
|
-
const requestContext = RequestContextService.get();
|
|
39
|
+
const requestContext = observability_request_context_1.RequestContextService.get();
|
|
37
40
|
const requestId = requestContext?.requestId;
|
|
38
41
|
// Determine status code and error details
|
|
39
|
-
let statusCode = HttpStatus.INTERNAL_SERVER_ERROR;
|
|
42
|
+
let statusCode = common_1.HttpStatus.INTERNAL_SERVER_ERROR;
|
|
40
43
|
let message = 'Internal server error';
|
|
41
44
|
let errorName = 'InternalServerError';
|
|
42
45
|
let stack;
|
|
43
|
-
if (exception instanceof HttpException) {
|
|
46
|
+
if (exception instanceof common_1.HttpException) {
|
|
44
47
|
statusCode = exception.getStatus();
|
|
45
48
|
const exceptionResponse = exception.getResponse();
|
|
46
49
|
if (typeof exceptionResponse === 'string') {
|
|
@@ -118,4 +121,4 @@ let GlobalExceptionFilter = (() => {
|
|
|
118
121
|
};
|
|
119
122
|
return GlobalExceptionFilter = _classThis;
|
|
120
123
|
})();
|
|
121
|
-
|
|
124
|
+
exports.GlobalExceptionFilter = GlobalExceptionFilter;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
3
|
import { Request, Response } from 'express';
|
|
4
|
-
import { MonitoringClient } from './monitoring-client
|
|
4
|
+
import { MonitoringClient } from './monitoring-client';
|
|
5
5
|
export declare const HTTP_TRACE_MONITORING_TOKEN = "HTTP_TRACE_MONITORING_CLIENT";
|
|
6
6
|
export interface HttpTrace {
|
|
7
7
|
id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-interceptor.d.ts","sourceRoot":"","sources":["../../src/lib/http-interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EACf,gBAAgB,EAChB,WAAW,EACZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAiB,MAAM,
|
|
1
|
+
{"version":3,"file":"http-interceptor.d.ts","sourceRoot":"","sources":["../../src/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EN = void 0;
|
|
4
|
+
exports.getHttpTraces = getHttpTraces;
|
|
5
|
+
exports.filterTraces = filterTraces;
|
|
6
|
+
exports.clearTraces = clearTraces;
|
|
7
|
+
exports.getTraceStats = getTraceStats;
|
|
8
|
+
exports.createHttpTraceMiddleware = createHttpTraceMiddleware;
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const operators_1 = require("rxjs/operators");
|
|
12
|
+
const monitoring_client_1 = require("./monitoring-client");
|
|
13
|
+
const observability_request_context_1 = require("@dex-monit/observability-request-context");
|
|
6
14
|
// Token for injecting monitoring client
|
|
7
|
-
|
|
15
|
+
exports.HTTP_TRACE_MONITORING_TOKEN = 'HTTP_TRACE_MONITORING_CLIENT';
|
|
8
16
|
// In-memory storage for recent traces (circular buffer)
|
|
9
17
|
const MAX_TRACES = 1000;
|
|
10
18
|
let traces = [];
|
|
@@ -12,13 +20,13 @@ let traceIndex = 0;
|
|
|
12
20
|
/**
|
|
13
21
|
* Get all captured HTTP traces
|
|
14
22
|
*/
|
|
15
|
-
|
|
23
|
+
function getHttpTraces() {
|
|
16
24
|
return [...traces].sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime());
|
|
17
25
|
}
|
|
18
26
|
/**
|
|
19
27
|
* Get traces filtered by criteria
|
|
20
28
|
*/
|
|
21
|
-
|
|
29
|
+
function filterTraces(options) {
|
|
22
30
|
return getHttpTraces().filter((trace) => {
|
|
23
31
|
if (options.method && trace.method !== options.method)
|
|
24
32
|
return false;
|
|
@@ -36,14 +44,14 @@ export function filterTraces(options) {
|
|
|
36
44
|
/**
|
|
37
45
|
* Clear all traces
|
|
38
46
|
*/
|
|
39
|
-
|
|
47
|
+
function clearTraces() {
|
|
40
48
|
traces = [];
|
|
41
49
|
traceIndex = 0;
|
|
42
50
|
}
|
|
43
51
|
/**
|
|
44
52
|
* Get trace statistics
|
|
45
53
|
*/
|
|
46
|
-
|
|
54
|
+
function getTraceStats() {
|
|
47
55
|
const allTraces = getHttpTraces();
|
|
48
56
|
const total = allTraces.length;
|
|
49
57
|
if (total === 0) {
|
|
@@ -103,7 +111,7 @@ export function getTraceStats() {
|
|
|
103
111
|
* HTTP Interceptor for capturing all requests
|
|
104
112
|
*/
|
|
105
113
|
let HttpTraceInterceptor = (() => {
|
|
106
|
-
let _classDecorators = [Injectable()];
|
|
114
|
+
let _classDecorators = [(0, common_1.Injectable)()];
|
|
107
115
|
let _classDescriptor;
|
|
108
116
|
let _classExtraInitializers = [];
|
|
109
117
|
let _classThis;
|
|
@@ -111,10 +119,10 @@ let HttpTraceInterceptor = (() => {
|
|
|
111
119
|
static { _classThis = this; }
|
|
112
120
|
static {
|
|
113
121
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
114
|
-
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
122
|
+
tslib_1.__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
115
123
|
HttpTraceInterceptor = _classThis = _classDescriptor.value;
|
|
116
124
|
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
117
|
-
__runInitializers(_classThis, _classExtraInitializers);
|
|
125
|
+
tslib_1.__runInitializers(_classThis, _classExtraInitializers);
|
|
118
126
|
}
|
|
119
127
|
monitoringClient;
|
|
120
128
|
constructor(monitoringClient) {
|
|
@@ -128,7 +136,7 @@ let HttpTraceInterceptor = (() => {
|
|
|
128
136
|
const http = context.switchToHttp();
|
|
129
137
|
const request = http.getRequest();
|
|
130
138
|
const response = http.getResponse();
|
|
131
|
-
const requestContext = RequestContextService.get();
|
|
139
|
+
const requestContext = observability_request_context_1.RequestContextService.get();
|
|
132
140
|
// Extract request info
|
|
133
141
|
const method = request.method;
|
|
134
142
|
const url = request.originalUrl || request.url;
|
|
@@ -140,7 +148,7 @@ let HttpTraceInterceptor = (() => {
|
|
|
140
148
|
const contentLength = request.headers['content-length']
|
|
141
149
|
? parseInt(request.headers['content-length'], 10)
|
|
142
150
|
: undefined;
|
|
143
|
-
return next.handle().pipe(tap((responseBody) => {
|
|
151
|
+
return next.handle().pipe((0, operators_1.tap)((responseBody) => {
|
|
144
152
|
const duration = Date.now() - startTime;
|
|
145
153
|
const statusCode = response.statusCode;
|
|
146
154
|
this.recordTrace({
|
|
@@ -160,7 +168,7 @@ let HttpTraceInterceptor = (() => {
|
|
|
160
168
|
params: request.params,
|
|
161
169
|
responseSize: this.getResponseSize(responseBody),
|
|
162
170
|
});
|
|
163
|
-
}), catchError((error) => {
|
|
171
|
+
}), (0, operators_1.catchError)((error) => {
|
|
164
172
|
const duration = Date.now() - startTime;
|
|
165
173
|
const statusCode = error.status || error.statusCode || 500;
|
|
166
174
|
this.recordTrace({
|
|
@@ -198,7 +206,7 @@ let HttpTraceInterceptor = (() => {
|
|
|
198
206
|
traceIndex = (traceIndex + 1) % MAX_TRACES;
|
|
199
207
|
}
|
|
200
208
|
// Add breadcrumb
|
|
201
|
-
addBreadcrumb({
|
|
209
|
+
(0, monitoring_client_1.addBreadcrumb)({
|
|
202
210
|
category: 'http',
|
|
203
211
|
type: 'http',
|
|
204
212
|
message: `${data.method} ${data.path}`,
|
|
@@ -293,12 +301,12 @@ let HttpTraceInterceptor = (() => {
|
|
|
293
301
|
};
|
|
294
302
|
return HttpTraceInterceptor = _classThis;
|
|
295
303
|
})();
|
|
296
|
-
|
|
304
|
+
exports.HttpTraceInterceptor = HttpTraceInterceptor;
|
|
297
305
|
/**
|
|
298
306
|
* Middleware to capture HTTP requests (alternative to interceptor)
|
|
299
307
|
* Use this if you need to capture requests before NestJS routing
|
|
300
308
|
*/
|
|
301
|
-
|
|
309
|
+
function createHttpTraceMiddleware() {
|
|
302
310
|
return (req, res, next) => {
|
|
303
311
|
const startTime = Date.now();
|
|
304
312
|
const method = req.method;
|
|
@@ -316,7 +324,7 @@ export function createHttpTraceMiddleware() {
|
|
|
316
324
|
const originalEnd = res.end.bind(res);
|
|
317
325
|
res.end = function (chunk, encoding, cb) {
|
|
318
326
|
const duration = Date.now() - startTime;
|
|
319
|
-
const requestContext = RequestContextService.get();
|
|
327
|
+
const requestContext = observability_request_context_1.RequestContextService.get();
|
|
320
328
|
const trace = {
|
|
321
329
|
id: `trace-${Date.now()}-${Math.random().toString(36).substring(7)}`,
|
|
322
330
|
timestamp: new Date().toISOString(),
|
|
@@ -342,7 +350,7 @@ export function createHttpTraceMiddleware() {
|
|
|
342
350
|
traceIndex = (traceIndex + 1) % MAX_TRACES;
|
|
343
351
|
}
|
|
344
352
|
// Add breadcrumb
|
|
345
|
-
addBreadcrumb({
|
|
353
|
+
(0, monitoring_client_1.addBreadcrumb)({
|
|
346
354
|
category: 'http',
|
|
347
355
|
type: 'http',
|
|
348
356
|
message: `${method} ${path}`,
|