UNPKG

apminsight

Version:

monitor nodejs applications

158 lines (144 loc) 4.69 kB
const constants = require("./../../constants"); const utils = require("./../../util/utils"); var logger = require("./../../util/logger"); let remoteHost, remotePort = 1521; function getQuery(invoker, params, returnObj, tracker, asynOpnInfo) { let info = {}; let th; if (asynOpnInfo && asynOpnInfo.curTxn) { th = utils.getGenericThreshold(asynOpnInfo.curTxn.getUrl()); } else { th = apmInsightAgentInstance.getThreshold(); } if (th.isSqlCaptureEnabled() && params && params.length > 0) { let queryInfo = params[0]; if (typeof queryInfo === "string") { info.query = queryInfo; } } if (!remoteHost) { info.host = remoteHost; info.port = remotePort; } tracker.updateInfo(info); } function getDbMethodsInfo(invoker, params, returnObj, tracker, asynOpnInfo) { let info = {}; if (params && params.length > 0) { let dbName = params[0]; if (typeof dbName === "string") { info.object = dbName; } } if (!remoteHost) { info.host = remoteHost; info.port = remotePort; } tracker.updateInfo(info); } function getCollectionMethodsInfo(invoker, params, returnObj, tracker, asynOpnInfo) { let info = {}; if (!utils.isEmpty(invoker.name)) { info.object = invoker.name; } if (!remoteHost) { info.host = remoteHost; info.port = remotePort; } tracker.updateInfo(info); } function getRemoteHostAndPort(connectString) { try { // Validate the input connection string. if (utils.isNonEmptyString(connectString)) { logger.critical("Invalid connection string provided. "+connectString); } const simpleMatch = connectString.match(constants.oracleSimpleConnectStringRegex); if (simpleMatch) { remoteHost = simpleMatch[1]; if (utils.isTypeNumber(simpleMatch[2])) { remotePort = simpleMatch[2] } return; } const descriptionMatch = connectString.match(constants.oracleDescriptionConnectStringRegex); if (descriptionMatch) { remoteHost = descriptionMatch[1]; if (utils.isTypeNumber(descriptionMatch[2])) { remotePort = descriptionMatch[2]; } return; } } catch (error) { logger.error("error in getRemoteHostAndPort: " + error); } if (!remoteHost) { logger.critical("Invalid connection string format " + connectString); } } function wrapPool(actual) { return function () { let pool = actual.apply(this, arguments); const cnctString = arguments[0].connectString || arguments[0].connectionString; getRemoteHostAndPort(cnctString); return pool; } } const componentName = "ORACLEDB"; const moduleInfo = { functions: [ { functionName: ["createPool"], component: componentName, wrapper: wrapPool }, { functionName: [ "Connection.prototype.execute", "Connection.prototype.executeMany" ], component: componentName, extractInfo: getQuery, trackerType: constants.dbTracker }, { functionName: [ "SodaDatabase.prototype.getCollectionNames", "SodaDatabase.prototype.createDocument", "SodaCollection.prototype.find", "SodaCollection.prototype.drop" ], component: componentName }, { functionName: [ "SodaCollection.prototype.dropIndex", "SodaCollection.prototype.createIndex", "SodaCollection.prototype.insertOne", "SodaCollection.prototype.insertMany" ], component: componentName, extractInfo: getCollectionMethodsInfo, trackerType: constants.dbTracker }, { functionName: [ "SodaDatabase.prototype.createCollection", "SodaDatabase.prototype.openCollection" ], component: componentName, extractInfo: getDbMethodsInfo, trackerType: constants.dbTracker } ] }; /* eslint-disable no-unused-vars */ // TODO : Oracle Database version 18.0 features const collectionMethods = [ "insertManyAndGet", "insertOneAndGet", "getDataGuide" ]; const operationMethods = ["remove", "replaceOne", "replaceOneAndGet"]; /* eslint-enable no-unused-vars */ module.exports = moduleInfo;