@munlib/common 1.0.147 → 1.0.149
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.
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
declare const apmInstance:
|
|
2
|
-
|
|
1
|
+
declare const apmInstance: any;
|
|
2
|
+
declare const loggerAPM: any;
|
|
3
|
+
export { apmInstance, loggerAPM };
|
package/build/middlewares/apm.js
CHANGED
|
@@ -1,12 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.apmInstance = void 0;
|
|
3
|
+
exports.loggerAPM = exports.apmInstance = void 0;
|
|
4
4
|
var apm = require('elastic-apm-node');
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
var winston = require('winston');
|
|
6
|
+
var ElasticsearchTransport = require('winston-elasticsearch').ElasticsearchTransport;
|
|
7
|
+
// Inicializa el APM
|
|
8
|
+
var apmInstance = apm.start({
|
|
9
|
+
serviceName: process.env.ELK_SERVICE_NAME || 'MUNICIPIO_OBSERVABILIDAD',
|
|
10
|
+
apiKey: process.env.ELK_API_KEY,
|
|
11
|
+
serverUrl: process.env.ELK_SERVER_URL,
|
|
12
|
+
environment: process.env.ELK_ENVIRONMENT || 'DEV',
|
|
13
|
+
logLevel: 'error',
|
|
14
|
+
});
|
|
12
15
|
exports.apmInstance = apmInstance;
|
|
16
|
+
// Configura el transport para Elasticsearch
|
|
17
|
+
var esTransport = new ElasticsearchTransport({
|
|
18
|
+
level: 'info',
|
|
19
|
+
clientOpts: {
|
|
20
|
+
node: process.env.ELK_SERVER_URL,
|
|
21
|
+
auth: {
|
|
22
|
+
apiKey: process.env.ELK_API_KEY, // Si es necesario
|
|
23
|
+
},
|
|
24
|
+
ssl: {
|
|
25
|
+
rejectUnauthorized: false, // Cambia a true si es necesario
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
// Configura el logger
|
|
30
|
+
var loggerAPM = winston.createLogger({
|
|
31
|
+
level: 'info',
|
|
32
|
+
format: winston.format.json(),
|
|
33
|
+
transports: [
|
|
34
|
+
esTransport,
|
|
35
|
+
new winston.transports.Console(),
|
|
36
|
+
],
|
|
37
|
+
});
|
|
38
|
+
exports.loggerAPM = loggerAPM;
|
|
39
|
+
// Captura errores y envíalos al APM
|
|
40
|
+
loggerAPM.on('error', function (error) {
|
|
41
|
+
apm.captureError(error); // Envía el error al APM
|
|
42
|
+
});
|
|
43
|
+
// Captura logs y envíalos al APM
|
|
44
|
+
loggerAPM.on('data', function (log) {
|
|
45
|
+
apm.captureError(log); // Captura el log en APM
|
|
46
|
+
});
|