@dex-monit/observability-sdk-node 1.0.6 → 1.0.8
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/lib/dex-logger.service.d.ts +88 -0
- package/dist/lib/dex-logger.service.d.ts.map +1 -0
- package/dist/lib/dex-logger.service.js +172 -0
- package/dist/lib/nest-logger-capture.d.ts +14 -0
- package/dist/lib/nest-logger-capture.d.ts.map +1 -0
- package/dist/lib/nest-logger-capture.js +92 -0
- package/dist/lib/sdk-node.d.ts +3 -0
- package/dist/lib/sdk-node.d.ts.map +1 -1
- package/dist/lib/sdk-node.js +3 -0
- package/dist/lib/sdk-node.module.d.ts +4 -1
- package/dist/lib/sdk-node.module.d.ts.map +1 -1
- package/dist/lib/sdk-node.module.js +49 -16
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { LoggerService } from '@nestjs/common';
|
|
2
|
+
import { MonitoringClient } from './monitoring-client.js';
|
|
3
|
+
/**
|
|
4
|
+
* Token for injecting DexLoggerService
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEX_LOGGER_TOKEN = "DEX_LOGGER_SERVICE";
|
|
7
|
+
/**
|
|
8
|
+
* DexLoggerService - NestJS compatible logger that sends logs to monitoring
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* 1. Inject in any service/controller: constructor(private logger: DexLoggerService)
|
|
12
|
+
* 2. Use as app logger: app.useLogger(app.get(DexLoggerService))
|
|
13
|
+
*
|
|
14
|
+
* Example:
|
|
15
|
+
* ```typescript
|
|
16
|
+
* @Injectable()
|
|
17
|
+
* export class MyService {
|
|
18
|
+
* constructor(private readonly logger: DexLoggerService) {
|
|
19
|
+
* this.logger.setContext('MyService');
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* doSomething() {
|
|
23
|
+
* this.logger.log('Doing something');
|
|
24
|
+
* this.logger.warn('This is a warning');
|
|
25
|
+
* this.logger.error('This is an error');
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare class DexLoggerService implements LoggerService {
|
|
31
|
+
private context?;
|
|
32
|
+
private monitoringClient?;
|
|
33
|
+
/**
|
|
34
|
+
* Set the monitoring client (called by module)
|
|
35
|
+
*/
|
|
36
|
+
setMonitoringClient(client?: MonitoringClient): void;
|
|
37
|
+
/**
|
|
38
|
+
* Set the context (usually the class name)
|
|
39
|
+
*/
|
|
40
|
+
setContext(context: string): this;
|
|
41
|
+
/**
|
|
42
|
+
* Log a message (info level)
|
|
43
|
+
*/
|
|
44
|
+
log(message: string, context?: string): void;
|
|
45
|
+
log(message: string, ...optionalParams: unknown[]): void;
|
|
46
|
+
/**
|
|
47
|
+
* Log an error message
|
|
48
|
+
*/
|
|
49
|
+
error(message: string, stackOrContext?: string): void;
|
|
50
|
+
error(message: string, stack?: string, context?: string): void;
|
|
51
|
+
/**
|
|
52
|
+
* Log a warning message
|
|
53
|
+
*/
|
|
54
|
+
warn(message: string, context?: string): void;
|
|
55
|
+
warn(message: string, ...optionalParams: unknown[]): void;
|
|
56
|
+
/**
|
|
57
|
+
* Log a debug message
|
|
58
|
+
*/
|
|
59
|
+
debug(message: string, context?: string): void;
|
|
60
|
+
debug(message: string, ...optionalParams: unknown[]): void;
|
|
61
|
+
/**
|
|
62
|
+
* Log a verbose message (maps to debug)
|
|
63
|
+
*/
|
|
64
|
+
verbose(message: string, context?: string): void;
|
|
65
|
+
verbose(message: string, ...optionalParams: unknown[]): void;
|
|
66
|
+
/**
|
|
67
|
+
* Log a fatal message
|
|
68
|
+
*/
|
|
69
|
+
fatal(message: string, context?: string): void;
|
|
70
|
+
fatal(message: string, ...optionalParams: unknown[]): void;
|
|
71
|
+
/**
|
|
72
|
+
* Internal: write log to console and send to monitoring
|
|
73
|
+
*/
|
|
74
|
+
private writeLog;
|
|
75
|
+
/**
|
|
76
|
+
* Get the appropriate console method for the log level
|
|
77
|
+
*/
|
|
78
|
+
private getConsoleMethod;
|
|
79
|
+
/**
|
|
80
|
+
* Extract context from optional params
|
|
81
|
+
*/
|
|
82
|
+
private extractContext;
|
|
83
|
+
/**
|
|
84
|
+
* Extract context and stack from error params
|
|
85
|
+
*/
|
|
86
|
+
private extractErrorParams;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=dex-logger.service.d.ts.map
|
|
@@ -0,0 +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,wBAAwB,CAAC;AAI1D;;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,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAC5C,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI;IAMxD;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI;IACrD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAM9D;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAC7C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI;IAMzD;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAC9C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI;IAM1D;;OAEG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAChD,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI;IAM5D;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAC9C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI;IAM1D;;OAEG;IACH,OAAO,CAAC,QAAQ;IAsChB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAgBxB;;OAEG;IACH,OAAO,CAAC,cAAc;IAQtB;;OAEG;IACH,OAAO,CAAC,kBAAkB;CA4B3B"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { __esDecorate, __runInitializers } from "tslib";
|
|
2
|
+
import { Injectable, Scope } from '@nestjs/common';
|
|
3
|
+
import { RequestContextService } from '@dex-monit/observability-request-context';
|
|
4
|
+
/**
|
|
5
|
+
* Token for injecting DexLoggerService
|
|
6
|
+
*/
|
|
7
|
+
export const DEX_LOGGER_TOKEN = 'DEX_LOGGER_SERVICE';
|
|
8
|
+
/**
|
|
9
|
+
* DexLoggerService - NestJS compatible logger that sends logs to monitoring
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* 1. Inject in any service/controller: constructor(private logger: DexLoggerService)
|
|
13
|
+
* 2. Use as app logger: app.useLogger(app.get(DexLoggerService))
|
|
14
|
+
*
|
|
15
|
+
* Example:
|
|
16
|
+
* ```typescript
|
|
17
|
+
* @Injectable()
|
|
18
|
+
* export class MyService {
|
|
19
|
+
* constructor(private readonly logger: DexLoggerService) {
|
|
20
|
+
* this.logger.setContext('MyService');
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* doSomething() {
|
|
24
|
+
* this.logger.log('Doing something');
|
|
25
|
+
* this.logger.warn('This is a warning');
|
|
26
|
+
* this.logger.error('This is an error');
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
let DexLoggerService = (() => {
|
|
32
|
+
let _classDecorators = [Injectable({ scope: Scope.TRANSIENT })];
|
|
33
|
+
let _classDescriptor;
|
|
34
|
+
let _classExtraInitializers = [];
|
|
35
|
+
let _classThis;
|
|
36
|
+
var DexLoggerService = class {
|
|
37
|
+
static { _classThis = this; }
|
|
38
|
+
static {
|
|
39
|
+
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);
|
|
41
|
+
DexLoggerService = _classThis = _classDescriptor.value;
|
|
42
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
43
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
44
|
+
}
|
|
45
|
+
context;
|
|
46
|
+
monitoringClient;
|
|
47
|
+
/**
|
|
48
|
+
* Set the monitoring client (called by module)
|
|
49
|
+
*/
|
|
50
|
+
setMonitoringClient(client) {
|
|
51
|
+
this.monitoringClient = client;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Set the context (usually the class name)
|
|
55
|
+
*/
|
|
56
|
+
setContext(context) {
|
|
57
|
+
this.context = context;
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
log(message, ...optionalParams) {
|
|
61
|
+
const ctx = this.extractContext(optionalParams);
|
|
62
|
+
this.writeLog('info', message, ctx);
|
|
63
|
+
}
|
|
64
|
+
error(message, ...optionalParams) {
|
|
65
|
+
const { context, stack } = this.extractErrorParams(optionalParams);
|
|
66
|
+
this.writeLog('error', message, context, { stack });
|
|
67
|
+
}
|
|
68
|
+
warn(message, ...optionalParams) {
|
|
69
|
+
const ctx = this.extractContext(optionalParams);
|
|
70
|
+
this.writeLog('warning', message, ctx);
|
|
71
|
+
}
|
|
72
|
+
debug(message, ...optionalParams) {
|
|
73
|
+
const ctx = this.extractContext(optionalParams);
|
|
74
|
+
this.writeLog('debug', message, ctx);
|
|
75
|
+
}
|
|
76
|
+
verbose(message, ...optionalParams) {
|
|
77
|
+
const ctx = this.extractContext(optionalParams);
|
|
78
|
+
this.writeLog('debug', message, ctx);
|
|
79
|
+
}
|
|
80
|
+
fatal(message, ...optionalParams) {
|
|
81
|
+
const ctx = this.extractContext(optionalParams);
|
|
82
|
+
this.writeLog('fatal', message, ctx);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Internal: write log to console and send to monitoring
|
|
86
|
+
*/
|
|
87
|
+
writeLog(level, message, context, extra) {
|
|
88
|
+
const ctx = context || this.context || 'Application';
|
|
89
|
+
const requestContext = RequestContextService.get();
|
|
90
|
+
const timestamp = new Date().toISOString();
|
|
91
|
+
// Format for console output
|
|
92
|
+
const logData = {
|
|
93
|
+
timestamp,
|
|
94
|
+
level: level.toUpperCase(),
|
|
95
|
+
context: ctx,
|
|
96
|
+
message,
|
|
97
|
+
requestId: requestContext?.requestId,
|
|
98
|
+
transactionId: requestContext?.transactionId,
|
|
99
|
+
...extra,
|
|
100
|
+
};
|
|
101
|
+
// Write to console (JSON format)
|
|
102
|
+
const consoleMethod = this.getConsoleMethod(level);
|
|
103
|
+
consoleMethod(JSON.stringify(logData));
|
|
104
|
+
// Send to monitoring (fire and forget)
|
|
105
|
+
if (this.monitoringClient) {
|
|
106
|
+
this.monitoringClient.captureLog(level, message, {
|
|
107
|
+
context: ctx,
|
|
108
|
+
requestId: requestContext?.requestId,
|
|
109
|
+
transactionId: requestContext?.transactionId,
|
|
110
|
+
...extra,
|
|
111
|
+
}).catch(() => {
|
|
112
|
+
// Silently fail
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get the appropriate console method for the log level
|
|
118
|
+
*/
|
|
119
|
+
getConsoleMethod(level) {
|
|
120
|
+
switch (level) {
|
|
121
|
+
case 'debug':
|
|
122
|
+
return console.debug.bind(console);
|
|
123
|
+
case 'info':
|
|
124
|
+
return console.log.bind(console);
|
|
125
|
+
case 'warning':
|
|
126
|
+
return console.warn.bind(console);
|
|
127
|
+
case 'error':
|
|
128
|
+
case 'fatal':
|
|
129
|
+
return console.error.bind(console);
|
|
130
|
+
default:
|
|
131
|
+
return console.log.bind(console);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Extract context from optional params
|
|
136
|
+
*/
|
|
137
|
+
extractContext(optionalParams) {
|
|
138
|
+
const lastParam = optionalParams[optionalParams.length - 1];
|
|
139
|
+
if (typeof lastParam === 'string') {
|
|
140
|
+
return lastParam;
|
|
141
|
+
}
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Extract context and stack from error params
|
|
146
|
+
*/
|
|
147
|
+
extractErrorParams(optionalParams) {
|
|
148
|
+
if (optionalParams.length === 0) {
|
|
149
|
+
return {};
|
|
150
|
+
}
|
|
151
|
+
if (optionalParams.length === 1) {
|
|
152
|
+
const param = optionalParams[0];
|
|
153
|
+
if (typeof param === 'string') {
|
|
154
|
+
// Could be stack or context - check if it looks like a stack
|
|
155
|
+
if (param.includes('\n') && param.includes('at ')) {
|
|
156
|
+
return { stack: param };
|
|
157
|
+
}
|
|
158
|
+
return { context: param };
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (optionalParams.length >= 2) {
|
|
162
|
+
return {
|
|
163
|
+
stack: typeof optionalParams[0] === 'string' ? optionalParams[0] : undefined,
|
|
164
|
+
context: typeof optionalParams[1] === 'string' ? optionalParams[1] : undefined,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
return {};
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
return DexLoggerService = _classThis;
|
|
171
|
+
})();
|
|
172
|
+
export { DexLoggerService };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MonitoringClient } from './monitoring-client.js';
|
|
2
|
+
/**
|
|
3
|
+
* Start capturing NestJS native Logger output
|
|
4
|
+
*/
|
|
5
|
+
export declare function startNestLoggerCapture(monitoringClient: MonitoringClient): void;
|
|
6
|
+
/**
|
|
7
|
+
* Stop capturing NestJS native Logger output
|
|
8
|
+
*/
|
|
9
|
+
export declare function stopNestLoggerCapture(): void;
|
|
10
|
+
/**
|
|
11
|
+
* Check if NestJS Logger capture is active
|
|
12
|
+
*/
|
|
13
|
+
export declare function isNestLoggerCaptureActive(): boolean;
|
|
14
|
+
//# sourceMappingURL=nest-logger-capture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nest-logger-capture.d.ts","sourceRoot":"","sources":["../../src/lib/nest-logger-capture.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AA2B1D;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,IAAI,CAsD/E;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAe5C;AAcD;;GAEG;AACH,wBAAgB,yBAAyB,IAAI,OAAO,CAEnD"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Logger as NestLogger } from '@nestjs/common';
|
|
2
|
+
import { RequestContextService } from '@dex-monit/observability-request-context';
|
|
3
|
+
const NEST_TO_SEVERITY = {
|
|
4
|
+
debug: 'debug',
|
|
5
|
+
verbose: 'debug',
|
|
6
|
+
log: 'info',
|
|
7
|
+
warn: 'warning',
|
|
8
|
+
error: 'error',
|
|
9
|
+
fatal: 'fatal',
|
|
10
|
+
};
|
|
11
|
+
let originalMethods = null;
|
|
12
|
+
let isCapturing = false;
|
|
13
|
+
/**
|
|
14
|
+
* Start capturing NestJS native Logger output
|
|
15
|
+
*/
|
|
16
|
+
export function startNestLoggerCapture(monitoringClient) {
|
|
17
|
+
if (isCapturing) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
// Store original static methods
|
|
21
|
+
originalMethods = {
|
|
22
|
+
log: NestLogger.log.bind(NestLogger),
|
|
23
|
+
error: NestLogger.error.bind(NestLogger),
|
|
24
|
+
warn: NestLogger.warn.bind(NestLogger),
|
|
25
|
+
debug: NestLogger.debug.bind(NestLogger),
|
|
26
|
+
verbose: NestLogger.verbose.bind(NestLogger),
|
|
27
|
+
fatal: NestLogger.fatal.bind(NestLogger),
|
|
28
|
+
};
|
|
29
|
+
const methods = ['log', 'error', 'warn', 'debug', 'verbose', 'fatal'];
|
|
30
|
+
for (const method of methods) {
|
|
31
|
+
const original = originalMethods[method];
|
|
32
|
+
const severity = NEST_TO_SEVERITY[method];
|
|
33
|
+
// Override the static method
|
|
34
|
+
NestLogger[method] = function (message, ...optionalParams) {
|
|
35
|
+
// Call original method first
|
|
36
|
+
original(message, ...optionalParams);
|
|
37
|
+
// Extract context from params
|
|
38
|
+
const context = extractContext(optionalParams);
|
|
39
|
+
const messageStr = typeof message === 'string' ? message : JSON.stringify(message);
|
|
40
|
+
// Skip SDK internal logs to avoid loops
|
|
41
|
+
if (context?.startsWith('DEX') || messageStr.startsWith('[DEX')) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
// Get request context
|
|
45
|
+
const requestContext = RequestContextService.get();
|
|
46
|
+
// Send to monitoring (fire and forget)
|
|
47
|
+
monitoringClient.captureLog(severity, messageStr, {
|
|
48
|
+
source: 'nest-logger',
|
|
49
|
+
context,
|
|
50
|
+
requestId: requestContext?.requestId,
|
|
51
|
+
transactionId: requestContext?.transactionId,
|
|
52
|
+
}).catch(() => {
|
|
53
|
+
// Silently ignore
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
isCapturing = true;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Stop capturing NestJS native Logger output
|
|
61
|
+
*/
|
|
62
|
+
export function stopNestLoggerCapture() {
|
|
63
|
+
if (!isCapturing || !originalMethods) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
// Restore original methods
|
|
67
|
+
NestLogger.log = originalMethods.log;
|
|
68
|
+
NestLogger.error = originalMethods.error;
|
|
69
|
+
NestLogger.warn = originalMethods.warn;
|
|
70
|
+
NestLogger.debug = originalMethods.debug;
|
|
71
|
+
NestLogger.verbose = originalMethods.verbose;
|
|
72
|
+
NestLogger.fatal = originalMethods.fatal;
|
|
73
|
+
originalMethods = null;
|
|
74
|
+
isCapturing = false;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Extract context from optional params
|
|
78
|
+
*/
|
|
79
|
+
function extractContext(optionalParams) {
|
|
80
|
+
// Last param is usually the context
|
|
81
|
+
const lastParam = optionalParams[optionalParams.length - 1];
|
|
82
|
+
if (typeof lastParam === 'string') {
|
|
83
|
+
return lastParam;
|
|
84
|
+
}
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Check if NestJS Logger capture is active
|
|
89
|
+
*/
|
|
90
|
+
export function isNestLoggerCaptureActive() {
|
|
91
|
+
return isCapturing;
|
|
92
|
+
}
|
package/dist/lib/sdk-node.d.ts
CHANGED
|
@@ -3,5 +3,8 @@ export * from './request-id.middleware.js';
|
|
|
3
3
|
export * from './global-exception.filter.js';
|
|
4
4
|
export * from './error-capture.interceptor.js';
|
|
5
5
|
export * from './monitoring-client.js';
|
|
6
|
+
export * from './remote-logger.js';
|
|
7
|
+
export * from './dex-logger.service.js';
|
|
6
8
|
export * from './console-capture.js';
|
|
9
|
+
export * from './nest-logger-capture.js';
|
|
7
10
|
//# sourceMappingURL=sdk-node.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk-node.d.ts","sourceRoot":"","sources":["../../src/lib/sdk-node.ts"],"names":[],"mappings":"AACA,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"sdk-node.d.ts","sourceRoot":"","sources":["../../src/lib/sdk-node.ts"],"names":[],"mappings":"AACA,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC"}
|
package/dist/lib/sdk-node.js
CHANGED
|
@@ -4,4 +4,7 @@ export * from './request-id.middleware.js';
|
|
|
4
4
|
export * from './global-exception.filter.js';
|
|
5
5
|
export * from './error-capture.interceptor.js';
|
|
6
6
|
export * from './monitoring-client.js';
|
|
7
|
+
export * from './remote-logger.js';
|
|
8
|
+
export * from './dex-logger.service.js';
|
|
7
9
|
export * from './console-capture.js';
|
|
10
|
+
export * from './nest-logger-capture.js';
|
|
@@ -16,6 +16,8 @@ export interface SdkNodeModuleConfig {
|
|
|
16
16
|
remoteLogLevel?: Severity;
|
|
17
17
|
/** Whether to capture console.log/warn/error (default: true) */
|
|
18
18
|
captureConsole?: boolean;
|
|
19
|
+
/** Whether to capture NestJS native Logger (default: true) */
|
|
20
|
+
captureNestLogger?: boolean;
|
|
19
21
|
}
|
|
20
22
|
export { LOGGER_TOKEN };
|
|
21
23
|
/**
|
|
@@ -29,8 +31,9 @@ export declare const MONITORING_CLIENT_TOKEN = "OBSERVABILITY_MONITORING_CLIENT"
|
|
|
29
31
|
* - Request ID middleware for tracing
|
|
30
32
|
* - Error capture interceptor (captures ALL errors, even if other filters exist)
|
|
31
33
|
* - Global exception filter for error capture
|
|
32
|
-
* -
|
|
34
|
+
* - DexLoggerService (NestJS compatible logger with remote capture)
|
|
33
35
|
* - Console capture (intercepts console.log/warn/error)
|
|
36
|
+
* - NestJS Logger capture (intercepts Logger.log/warn/error)
|
|
34
37
|
* - Monitoring client instance
|
|
35
38
|
*/
|
|
36
39
|
export declare class SdkNodeModule implements NestModule, OnModuleDestroy {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk-node.module.d.ts","sourceRoot":"","sources":["../../src/lib/sdk-node.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,EAEb,kBAAkB,EAClB,UAAU,EACV,eAAe,EAChB,MAAM,gBAAgB,CAAC;AAKxB,OAAO,EAEL,sBAAsB,EAEvB,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"sdk-node.module.d.ts","sourceRoot":"","sources":["../../src/lib/sdk-node.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,EAEb,kBAAkB,EAClB,UAAU,EACV,eAAe,EAChB,MAAM,gBAAgB,CAAC;AAKxB,OAAO,EAEL,sBAAsB,EAEvB,MAAM,wBAAwB,CAAC;AAKhC,OAAO,EAEL,YAAY,EACZ,YAAY,EACb,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,2BAA2B;IAC3B,MAAM,EAAE,YAAY,CAAC;IACrB,yFAAyF;IACzF,UAAU,CAAC,EAAE,sBAAsB,CAAC;IACpC,2CAA2C;IAC3C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,0EAA0E;IAC1E,cAAc,CAAC,EAAE,QAAQ,CAAC;IAC1B,gEAAgE;IAChE,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,8DAA8D;IAC9D,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAGD,OAAO,EAAE,YAAY,EAAE,CAAC;AAExB;;GAEG;AACH,eAAO,MAAM,uBAAuB,oCAAoC,CAAC;AAEzE;;;;;;;;;;;GAWG;AACH,qBAEa,aAAc,YAAW,UAAU,EAAE,eAAe;IAC/D,OAAO,CAAC,MAAM,CAAC,YAAY,CAA6B;IAExD;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,mBAAmB,GAAG,aAAa;IAgG1D;;OAEG;IACH,SAAS,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI;IAK7C;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;CAUvC"}
|
|
@@ -6,7 +6,9 @@ import { GlobalExceptionFilter } from './global-exception.filter.js';
|
|
|
6
6
|
import { ErrorCaptureInterceptor } from './error-capture.interceptor.js';
|
|
7
7
|
import { MonitoringClient, createMonitoringClient, } from './monitoring-client.js';
|
|
8
8
|
import { RemoteLogger, createRemoteLogger } from './remote-logger.js';
|
|
9
|
+
import { DexLoggerService, DEX_LOGGER_TOKEN } from './dex-logger.service.js';
|
|
9
10
|
import { startConsoleCapture, stopConsoleCapture } from './console-capture.js';
|
|
11
|
+
import { startNestLoggerCapture, stopNestLoggerCapture } from './nest-logger-capture.js';
|
|
10
12
|
import { Logger, LOGGER_TOKEN, } from '@dex-monit/observability-logger';
|
|
11
13
|
// Re-export LOGGER_TOKEN for convenience
|
|
12
14
|
export { LOGGER_TOKEN };
|
|
@@ -21,8 +23,9 @@ export const MONITORING_CLIENT_TOKEN = 'OBSERVABILITY_MONITORING_CLIENT';
|
|
|
21
23
|
* - Request ID middleware for tracing
|
|
22
24
|
* - Error capture interceptor (captures ALL errors, even if other filters exist)
|
|
23
25
|
* - Global exception filter for error capture
|
|
24
|
-
* -
|
|
26
|
+
* - DexLoggerService (NestJS compatible logger with remote capture)
|
|
25
27
|
* - Console capture (intercepts console.log/warn/error)
|
|
28
|
+
* - NestJS Logger capture (intercepts Logger.log/warn/error)
|
|
26
29
|
* - Monitoring client instance
|
|
27
30
|
*/
|
|
28
31
|
let SdkNodeModule = (() => {
|
|
@@ -54,13 +57,47 @@ let SdkNodeModule = (() => {
|
|
|
54
57
|
});
|
|
55
58
|
// Store reference for cleanup
|
|
56
59
|
SdkNodeModule.remoteLogger = logger;
|
|
57
|
-
// Start
|
|
58
|
-
if (monitoringClient
|
|
59
|
-
|
|
60
|
+
// Start captures if monitoring is configured
|
|
61
|
+
if (monitoringClient) {
|
|
62
|
+
// Console capture (default: true)
|
|
63
|
+
if (config.captureConsole ?? true) {
|
|
64
|
+
startConsoleCapture(monitoringClient);
|
|
65
|
+
}
|
|
66
|
+
// NestJS Logger capture (default: true)
|
|
67
|
+
if (config.captureNestLogger ?? true) {
|
|
68
|
+
startNestLoggerCapture(monitoringClient);
|
|
69
|
+
}
|
|
60
70
|
}
|
|
61
71
|
return {
|
|
62
72
|
module: SdkNodeModule,
|
|
63
73
|
providers: [
|
|
74
|
+
// Monitoring Client
|
|
75
|
+
{
|
|
76
|
+
provide: MONITORING_CLIENT_TOKEN,
|
|
77
|
+
useValue: monitoringClient,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
provide: MonitoringClient,
|
|
81
|
+
useValue: monitoringClient,
|
|
82
|
+
},
|
|
83
|
+
// DexLoggerService - the main logger to use
|
|
84
|
+
{
|
|
85
|
+
provide: DEX_LOGGER_TOKEN,
|
|
86
|
+
useFactory: () => {
|
|
87
|
+
const dexLogger = new DexLoggerService();
|
|
88
|
+
dexLogger.setMonitoringClient(monitoringClient);
|
|
89
|
+
return dexLogger;
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
provide: DexLoggerService,
|
|
94
|
+
useFactory: () => {
|
|
95
|
+
const dexLogger = new DexLoggerService();
|
|
96
|
+
dexLogger.setMonitoringClient(monitoringClient);
|
|
97
|
+
return dexLogger;
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
// Legacy Logger support
|
|
64
101
|
{
|
|
65
102
|
provide: LOGGER_TOKEN,
|
|
66
103
|
useValue: logger,
|
|
@@ -73,16 +110,7 @@ let SdkNodeModule = (() => {
|
|
|
73
110
|
provide: RemoteLogger,
|
|
74
111
|
useValue: logger,
|
|
75
112
|
},
|
|
76
|
-
{
|
|
77
|
-
provide: MONITORING_CLIENT_TOKEN,
|
|
78
|
-
useValue: monitoringClient,
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
provide: MonitoringClient,
|
|
82
|
-
useValue: monitoringClient,
|
|
83
|
-
},
|
|
84
113
|
// Interceptor captures errors BEFORE any exception filter
|
|
85
|
-
// This ensures we capture errors even if another filter handles them
|
|
86
114
|
{
|
|
87
115
|
provide: APP_INTERCEPTOR,
|
|
88
116
|
useFactory: () => new ErrorCaptureInterceptor(monitoringClient),
|
|
@@ -95,11 +123,15 @@ let SdkNodeModule = (() => {
|
|
|
95
123
|
RequestIdMiddleware,
|
|
96
124
|
],
|
|
97
125
|
exports: [
|
|
126
|
+
// Main exports
|
|
127
|
+
DexLoggerService,
|
|
128
|
+
DEX_LOGGER_TOKEN,
|
|
129
|
+
MONITORING_CLIENT_TOKEN,
|
|
130
|
+
MonitoringClient,
|
|
131
|
+
// Legacy exports
|
|
98
132
|
LOGGER_TOKEN,
|
|
99
133
|
Logger,
|
|
100
134
|
RemoteLogger,
|
|
101
|
-
MONITORING_CLIENT_TOKEN,
|
|
102
|
-
MonitoringClient,
|
|
103
135
|
],
|
|
104
136
|
};
|
|
105
137
|
}
|
|
@@ -114,8 +146,9 @@ let SdkNodeModule = (() => {
|
|
|
114
146
|
* Cleanup on module destroy
|
|
115
147
|
*/
|
|
116
148
|
async onModuleDestroy() {
|
|
117
|
-
// Stop
|
|
149
|
+
// Stop captures
|
|
118
150
|
stopConsoleCapture();
|
|
151
|
+
stopNestLoggerCapture();
|
|
119
152
|
// Flush remaining logs
|
|
120
153
|
if (SdkNodeModule.remoteLogger) {
|
|
121
154
|
await SdkNodeModule.remoteLogger.close();
|