Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Config] pinoWillSendConfig leads to configuration mutation #1963

Closed
nioc opened this issue May 2, 2024 · 4 comments · Fixed by #1973
Closed

[Config] pinoWillSendConfig leads to configuration mutation #1963

nioc opened this issue May 2, 2024 · 4 comments · Fixed by #1973

Comments

@nioc
Copy link

nioc commented May 2, 2024

Hello,

I just upgrade from pino 8.19.0 to 8.21.0 and my code encounter this error:

Error: Can not update runtime configuration property: "pinoWillSendConfig". Configuration objects are immutable unless ALLOW_CONFIG_MUTATIONS is set.
    at Object.set (/home/nicolas/Dev/brewery/node_modules/config/lib/config.js:421:19)
    at transport (/home/nicolas/Dev/brewery/node_modules/pino/lib/transport.js:114:30)
    at normalizeArgs (/home/nicolas/Dev/brewery/node_modules/pino/lib/tools.js:316:16)
    at pino (/home/nicolas/Dev/brewery/node_modules/pino/pino.js:90:28)
    at createPinoLogger (/home/nicolas/Dev/brewery/node_modules/fastify/lib/logger.js:42:14)
    at createLogger (/home/nicolas/Dev/brewery/node_modules/fastify/lib/logger.js:101:18)
    at fastify (/home/nicolas/Dev/brewery/node_modules/fastify/fastify.js:135:33)
    at exports.default (/home/nicolas/Dev/brewery/apps/server/src/api/index.ts:22:25)

Here is my code on src/api/index.ts:

import Fastify, { FastifyLoggerOptions } from 'fastify'
import { PinoLoggerOptions } from 'fastify/types/logger'
import config from 'config'
// ...

export default async () => {
  const server = Fastify({
    logger: config.get('api.logger') as PinoLoggerOptions | FastifyLoggerOptions,
  })
 // ...
}

And the config:

{
  "api": {
    "logger": {
      "level": "debug",
      "redact": {
        "paths": [
          "req.headers.authorization",
          "api.session.secret"
        ],
        "censor": "****"
      },
      "transport": {
        "target": "pino-pretty",
        "options": {
          "translateTime": "HH:MM:ss Z",
          "ignore": "pid,hostname"
        }
      }
    }
  }
}

I try to add a attribute in both logger and logger.transport.options, nothing changes... So the logger received this config object:

{
  "pinoWillSendConfig": true,
  "level": "debug",
  "redact": {
    "paths": [
      "req.headers.authorization",
      "api.session.secret"
    ],
    "censor": "****"
  },
  "transport": {
    "target": "pino-pretty",
    "options": {
      "pinoWillSendConfig": true,
      "translateTime": "HH:MM:ss Z",
      "ignore": "pid,hostname"
    }
  }
}

It seems it is #1930 which add this, can you help me?

@nioc
Copy link
Author

nioc commented May 2, 2024

As a workaround, downgrading to 8.20 (with overrides in package.json as fastyify dependency was set to ^8.17.0):

{
  "dependencies": {
    "pino": "8.20",
  },
  "overrides": {
    "fastify": {
      "pino": "8.20"
    }
  }
}

@nioc nioc changed the title [Fastify/Pino pretty] Error: Can not update runtime configuration property: "pinoWillSendConfig". Configuration objects are immutable unless ALLOW_CONFIG_MUTATIONS is set. [Fastify/Config/Pino pretty] pinoWillSendConfig leads to configuration mutation May 4, 2024
@nioc
Copy link
Author

nioc commented May 5, 2024

Reproduced with simpler code:

import pino, { LoggerOptions } from 'pino'
import config from 'config'

// this does not work:
const loggerConfig = config.get('api.logger') as LoggerOptions

// this works but is ugly:
const loggerConfigWorkaround = JSON.parse(JSON.stringify(config.get('api.logger'))) as LoggerOptions

export const logger = pino({
  ...loggerConfig,
})
/home/nicolas/Dev/brewery/node_modules/config/lib/config.js:421
            throw Error(`Can not ${message} runtime configuration property: "${name}". Configuration objects are immutable unless ALLOW_CONFIG_MUTATIONS is set.`)
                  ^
Error: Can not add runtime configuration property: "pinoWillSendConfig". Configuration objects are immutable unless ALLOW_CONFIG_MUTATIONS is set.
    at Object.set (/home/nicolas/Dev/brewery/node_modules/config/lib/config.js:421:19)
    at transport (/home/nicolas/Dev/brewery/apps/server/node_modules/pino/lib/transport.js:114:30)
    at normalizeArgs (/home/nicolas/Dev/brewery/apps/server/node_modules/pino/lib/tools.js:316:16)
    at pino (/home/nicolas/Dev/brewery/apps/server/node_modules/pino/pino.js:90:28)
    at Object.<anonymous> (/home/nicolas/Dev/brewery/apps/server/src/logger.ts:6:27)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module.m._compile (/home/nicolas/Dev/brewery/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Object.require.extensions.<computed> [as .ts] (/home/nicolas/Dev/brewery/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1207:32)

@nioc nioc changed the title [Fastify/Config/Pino pretty] pinoWillSendConfig leads to configuration mutation [Config] pinoWillSendConfig leads to configuration mutation May 5, 2024
@inwenis
Copy link

inwenis commented May 7, 2024

Encountered same issue, thank you for the solution @nioc

@nioc
Copy link
Author

nioc commented May 15, 2024

Thanks @mcollina for the fix ; now I'm waiting for testing it in 9.2.0 (or 9.1.1) release 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants