@@ -4,82 +4,82 @@ const emitter = require('../emitter')
44const requestIdMap = { }
55
66const onStart = ( event ) => {
7- // {
8- // address: '10.60.3.8:27017',
9- // connectionId: 2,
10- // requestId: 5,
11- // databaseName: 'user_profiler',
12- // commandName: 'createIndexes',
13- // command: {
14- // createIndexes: 'reasons',
15- // indexes: [ [Object] ],
16- // lsid: { id: [Binary] },
17- // '$db': 'user_profiler'
18- // }
19- // }
20- const {
21- databaseName,
22- commandName,
23- command,
24- requestId
25- } = event ;
26- const {
27- filter = { } ,
28- projection = { } ,
7+ // {
8+ // address: '10.60.3.8:27017',
9+ // connectionId: 2,
10+ // requestId: 5,
11+ // databaseName: 'user_profiler',
12+ // commandName: 'createIndexes',
13+ // command: {
14+ // createIndexes: 'reasons',
15+ // indexes: [ [Object] ],
16+ // lsid: { id: [Binary] },
17+ // '$db': 'user_profiler'
18+ // }
19+ // }
20+ const {
21+ databaseName,
22+ commandName,
23+ command,
24+ requestId
25+ } = event ;
26+ const {
27+ filter = { } ,
28+ projection = { } ,
29+ limit,
30+ query = { }
31+ } = command
32+ const collection = command [ commandName ]
33+ const operation_name = `${ databaseName } .${ collection } .${ commandName } `
34+ // set operation name
35+ requestIdMap [ requestId ] = `${ databaseName } .${ collection } .${ commandName } `
36+ if ( ! operation_name . includes ( 'Index' ) ) {
37+ emitter . emit ( 'mongodb' , {
38+ db_type : 'mongodb' ,
39+ operation_name,
40+ data : {
41+ filter,
42+ projection,
2943 limit,
30- query = { }
31- } = command
32- const collection = command [ commandName ]
33- const operation_name = `${ databaseName } .${ collection } .${ commandName } `
34- // set operation name
35- requestIdMap [ requestId ] = `${ databaseName } .${ collection } .${ commandName } `
36- if ( ! operation_name . includes ( 'Index' ) ) {
37- emitter . emit ( 'mongodb' , {
38- db_type : 'mongodb' ,
39- operation_name,
40- data : {
41- filter,
42- projection,
43- limit,
44- query,
45- }
46- } )
47- }
44+ query,
45+ }
46+ } )
47+ }
4848}
4949
5050const onEnd = ( event ) => {
51- const {
52- requestId,
53- reply = { } ,
54- duration = 0
55- } = event ;
56- const {
57- cursor = { } ,
58- value = { }
59- } = reply
60- const operation_name = requestIdMap [ requestId ] + ` _response`
61- const firstBatch = cursor ?. firstBatch || [ ]
62- if ( ! operation_name . includes ( 'Index' ) ) {
63- emitter . emit ( 'mongodb' , {
64- db_type : 'mongodb' ,
65- operation_name,
66- data : {
67- command_duration_ms : duration ,
68- write_operation_response : value ,
69- read_operation_response : firstBatch
70- }
71- } )
72- }
73- delete requestIdMap [ requestId ]
51+ const {
52+ requestId,
53+ reply = { } ,
54+ duration = 0
55+ } = event ;
56+ const {
57+ cursor = { } ,
58+ value = { }
59+ } = reply
60+ const operation_name = requestIdMap [ requestId ] + ' _response'
61+ const firstBatch = cursor ?. firstBatch || [ ]
62+ if ( ! operation_name . includes ( 'Index' ) ) {
63+ emitter . emit ( 'mongodb' , {
64+ db_type : 'mongodb' ,
65+ operation_name,
66+ data : {
67+ command_duration_ms : duration ,
68+ write_operation_response : value ,
69+ read_operation_response : firstBatch
70+ }
71+ } )
72+ }
73+ delete requestIdMap [ requestId ]
7474}
7575
7676const start = ( ) => {
77- const path = process . cwd ( )
78- const listener = require ( path + '/node_modules/mongodb' ) . instrument ( )
79- listener . on ( " started" , onStart )
80- listener . on ( " succeeded" , onEnd )
77+ const path = process . cwd ( )
78+ const listener = require ( path + '/node_modules/mongodb' ) . instrument ( )
79+ listener . on ( ' started' , onStart )
80+ listener . on ( ' succeeded' , onEnd )
8181}
8282
8383module . exports = {
84- start
84+ start
8585}
0 commit comments