11'use strict'
2- const { stringify } = require ( "flatted/cjs" ) ;
3- const opentracing = require ( "opentracing" ) ;
4- const context = require ( '../context' )
5- const helper = require ( '../helper' )
62
3+ const emitter = require ( '../emitter' )
74const requestIdMap = { }
85
9- const onStart = ( event ) => {
10- const {
11- databaseName,
12- commandName,
13- command,
14- requestId
15- } = event ;
16- const {
17- filter= { } ,
18- projection= { } ,
19- limit,
20- query= { }
21- } = command
22- const collection = command [ commandName ]
23- const operation_name = `${ databaseName } .${ collection } .${ commandName } `
24- // set operation name
25- requestIdMap [ requestId ] = `${ databaseName } .${ collection } .${ commandName } `
26- emitter . emit ( 'mongodb' , 'mongodb' , operation_name , {
27- filter= { } ,
28- projection= { } ,
29- limit,
30- query= { }
31- } )
6+ const onStart = ( event ) => {
327 // {
338 // address: '10.60.3.8:27017',
349 // connectionId: 2,
@@ -42,68 +17,67 @@ const onStart = (event)=>{
4217 // '$db': 'user_profiler'
4318 // }
4419 // }
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,
43+ limit,
44+ query,
45+ }
46+ } )
47+ }
4548}
4649
47- const onEnd = ( event ) => {
50+ const onEnd = ( event ) => {
4851 const {
4952 requestId,
50- reply= { } ,
51- duration= 0
52- } = event ;
53+ reply = { } ,
54+ duration = 0
55+ } = event ;
5356 const {
54- cursor= { } ,
55- value= { }
57+ cursor = { } ,
58+ value = { }
5659 } = reply
57- const operation_name = requestIdMap [ requestId ] + `_response`
58- const firstBatch = cursor ?. firstBatch || [ ]
59- emitter . emit ( 'mongodb' , 'mongodb' , operation_name , {
60- command_duration_ms : duration ,
61- write_operation_response : value ,
62- read_operation_response : firstBatch
63- } )
64-
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+ }
6573 delete requestIdMap [ requestId ]
66-
67- // {
68- // address: '10.60.3.8:27017',
69- // connectionId: 2,
70- // requestId: 3,
71- // commandName: 'find',
72- // duration: 16,
73- // reply: {
74- // cursor: { firstBatch: [Array], id: 0, ns: 'user_profiler.reasons' },
75- // ok: 1
76- // }
77- // }
78-
79- // {
80- // address: '10.60.3.8:27017',
81- // connectionId: 1,
82- // requestId: 6,
83- // commandName: 'findAndModify',
84- // duration: 11,
85- // reply: {
86- // lastErrorObject: { n: 1, updatedExisting: true },
87- // value: {
88- // _id: 60caf63a9d634c2eb2a8b2ed,
89- // is_deleted: false,
90- // name: 'abccc',
91- // created_at: 2021-06-17T07:14:02.702Z,
92- // updated_at: 2021-06-17T07:27:40.084Z,
93- // __v: 0
94- // },
95- // ok: 1
96- // }
97- // }
98-
9974}
10075
101- const start = ( ) => {
76+ const start = ( ) => {
10277 const path = process . cwd ( )
103- const listener = require ( path + '/node_modules/mongodb' ) . instrument ( )
78+ const listener = require ( path + '/node_modules/mongodb' ) . instrument ( )
10479 listener . on ( "started" , onStart )
10580 listener . on ( "succeeded" , onEnd )
106- // listener.on("failed", onEnd)
10781}
10882
10983module . exports = {
0 commit comments