appdynamics
Version:
Performance Profiler and Monitor
72 lines (58 loc) • 2.08 kB
JavaScript
exports.TediousProbe = TediousProbe;
function TediousProbe(agent) {
this.agent = agent;
this.packages = ['tedious'];
}
TediousProbe.prototype.init = function () {};
TediousProbe.prototype.attach = function (obj) {
if(obj.__appdynamicsProbeAttached__) return;
obj.__appdynamicsProbeAttached__ = true;
if(process.env.APPDYNAMICS_TEDIOUS_PROBE_DISABLE == true || process.env.APPDYNAMICS_TEDIOUS_PROBE_DISABLE == 'true') {
return;
}
let self = this;
self.agent.on('destroy', function() {
if(obj.__appdynamicsProbeAttached__) {
delete obj.__appdynamicsProbeAttached__;
proxy.release(obj.Connection.prototype.execSql);
}
});
let proxy = self.agent.proxy;
let profiler = self.agent.profiler;
proxy.before(obj.Connection.prototype, 'execSql',
function before(obj, args) {
if(self.agent.context.get('mssql_interceptor_active')) {
self.agent.logger.trace('Mssql probe active, skipping Tedious probe');
return;
}
if(!args || !args[0]) return;
let exitCall = self.createExitCall(obj.config, args[0].sqlTextOrProcedure, args[0].params);
proxy.before(args[0], 'callback', function(obj, args) {
var err = proxy.getErrorObject(args);
if (!exitCall) return;
if (!profiler.time().done()) return;
profiler.addExitCall(profiler.time, exitCall, err);
});
});
};
TediousProbe.prototype.createExitCall = function(config, command, params) {
var self = this;
var agent = self.agent;
var profiler = agent.profiler;
var supportedProperties = {
'HOST': config.host || config.server || 'localhost',
'PORT': config.options.port && config.options.port.toString() || '1433',
'DATABASE': config.options.database,
'VENDOR': 'Tedious'
};
//console.log(supportedProperties);
var trace = profiler.stackTrace();
return profiler.createExitCall(profiler.time(), {
exitType: 'EXIT_DB',
supportedProperties: supportedProperties,
command: profiler.sanitize(command),
commandArgs: profiler.sanitize(params),
stackTrace: trace,
isSql: true
});
};