-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: removed "getLogger" usage #1556
base: main
Are you sure you want to change the base?
Conversation
61df358
to
1a95836
Compare
} else { | ||
logger.debug(`Sending data to ${path}, ${agentOpts}`); | ||
} | ||
logger.debug(`Sending data to ${path}, ${agentOpts}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to me: revert
cmdline.init(config); | ||
pidStore = _pidStore; | ||
|
||
cpuSetFileContent = getCpuSetFileContent(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: Moved from root initialization to init fn. We should never initialize components on root.
// NOTE: By default we set our instana internal logger | ||
config.logger = logger; | ||
|
||
pidStore.init(config); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: We define & init the pidstore in the parent module (collector) and pass it on to all modules, who use the pidstore. Dependency injection.
const registry = {}; | ||
let instanaLogger; | ||
|
||
class InstanaLogger { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: The class instance makes it possible to update the logger without having to reinitialize all components.
It makes the old wrong logging design obsolete.
e.g.
if (isReInit) {
Object.keys(registry).forEach(loggerName => {
const reInitFn = registry[loggerName];
reInitFn(exports.getLogger(loggerName));
});
// cascade re-init to @instana/core
logger.init(config);
}
e.g.
exports.setLogger = function setLogger(_logger) {
logger = _logger;
config.logger = logger;
instanaCore.logger.init(config);
};
e.g.
exports.setLogger = function setLogger(logger) {
metricsModules.forEach(metricModule => {
if (typeof metricModule.setLogger === 'function') {
metricModule.setLogger(logger);
}
});
};
Look at these complicated code constructs.
packages/collector/src/logger.js
Outdated
@@ -45,7 +104,8 @@ exports.init = function init(config, isReInit) { | |||
// we create later on. | |||
parentLogger = uninstrumentedLogger({ | |||
name: '@instana/collector', | |||
level: 'info' | |||
level: 'info', | |||
base: { threadId } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: this removes pid & hostname
e7eae88
to
7fceedb
Compare
|
||
coreMetrics.registerAdditionalMetrics(sharedMetrics.allMetrics); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: Same here. No initialization on the root file.
// @ts-ignore - Cannot redeclare exported variable | ||
exports.immediate = path.join(__dirname, '..', '..', '..', 'immediate.js'); | ||
|
||
if (!fs.existsSync(exports.immediate)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We print the warning on the caller component.
It was anyway wrong that we log on root file.
@@ -7,7 +7,7 @@ | |||
|
|||
// NOTE: c8 bug https://github.com/bcoe/c8/issues/166 | |||
process.on('SIGTERM', () => { | |||
process.disconnect(); | |||
process.disconnect && process.disconnect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: ?
@@ -47,6 +46,7 @@ exports.findAndRequire = function findAndRequire(baseDir) { | |||
.filter( | |||
moduleName => | |||
moduleName.indexOf('.js') === moduleName.length - 3 && | |||
// TODO: move the extra metrics into a separate folder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed while coding. Bad code quality. Ignore this change if you want.
@@ -0,0 +1,163 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Putting it here. Same concept as our collector logger. Just with a little bit less logic.
@@ -36,32 +36,36 @@ let warningsHaveBeenLogged = false; | |||
const disableCaCheckEnvVar = 'INSTANA_DISABLE_CA_CHECK'; | |||
const disableCaCheck = process.env[disableCaCheckEnvVar] === 'true'; | |||
|
|||
if (process.env[proxyEnvVar] && !environmentUtil.sendUnencrypted) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just moved into init fn.
* @return {(...args: *) => *} A wrapped function which will forward the first call to `cb` | ||
* and log any successive calls. | ||
*/ | ||
exports.atMostOnce = function atMostOnce(name, cb) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the content of the file "atMostOnce" into this file for now, because I could not find a nice way to add an init fn to this little helper.
1848a47
to
32268f6
Compare
refs https://jsw.ibm.com/browse/INSTA-13498 Extracted from #1556 With this refactoring, we can easily forward the config object now to the aws v3 pkg. Each class is instantiated with the config object, which contains the logger.
32268f6
to
3731ce9
Compare
96425d4
to
cbc832d
Compare
cbc832d
to
d042d81
Compare
@@ -6,24 +6,17 @@ | |||
'use strict'; | |||
|
|||
const { util, uninstrumentedHttp, uninstrumentedFs: fs } = require('@instana/core'); | |||
const http = uninstrumentedHttp.http; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorted requires and variables. Just moved down
|
||
const circularReferenceRemover = require('./util/removeCircular'); | ||
const agentOpts = require('./agent/opts'); | ||
const pidStore = require('./pidStore'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pidStore is injected. See later comments.
const agentConnection = require('../agentConnection'); | ||
const agentOpts = require('../agent/opts'); | ||
const initializedTooLate = require('../util/initializedTooLate'); | ||
const metrics = require('../metrics'); | ||
const pidStore = require('../pidStore'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Dependency injection. pidStore is defined in the upper unit.
log.init(_config); | ||
} | ||
|
||
// TODO: The idea of having a config per parent module probably makes, sense |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not solved as part of this PR.
refs https://jsw.ibm.com/browse/INSTA-13498
Reasons why we have to move away from
getLogger('tracing/xxx')
:getLogger('tracing/blubb')
- without knowing what the actual logging instance is. We should only accessconfig.logger
in the init function of each module. This gives us control over the codeflow.getLogger
too early e.g. logs fromnormalizeConfig
did not appear from serverless correctly.I have not found a good reason to keep the child logger logic. We now create only one child logger: the instana internal logger if you provide a custom logger. Otherwise we only have one logger instance.
If we want to re-add log prefixes, we can easily do that by adding e.g.
logger = config.logger.prefix('xxx')
. This helper fn will wrap the log calls and automatically adds a prefix such astracing/kafka: error msg
.let logger
to prevent bugs