File tree 6 files changed +65
-3
lines changed
6 files changed +65
-3
lines changed Original file line number Diff line number Diff line change @@ -4,4 +4,16 @@ STORAGE_LOCATION=files
4
4
SYSTEM_SHUTDOWN_DELAY = 0
5
5
MONGODB_URL = ' mongodb://localhost:27017/example?maxPoolSize=10&socketTimeoutMS=10000&connectTimeoutMS=10000&useUnifiedTopology=true'
6
6
AUTH_BASIC_USERNAME =
7
- AUTH_BASIC_PASSWORD =
7
+ AUTH_BASIC_PASSWORD =
8
+
9
+ LOGSTASH_IS_ENABLE = false
10
+ LOGSTASH_BASE_URL =
11
+ LOGSTASH_PORT_URL =
12
+ LOGSTASH_SSL_ENABLE =
13
+ LOGSTASH_MAX_CONNECT_RETRIES =
14
+
15
+ ELASTIC_APM_IS_ENABLE = false
16
+ ELASTIC_APM_SERVER_URL =
17
+ ELASTIC_APM_SECRET_TOKEN =
18
+ ELASTIC_APM_API_KEY =
19
+ ELASTIC_APM_OPTIONS = ' {}'
Original file line number Diff line number Diff line change 1
1
const project = require ( '../../package.json' ) ;
2
2
const configs = require ( '../helpers/configs/global_config' ) ;
3
+ const apm = require ( '../helpers/components/elastic-apm/apm' ) ;
3
4
const { GracefulShutdown, livenessProbe, readinessProbe } = require ( '../helpers/components/system/graceful_shutdown' ) ;
4
5
const observers = require ( './observers' ) ;
5
6
const multer = require ( "multer" ) ;
@@ -37,7 +38,10 @@ class AppServer {
37
38
async init ( ) {
38
39
// Initiation
39
40
try {
40
- await Promise . all ( [ observers . init ( ) ] ) ;
41
+ await Promise . all ( [
42
+ observers . init ( ) ,
43
+ apm . init ( )
44
+ ] ) ;
41
45
42
46
const gs = new GracefulShutdown ( configs . get ( '/system/shutdownDelay' ) ) ;
43
47
gs . enable ( this . server ) ;
Original file line number Diff line number Diff line change
1
+ const apm = require ( 'elastic-apm-node' ) ;
2
+ const project = require ( '../../../../package.json' ) ;
3
+ const configs = require ( '../../../infra/configs/global_config' ) ;
4
+
5
+ const init = ( ) => {
6
+ if ( configs . get ( '/elasticApm/isEnable' ) ) {
7
+ const options = {
8
+ serviceName : project . name ,
9
+ serviceVersion : project . version ,
10
+ serverUrl : configs . get ( '/elasticApm/serverUrl' ) ,
11
+ secretToken : configs . get ( '/elasticApm/secretToken' ) ,
12
+ apiKey : configs . get ( '/elasticApm/apiKey' ) ,
13
+ } ;
14
+ options = { ...options , ...configs . get ( '/elasticApm/options' ) } ;
15
+ apm . start ( options ) ;
16
+ }
17
+ } ;
18
+
19
+ module . exports = {
20
+ init
21
+ } ;
Original file line number Diff line number Diff line change @@ -19,6 +19,20 @@ const config = {
19
19
mongodb : {
20
20
url : process . env . MONGODB_URL ,
21
21
} ,
22
+ logstash : {
23
+ isEnable : process . env . LOGSTASH_IS_ENABLE === 'true' ,
24
+ host : process . env . LOGSTASH_BASE_URL ,
25
+ port : process . env . LOGSTASH_PORT_URL ,
26
+ ssl_enable : process . env . LOGSTASH_SSL_ENABLE === 'true' ,
27
+ max_connect_retries : process . env . LOGSTASH_MAX_CONNECT_RETRIES ,
28
+ } ,
29
+ elasticApm : {
30
+ isEnable : process . env . ELASTIC_APM_IS_ENABLE === 'true' ,
31
+ serverUrl : process . env . ELASTIC_APM_SERVER_URL ,
32
+ secretToken : process . env . ELASTIC_APM_SECRET_TOKEN ,
33
+ apiKey : process . env . ELASTIC_APM_API_KEY ,
34
+ options : ( process . env . ELASTIC_APM_OPTIONS ? JSON . parse ( process . env . ELASTIC_APM_OPTIONS ) : { } ) ,
35
+ } ,
22
36
} ;
23
37
24
38
const store = new confidence . Store ( config ) ;
Original file line number Diff line number Diff line change
1
+ const project = require ( '../../../package.json' ) ;
1
2
const winston = require ( 'winston' ) ;
2
3
3
4
let transports = [
@@ -10,6 +11,14 @@ let transports = [
10
11
} ) ,
11
12
] ;
12
13
14
+ if ( config . get ( '/logstash/isEnable' ) ) {
15
+ const logstashConfig = config . get ( '/logstash' ) ;
16
+ logstashConfig . node_name = project . name ;
17
+ transports . push (
18
+ new winston . transports . Logstash ( logstashConfig )
19
+ ) ;
20
+ }
21
+
13
22
let logger = winston . createLogger ( {
14
23
transports : transports ,
15
24
exitOnError : false
Original file line number Diff line number Diff line change 15
15
"body-parser" : " ^1.20.2" ,
16
16
"confidence" : " ^5.0.1" ,
17
17
"dotenv" : " ^16.4.0" ,
18
+ "elastic-apm-node" : " ^4.4.0" ,
18
19
"express" : " ^4.18.2" ,
19
20
"http-errors" : " ^2.0.0" ,
20
21
"http-status-codes" : " ^2.3.0" ,
27
28
"passport-http" : " ^0.3.0" ,
28
29
"uuid" : " ^9.0.1" ,
29
30
"validate.js" : " ^0.13.1" ,
30
- "winston" : " ^3.11.0"
31
+ "winston" : " ^3.11.0" ,
32
+ "winston-logstash" : " ^1.2.1"
31
33
}
32
34
}
You can’t perform that action at this time.
0 commit comments