/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/apminsight@5.4.0/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
var dotenv=require("dotenv");dotenv.config();var agent=require("./lib/agent"),utils=require("./lib/util/utils"),packageJson=require("./package.json"),path=require("path"),fs=require("fs");const constants=require("./lib/constants.js");var agentInstance;function includeAgentInfo(n){n=n||{};var t=packageJson.version,e=t.lastIndexOf(".");n.agentVersion=t.substring(0,e),n.agentFullVersion=t,n.agentInstallPath=__dirname}function AgentAPI(){if(!process.env.APMINSIGHT_AGENT_DISABLE||"true"!=process.env.APMINSIGHT_AGENT_DISABLE.toLowerCase()){if(!agentInstance){var n=readInfoFromFile();includeAgentInfo(n),agent.init(n),agentInstance=global.apmInsightAgentInstance}return AgentAPI}process.stdout.write("\n[APM] Apminsight agent is disabled.\n")}function readInfoFromFile(){var n={};if(process.env.APMINSIGHT_AUTOPROFILER_CONF_FILEPATH&&fs.existsSync(process.env.APMINSIGHT_AUTOPROFILER_CONF_FILEPATH))try{let t=utils.parseIniFile(process.env.APMINSIGHT_AUTOPROFILER_CONF_FILEPATH);if(!utils.isEmpty(t)){let e=t[constants.oneAgentSectionInfo];const s=e[constants.oneAgentLicenseKey],i=e[constants.oneAgentIV],a=e[constants.oneAgentSaltKey],r=e[constants.oneAgentServerMonitorKey],o=s&&a&&i&&utils.toDecryptKey(s,a,i);if(utils.isEmpty(o))throw new Error("oneagent decryption failed with empty");return n.licenseKey=s,utils.isEmpty(i)||(constants.initVector=i),utils.isEmpty(a)||(constants.securitykey=a),utils.isEmpty(r)||(n.serverMonitorKey=r),n}}catch(t){n={}}var t=path.join(process.cwd(),"apminsightnode.json");if(!fs.existsSync(t))return process.env.APMINSIGHT_LICENSE_KEY&&process.env.APMINSIGHT_APP_NAME||utils.writeStream().write("[APM] This version of APM Insight Node.js Agent requires creation of a configuration file (apminsightnode.json) in "+process.cwd()+" or Use of Environment variables. Please refer the help docs for more information.\n"),n;try{var e=fs.readFileSync(t,{encoding:"utf8",flag:"r"});if(utils.isEmpty(e))utils.writeStream().write("[APM] apminsightnode.json file is empty.\n");else{var s=getEncryptedKey(n=JSON.parse(e));if(!utils.isBoolean(s)){n.licenseKey=s;try{fs.writeFileSync(t,JSON.stringify(n))}catch(n){}}}return n.agentInfoPath=t,n}catch(t){return utils.writeStream().write("[APM] Error while reading the apminsightnode.json file :: "+t+"\n"),n}}function getEncryptedKey(n){var t=utils.toDecryptKey(n.licenseKey);return!!utils.isBoolean(t)&&utils.toEncryptKey(n.licenseKey)}AgentAPI(),AgentAPI.config=function(){if(process.env.APMINSIGHT_AGENT_DISABLE)process.stdout.write("\n[APM] Apminsight agent is disabled.\n");else if(!agentInstance){var n=readInfoFromFile();includeAgentInfo(n),agent.init(n),agentInstance=global.apmInsightAgentInstance}},AgentAPI.startWebTransaction=function(n,t){if(!agentInstance)return t();apmInsightAgentInstance.startApiTransaction(n,t,!1)},AgentAPI.startBackgroundTransaction=function(n,t){if(!agentInstance)return t();apmInsightAgentInstance.startApiTransaction(n,t,!0)},AgentAPI.endTransaction=function(n){agentInstance&&apmInsightAgentInstance.endApiTxn(n)},AgentAPI.startTracker=function(n,t,e,s){if(!agentInstance)return e();apmInsightAgentInstance.createCustomTracker(n,t,e,s)},AgentAPI.trackError=function(n){agentInstance&&apmInsightAgentInstance.trackError(n)},AgentAPI.setTransactionName=function(n){agentInstance&&utils.isNonEmptyString(n)&&apmInsightAgentInstance.setTransactionName(n)},AgentAPI.addParameter=function(n,t){agentInstance&&utils.isNonEmptyString(n)&&agentInstance.addParameter(n,t)},AgentAPI.ignoreCurrentTransaction=function(){agentInstance&&apmInsightAgentInstance.ignoreCurTxn()},AgentAPI.incrementCustomMetric=function(n,t){agentInstance&&apmInsightAgentInstance.incrementCustomMetric(n,t)},AgentAPI.averageCustomMetric=function(n,t){agentInstance&&apmInsightAgentInstance.averageCustomMetric(n,t)},AgentAPI.getRumScript=function(){return apmInsightAgentInstance.getRumScript()},AgentAPI.instrumentWebFramework=function(n,t){agentInstance&&apmInsightAgentInstance.instrumentingWebFramework(n,t)},module.exports=AgentAPI;
//# sourceMappingURL=/sm/be9abcb50c5a699c8b08fd3fd919ab2fb8a85b7f8a1305c2994d0932b4800ef1.map