Repository URL to install this package:
|
Version:
0.9.2-rc0 ▾
|
// (c) Copyright 2023 Supertenant Ltd. - all rights reserved.
// See LICENSE file in project root for license terms.
'use strict';
// If a process is started with `npm start` or `yarn start`, two separate processes will be started. The first is
// `node /path/to/npm` (or `node /path/to/yarn`). This process will kick off another process with the actual application
// (for example, `node /usr/src/app`). When
// NODE_OPTIONS="--require /usr/src/app/node_modules/@supertenant/collector/src/immediate" is set, we would instrument both
// processes, that is, npm/yarn as well as the actual application. Attempting to instrument the npm or yarn process has
// no value and also creates confusing log output, so we exclude them here explicitly.
const excludePattern = /^.*\/(?:npm(?:\.js)?|npm-cli(?:\.js)?|yarn(?:\.js)?|yarn\/lib\/cli(?:\.js)?)$/i;
/**
* @type {Function}
* @returns {boolean}
*/
module.exports = exports = function isExcludedFromInstrumentation() {
const mainModule = process.argv[1];
const excludedFromInstrumentation = typeof mainModule === 'string' && excludePattern.test(mainModule);
if (excludedFromInstrumentation) {
const logLevelIsDebugOrInfo =
process.env.SUPERTENANT_SUPERBRAIN_DEBUG_MODE ||
(process.env.SUPERTENANT_SUPERBRAIN_LOG__LEVEL &&
(process.env.SUPERTENANT_SUPERBRAIN_LOG__LEVEL.toLowerCase() === 'info' ||
process.env.SUPERTENANT_SUPERBRAIN_LOG__LEVEL.toLowerCase() === 'debug' ||
process.env.SUPERTENANT_SUPERBRAIN_LOG__LEVEL.toLowerCase() === 'trace'));
if (logLevelIsDebugOrInfo) {
// eslint-disable-next-line no-console
console.log(
`[supertenant-supermeter] INFO: Not instrumenting process ${process.pid}: ${process.argv[0]} ${mainModule}` +
' - this Node.js process seems to be npm or yarn. A child process started via "npm start" or "yarn start" ' +
'_will_ be instrumented, but not npm or yarn itself.'
);
}
}
return excludedFromInstrumentation;
};