diff --git a/packages/collector/package.json b/packages/collector/package.json index 85d5305b0d..0b8a554a56 100644 --- a/packages/collector/package.json +++ b/packages/collector/package.json @@ -82,7 +82,7 @@ "dependencies": { "@instana/core": "4.0.1", "@instana/shared-metrics": "4.0.1", - "bunyan": "^1.8.15", + "pino": "^9.5.0", "semver": "^7.5.4", "serialize-error": "^8.1.0" }, @@ -90,7 +90,6 @@ "@instana/autoprofile": "4.0.1" }, "devDependencies": { - "@types/bunyan": "^1.8.8", "opentracing": "^0.14.5", "typeorm": "^0.3.20" } diff --git a/packages/collector/src/agent/bunyanToAgentStream.js b/packages/collector/src/agent/loggerToAgentStream.js similarity index 100% rename from packages/collector/src/agent/bunyanToAgentStream.js rename to packages/collector/src/agent/loggerToAgentStream.js diff --git a/packages/collector/src/logger.js b/packages/collector/src/logger.js index 2fd3281615..103c942259 100644 --- a/packages/collector/src/logger.js +++ b/packages/collector/src/logger.js @@ -16,12 +16,11 @@ try { // thread (0). } -const bunyan = require('bunyan'); +const pino = require('pino'); const { logger } = require('@instana/core'); +const pinoToAgentStream = require('./agent/loggerToAgentStream'); -const bunyanToAgentStream = require('./agent/bunyanToAgentStream'); - -/** @type {bunyan | import('@instana/core/src/core').GenericLogger} */ +/** @type {pino.Logger | import('@instana/core/src/core').GenericLogger} */ let parentLogger = null; /** @type {Object. *>} */ const registry = {}; @@ -31,40 +30,39 @@ const registry = {}; * @param {boolean} [isReInit] */ exports.init = function init(config, isReInit) { - if (config.logger && typeof config.logger.child === 'function') { - // A bunyan or pino logger has been provided via config. In either case we create a child logger directly under the - // given logger which serves as the parent for all loggers we create later on. + if (config.logger && isPino(config.logger)) { + // A pino logger has been provided via config; create a child logger directly under it. parentLogger = config.logger.child({ module: 'instana-nodejs-logger-parent', __in: 1 }); } else if (config.logger && hasLoggingFunctions(config.logger)) { - // A custom non-bunyan logger has been provided via config. We use it as is. + // A custom logger has been provided; use it as is. parentLogger = config.logger; } else { - // No custom logger has been provided via config, we create a new bunyan logger as the parent logger for all loggers - // we create later on. - parentLogger = bunyan.createLogger({ + // No custom logger has been provided; create a new pino logger as the parent logger for all loggers + parentLogger = pino({ name: '@instana/collector', - thread: threadId, - __in: 1 - }); - } - if (isBunyan(parentLogger)) { - // in case we are using a bunyan logger we also forward logs to the agent - /** @type {bunyan} */ (parentLogger).addStream({ - type: 'raw', - stream: bunyanToAgentStream, - level: 'info' + level: 'info', + base: { + thread: threadId, + __in: 1 + }, + transport: { + target: 'pino/file', + options: { + destination: pinoToAgentStream, + sync: false + } + } }); + if (process.env['INSTANA_DEBUG']) { - /** @type {bunyan} */ (parentLogger).level('debug'); + parentLogger.level = 'debug'; } else if (config.level) { - /** @type {bunyan} */ (parentLogger).level(/** @type {import('bunyan').LogLevel} */ (config.level)); + parentLogger.level = config.level; } else if (process.env['INSTANA_LOG_LEVEL']) { - /** @type {bunyan} */ (parentLogger).level( - /** @type {import('bunyan').LogLevel} */ (process.env['INSTANA_LOG_LEVEL'].toLowerCase()) - ); + parentLogger.level = process.env['INSTANA_LOG_LEVEL'].toLowerCase(); } } @@ -110,11 +108,12 @@ exports.getLogger = function getLogger(loggerName, reInitFn) { }; /** - * @param {import('bunyan') | *} _logger + * @param {import('pino').Logger | *} _logger * @returns {boolean} */ -function isBunyan(_logger) { - return _logger instanceof bunyan; +function isPino(_logger) { + // _logger.hasOwnProperty('pino') + return _logger && _logger[Symbol.for('pino.logger')] === true; } /**