UNPKG

atatus-nodejs

Version:

Atatus APM agent for Node.js

46 lines (43 loc) 1.29 kB
/** * Returns Object includes of host and port of connection. * * @param {string} connArgs the connectionArugment which will be parsed. * @returns {{host:string,port:number}} */ function parseConnectionArgs(connArgs) { const params = {} function isString(obj) { return typeof obj === 'string' || obj instanceof String } if (isString(connArgs)) { connArgs = new URL(connArgs) params.host = connArgs.hostname if (connArgs.port) { params.port = parseInt(connArgs.port, 10) } } else { params.port = connArgs.port || (connArgs.protocol === 'amqp' ? 5672 : 5671) params.host = connArgs.hostname } return params } /** * Returns true if we have to ignore messages on the given topic * * @param {string} topic the topic where client is publishing/consuming * @param {{ ignoreMessageQueuesRegExp: RegExp[] }} config the agent's configuration object * @returns {boolean} */ function shouldIgnoreTopic(topic, config) { if (config.ignoreMessageQueuesRegExp) { for (const rule of config.ignoreMessageQueuesRegExp) { if (rule.test(topic)) { return true; } } } } module.exports = { parseConnectionArgs, shouldIgnoreTopic }