@@ -20,17 +20,19 @@ var util = require('util');
2020var am = require ( '../' ) ;
2121
2222function MongoProbe ( ) {
23- Probe . call ( this , 'mongodb' ) ;
23+ Probe . call ( this , 'mongodb' ) ;
2424}
2525util . inherits ( MongoProbe , Probe ) ;
2626
2727MongoProbe . prototype . aspectCollectionMethod = function ( coll , method ) {
28- var that = this ;
28+ var that = this ;
2929 var req ;
3030 aspect . around ( coll , method ,
3131 function ( target , methodName , methodArgs , probeData ) {
32- that . metricsProbeStart ( probeData , target , method , methodArgs ) ;
33- that . requestProbeStart ( probeData , target , method , methodArgs ) ;
32+ var collectionName = target . collectionName ;
33+
34+ that . metricsProbeStart ( probeData , target , method , methodArgs ) ;
35+ that . requestProbeStart ( probeData , target , method , methodArgs ) ;
3436 if ( aspect . findCallbackArg ( methodArgs ) != undefined ) {
3537 aspect . aroundCallback ( methodArgs , probeData , function ( target , args , probeData ) {
3638
@@ -39,24 +41,26 @@ MongoProbe.prototype.aspectCollectionMethod = function(coll, method) {
3941 if ( typeof ( callbackPosition ) != 'undefined' ) {
4042 aspect . strongTraceTransactionLink ( 'mongodb: ' , methodName , methodArgs [ callbackPosition ] ) ;
4143 }
42-
43- that . metricsProbeEnd ( probeData , method , methodArgs ) ;
44- that . requestProbeEnd ( probeData , method , methodArgs ) ;
44+
45+ that . metricsProbeEnd ( probeData , collectionName , method , methodArgs ) ;
46+ that . requestProbeEnd ( probeData , method , methodArgs ) ;
4547 } ) ;
4648 }
47- } ,
49+ } ,
4850 function ( target , methodName , methodArgs , probeData , rc ) {
51+ var collectionName = target . collectionName ;
52+
4953 if ( aspect . findCallbackArg ( methodArgs ) == undefined ) {
50- that . metricsProbeEnd ( probeData , method , methodArgs ) ;
51- that . requestProbeEnd ( probeData , method , methodArgs ) ;
54+ that . metricsProbeEnd ( probeData , collectionName , method , methodArgs ) ;
55+ that . requestProbeEnd ( probeData , method , methodArgs ) ;
5256 }
5357 return rc ;
54- }
58+ }
5559 ) ;
5660}
5761
5862MongoProbe . prototype . attach = function ( name , target ) {
59- var that = this ;
63+ var that = this ;
6064 if ( name != "mongodb" ) return target ;
6165 if ( target . __ddProbeAttached__ ) return target ;
6266 target . __ddProbeAttached__ = true ;
@@ -65,18 +69,20 @@ MongoProbe.prototype.attach = function(name, target) {
6569 var method = 'find' ;
6670 aspect . around ( coll , "find" ,
6771 function ( target , methodName , methodArgs , probeData ) {
68- that . metricsProbeStart ( probeData , target , method , methodArgs ) ;
69- that . requestProbeStart ( probeData , target , method , methodArgs ) ;
70- } ,
72+ that . metricsProbeStart ( probeData , target , method , methodArgs ) ;
73+ that . requestProbeStart ( probeData , target , method , methodArgs ) ;
74+ } ,
7175 function ( target , methodName , findArgs , probeData , rc ) {
76+ var collectionName = target . collectionName ;
77+
7278 if ( rc == undefined ) {
73- that . metricsProbeEnd ( probeData , method , findArgs ) ;
74- that . requestProbeEnd ( probeData , method , findArgs ) ;
79+ that . metricsProbeEnd ( probeData , collectionName , method , findArgs ) ;
80+ that . requestProbeEnd ( probeData , method , findArgs ) ;
7581 } else {
7682 aspect . before ( rc , "toArray" , function ( target , methodName , args , context ) {
7783 aspect . aroundCallback ( args , probeData , function ( target , args , probeData ) {
78- that . metricsProbeEnd ( probeData , method , findArgs ) ;
79- that . requestProbeEnd ( probeData , method , findArgs ) ;
84+ that . metricsProbeEnd ( probeData , collectionName , method , findArgs ) ;
85+ that . requestProbeEnd ( probeData , method , findArgs ) ;
8086 } ) ;
8187 } ) ;
8288 }
@@ -101,24 +107,27 @@ MongoProbe.prototype.attach = function(name, target) {
101107 * Lightweight metrics probe for MongoDB queries
102108 *
103109 * These provide:
104- * time: time event started
105- * query: the query itself
106- * duration: the time for the request to respond
110+ * time: time event started
111+ * query: the query itself
112+ * duration: the time for the request to respond
113+ * method: the executed method for the query, such as find, update
114+ * collection: the mongo collection
107115 */
108- MongoProbe . prototype . metricsEnd = function ( probeData , method , methodArgs ) {
109- probeData . timer . stop ( ) ;
110- am . emit ( 'mongo' , { time : probeData . timer . startTimeMillis , query : JSON . stringify ( methodArgs [ 0 ] ) , duration : probeData . timer . timeDelta } ) ;
116+ MongoProbe . prototype . metricsEnd = function ( probeData , collectionName , method , methodArgs ) {
117+ probeData . timer . stop ( ) ;
118+ am . emit ( 'mongo' , { time : probeData . timer . startTimeMillis , query : JSON . stringify ( methodArgs [ 0 ] ) , duration : probeData . timer . timeDelta ,
119+ method : method , collection : collectionName } ) ;
111120} ;
112121
113122/*
114123 * Heavyweight request probes for MongoDB queries
115124 */
116125MongoProbe . prototype . requestStart = function ( probeData , target , method , methodArgs ) {
117- probeData . req = request . startRequest ( 'DB' , method + "(" + target . collectionName + ")" , false , probeData . timer ) ;
126+ probeData . req = request . startRequest ( 'DB' , method + "(" + target . collectionName + ")" , false , probeData . timer ) ;
118127} ;
119128
120129MongoProbe . prototype . requestEnd = function ( probeData , method , methodArgs ) {
121- probeData . req . stop ( { query : JSON . stringify ( methodArgs [ 0 ] ) } ) ;
130+ probeData . req . stop ( { query : JSON . stringify ( methodArgs [ 0 ] ) } ) ;
122131} ;
123132
124- module . exports = MongoProbe ;
133+ module . exports = MongoProbe ;
0 commit comments