Skip to content

fix(pino-logging-gcp-config): log mutates input#192

Merged
nielm merged 1 commit intoGoogleCloudPlatform:mainfrom
tohalla:main
Jun 18, 2025
Merged

fix(pino-logging-gcp-config): log mutates input#192
nielm merged 1 commit intoGoogleCloudPlatform:mainfrom
tohalla:main

Conversation

@tohalla
Copy link
Copy Markdown
Contributor

@tohalla tohalla commented Jun 18, 2025

formatLogObject mutates input

Pino supports passing mergingObject as the first parameter for logging. Current implementation mutates the passed object instead of its copy (e.g. https://github.com/pinojs/pino/blob/116b1b17935630b97222fbfd1c053d199d18ca4b/test/formatters.test.js#L85).

We noticed the issue as we had request body passed as the first argument to pino logging.

Expected behaviour

const obj = {foo: "bar"}
pino(createGcpLoggingPinoConfig(
  { serviceContext: { service: "..." } },
  {},
)).info(obj)
// obj is still {foo: 'bar'}

Current behaviour

const obj = {foo: "bar"}
pino(createGcpLoggingPinoConfig(
  { serviceContext: { service: "..." } },
  {},
)).info(obj)
// obj is now {
//   foo: 'bar',
//   serviceContext: { service: '...' },
//   'logging.googleapis.com/insertId': '...'
// }

@google-cla
Copy link
Copy Markdown

google-cla Bot commented Jun 18, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Copy Markdown
Collaborator

@nielm nielm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this PR.

@nielm nielm merged commit 1e9fbbd into GoogleCloudPlatform:main Jun 18, 2025
2 checks passed
@nielm
Copy link
Copy Markdown
Collaborator

nielm commented Jun 18, 2025

@nielm
Copy link
Copy Markdown
Collaborator

nielm commented Jun 19, 2025

Apologies - v1.0.5 was built against an older version of the code without this fix - please use newly released 1.0.6

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 this pull request may close these issues.

2 participants