From 94bd095f7cc268355d8f26049e4e3cdb5066d4b6 Mon Sep 17 00:00:00 2001 From: Abhilash Date: Tue, 24 Dec 2024 19:05:11 +0530 Subject: [PATCH] chore: adapt pr comments --- packages/collector/src/agentConnection.js | 8 ++++---- packages/collector/src/logger.js | 7 ++----- .../core/src/tracing/instrumentation/loggers/bunyan.js | 7 +++++++ packages/core/src/uninstrumentedLogger.js | 4 ++-- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/collector/src/agentConnection.js b/packages/collector/src/agentConnection.js index 4d3e34d2d7..8e0f483591 100644 --- a/packages/collector/src/agentConnection.js +++ b/packages/collector/src/agentConnection.js @@ -267,11 +267,11 @@ exports.sendSpans = function sendSpans(spans, cb) { if (err && !maxContentErrorHasBeenLogged && err instanceof PayloadTooLargeError) { logLargeSpans(spans); } else if (err) { - const obj = getSpanLengthInfo(spans); - logger.debug({ obj }, 'Failed to transmit.'); + const spanInfo = getSpanLengthInfo(spans); + logger.debug({ spanInfo }, 'Failed to send.'); } else { - const obj = getSpanLengthInfo(spans); - logger.debug({ obj }, 'Successfully transmitted'); + const spanInfo = getSpanLengthInfo(spans); + logger.debug({ spanInfo }, 'Successfully sent'); } cb(err); }); diff --git a/packages/collector/src/logger.js b/packages/collector/src/logger.js index fe702fc4fc..69cf27ee50 100644 --- a/packages/collector/src/logger.js +++ b/packages/collector/src/logger.js @@ -16,9 +16,7 @@ try { // thread (0). } -const { uninstrumentedLogger: pinoCopy } = require('@instana/core'); - -const pino = pinoCopy; +const { uninstrumentedLogger: pino } = require('@instana/core'); const { logger } = require('@instana/core'); const pinoToAgentStream = require('./agent/loggerToAgentStream'); @@ -55,8 +53,7 @@ exports.init = function init(config, isReInit) { write(chunk) { consoleStream.write(chunk); - const logRecord = JSON.parse(chunk); - pinoToAgentStream.write(logRecord); + pinoToAgentStream.write(chunk); } }; diff --git a/packages/core/src/tracing/instrumentation/loggers/bunyan.js b/packages/core/src/tracing/instrumentation/loggers/bunyan.js index 780f17c76a..c1445ef12e 100644 --- a/packages/core/src/tracing/instrumentation/loggers/bunyan.js +++ b/packages/core/src/tracing/instrumentation/loggers/bunyan.js @@ -29,6 +29,13 @@ function instrument(Logger) { function shimLog(markAsError) { return originalLog => function () { + if (arguments.length === 0) { + // * arguments.length === 0 -> This is a logger.warn() type of call (without arguments), this will not log + // anything but simply return whether the log level in question is enabled for this logger. + // * this.fields.__in -> This is one of Instana's own loggers, we never want to trace those log calls. + return originalLog.apply(this, arguments); + } + if (cls.skipExitTracing({ isActive, skipAllowRootExitSpanPresence: true })) { return originalLog.apply(this, arguments); } diff --git a/packages/core/src/uninstrumentedLogger.js b/packages/core/src/uninstrumentedLogger.js index 15654b946a..8bbbb09057 100644 --- a/packages/core/src/uninstrumentedLogger.js +++ b/packages/core/src/uninstrumentedLogger.js @@ -8,12 +8,12 @@ const logger = require('pino'); function createCustomLogger() { - const customPino = Object.assign(function (/** @type {any} */ ...args) { + const customLogger = Object.assign(function (/** @type {any} */ ...args) { // @ts-ignore return logger(...args); }, logger); - return customPino; + return customLogger; } module.exports = createCustomLogger();