@gus-eip/loggers 3.3.8 → 3.4.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.
@@ -3,11 +3,14 @@ export declare class CloudWatchLoggerService implements ILogger {
|
|
3
3
|
private readonly cloudwatch;
|
4
4
|
private region;
|
5
5
|
private logGroupName;
|
6
|
-
|
6
|
+
private teamWebhoookUrl;
|
7
|
+
private isAlertNeeded;
|
8
|
+
constructor(region: string, logGroupName: string, teamWebhoookUrl: string, isAlertNeeded: boolean);
|
7
9
|
private version;
|
8
10
|
createLogStream(logStreamName: string): Promise<any>;
|
9
11
|
logToCloudWatch(type: string, logObject: any, logStreamName: string): Promise<void>;
|
10
12
|
logStreamExists(logStreamName: string): Promise<boolean>;
|
13
|
+
sendAlerttoTeams(errorMessage: any, handler: any, input: any): Promise<any>;
|
11
14
|
log(correlationId: string, timestamp: string, component: string, source: string, destination: string, event: string, usecase: string, sourcePayload: any, destinationPayload: any, logMessage: any, brand: any, secondaryKey: string, logStreamName: string, destinationObjectType?: string, destinationObjectId?: string, sourceObjectType?: string, sourceObjectId?: string, destinationResponse?: any): Promise<any>;
|
12
15
|
error(correlationId: string, timestamp: string, component: string, source: string, destination: string, event: string, usecase: string, sourcePayload: any, destinationPayload: any, errorMessage: any, brand: any, secondaryKey: string, logStreamName: string, destinationObjectType?: string, destinationObjectId?: string, sourceObjectType?: string, sourceObjectId?: string, destinationResponse?: any): Promise<any>;
|
13
16
|
}
|
@@ -13,12 +13,15 @@ exports.CloudWatchLoggerService = void 0;
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
14
14
|
const aws_sdk_1 = require("aws-sdk");
|
15
15
|
const cloudwatch_event_formatter_1 = require("./cloudwatch.event.formatter");
|
16
|
+
const axios_1 = require("axios");
|
16
17
|
let CloudWatchLoggerService = class CloudWatchLoggerService {
|
17
|
-
constructor(region, logGroupName) {
|
18
|
+
constructor(region, logGroupName, teamWebhoookUrl, isAlertNeeded) {
|
18
19
|
this.version = 'v1';
|
19
20
|
this.cloudwatch = new aws_sdk_1.CloudWatchLogs({ region: region });
|
20
21
|
this.region = region;
|
21
22
|
this.logGroupName = logGroupName;
|
23
|
+
this.teamWebhoookUrl = teamWebhoookUrl;
|
24
|
+
this.isAlertNeeded = isAlertNeeded;
|
22
25
|
}
|
23
26
|
async createLogStream(logStreamName) {
|
24
27
|
const createParams = {
|
@@ -70,6 +73,55 @@ let CloudWatchLoggerService = class CloudWatchLoggerService {
|
|
70
73
|
console.error('Error checking log stream:', error);
|
71
74
|
}
|
72
75
|
}
|
76
|
+
async sendAlerttoTeams(errorMessage, handler, input) {
|
77
|
+
console.log("Error message", errorMessage);
|
78
|
+
const webhookUrl = this.teamWebhoookUrl;
|
79
|
+
const timestamp = new Date().toISOString();
|
80
|
+
const environment = process.env.NODE_ENV || "unknown";
|
81
|
+
const inputFacts = Object.keys(input).map(key => ({
|
82
|
+
name: `${key}:`,
|
83
|
+
value: typeof input[key] === 'object' ? JSON.stringify(input[key], null, 2) : String(input[key])
|
84
|
+
}));
|
85
|
+
const alertMessage = {
|
86
|
+
"@type": "MessageCard",
|
87
|
+
"@context": "http://schema.org/extensions",
|
88
|
+
"summary": "Error Alert",
|
89
|
+
"themeColor": "FF0000",
|
90
|
+
"title": "🚨 Application Error Alert 🚨",
|
91
|
+
"sections": [
|
92
|
+
{
|
93
|
+
"facts": [
|
94
|
+
{
|
95
|
+
"name": "errorMessage:",
|
96
|
+
"value": `\`\`\`${errorMessage}\`\`\``
|
97
|
+
},
|
98
|
+
{
|
99
|
+
"name": "component:",
|
100
|
+
"value": handler
|
101
|
+
},
|
102
|
+
{
|
103
|
+
"name": "timestamp:",
|
104
|
+
"value": timestamp
|
105
|
+
},
|
106
|
+
...inputFacts,
|
107
|
+
],
|
108
|
+
"markdown": true
|
109
|
+
}
|
110
|
+
]
|
111
|
+
};
|
112
|
+
try {
|
113
|
+
await axios_1.default.post(webhookUrl, alertMessage, {
|
114
|
+
headers: {
|
115
|
+
"Content-Type": "application/json",
|
116
|
+
},
|
117
|
+
});
|
118
|
+
console.log("Message sent successfully");
|
119
|
+
}
|
120
|
+
catch (error) {
|
121
|
+
console.error("Error sending message:", error);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
;
|
73
125
|
async log(correlationId, timestamp, component, source, destination, event, usecase, sourcePayload, destinationPayload, logMessage, brand, secondaryKey, logStreamName, destinationObjectType, destinationObjectId, sourceObjectType, sourceObjectId, destinationResponse) {
|
74
126
|
const logObject = {
|
75
127
|
correlationId,
|
@@ -115,10 +167,13 @@ let CloudWatchLoggerService = class CloudWatchLoggerService {
|
|
115
167
|
destinationResponse
|
116
168
|
};
|
117
169
|
await this.logToCloudWatch('error', logObject, logStreamName);
|
170
|
+
if (this.isAlertNeeded) {
|
171
|
+
await this.sendAlerttoTeams(errorMessage, component, logObject);
|
172
|
+
}
|
118
173
|
}
|
119
174
|
};
|
120
|
-
CloudWatchLoggerService =
|
175
|
+
exports.CloudWatchLoggerService = CloudWatchLoggerService;
|
176
|
+
exports.CloudWatchLoggerService = CloudWatchLoggerService = __decorate([
|
121
177
|
(0, common_1.Injectable)(),
|
122
|
-
__metadata("design:paramtypes", [String, String])
|
178
|
+
__metadata("design:paramtypes", [String, String, String, Boolean])
|
123
179
|
], CloudWatchLoggerService);
|
124
|
-
exports.CloudWatchLoggerService = CloudWatchLoggerService;
|
package/dist/enum.js
CHANGED
package/dist/module.js
CHANGED
@@ -19,7 +19,7 @@ let LoggerModule = LoggerModule_1 = class LoggerModule {
|
|
19
19
|
};
|
20
20
|
const cloudwatchProviders = {
|
21
21
|
provide: params.options,
|
22
|
-
useFactory: () => new cloudwatch_logger_1.CloudWatchLoggerService(params.region, params.logGroupName),
|
22
|
+
useFactory: () => new cloudwatch_logger_1.CloudWatchLoggerService(params.region, params.logGroupName, params.teamWebhoookUrl, params.isAlertNeeded),
|
23
23
|
};
|
24
24
|
return {
|
25
25
|
module: LoggerModule_1,
|
@@ -28,7 +28,7 @@ let LoggerModule = LoggerModule_1 = class LoggerModule {
|
|
28
28
|
};
|
29
29
|
}
|
30
30
|
};
|
31
|
-
LoggerModule =
|
31
|
+
exports.LoggerModule = LoggerModule;
|
32
|
+
exports.LoggerModule = LoggerModule = LoggerModule_1 = __decorate([
|
32
33
|
(0, common_1.Module)({})
|
33
34
|
], LoggerModule);
|
34
|
-
exports.LoggerModule = LoggerModule;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@gus-eip/loggers",
|
3
|
-
"version": "3.
|
3
|
+
"version": "3.4.0",
|
4
4
|
"description": "@gus-eip/loggers is a package designed to provide logging functionality for your Node.js applications.",
|
5
5
|
"author": "gus",
|
6
6
|
"readmeFilename": "README.md",
|
@@ -31,7 +31,8 @@
|
|
31
31
|
"access": "public"
|
32
32
|
},
|
33
33
|
"dependencies": {
|
34
|
-
"aws-sdk": "^2.1590.0"
|
34
|
+
"aws-sdk": "^2.1590.0",
|
35
|
+
"axios": "^1.7.4"
|
35
36
|
},
|
36
37
|
"devDependencies": {
|
37
38
|
"@nestjs/common": "^10.0.2",
|
@@ -40,6 +41,7 @@
|
|
40
41
|
"@nestjs/testing": "10.0.2",
|
41
42
|
"@types/express": "4.17.17",
|
42
43
|
"@types/jest": "29.5.2",
|
44
|
+
"@types/lodash": "^4.17.7",
|
43
45
|
"@types/node": "20.3.1",
|
44
46
|
"@types/supertest": "2.0.12",
|
45
47
|
"@typescript-eslint/eslint-plugin": "^5.60.0",
|
@@ -57,7 +59,7 @@
|
|
57
59
|
"tsc-watch": "6.0.4",
|
58
60
|
"tsconfig-paths": "4.2.0",
|
59
61
|
"tslint": "5.20.1",
|
60
|
-
"typescript": "5.
|
62
|
+
"typescript": "^5.5.4"
|
61
63
|
},
|
62
64
|
"jest": {
|
63
65
|
"moduleFileExtensions": [
|