Skip to content

Commit 802c17d

Browse files
committed
doc(apm): document apm events that are emitted from topologies
NODE-1390
1 parent ad1d7d2 commit 802c17d

File tree

7 files changed

+108
-40
lines changed

7 files changed

+108
-40
lines changed

index.js

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ connect.instrument = function(options, callback) {
5555
options = {};
5656
}
5757

58-
// return new Instrumentation(core, options, callback);
5958
const instrumentation = new Instrumentation();
6059
instrumentation.instrument(connect.MongoClient, callback);
6160
return instrumentation;

lib/apm.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Instrumentation extends EventEmitter {
1313

1414
const instrumentation = this;
1515
MongoClient.prototype.connect = function(callback) {
16-
this.s.options.enableCommandMonitoring = true;
16+
this.s.options.monitorCommands = true;
1717
this.on('commandStarted', event => instrumentation.emit('started', event));
1818
this.on('commandSucceeded', event => instrumentation.emit('succeeded', event));
1919
this.on('commandFailed', event => instrumentation.emit('failed', event));

lib/mongo_client.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ var validOptionNames = [
107107
'numberOfRetries',
108108
'auto_reconnect',
109109
'minSize',
110-
'enableCommandMonitoring'
110+
'monitorCommands'
111111
];
112112

113113
var ignoreOptionNames = ['native_parser'];
@@ -200,7 +200,7 @@ function validOptions(options) {
200200
* @param {array} [options.readPreferenceTags=null] Read preference tags
201201
* @param {number} [options.numberOfRetries=5] The number of retries for a tailable cursor
202202
* @param {boolean} [options.auto_reconnect=true] Enable auto reconnecting for single server instances
203-
* @param {boolean} [options.enableCommandMonitoring=false] Enable command monitoring for this client
203+
* @param {boolean} [options.monitorCommands=false] Enable command monitoring for this client
204204
* @param {MongoClient~connectCallback} [callback] The command result callback
205205
* @return {MongoClient} a MongoClient instance
206206
*/

lib/topologies/mongos.js

+28-5
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ var legalOptionNames = [
5959
'promoteValues',
6060
'promoteBuffers',
6161
'promiseLibrary',
62-
'enableCommandMonitoring'
62+
'monitorCommands'
6363
];
6464

6565
/**
@@ -90,6 +90,7 @@ var legalOptionNames = [
9090
* @param {number} [options.socketOptions.connectTimeoutMS=0] TCP Connection timeout setting
9191
* @param {number} [options.socketOptions.socketTimeoutMS=0] TCP Socket timeout setting
9292
* @param {boolean} [options.domainsEnabled=false] Enable the wrapping of the callback in the current domain, disabled by default to avoid perf hit.
93+
* @param {boolean} [options.monitorCommands=false] Enable command monitoring for this topology
9394
* @fires Mongos#connect
9495
* @fires Mongos#ha
9596
* @fires Mongos#joined
@@ -100,6 +101,9 @@ var legalOptionNames = [
100101
* @fires Mongos#error
101102
* @fires Mongos#timeout
102103
* @fires Mongos#parseError
104+
* @fires Mongos#commandStarted
105+
* @fires Mongos#commandSucceeded
106+
* @fires Mongos#commandFailed
103107
* @property {string} parserType the parser type used (c++ or js).
104108
* @return {Mongos} a Mongos instance.
105109
*/
@@ -151,10 +155,8 @@ class Mongos extends TopologyBase {
151155
reconnect: reconnect,
152156
emitError: typeof options.emitError === 'boolean' ? options.emitError : true,
153157
size: typeof options.poolSize === 'number' ? options.poolSize : 5,
154-
enableCommandMonitoring:
155-
typeof options.enableCommandMonitoring === 'boolean'
156-
? options.enableCommandMonitoring
157-
: false
158+
monitorCommands:
159+
typeof options.monitorCommands === 'boolean' ? options.monitorCommands : false
158160
}
159161
);
160162

@@ -454,4 +456,25 @@ define.classMethod('connections', { callback: false, promise: false, returns: [A
454456
* @type {object}
455457
*/
456458

459+
/**
460+
* An event emitted indicating a command was started, if command monitoring is enabled
461+
*
462+
* @event Mongos#commandStarted
463+
* @type {object}
464+
*/
465+
466+
/**
467+
* An event emitted indicating a command succeeded, if command monitoring is enabled
468+
*
469+
* @event Mongos#commandSucceeded
470+
* @type {object}
471+
*/
472+
473+
/**
474+
* An event emitted indicating a command failed, if command monitoring is enabled
475+
*
476+
* @event Mongos#commandFailed
477+
* @type {object}
478+
*/
479+
457480
module.exports = Mongos;

lib/topologies/replset.js

+28-5
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ var legalOptionNames = [
6767
'maxStalenessSeconds',
6868
'promiseLibrary',
6969
'minSize',
70-
'enableCommandMonitoring'
70+
'monitorCommands'
7171
];
7272

7373
/**
@@ -101,6 +101,7 @@ var legalOptionNames = [
101101
* @param {number} [options.socketOptions.socketTimeoutMS=0] TCP Socket timeout setting
102102
* @param {boolean} [options.domainsEnabled=false] Enable the wrapping of the callback in the current domain, disabled by default to avoid perf hit.
103103
* @param {number} [options.maxStalenessSeconds=undefined] The max staleness to secondary reads (values under 10 seconds cannot be guaranteed);
104+
* @param {boolean} [options.monitorCommands=false] Enable command monitoring for this topology
104105
* @fires ReplSet#connect
105106
* @fires ReplSet#ha
106107
* @fires ReplSet#joined
@@ -111,6 +112,9 @@ var legalOptionNames = [
111112
* @fires ReplSet#error
112113
* @fires ReplSet#timeout
113114
* @fires ReplSet#parseError
115+
* @fires ReplSet#commandStarted
116+
* @fires ReplSet#commandSucceeded
117+
* @fires ReplSet#commandFailed
114118
* @property {string} parserType the parser type used (c++ or js).
115119
* @return {ReplSet} a ReplSet instance.
116120
*/
@@ -158,10 +162,8 @@ class ReplSet extends TopologyBase {
158162
reconnect: false,
159163
emitError: typeof options.emitError === 'boolean' ? options.emitError : true,
160164
size: typeof options.poolSize === 'number' ? options.poolSize : 5,
161-
enableCommandMonitoring:
162-
typeof options.enableCommandMonitoring === 'boolean'
163-
? options.enableCommandMonitoring
164-
: false
165+
monitorCommands:
166+
typeof options.monitorCommands === 'boolean' ? options.monitorCommands : false
165167
}
166168
);
167169

@@ -498,4 +500,25 @@ define.classMethod('connections', { callback: false, promise: false, returns: [A
498500
* @type {object}
499501
*/
500502

503+
/**
504+
* An event emitted indicating a command was started, if command monitoring is enabled
505+
*
506+
* @event ReplSet#commandStarted
507+
* @type {object}
508+
*/
509+
510+
/**
511+
* An event emitted indicating a command succeeded, if command monitoring is enabled
512+
*
513+
* @event ReplSet#commandSucceeded
514+
* @type {object}
515+
*/
516+
517+
/**
518+
* An event emitted indicating a command failed, if command monitoring is enabled
519+
*
520+
* @event ReplSet#commandFailed
521+
* @type {object}
522+
*/
523+
501524
module.exports = ReplSet;

lib/topologies/server.js

+28-5
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ var legalOptionNames = [
6262
'promoteBuffers',
6363
'compression',
6464
'promiseLibrary',
65-
'enableCommandMonitoring'
65+
'monitorCommands'
6666
];
6767

6868
/**
@@ -96,12 +96,16 @@ var legalOptionNames = [
9696
* @param {number} [options.monitoring=true] Triggers the server instance to call ismaster
9797
* @param {number} [options.haInterval=10000] The interval of calling ismaster when monitoring is enabled.
9898
* @param {boolean} [options.domainsEnabled=false] Enable the wrapping of the callback in the current domain, disabled by default to avoid perf hit.
99+
* @param {boolean} [options.monitorCommands=false] Enable command monitoring for this topology
99100
* @fires Server#connect
100101
* @fires Server#close
101102
* @fires Server#error
102103
* @fires Server#timeout
103104
* @fires Server#parseError
104105
* @fires Server#reconnect
106+
* @fires Server#commandStarted
107+
* @fires Server#commandSucceeded
108+
* @fires Server#commandFailed
105109
* @property {string} parserType the parser type used (c++ or js).
106110
* @return {Server} a Server instance.
107111
*/
@@ -151,10 +155,8 @@ class Server extends TopologyBase {
151155
reconnect: reconnect,
152156
emitError: typeof options.emitError === 'boolean' ? options.emitError : true,
153157
size: typeof options.poolSize === 'number' ? options.poolSize : 5,
154-
enableCommandMonitoring:
155-
typeof options.enableCommandMonitoring === 'boolean'
156-
? options.enableCommandMonitoring
157-
: false
158+
monitorCommands:
159+
typeof options.monitorCommands === 'boolean' ? options.monitorCommands : false
158160
}
159161
);
160162

@@ -458,4 +460,25 @@ define.classMethod('connections', { callback: false, promise: false, returns: [A
458460
* @type {object}
459461
*/
460462

463+
/**
464+
* An event emitted indicating a command was started, if command monitoring is enabled
465+
*
466+
* @event Server#commandStarted
467+
* @type {object}
468+
*/
469+
470+
/**
471+
* An event emitted indicating a command succeeded, if command monitoring is enabled
472+
*
473+
* @event Server#commandSucceeded
474+
* @type {object}
475+
*/
476+
477+
/**
478+
* An event emitted indicating a command failed, if command monitoring is enabled
479+
*
480+
* @event Server#commandFailed
481+
* @type {object}
482+
*/
483+
461484
module.exports = Server;

0 commit comments

Comments
 (0)