UNPKG

apminsight

Version:

monitor nodejs applications

80 lines (74 loc) 2.37 kB
// supported upto v7.4.0 var constants = require("./../../constants"); var utils = require("./../../util/utils"); var moduleInfo = { functions: [ { functionName: "Client.prototype.connect", component: "PGSQL" }, { functionName: "Client.prototype.query", component: "PGSQL", extractInfo: getQuery, trackerType: constants.dbTracker }, { functionName: "Pool.prototype.connect", component: "PGSQL" }, { functionName: "Pool.prototype.query", component: "PGSQL", extractInfo: getQuery, trackerType: constants.dbTracker }, { functionName: "Pool.prototype.end", component: "POJSO" }, { functionName: "connect", component: "POJSO" } ] }; /* eslint-disable no-unused-vars */ function getRemoteHost(invoker, params) { var info = {}; if (!invoker) { return info; } if (invoker.host && invoker.port) { info.host = invoker.host; info.port = invoker.port; } var options = invoker.options; if (options && options.host && options.port) { info.host = options.host; info.port = options.port; } return info; } function getQuery(invoker, params, returnObj, tracker, asynOpnInfo) { var info = getRemoteHost(invoker, params); let isSqlCaptureEnabled = apmInsightAgentInstance.getConfig().isDataExporterEnabled(); if (!isSqlCaptureEnabled) { let txn = asynOpnInfo && asynOpnInfo.curTxn; const threshold = txn ? utils.getGenericThreshold(txn.getUrl()) : apmInsightAgentInstance.getThreshold(); isSqlCaptureEnabled = threshold.isSqlCaptureEnabled(); } if (isSqlCaptureEnabled && params && params.length > 0) { var queryInfo = params[0]; if (typeof queryInfo === "string") { info.query = queryInfo; } else if (typeof queryInfo === "object" && queryInfo.text) { info.query = queryInfo.text; } else if (typeof queryInfo === "object" && queryInfo.cursor.text) { info.query = queryInfo.cursor.text; } } tracker.updateInfo(info); } /* eslint-enable no-unused-vars */ module.exports = moduleInfo;