Skip to content
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

fix: resolved logging objects being undefined or missing #1509

Merged
merged 5 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 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,9 @@ 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. ${e.message} ${e.stack}`
);
}
});
}
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
4 changes: 3 additions & 1 deletion packages/collector/src/actions/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ 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.message} ${error.stack}`
);
multiCb({
error: `Could not load file. Error: ${error.message}`
});
Expand Down
7 changes: 4 additions & 3 deletions packages/collector/src/agent/requestHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ 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}.
Error: ${error.message} ${error.stack}`
);
}
});
}
Expand Down
6 changes: 3 additions & 3 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 @@ -372,9 +372,9 @@ function sendData(path, data, cb, ignore404 = false) {

const payloadAsString = JSON.stringify(data, circularReferenceRemover());
if (typeof logger.trace === 'function') {
logger.trace('Sending data to %s', path);
logger.trace(`Sending data to ${path}.`);
} else {
logger.debug('Sending data to %s', path, agentOpts);
logger.debug(`Sending data to ${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. ${err.message} ${err.stack}`
);
}
}
);
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: ${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}`);
};
};
4 changes: 2 additions & 2 deletions packages/google-cloud-run/src/activate.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ 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.
Error: ${err.message} ${err.stack}`
);
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. ${err.message} ${err.stack}`);
return resolve();
}

Expand Down
9 changes: 6 additions & 3 deletions packages/serverless/src/backend_connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,14 @@ function send(resourcePath, payload, finalLambdaRequest, callback) {
if (proxyAgent) {
logger.warn(
'Could not send traces and metrics to Instana. Could not connect to the configured proxy ' +
`${process.env[proxyEnvVar]}.`,
e
`${process.env[proxyEnvVar]}.` +
`${e.message} ${e.stack}`
);
} 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.
${e.message} , ${e.stack}`
);
}
}

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
12 changes: 9 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,16 @@ 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.message} ${error.stack}`
);
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.message} ${tarErr.stack}`);
callback(false);
});
});
Expand Down Expand Up @@ -245,7 +249,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