UNPKG

ca-apm-probe

Version:

CA APM Node.js Agent monitors real-time health and performance of Node.js applications

62 lines (51 loc) 2.26 kB
/** * Copyright (c) 2015 CA. All rights reserved. * * This software and all information contained therein is confidential and proprietary and * shall not be duplicated, used, disclosed or disseminated in any way except as authorized * by the applicable license agreement, without the express written permission of CA. All * authorized reproductions must be marked with this language. * * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT WARRANTY * OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL CA BE * LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY LOSS OR DAMAGE, DIRECT OR * INDIRECT, FROM THE USE OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, LOST * PROFITS, BUSINESS INTERRUPTION, GOODWILL, OR LOST DATA, EVEN IF CA IS * EXPRESSLY ADVISED OF SUCH LOSS OR DAMAGE. */ var semver = require('semver'); var util = require('util'); var logger = require("../logger.js"); var PATH_UNFORMATTED = './mongodb/%s/mongodb.js'; var SUPPORTED_VERSIONS = ['1.4.x', '2.1.x']; var load = module.exports = function (mongodb) { // find probe version to load var version = identifyProbeVersion(mongodb); if (version) { logger.debug('Selected mongodb probe version: ' + version); var delegate = require(util.format(PATH_UNFORMATTED, version)); // call appropriate probe delegate(mongodb); } } function identifyProbeVersion(mongodb) { var probeVersion; var version = semver.valid(mongodb.version); if (version) { for (var i = 0; i < SUPPORTED_VERSIONS.length; i++) { if (semver.satisfies(version, SUPPORTED_VERSIONS[i])) { probeVersion = SUPPORTED_VERSIONS[i]; break; } } } else { // in absence of explicit version information, use exported functions to assert mongodb driver version // instrumentation API was added in 2.0 - http://mongodb.github.io/node-mongodb-native/2.0/whats-new/ if (mongodb.instrument) { probeVersion = SUPPORTED_VERSIONS[1];; } } return probeVersion; }