ca-apm-probe
Version:
CA APM Node.js Agent monitors real-time health and performance of Node.js applications
66 lines (52 loc) • 2.63 kB
JavaScript
/**
* Copyright (c) 2016 CA. All rights reserved.
*
* This software and all information contained therein is confidential and proprietary and
* shall not be duplicated, used, disclosed or disseminated in any way except as authorized
* by the applicable license agreement, without the express written permission of CA. All
* authorized reproductions must be marked with this language.
*
* EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
* PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT WARRANTY
* OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL CA BE
* LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY LOSS OR DAMAGE, DIRECT OR
* INDIRECT, FROM THE USE OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, LOST
* PROFITS, BUSINESS INTERRUPTION, GOODWILL, OR LOST DATA, EVEN IF CA IS
* EXPRESSLY ADVISED OF SUCH LOSS OR DAMAGE.
*/
// probe for mongodb driver 2.1.*
;
var agent = require('../../../agent');
var proxy = require('../../../proxy');
var util = require('util');
var instrUtil = require("../../..//utils/instrument-util");
var logger = require("../../../logger.js");
var DEFAULT_HOST = 'default_host';
var DEFAULT_PORT = 'default_port';
var DEFAULT_SERVER_INFO = util.format('%s:%s', DEFAULT_HOST, DEFAULT_PORT);
var debug = true;
module.exports = function (mongodbCore) {
logger.info('Loading mongodb-core probe');
proxy.before(mongodbCore.Server.prototype, 'command', function caMongodbCoreServerBeforeHook(server, args, storage) {
var command = args[1] || {};
var ctx = storage.get('ctx');
var internalState = server.s;
if(command.cursor)
{
if (debug) {
logger.debug('cursor command is: %s', JSON.stringify(command));
}
}
if (ctx && internalState && command && (command.insert || command.update || command.delete)) {
if (debug) {
logger.debug('server picked for executing mongodb command is: %s', JSON.stringify(internalState.serverDetails));
}
// update context(ctx) with information about server which executed the command.
// ctx must be created by mongodb collection operation probe.
// since collection operation e.g. 'insertMany' and server command execution happens in sync
// we can assume we are updating correct ctx.
ctx.serverInfo = internalState.serverDetails ? internalState.serverDetails.name : DEFAULT_SERVER_INFO;
}
});
}