Skip to content

Commit

Permalink
fix: reduced log flooding when collector is not rdy
Browse files Browse the repository at this point in the history
refs #849
  • Loading branch information
kirrg001 committed Aug 23, 2023
1 parent 5fa039c commit 6751122
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/collector/src/announceCycle/agentready.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ function enter(_ctx) {
requestHandler.handleRequests(requests);
},
function onError() {
tracing.getCls().setIsLoggingEnabled(false);
ctx.transitionTo('unannounced');
}
);
Expand All @@ -124,6 +125,7 @@ function enter(_ctx) {
}

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

function leave() {
Expand Down
13 changes: 11 additions & 2 deletions packages/core/src/tracing/cls.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const w3cTraceContextKey = 'com.instana.w3ctc';
let serviceName;
/** @type {import('../../../collector/src/pidStore')} */
let processIdentityProvider = null;
let isLoggingEnabled = false;

/*
* Access the Instana namespace in continuation local storage.
Expand Down Expand Up @@ -569,7 +570,7 @@ function skipExitTracing(options) {
}

if (!opts.skipParentSpanCheck && (!parentSpan || isExitSpanResult)) {
if (opts.log) {
if (opts.log && isLoggingEnabled) {
logger.warn(
// eslint-disable-next-line max-len
`Cannot start an exit span as this requires an active entry (or intermediate) span as parent. ${
Expand All @@ -591,6 +592,13 @@ function skipExitTracing(options) {
else return skip;
}

/**
* @param {boolean} bool
*/
function setIsLoggingEnabled(bool) {
isLoggingEnabled = bool;
}

module.exports = {
skipExitTracing,
currentEntrySpanKey,
Expand All @@ -616,5 +624,6 @@ module.exports = {
enterAsyncContext,
leaveAsyncContext,
runInAsyncContext,
runPromiseInAsyncContext
runPromiseInAsyncContext,
setIsLoggingEnabled
};

0 comments on commit 6751122

Please sign in to comment.