Skip to content

Commit

Permalink
refactor: Updated pino instrumentation to separate the wrapping of as…
Browse files Browse the repository at this point in the history
…Json into its own function (#2464)
  • Loading branch information
bizob2828 authored Aug 14, 2024
1 parent a4570e9 commit 81fdde1
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions lib/instrumentation/pino/pino.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const {
} = require('../../util/application-logging')
const semver = require('semver')

// eslint-disable-next-line sonarjs/cognitive-complexity
module.exports = function instrument(shim, tools) {
const pinoVersion = shim.pkgVersion

Expand All @@ -35,7 +34,20 @@ module.exports = function instrument(shim, tools) {
const metrics = agent.metrics
createModuleUsageMetric('pino', metrics)

wrapAsJson({ shim, tools })
}

/**
* Wraps `asJson` to properly decorate and forward logs
*
* @param {object} params to function
* @param {Shim} params.shim instance of shim
* @param {object} params.tools exported `pino/lib/tools`
*/
function wrapAsJson({ shim, tools }) {
const symbols = shim.require('./lib/symbols')
const { agent } = shim
const { config, metrics } = agent

shim.wrap(tools, 'asJson', function wrapJson(shim, asJson) {
/**
Expand Down Expand Up @@ -98,16 +110,14 @@ module.exports = function instrument(shim, tools) {
* reformats error and assigns NR context data
* to log line
*
* @param logLine.logLine
* @param {object} logLine log line
* @param {object} metadata NR context data
* @param {string} chindings serialized string of all common log line data
* @param logLine.args
* @param logLine.agent
* @param logLine.chindings
* @param logLine.msg
* @param logLine.level
* @param logLine.logger
* @param {object} params to function
* @param {object} params.logLine log line
* @param {string} params.msg message of log line
* @param {object} params.agent instance of agent
* @param {string} params.chindings serialized string of all common log line data
* @param {string} params.level log level
* @param {object} params.logger instance of agent logger
* @returns {function} wrapped log formatter function
*/
function reformatLogLine({ logLine, msg, agent, chindings = '', level, logger }) {
const metadata = agent.getLinkingMetadata()
Expand Down

0 comments on commit 81fdde1

Please sign in to comment.