Skip to content

Commit

Permalink
chore: improve announce cycle log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastian Krol committed Mar 27, 2023
1 parent 23393ff commit d0ac134
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 28 deletions.
25 changes: 15 additions & 10 deletions packages/collector/src/announceCycle/agentHostLookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,21 @@ function enter(ctx) {
return;
}

logger.debug('%s:%s is not running the agent. Trying default gateway...', agentHost, agentOpts.port, {
error: localhostCheckErr
});
logger.debug(
'No Instana host agent is running on %s:%s. Trying the default gateway next.',
agentHost,
agentOpts.port,
{
error: localhostCheckErr
}
);

getDefaultGateway(function onGetDefaultGateway(getDefaultGatewayErr, defaultGateway) {
if (getDefaultGatewayErr) {
logger.debug('Error while trying to determine default gateway.', { error: getDefaultGatewayErr });
logger.debug('Error while trying to determine the default gateway.', { error: getDefaultGatewayErr });
logger.warn(
'Agent cannot be contacted via %s:%s and default gateway cannot be determined. ' +
'Scheduling reattempt of agent host lookup in %s millis.',
'The Instana host agent cannot be contacted via %s:%s and the default gateway cannot be determined. ' +
'Scheduling another attempt to establish a connection to the Instana host agent in %s ms.',
agentHost,
agentOpts.port,
retryTimeoutMillis
Expand All @@ -75,12 +80,12 @@ function enter(ctx) {
return;
}

logger.debug('Failed to contact agent via default gateway %s', defaultGateway, {
logger.debug('Failed to reach the Instana host agent via the default gateway %s', defaultGateway, {
error: defaultGatewayCheckErr
});
logger.warn(
'Agent cannot be contacted via %s:%s nor via default gateway %s:%s. ' +
'Scheduling reattempt of agent host lookup in %s millis.',
'The Instana host agent can neither be reached via %s:%s nor via the default gateway %s:%s. ' +
'Scheduling another attempt to establish a connection to the Instana host agent in %s ms.',
agentHost,
agentOpts.port,
defaultGateway,
Expand Down Expand Up @@ -157,6 +162,6 @@ function checkHost(host, cb) {
* @param {string} host
*/
function setAgentHost(host) {
logger.info('Attempting agent communication via %s:%s', host, agentOpts.port);
logger.info('Trying to reach the Instana host agent on %s:%s', host, agentOpts.port);
agentOpts.host = host;
}
19 changes: 14 additions & 5 deletions packages/collector/src/announceCycle/agentready.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function enter(_ctx) {
profiler.start();
}

logger.info('The Instana Node.js collector is now fully initialized.');
logger.info('The Instana Node.js collector is now fully initialized and connected to the Instana host agent.');
}

function leave() {
Expand All @@ -146,9 +146,15 @@ function sendTracingMetrics() {
const payload = tracing._getAndResetTracingMetrics();
agentConnection.sendTracingMetricsToAgent(payload, error => {
if (error) {
logger.warn('Error received while trying to send tracing metrics to agent: %s', error.message);
logger.info(
'Error received while trying to send tracing metrics to agent: %s. This will not affect monitoring or tracing.',
error.message
);
if (typeof error.message === 'string' && error.message.indexOf('Got status code 404')) {
logger.warn('Apparently the agent does not support POST /tracermetrics, will stop sending tracing metrics.');
logger.info(
'Apparently the version of the Instana host agent on this host does not support the POST /tracermetrics ' +
'endpoint, will stop sending tracing metrics.'
);
return;
}
}
Expand All @@ -171,7 +177,10 @@ function deScheduleTracingMetrics() {
function fireMonitoringEvent() {
agentConnection.sendAgentMonitoringEvent('nodejs_collector_native_addon_autoprofile_missing', 'PROFILER', error => {
if (error) {
logger.error('Error received while trying to send Agent Monitoring Event to agent: %s', error.message);
logger.error(
'Error received while trying to send a monitoring event to the Instana host agent: %s',
error.message
);
}
});
}
Expand All @@ -193,7 +202,7 @@ function sendEOLEvent() {
},
err => {
if (err) {
logger.debug('Node.js version EOL', err);
logger.debug('Sending a monitoring event for the Node.js version end-of-life check has failed.', err);
}
}
);
Expand Down
5 changes: 3 additions & 2 deletions packages/collector/src/announceCycle/announced.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ module.exports = {
function checkWhetherAgentIsReadyToAccept(totalNumberOfAttempts, ctx) {
agentConnection.checkWhetherAgentIsReadyToAcceptData(ready => {
if (ready) {
logger.info('Agent is ready to accept.');
logger.info('The Instana host agent is ready to accept data.');
ctx.transitionTo('agentready');
} else if (totalNumberOfAttempts > MAX_RETRIES) {
logger.warn(
'Agent is not ready to accept data after %s attempts. Restarting announce cycle.',
'The Instana host agent is not yet ready to accept data after %s attempts. Restarting the cycle to establish ' +
'a connection.',
totalNumberOfAttempts
);
ctx.transitionTo('unannounced');
Expand Down
35 changes: 24 additions & 11 deletions packages/collector/src/announceCycle/unannounced.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ function tryToAnnounce(ctx, retryDelay = initialRetryDelay) {
}
agentConnection.announceNodeCollector((err, rawResponse) => {
if (err) {
logger.debug('Announce attempt failed: %s. Will retry in %s ms', err.message, retryDelay);
logger.info(
'Establishing the connection to the Instana host agent has failed: %s. This usually means that the Instana ' +
'host agent is not yet ready to accept connections. This is not an error. Establishing the connection will ' +
'be retried in %s ms.',
err.message,
retryDelay
);
setTimeout(tryToAnnounce, retryDelay, ctx, nextRetryDelay).unref();
return;
}
Expand All @@ -86,19 +92,26 @@ function tryToAnnounce(ctx, retryDelay = initialRetryDelay) {
try {
agentResponse = JSON.parse(rawResponse);
} catch (e) {
logger.warn(
'Failed to JSON.parse agent response. Response was %s. Will retry in %s ms',
rawResponse,
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
);
setTimeout(tryToAnnounce, retryDelay, ctx, nextRetryDelay).unref();
return;
}

const pid = agentResponse.pid;
logger.info('Overwriting pid for reporting purposes to: %s', pid);
pidStore.pid = pid;
if (pidStore.pid !== agentResponse.pid) {
logger.info(
'Reporting data to the Instana host agent with the PID from the root namespace (%s) instead of the ' +
'in-container PID (%s).',
agentResponse.pid,
pidStore.pid
);
pidStore.pid = agentResponse.pid;
}

agentOpts.agentUuid = agentResponse.agentUuid;
applyAgentConfiguration(agentResponse);
Expand All @@ -123,17 +136,17 @@ function applySecretsConfiguration(agentResponse) {
if (agentResponse.secrets) {
if (!(typeof agentResponse.secrets.matcher === 'string')) {
logger.warn(
'Received invalid secrets configuration from agent, attribute matcher is not a string: $s',
'Received an invalid secrets configuration from the Instana host agent, attribute matcher is not a string: $s',
agentResponse.secrets.matcher
);
} else if (Object.keys(secrets.matchers).indexOf(agentResponse.secrets.matcher) < 0) {
logger.warn(
'Received invalid secrets configuration from agent, matcher is not supported: $s',
'Received an invalid secrets configuration from the Intana agent, matcher is not supported: $s',
agentResponse.secrets.matcher
);
} else if (!Array.isArray(agentResponse.secrets.list)) {
logger.warn(
'Received invalid secrets configuration from agent, attribute list is not an array: $s',
'Received an invalid secrets configuration from the Instana host agent, attribute list is not an array: $s',
agentResponse.secrets.list
);
} else {
Expand Down Expand Up @@ -207,7 +220,7 @@ function applySpanBatchingConfiguration(agentResponse) {
// Fallback for Node.js discovery prior to version 1.2.18, which did not sent the span-batching-enabled config in the
// common tracing options section. We can remove this legacy fallback approximately in May 2023.
if (agentResponse.spanBatchingEnabled === true || agentResponse.spanBatchingEnabled === 'true') {
logger.info('Enabling span batching via agent configuration.');
logger.info('Enabling span batching via Instana host agent configuration.');
ensureNestedObjectExists(agentOpts.config, ['tracing']);
agentOpts.config.tracing.spanBatchingEnabled = true;
}
Expand Down

0 comments on commit d0ac134

Please sign in to comment.