UNPKG

appdynamics

Version:

Performance Profiler and Monitor

77 lines (63 loc) 2.13 kB
/* Copyright (c) AppDynamics, Inc., and its affiliates 2015 All Rights Reserved */ 'use strict'; var RabbitMQEntryProbe = require('./rabbitmq-entry-probe').RabbitMQEntryProbe; var RabbitMQExitProbe = require('./rabbitmq-exit-probe').RabbitMQExitProbe; function RabbitMQProbe(agent) { this.agent = agent; this.packages = ['amqplib/lib/connect', 'amqplib/lib/callback_model', 'amqplib/lib/channel_model']; this.packageAttached = {}; this.entryProbe = new RabbitMQEntryProbe(agent); this.exitProbe = new RabbitMQExitProbe(agent); this.init(); } exports.RabbitMQProbe = RabbitMQProbe; RabbitMQProbe.prototype.init = function() { this.entryProbe.init(); this.exitProbe.init(); }; RabbitMQProbe.prototype.attach = function(obj, moduleName) { var self = this; if (!self.agent.opts.rabbitmqEnabled) return; if (self.packageAttached[moduleName]) { return; } self.packageAttached[moduleName] = obj; self.agent.on('destroy', function() { for (const [name, obj] of Object.entries(self.packageAttached)) { if(name && obj) { self.unwrapModule(name, obj); } } }); self.entryProbe.attach(obj, moduleName); self.exitProbe.attach(obj, moduleName); }; RabbitMQProbe.prototype.unwrapConnect = function(obj) { var self = this; var proxy = self.agent.proxy; proxy.release(obj.connect); }; RabbitMQProbe.prototype.unwrapChannel = function(obj) { var self = this; var proxy = self.agent.proxy; proxy.release(obj.Channel.prototype.publish); proxy.release(obj.Channel.prototype.consume); proxy.release(obj.Channel.prototype.ack); proxy.release(obj.Channel.prototype.nack); proxy.release(obj.Channel.prototype.ackAll); proxy.release(obj.Channel.prototype.emit); proxy.release(obj.Channel.prototype.reject); }; RabbitMQProbe.prototype.unwrapModule = function(moduleName, moduleExport) { var self = this; if(moduleName == 'amqplib/lib/connect') { self.unwrapConnect(moduleExport); } else if (moduleName == 'amqplib/lib/callback_model' || moduleName == 'amqplib/lib/channel_model') { self.unwrapChannel(moduleExport); } };