@dex-monit/observability-sdk-node 1.0.5 → 1.0.7
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/console-capture.d.ts +14 -0
- package/dist/lib/console-capture.d.ts.map +1 -0
- package/dist/lib/console-capture.js +87 -0
- 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/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 +12 -4
- package/dist/lib/sdk-node.module.d.ts.map +1 -1
- package/dist/lib/sdk-node.module.js +64 -21
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MonitoringClient } from './monitoring-client.js';
|
|
2
|
+
/**
|
|
3
|
+
* Start capturing console output and sending to monitoring
|
|
4
|
+
*/
|
|
5
|
+
export declare function startConsoleCapture(monitoringClient: MonitoringClient): void;
|
|
6
|
+
/**
|
|
7
|
+
* Stop capturing console output
|
|
8
|
+
*/
|
|
9
|
+
export declare function stopConsoleCapture(): void;
|
|
10
|
+
/**
|
|
11
|
+
* Check if console capture is active
|
|
12
|
+
*/
|
|
13
|
+
export declare function isConsoleCaptureActive(): boolean;
|
|
14
|
+
//# sourceMappingURL=console-capture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console-capture.d.ts","sourceRoot":"","sources":["../../src/lib/console-capture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAwB1D;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,IAAI,CAyC5E;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAazC;AAqBD;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,OAAO,CAEhD"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
const CONSOLE_TO_SEVERITY = {
|
|
2
|
+
debug: 'debug',
|
|
3
|
+
log: 'info',
|
|
4
|
+
info: 'info',
|
|
5
|
+
warn: 'warning',
|
|
6
|
+
error: 'error',
|
|
7
|
+
};
|
|
8
|
+
let originalMethods = null;
|
|
9
|
+
let isCapturing = false;
|
|
10
|
+
/**
|
|
11
|
+
* Start capturing console output and sending to monitoring
|
|
12
|
+
*/
|
|
13
|
+
export function startConsoleCapture(monitoringClient) {
|
|
14
|
+
if (isCapturing) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
// Store original methods
|
|
18
|
+
originalMethods = {
|
|
19
|
+
log: console.log.bind(console),
|
|
20
|
+
info: console.info.bind(console),
|
|
21
|
+
warn: console.warn.bind(console),
|
|
22
|
+
error: console.error.bind(console),
|
|
23
|
+
debug: console.debug.bind(console),
|
|
24
|
+
};
|
|
25
|
+
const methods = ['log', 'info', 'warn', 'error', 'debug'];
|
|
26
|
+
for (const method of methods) {
|
|
27
|
+
const original = originalMethods[method];
|
|
28
|
+
const severity = CONSOLE_TO_SEVERITY[method];
|
|
29
|
+
console[method] = (...args) => {
|
|
30
|
+
// Call original console method first
|
|
31
|
+
original(...args);
|
|
32
|
+
// Skip if it's our own SDK log to avoid infinite loops
|
|
33
|
+
const message = formatConsoleArgs(args);
|
|
34
|
+
if (message.startsWith('[DEX SDK]') || message.startsWith('[MonitoringClient]') || message.startsWith('[RemoteLogger]')) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
// Send to monitoring (fire and forget)
|
|
38
|
+
monitoringClient.captureLog(severity, message, {
|
|
39
|
+
source: 'console',
|
|
40
|
+
method,
|
|
41
|
+
}).catch(() => {
|
|
42
|
+
// Silently ignore - don't use console.error here to avoid loops
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
isCapturing = true;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Stop capturing console output
|
|
50
|
+
*/
|
|
51
|
+
export function stopConsoleCapture() {
|
|
52
|
+
if (!isCapturing || !originalMethods) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
console.log = originalMethods.log;
|
|
56
|
+
console.info = originalMethods.info;
|
|
57
|
+
console.warn = originalMethods.warn;
|
|
58
|
+
console.error = originalMethods.error;
|
|
59
|
+
console.debug = originalMethods.debug;
|
|
60
|
+
originalMethods = null;
|
|
61
|
+
isCapturing = false;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Format console arguments into a single message string
|
|
65
|
+
*/
|
|
66
|
+
function formatConsoleArgs(args) {
|
|
67
|
+
return args.map(arg => {
|
|
68
|
+
if (typeof arg === 'string') {
|
|
69
|
+
return arg;
|
|
70
|
+
}
|
|
71
|
+
if (arg instanceof Error) {
|
|
72
|
+
return `${arg.name}: ${arg.message}\n${arg.stack || ''}`;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
return JSON.stringify(arg, null, 2);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return String(arg);
|
|
79
|
+
}
|
|
80
|
+
}).join(' ');
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Check if console capture is active
|
|
84
|
+
*/
|
|
85
|
+
export function isConsoleCaptureActive() {
|
|
86
|
+
return isCapturing;
|
|
87
|
+
}
|
|
@@ -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 };
|
package/dist/lib/sdk-node.d.ts
CHANGED
|
@@ -3,4 +3,7 @@ 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';
|
|
8
|
+
export * from './console-capture.js';
|
|
6
9
|
//# 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"}
|
|
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"}
|
package/dist/lib/sdk-node.js
CHANGED
|
@@ -4,3 +4,6 @@ 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';
|
|
9
|
+
export * from './console-capture.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DynamicModule, MiddlewareConsumer, NestModule } from '@nestjs/common';
|
|
1
|
+
import { DynamicModule, MiddlewareConsumer, NestModule, OnModuleDestroy } from '@nestjs/common';
|
|
2
2
|
import { MonitoringClientConfig } from './monitoring-client.js';
|
|
3
3
|
import { LoggerConfig, LOGGER_TOKEN } from '@dex-monit/observability-logger';
|
|
4
4
|
import { Severity } from '@dex-monit/observability-contracts';
|
|
@@ -12,8 +12,10 @@ export interface SdkNodeModuleConfig {
|
|
|
12
12
|
monitoring?: MonitoringClientConfig;
|
|
13
13
|
/** Whether to apply middleware globally */
|
|
14
14
|
global?: boolean;
|
|
15
|
-
/** Minimum log level to send remotely (default: '
|
|
15
|
+
/** Minimum log level to send remotely (default: 'debug' = capture all) */
|
|
16
16
|
remoteLogLevel?: Severity;
|
|
17
|
+
/** Whether to capture console.log/warn/error (default: true) */
|
|
18
|
+
captureConsole?: boolean;
|
|
17
19
|
}
|
|
18
20
|
export { LOGGER_TOKEN };
|
|
19
21
|
/**
|
|
@@ -27,10 +29,12 @@ export declare const MONITORING_CLIENT_TOKEN = "OBSERVABILITY_MONITORING_CLIENT"
|
|
|
27
29
|
* - Request ID middleware for tracing
|
|
28
30
|
* - Error capture interceptor (captures ALL errors, even if other filters exist)
|
|
29
31
|
* - Global exception filter for error capture
|
|
30
|
-
* -
|
|
32
|
+
* - DexLoggerService (NestJS compatible logger with remote capture)
|
|
33
|
+
* - Console capture (intercepts console.log/warn/error)
|
|
31
34
|
* - Monitoring client instance
|
|
32
35
|
*/
|
|
33
|
-
export declare class SdkNodeModule implements NestModule {
|
|
36
|
+
export declare class SdkNodeModule implements NestModule, OnModuleDestroy {
|
|
37
|
+
private static remoteLogger;
|
|
34
38
|
/**
|
|
35
39
|
* Register the module with configuration
|
|
36
40
|
*/
|
|
@@ -39,5 +43,9 @@ export declare class SdkNodeModule implements NestModule {
|
|
|
39
43
|
* Configure middleware
|
|
40
44
|
*/
|
|
41
45
|
configure(consumer: MiddlewareConsumer): void;
|
|
46
|
+
/**
|
|
47
|
+
* Cleanup on module destroy
|
|
48
|
+
*/
|
|
49
|
+
onModuleDestroy(): Promise<void>;
|
|
42
50
|
}
|
|
43
51
|
//# sourceMappingURL=sdk-node.module.d.ts.map
|
|
@@ -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,
|
|
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;AAIhC,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;CAC1B;AAGD,OAAO,EAAE,YAAY,EAAE,CAAC;AAExB;;GAEG;AACH,eAAO,MAAM,uBAAuB,oCAAoC,CAAC;AAEzE;;;;;;;;;;GAUG;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;IAwF1D;;OAEG;IACH,SAAS,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI;IAK7C;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;CASvC"}
|
|
@@ -6,6 +6,8 @@ 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';
|
|
10
|
+
import { startConsoleCapture, stopConsoleCapture } from './console-capture.js';
|
|
9
11
|
import { Logger, LOGGER_TOKEN, } from '@dex-monit/observability-logger';
|
|
10
12
|
// Re-export LOGGER_TOKEN for convenience
|
|
11
13
|
export { LOGGER_TOKEN };
|
|
@@ -20,7 +22,8 @@ export const MONITORING_CLIENT_TOKEN = 'OBSERVABILITY_MONITORING_CLIENT';
|
|
|
20
22
|
* - Request ID middleware for tracing
|
|
21
23
|
* - Error capture interceptor (captures ALL errors, even if other filters exist)
|
|
22
24
|
* - Global exception filter for error capture
|
|
23
|
-
* -
|
|
25
|
+
* - DexLoggerService (NestJS compatible logger with remote capture)
|
|
26
|
+
* - Console capture (intercepts console.log/warn/error)
|
|
24
27
|
* - Monitoring client instance
|
|
25
28
|
*/
|
|
26
29
|
let SdkNodeModule = (() => {
|
|
@@ -35,8 +38,8 @@ let SdkNodeModule = (() => {
|
|
|
35
38
|
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
36
39
|
SdkNodeModule = _classThis = _classDescriptor.value;
|
|
37
40
|
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
38
|
-
__runInitializers(_classThis, _classExtraInitializers);
|
|
39
41
|
}
|
|
42
|
+
static remoteLogger = null;
|
|
40
43
|
/**
|
|
41
44
|
* Register the module with configuration
|
|
42
45
|
*/
|
|
@@ -44,17 +47,48 @@ let SdkNodeModule = (() => {
|
|
|
44
47
|
const monitoringClient = config.monitoring
|
|
45
48
|
? createMonitoringClient(config.monitoring)
|
|
46
49
|
: undefined;
|
|
47
|
-
// Use RemoteLogger if monitoring is configured
|
|
48
|
-
const logger =
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
// Use RemoteLogger if monitoring is configured
|
|
51
|
+
const logger = createRemoteLogger({
|
|
52
|
+
...config.logger,
|
|
53
|
+
monitoringClient,
|
|
54
|
+
remoteLevel: config.remoteLogLevel || 'debug', // Default: capture ALL logs
|
|
55
|
+
});
|
|
56
|
+
// Store reference for cleanup
|
|
57
|
+
SdkNodeModule.remoteLogger = logger;
|
|
58
|
+
// Start console capture if enabled (default: true)
|
|
59
|
+
if (monitoringClient && (config.captureConsole ?? true)) {
|
|
60
|
+
startConsoleCapture(monitoringClient);
|
|
61
|
+
}
|
|
55
62
|
return {
|
|
56
63
|
module: SdkNodeModule,
|
|
57
64
|
providers: [
|
|
65
|
+
// Monitoring Client
|
|
66
|
+
{
|
|
67
|
+
provide: MONITORING_CLIENT_TOKEN,
|
|
68
|
+
useValue: monitoringClient,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
provide: MonitoringClient,
|
|
72
|
+
useValue: monitoringClient,
|
|
73
|
+
},
|
|
74
|
+
// DexLoggerService - the main logger to use
|
|
75
|
+
{
|
|
76
|
+
provide: DEX_LOGGER_TOKEN,
|
|
77
|
+
useFactory: () => {
|
|
78
|
+
const dexLogger = new DexLoggerService();
|
|
79
|
+
dexLogger.setMonitoringClient(monitoringClient);
|
|
80
|
+
return dexLogger;
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
provide: DexLoggerService,
|
|
85
|
+
useFactory: () => {
|
|
86
|
+
const dexLogger = new DexLoggerService();
|
|
87
|
+
dexLogger.setMonitoringClient(monitoringClient);
|
|
88
|
+
return dexLogger;
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
// Legacy Logger support
|
|
58
92
|
{
|
|
59
93
|
provide: LOGGER_TOKEN,
|
|
60
94
|
useValue: logger,
|
|
@@ -67,16 +101,7 @@ let SdkNodeModule = (() => {
|
|
|
67
101
|
provide: RemoteLogger,
|
|
68
102
|
useValue: logger,
|
|
69
103
|
},
|
|
70
|
-
{
|
|
71
|
-
provide: MONITORING_CLIENT_TOKEN,
|
|
72
|
-
useValue: monitoringClient,
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
provide: MonitoringClient,
|
|
76
|
-
useValue: monitoringClient,
|
|
77
|
-
},
|
|
78
104
|
// Interceptor captures errors BEFORE any exception filter
|
|
79
|
-
// This ensures we capture errors even if another filter handles them
|
|
80
105
|
{
|
|
81
106
|
provide: APP_INTERCEPTOR,
|
|
82
107
|
useFactory: () => new ErrorCaptureInterceptor(monitoringClient),
|
|
@@ -89,11 +114,15 @@ let SdkNodeModule = (() => {
|
|
|
89
114
|
RequestIdMiddleware,
|
|
90
115
|
],
|
|
91
116
|
exports: [
|
|
117
|
+
// Main exports
|
|
118
|
+
DexLoggerService,
|
|
119
|
+
DEX_LOGGER_TOKEN,
|
|
120
|
+
MONITORING_CLIENT_TOKEN,
|
|
121
|
+
MonitoringClient,
|
|
122
|
+
// Legacy exports
|
|
92
123
|
LOGGER_TOKEN,
|
|
93
124
|
Logger,
|
|
94
125
|
RemoteLogger,
|
|
95
|
-
MONITORING_CLIENT_TOKEN,
|
|
96
|
-
MonitoringClient,
|
|
97
126
|
],
|
|
98
127
|
};
|
|
99
128
|
}
|
|
@@ -104,6 +133,20 @@ let SdkNodeModule = (() => {
|
|
|
104
133
|
// Apply RequestIdMiddleware to all routes
|
|
105
134
|
consumer.apply(RequestIdMiddleware).forRoutes('*');
|
|
106
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Cleanup on module destroy
|
|
138
|
+
*/
|
|
139
|
+
async onModuleDestroy() {
|
|
140
|
+
// Stop console capture
|
|
141
|
+
stopConsoleCapture();
|
|
142
|
+
// Flush remaining logs
|
|
143
|
+
if (SdkNodeModule.remoteLogger) {
|
|
144
|
+
await SdkNodeModule.remoteLogger.close();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
static {
|
|
148
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
149
|
+
}
|
|
107
150
|
};
|
|
108
151
|
return SdkNodeModule = _classThis;
|
|
109
152
|
})();
|