@instana/core
Advanced tools
Comparing version 1.126.2 to 1.127.0
{ | ||
"name": "@instana/core", | ||
"version": "1.126.2", | ||
"version": "1.127.0", | ||
"description": "Core library for Instana's Node.js packages", | ||
@@ -130,9 +130,9 @@ "main": "src/index.js", | ||
"devDependencies": { | ||
"eslint": "^7.27.0", | ||
"eslint": "^7.30.0", | ||
"eslint-config-airbnb": "^18.2.1", | ||
"eslint-plugin-mocha": "^8.1.0", | ||
"mocha": "^7.2.0", | ||
"prettier": "^2.2.1" | ||
"prettier": "^2.3.2" | ||
}, | ||
"gitHead": "54884807739adf043c25dfb3789ec9444bcd2c01" | ||
"gitHead": "17186489c515d8b4df5b4142c9d4d6269496d155" | ||
} |
@@ -6,4 +6,2 @@ /* | ||
// @ts-nocheck | ||
'use strict'; | ||
@@ -16,2 +14,6 @@ | ||
const uninstrumentedHttp = require('./uninstrumentedHttp'); | ||
const metrics = require('./metrics'); | ||
const secrets = require('./secrets'); | ||
const tracing = require('./tracing'); | ||
const util = require('./util'); | ||
@@ -32,34 +34,51 @@ /** | ||
module.exports = exports = { | ||
logger: log, | ||
metrics: require('./metrics'), | ||
secrets: require('./secrets'), | ||
tracing: require('./tracing'), | ||
uninstrumentedHttp, | ||
util: require('./util') | ||
}; | ||
/** | ||
* @typedef {Object} InstanaCore | ||
* @property {import('./metrics/index')} metrics | ||
* @property {import('./secrets')} secrets | ||
* @property {import('./tracing/index')} tracing | ||
*/ | ||
exports.registerAdditionalInstrumentations = function registerAdditionalInstrumentations( | ||
additionalInstrumentationModules | ||
) { | ||
exports.tracing.registerAdditionalInstrumentations(additionalInstrumentationModules); | ||
}; | ||
/** | ||
* @param {Array.<import('./tracing/index').InstanaInstrumentedModule>} additionalInstrumentationModules | ||
*/ | ||
function registerAdditionalInstrumentations(additionalInstrumentationModules) { | ||
tracing.registerAdditionalInstrumentations(additionalInstrumentationModules); | ||
} | ||
exports.preInit = function preInit() { | ||
var preliminaryConfig = normalizeConfig(); | ||
exports.util.hasThePackageBeenInitializedTooLate(); | ||
exports.util.requireHook.init(preliminaryConfig); | ||
exports.tracing.preInit(preliminaryConfig); | ||
function preInit() { | ||
const preliminaryConfig = normalizeConfig(); | ||
util.hasThePackageBeenInitializedTooLate(); | ||
util.requireHook.init(preliminaryConfig); | ||
tracing.preInit(preliminaryConfig); | ||
// Initialize secrets as early as possible, in particular for env var collection in fargate/google-cloud-run when | ||
// the config comes from INSTANA_SECRETS. | ||
exports.secrets.init(preliminaryConfig); | ||
}; | ||
secrets.init(/** @type {secrets.SecretOption} */ (preliminaryConfig)); | ||
} | ||
exports.init = function init(config, downstreamConnection, processIdentityProvider) { | ||
log.init(config); | ||
exports.util.hasThePackageBeenInitializedTooLate(); | ||
/** | ||
* | ||
* @param {import('./util/normalizeConfig').InstanaConfig} config | ||
* @param {tracing.spanBuffer.TemporaryAgentConnection} downstreamConnection | ||
* @param {ProcessIdentityProvider} processIdentityProvider | ||
*/ | ||
function init(config, downstreamConnection, processIdentityProvider) { | ||
log.init(/** @type {log.LoggerConfig} */ (config)); | ||
util.hasThePackageBeenInitializedTooLate(); | ||
config = normalizeConfig(config); | ||
exports.secrets.init(config); | ||
exports.util.requireHook.init(config); | ||
exports.tracing.init(config, downstreamConnection, processIdentityProvider); | ||
secrets.init(/** @type {secrets.SecretOption} */ (config)); | ||
util.requireHook.init(config); | ||
tracing.init(config, downstreamConnection, processIdentityProvider); | ||
} | ||
module.exports = { | ||
logger: log, | ||
metrics, | ||
secrets, | ||
tracing, | ||
uninstrumentedHttp, | ||
util, | ||
init, | ||
preInit, | ||
registerAdditionalInstrumentations | ||
}; |
@@ -5,3 +5,2 @@ /* | ||
*/ | ||
// @ts-nocheck | ||
@@ -13,4 +12,10 @@ 'use strict'; | ||
/** @typedef {import('../util/normalizeConfig').InstanaConfig} InstanaConfig */ | ||
/** @type {InstanaConfig} */ | ||
let config; | ||
/** | ||
* @param {InstanaConfig} _config | ||
*/ | ||
exports.init = _config => { | ||
@@ -20,2 +25,15 @@ config = _config; | ||
/** | ||
* @typedef {Object} InstanaMetricsModule | ||
* @property {string} payloadPrefix | ||
* @property {string} currentPayload | ||
* @property {(config?: InstanaConfig) => void} activate | ||
* @property {() => void} deactivate | ||
* @property {(logger: import('../logger').GenericLogger) => void} [setLogger] | ||
*/ | ||
/** | ||
* @param {string} baseDir | ||
* @returns | ||
*/ | ||
exports.findAndRequire = function findAndRequire(baseDir) { | ||
@@ -36,4 +54,8 @@ return ( | ||
/** @type {Array.<InstanaMetricsModule>} */ | ||
let metricsModules = exports.findAndRequire(__dirname); | ||
/** | ||
* @param {Array.<InstanaMetricsModule>} additionalMetricsModules | ||
*/ | ||
exports.registerAdditionalMetrics = function registerAdditionalMetrics(additionalMetricsModules) { | ||
@@ -59,3 +81,7 @@ metricsModules = metricsModules.concat(additionalMetricsModules); | ||
/** | ||
* @returns {Object.<string, string>} | ||
*/ | ||
exports.gatherData = function gatherData() { | ||
/** @type {Object.<string, string>} */ | ||
const payload = {}; | ||
@@ -70,2 +96,5 @@ | ||
/** | ||
* @param {import('../logger').GenericLogger} logger | ||
*/ | ||
exports.setLogger = function setLogger(logger) { | ||
@@ -72,0 +101,0 @@ metricsModules.forEach(metricModule => { |
@@ -19,7 +19,7 @@ /* | ||
* @typedef {Object} SecretMatchers | ||
* @property {(secrets: Array<string>) => (key: string) => boolean} equals-ignore-case | ||
* @property {(secrets: Array<string>) => (key: string) => boolean} equals | ||
* @property {(secrets: Array<string>) => (key: string) => boolean} contains-ignore-case | ||
* @property {(secrets: Array<string>) => (key: string) => boolean} contains | ||
* @property {(secrets: Array<string>) => (key: string) => boolean} regex | ||
* @property {(secrets: Array.<string>) => (key: string) => boolean} equals-ignore-case | ||
* @property {(secrets: Array.<string>) => (key: string) => boolean} equals | ||
* @property {(secrets: Array.<string>) => (key: string) => boolean} contains-ignore-case | ||
* @property {(secrets: Array.<string>) => (key: string) => boolean} contains | ||
* @property {(secrets: Array.<string>) => (key: string) => boolean} regex | ||
* @property {() => () => boolean} none | ||
@@ -31,3 +31,3 @@ */ | ||
/** | ||
* @param {Array<string>} secrets | ||
* @param {Array.<string>} secrets | ||
* @returns {(key: string) => boolean} | ||
@@ -51,3 +51,3 @@ */ | ||
/** | ||
* @param {Array<string>} secrets | ||
* @param {Array.<string>} secrets | ||
* @returns {(key: string) => boolean} | ||
@@ -71,3 +71,3 @@ */ | ||
/** | ||
* @param {Array<string>} secrets | ||
* @param {Array.<string>} secrets | ||
* @returns {(key: string) => boolean} | ||
@@ -91,3 +91,3 @@ */ | ||
/** | ||
* @param {Array<string>} secrets | ||
* @param {Array.<string>} secrets | ||
* @returns {(key: string) => boolean} | ||
@@ -111,3 +111,3 @@ */ | ||
/** | ||
* @param {Array<string>} secrets | ||
* @param {Array.<string>} secrets | ||
* @returns {(key: string) => boolean} | ||
@@ -117,3 +117,3 @@ */ | ||
secrets = checkSecrets(secrets); | ||
/** @type {Array<RegExp>} */ | ||
/** @type {Array.<RegExp>} */ | ||
const regexes = []; | ||
@@ -163,4 +163,4 @@ secrets.forEach(regexString => { | ||
/** | ||
* @param {Array<string>} configuredSecrets | ||
* @returns {Array<string>} | ||
* @param {Array.<string>} configuredSecrets | ||
* @returns {Array.<string>} | ||
*/ | ||
@@ -171,3 +171,3 @@ function checkSecrets(configuredSecrets) { | ||
} | ||
/** @type {Array<string>} */ | ||
/** @type {Array.<string>} */ | ||
const secrets = []; | ||
@@ -185,3 +185,3 @@ configuredSecrets.forEach(s => { | ||
/** | ||
* @param {Array<string>} configuredSecrets | ||
* @param {Array.<string>} configuredSecrets | ||
*/ | ||
@@ -192,3 +192,3 @@ function toLowerCase(configuredSecrets) { | ||
} | ||
/** @type {Array<string>} */ | ||
/** @type {Array.<string>} */ | ||
const secrets = []; | ||
@@ -234,3 +234,3 @@ configuredSecrets.forEach(s => { | ||
* @param {MatchingOptions} matcherId | ||
* @param {Array<*>} secretsList | ||
* @param {Array.<*>} secretsList | ||
*/ | ||
@@ -237,0 +237,0 @@ exports.setMatcher = function setMatcher(matcherId, secretsList) { |
@@ -33,5 +33,6 @@ /* | ||
const instrumentations = [ | ||
'./instrumentation/cloud/aws/index', | ||
'./instrumentation/cloud/aws/sdk', | ||
'./instrumentation/cloud/aws/sqs', | ||
'./instrumentation/cloud/aws-sdk/v2/index', | ||
'./instrumentation/cloud/aws-sdk/v3/index', | ||
'./instrumentation/cloud/aws-sdk/v2/sdk', | ||
'./instrumentation/cloud/aws-sdk/v2/sqs', | ||
'./instrumentation/cloud/gcp/pubsub', | ||
@@ -38,0 +39,0 @@ './instrumentation/cloud/gcp/storage', |
@@ -5,3 +5,2 @@ /* | ||
*/ | ||
// @ts-nocheck | ||
@@ -13,2 +12,9 @@ 'use strict'; | ||
/** | ||
* @typedef {Object} UninstrumentedHTTP | ||
* @property {import('http') & {agent: import('http').Agent}} http | ||
* @property {import('https')} https | ||
*/ | ||
/** @type {UninstrumentedHTTP} */ | ||
module.exports = exports = { | ||
@@ -15,0 +21,0 @@ http: Object.create(http), |
@@ -19,24 +19,38 @@ /* | ||
// and identification of these values is expensive. | ||
/** @type {*} */ | ||
/** @type {Object.<string, *>} */ | ||
let parsedMainPackageJson; | ||
/** @type {*} */ | ||
/** @type {string} */ | ||
let mainPackageJsonPath; | ||
/** @type {*} */ | ||
/** @type {Array.<string>} */ | ||
let nodeModulesPath; | ||
let appInstalledIntoNodeModules = false; | ||
exports.isAppInstalledIntoNodeModules = function isAppInstalledIntoNodeModules() { | ||
function isAppInstalledIntoNodeModules() { | ||
return appInstalledIntoNodeModules; | ||
}; | ||
} | ||
/** | ||
* @param {string} startDirectory | ||
* @param {Function} cb | ||
* Looks for the app's main package.json file, parses it and returns the parsed content. The search is started at | ||
* path.dirname(process.mainModule.filename). | ||
* | ||
* In case the search is successful, the result will be cached for consecutive invocations. | ||
* | ||
* @param {(err: Error, parsedMainPackageJson: Object.<string, *>) => void } cb - the callback will be called with an | ||
* error or the parsed package.json file as a JS object. | ||
*/ | ||
exports.getMainPackageJson = function getMainPackageJson(startDirectory, cb) { | ||
if (typeof startDirectory === 'function') { | ||
cb = startDirectory; | ||
startDirectory = null; | ||
} | ||
function getMainPackageJsonStartingAtMainModule(cb) { | ||
return getMainPackageJsonStartingAtDirectory(null, cb); | ||
} | ||
/** | ||
* Looks for the app's main package.json file, parses it and returns the parsed content. If the given directory is null | ||
* or undefined, the search will start at path.dirname(process.mainModule.filename). | ||
* | ||
* In case the search is successful, the result will be cached for consecutive invocations. | ||
* | ||
* @param {string} startDirectory - the directory in which to start searching. | ||
* @param {(err: Error, parsedMainPackageJson: Object.<string, *>) => void } cb - the callback will be called with an | ||
* error or the parsed package.json file as a JS object. | ||
*/ | ||
function getMainPackageJsonStartingAtDirectory(startDirectory, cb) { | ||
if (parsedMainPackageJson !== undefined) { | ||
@@ -46,3 +60,3 @@ return process.nextTick(cb, null, parsedMainPackageJson); | ||
exports.getMainPackageJsonPath(startDirectory, (err, packageJsonPath) => { | ||
getMainPackageJsonPathStartingAtDirectory(startDirectory, (err, packageJsonPath) => { | ||
if (err) { | ||
@@ -71,14 +85,27 @@ // fs.readFile would have called cb asynchronously later, so we use process.nextTick here to make all paths async. | ||
}); | ||
}; | ||
} | ||
/** | ||
* @param {string} startDirectory | ||
* @param {(err: Error, packageJsonPath: string) => void} cb | ||
* Looks for path of the app's main package.json file, starting the search at path.dirname(process.mainModule.filename). | ||
* | ||
* In case the search is successful, the result will be cached for consecutive invocations. | ||
* | ||
* @param {(err: Error, packageJsonPath: string) => void} cb - the callback will be called with an error or the path to | ||
* the package.json file | ||
*/ | ||
exports.getMainPackageJsonPath = function getMainPackageJsonPath(startDirectory, cb) { | ||
if (typeof startDirectory === 'function') { | ||
cb = startDirectory; | ||
startDirectory = null; | ||
} | ||
function getMainPackageJsonPathStartingAtMainModule(cb) { | ||
return getMainPackageJsonPathStartingAtDirectory(null, cb); | ||
} | ||
/** | ||
* Looks for path of the app's main package.json file, starting the search at the given directory. If the given | ||
* directory is null or undefined, the search will start at path.dirname(process.mainModule.filename). | ||
* | ||
* In case the search is successful, the result will be cached for consecutive invocations. | ||
* | ||
* @param {string} startDirectory - the directory in which to start searching. | ||
* @param {(err: Error, packageJsonPath: string) => void} cb - the callback will be called with an error or the path to | ||
* the package.json file | ||
*/ | ||
function getMainPackageJsonPathStartingAtDirectory(startDirectory, cb) { | ||
if (mainPackageJsonPath !== undefined) { | ||
@@ -115,3 +142,3 @@ // searchForPackageJsonInDirectoryTreeUpwards would have called cb asynchronously later, | ||
}); | ||
}; | ||
} | ||
@@ -180,5 +207,5 @@ /** | ||
/** | ||
* @param {Function} cb | ||
* @param {(errNodeModules: *, nodeModulesFolder: *) => *} cb | ||
*/ | ||
exports.findNodeModulesFolder = function findNodeModulesFolder(cb) { | ||
function findNodeModulesFolder(cb) { | ||
if (nodeModulesPath !== undefined) { | ||
@@ -202,3 +229,3 @@ return process.nextTick(cb, null, nodeModulesPath); | ||
}); | ||
}; | ||
} | ||
@@ -248,1 +275,10 @@ /** | ||
} | ||
module.exports = { | ||
isAppInstalledIntoNodeModules, | ||
getMainPackageJsonStartingAtMainModule, | ||
getMainPackageJsonStartingAtDirectory, | ||
getMainPackageJsonPathStartingAtMainModule, | ||
getMainPackageJsonPathStartingAtDirectory, | ||
findNodeModulesFolder | ||
}; |
@@ -8,4 +8,3 @@ /* | ||
/** @type {*} */ | ||
module.exports = exports = { | ||
module.exports = { | ||
applicationUnderMonitoring: require('./applicationUnderMonitoring'), | ||
@@ -12,0 +11,0 @@ atMostOnce: require('./atMostOnce'), |
@@ -63,6 +63,5 @@ /* | ||
/** | ||
* @type {Function} | ||
* @returns {boolean} | ||
*/ | ||
module.exports = exports = function hasThePackageBeenInitializedTooLate() { | ||
module.exports = function hasThePackageBeenInitializedTooLate() { | ||
if (firstCall) { | ||
@@ -69,0 +68,0 @@ const loadedModules = Object.keys(require.cache); |
@@ -96,7 +96,6 @@ /* | ||
/** | ||
* @type {Function} | ||
* @param {InstanaConfig} config | ||
* @param {InstanaConfig} [config] | ||
* @returns {InstanaConfig} | ||
*/ | ||
module.exports = exports = function normalizeConfig(config) { | ||
module.exports = function normalizeConfig(config) { | ||
if (config == null) { | ||
@@ -103,0 +102,0 @@ config = {}; |
@@ -45,3 +45,7 @@ /* | ||
exports.init = function () { | ||
/** | ||
* @param {import('./normalizeConfig').InstanaConfig} [config] | ||
*/ | ||
// eslint-disable-next-line no-unused-vars | ||
exports.init = function (config) { | ||
/** @type {*} */ (Module)._load = patchedModuleLoad; | ||
@@ -48,0 +52,0 @@ }; |
517808
102
14713