Skip to content

Commit

Permalink
fix: resolved logging objects being undefined or missing
Browse files Browse the repository at this point in the history
 - refs INSTA-12533
 - some log messages did not log the corresponding objects
  • Loading branch information
abhilash-sivan committed Jan 13, 2025
1 parent 9472c5c commit fe99ffb
Show file tree
Hide file tree
Showing 24 changed files with 47 additions and 38 deletions.
7 changes: 5 additions & 2 deletions packages/aws-fargate/src/activate.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ function init() {

metrics.init(config, function onReady(err, ecsContainerPayload) {
if (err) {
logger.error('Initializing @instana/aws-fargate failed. This fargate task will not be monitored.', err);
logger.error(
`Initializing @instana/aws-fargate failed. This fargate task will not be monitored. ${err.message} ${err.stack}`
);
metrics.deactivate();
return;
}
Expand Down Expand Up @@ -68,7 +70,8 @@ function init() {
// eslint-disable-next-line no-unused-expressions
process.send && process.send('instana.aws-fargate.initialized');
} catch (e) {
logger.error('Initializing @instana/aws-fargate failed. This fargate task will not be monitored.', e);
logger.error(`Initializing @instana/aws-fargate failed. This fargate task will not be monitored.
${JSON.stingify(e)}`);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-lambda/src/metrics/npmPackageDescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exports.currentPayload = undefined;
exports.activate = function activate() {
coreUtil.applicationUnderMonitoring.getMainPackageJsonStartingAtDirectory(rootDir.root, (err, pckg) => {
if (err) {
logger.warn('Failed to determine main package json. Reason: ', err.message, err.stack);
logger.warn(`Failed to determine main package json. Reason: ${err.message} ${err.stack}`);
}

if (!err && pckg) {
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-lambda/src/metrics/npmPackageName.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exports.currentPayload = undefined;
exports.activate = function activate() {
coreUtil.applicationUnderMonitoring.getMainPackageJsonStartingAtDirectory(rootDir.root, (err, pckg) => {
if (err) {
logger.warn('Failed to determine main package json. Reason: ', err.message, err.stack);
logger.warn(`Failed to determine main package json. Reason: ${err.message} ${err.stack}`);
}

if (!err && pckg) {
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-lambda/src/metrics/npmPackageVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exports.currentPayload = undefined;
exports.activate = function activate() {
coreUtil.applicationUnderMonitoring.getMainPackageJsonStartingAtDirectory(rootDir.root, (err, pckg) => {
if (err) {
logger.warn('Failed to determine main package json. Reason: ', err.message, err.stack);
logger.warn(`Failed to determine main package json. Reason: ${err.message} ${err.stack}`);
}

if (!err && pckg) {
Expand Down
2 changes: 1 addition & 1 deletion packages/collector/src/actions/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ exports.getSourceFile = (request, multiCb) => {
function readFile(request, multiCb) {
fs.readFile(request.args.file, { encoding: 'utf8' }, (error, content) => {
if (error) {
logger.debug('Failed to retrieve source file for user request: %s.', request.args.file, { error });
logger.debug(`Failed to retrieve source file for user request: ${request.args.file}. ${error}`);
multiCb({
error: `Could not load file. Error: ${error.message}`
});
Expand Down
5 changes: 2 additions & 3 deletions packages/collector/src/agent/requestHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ function handleRequest(request) {
function sendResponse(request, response) {
agentConnection.sendAgentResponseToAgent(request.messageId, response, error => {
if (error) {
logger.warn('Failed to send agent response for action %s and message ID %s', request.action, request.messageId, {
error
});
logger.warn(`Failed to send agent response for action ${request.action} and message ID ${request.messageId}`);
logger.warn(`Error: ${error}`);
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/collector/src/agentConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ exports.sendSpans = function sendSpans(spans, cb) {
logger.debug(`Failed to send: ${JSON.stringify(spanInfo)}`);
} else {
const spanInfo = getSpanLengthInfo(spans);
logger.debug(`Successfully sent:${JSON.stringify(spanInfo)}`);
logger.debug(`Successfully sent: ${JSON.stringify(spanInfo)}`);
}
cb(err);
});
Expand Down Expand Up @@ -374,7 +374,7 @@ function sendData(path, data, cb, ignore404 = false) {
if (typeof logger.trace === 'function') {
logger.trace('Sending data to %s', path);
} else {
logger.debug('Sending data to %s', path, agentOpts);
logger.debug('Sending data to %s %o', path, agentOpts);
}

// Convert payload to a buffer to correctly identify content-length ahead of time.
Expand Down
4 changes: 3 additions & 1 deletion packages/collector/src/announceCycle/agentready.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ function sendEOLEvent() {
},
err => {
if (err) {
logger.debug('Sending a monitoring event for the Node.js version end-of-life check has failed.', err);
logger.debug(
`Sending a monitoring event for the Node.js version end-of-life check has failed. ${JSON.stringify(err)}`
);
}
}
);
Expand Down
8 changes: 3 additions & 5 deletions packages/collector/src/announceCycle/unannounced.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,9 @@ function tryToAnnounce(ctx, retryDelay = initialRetryDelay) {
agentResponse = JSON.parse(rawResponse);
} catch (e) {
logger.error(
"Failed to parse the JSON payload from the Instana host agent's response. Establishing the " +
'connection to the Instana host agent will be retried in %s ms. The response payload was %s.',
retryDelay,
rawResponse,
e
"Failed to parse the JSON payload from the Instana host agent's response. Establishing the connection" +
`to the Instana host agent will be retried in ${retryDelay} ms. The response payload was ${rawResponse}.` +
`${e?.message} ${e?.stack}`
);
setTimeout(tryToAnnounce, retryDelay, ctx, nextRetryDelay).unref();
return;
Expand Down
2 changes: 1 addition & 1 deletion packages/collector/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function init(_config) {
require('./metrics').init(config);
}

logger.info('@instana/collector module version:', require(path.join(__dirname, '..', 'package.json')).version);
logger.info('@instana/collector module version: %s', require(path.join(__dirname, '..', 'package.json')).version);
require('./announceCycle').start();

return init;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/tracing/cls.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,11 @@ function putPseudoSpan(spanName, kind, traceId, spanId) {
span.k = kind;

if (!traceId) {
logger.warn('Cannot start a pseudo span without a trace ID', spanName, kind);
logger.warn(`Cannot start a pseudo span without a trace ID": ${spanName}, ${kind}`);
return;
}
if (!spanId) {
logger.warn('Cannot start a pseudo span without a span ID', spanName, kind);
logger.warn(`Cannot start a pseudo span without a span ID": ${spanName}, ${kind}`);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/tracing/spanBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ function transmitSpans() {
// since sending spans downstream will take a few milliseconds, even that will be rare (and it is acceptable).
downstreamConnection.sendSpans(spansToSend, function sendSpans(/** @type {Error} */ error) {
if (error) {
logger.warn(`Failed to transmit spans, will retry in ${transmissionDelay} ms.`, error.message);
logger.warn(`Failed to transmit spans, will retry in ${transmissionDelay} ms. ${error?.message} ${error?.stack}`);
spans = spans.concat(spansToSend);
removeSpansIfNecessary();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/util/applicationUnderMonitoring.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function readFile(packageJsonPath, cb) {
try {
parsedMainPackageJson = JSON.parse(contents);
} catch (e) {
logger.warn('Package.json file %s cannot be parsed: %s', packageJsonPath, e);
logger.warn(`Package.json file ${packageJsonPath} cannot be parsed: ${e?.message} ${e?.stack}`);
return cb(e, null);
}
return cb(null, parsedMainPackageJson);
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/util/atMostOnce.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ module.exports = function atMostOnce(name, cb) {
if (callCount === 1) {
return cb.apply(null, arguments);
}

logger.debug('Function %s was called %s times. This time with the following arguments.', name, callCount, {
const argObj = {
args: Array.prototype.slice.call(arguments)
});
};

logger.debug(`Function ${name} was called ${callCount} times. This time with the following arguments: ${argObj}`);
};
};
3 changes: 1 addition & 2 deletions packages/google-cloud-run/src/activate.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ function init() {
metrics.init(config, function onReady(err, serviceRevisionPayload) {
if (err) {
logger.error(
'Initializing @instana/google-cloud-run failed. This container instance will not be monitored.',
err
`Initializing @instana/google-cloud-run failed. This container instance will not be monitored. ${err}`
);
metrics.deactivate();
return;
Expand Down
4 changes: 3 additions & 1 deletion packages/serverless-collector/src/activate.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ async function init() {
// eslint-disable-next-line no-unused-expressions
process.send && process.send('instana.serverless-collector.initialized');
} catch (e) {
logger.error('Initializing @instana/serverless-collector failed. This process will not be traced.', e);
logger.error(
`Initializing @instana/serverless-collector failed. This process will not be traced. ${e?.message} ${e?.stack}`
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/serverless-collector/src/metrics/name.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = (config, logger) => {
return new Promise(resolve => {
instanaCore.util.applicationUnderMonitoring.getMainPackageJsonStartingAtMainModule(config, (err, packageJson) => {
if (err) {
logger.debug('Failed to determine main package.json.', err);
logger.debug(`Failed to determine main package.json.', ${JSON.stingify(err)}`);
return resolve();
}

Expand Down
5 changes: 4 additions & 1 deletion packages/serverless/src/backend_connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,10 @@ function send(resourcePath, payload, finalLambdaRequest, callback) {
e
);
} else {
logger.warn('Could not send traces and metrics to Instana. The Instana back end seems to be unavailable.', e);
logger.warn(
`Could not send traces and metrics to Instana. The Instana back end seems to be unavailable.
${JSON.stringify(e)}`
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/shared-metrics/src/description.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ exports.activate = function activate(config) {
attempts++;
applicationUnderMonitoring.getMainPackageJsonStartingAtMainModule(config, (err, packageJson) => {
if (err) {
return logger.warn('Failed to determine main package json. Reason: ', err.message, err.stack);
return logger.warn(`Failed to determine main package json. Reason: ${err.message} ${err.stack}`);
} else if (!packageJson && attempts < MAX_ATTEMPTS) {
setTimeout(() => {
exports.activate(config);
Expand Down
2 changes: 1 addition & 1 deletion packages/shared-metrics/src/healthchecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function gatherHealthcheckResults() {
.catch(function onHealthcheckResultFailure(/** @type {*} */ err) {
// @ts-ignore
exports.currentPayload = {};
logger.warn('Unexpected error while getting healthcheck results', err);
logger.warn(`Unexpected error while getting healthcheck results. ${err?.message} ${err?.stack}`);
timeoutHandle = setTimeout(gatherHealthcheckResults, timeBetweenHealthcheckCalls);
timeoutHandle.unref();
});
Expand Down
2 changes: 1 addition & 1 deletion packages/shared-metrics/src/keywords.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ exports.activate = function activate(config) {
attempts++;
applicationUnderMonitoring.getMainPackageJsonStartingAtMainModule(config, (err, packageJson) => {
if (err) {
return logger.warn('Failed to determine main package json. Reason: ', err.message, err.stack);
return logger.warn(`Failed to determine main package json. Reason: ${err?.message} ${err?.stack}`);
} else if (!packageJson && attempts < MAX_ATTEMPTS) {
setTimeout(() => {
exports.activate(config);
Expand Down
2 changes: 1 addition & 1 deletion packages/shared-metrics/src/name.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ exports.activate = function activate(config) {

applicationUnderMonitoring.getMainPackageJsonStartingAtMainModule(config, (err, packageJson) => {
if (err) {
return logger.warn('Failed to determine main package json. Reason: ', err.message, err.stack);
return logger.warn(`Failed to determine main package json. Reason: ${err?.message} ${err?.stack}`);
} else if (!packageJson && attempts < exports.MAX_ATTEMPTS) {
logger.debug('Main package.json could not be found. Will try again later.');

Expand Down
8 changes: 5 additions & 3 deletions packages/shared-metrics/src/util/nativeModuleRetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ function copyPrecompiled(opts, loaderEmitter, callback) {
callback(true);
})
.catch(error => {
logger.warn(`Copying the precompiled build for ${opts.nativeModuleName} ${label} failed.`, error);
logger.warn(`Copying the precompiled build for ${opts.nativeModuleName} ${label} failed. ${error}`);
callback(false);
});
})
.catch(tarErr => {
logger.warn(`Unpacking the precompiled build for ${opts.nativeModuleName} ${label} failed.`, tarErr);
logger.warn(`Unpacking the precompiled build for ${opts.nativeModuleName} ${label} failed. ${tarErr}`);
callback(false);
});
});
Expand Down Expand Up @@ -245,7 +245,9 @@ function findNativeModulePath(opts) {
opts.nativeModuleParentPath = path.join(opts.nativeModulePath, '..');
return true;
} catch (e) {
logger.debug(`Could not find location for ${opts.nativeModuleName}. Will create a path for it.`, e);
logger.debug(
`Could not find location for ${opts.nativeModuleName}. Will create a path for it. ${e?.message} ${e.stack}`
);
return createNativeModulePath(opts);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/shared-metrics/src/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ exports.activate = function activate(config) {
attempts++;
applicationUnderMonitoring.getMainPackageJsonStartingAtMainModule(config, (err, packageJson) => {
if (err) {
return logger.warn('Failed to determine main package json. Reason: ', err.message, err.stack);
return logger.warn(`Failed to determine main package json. Reason: ${err?.message} ${err?.stack}`);
} else if (!packageJson && attempts < MAX_ATTEMPTS) {
setTimeout(() => {
exports.activate(config);
Expand Down

0 comments on commit fe99ffb

Please sign in to comment.