ca-apm-probe
Version:
CA APM Node.js Agent monitors real-time health and performance of Node.js applications
72 lines (62 loc) • 2.51 kB
JavaScript
/**
* Copyright (c) 2015 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.
*/
var agent = require('../agent');
var proxy = require('../proxy');
var extend = require('util')._extend;
var inspect = require('util').inspect;
var commands = {
readFile: 'readFile',
writeFile: 'writeFile',
};
module.exports = function(fs) {
function createPatcher(obj) {
return function patch(command) {
var _old = fs[command];
proxy.before(obj, command, function(obj, args, storage) {
var cmd = commands[command];
var path = ''
if (typeof args[0] === 'string') {
path = args[0];
}
//CA code start
var eventNameFormatted = 'fs.' + cmd;
var ctx = storage.get('ctx');
if (ctx != null) {
ctx = agent.asynchEventStart(ctx, eventNameFormatted, null);
storage.set('ctx', ctx);
}
// CA code end
proxy.callback(args, -1, function(obj, args, storage) {
//var errorObject = agent.checkAndSetErrorObject(args, 'FSError');
// CA code start
if (ctx != null) {
ctx = agent.asynchEventDone(ctx, eventNameFormatted, null);
//ctx = agent.asynchEventDone(ctx, eventNameFormatted, null, errorObject);
storage.set('ctx', ctx);
}
},
function(obj, args) {
if (ctx != null) agent.asynchEventFinish(ctx);
}); // CA code end
});
extend(fs[command], _old);
};
}
Object.keys(commands).forEach(createPatcher(fs));
//Object.keys(commands).forEach(createPatcher(fs.prototype));
};