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

Apply err serializer everywhere. #896

Merged
merged 4 commits into from
Oct 22, 2020
Merged

Conversation

mcollina
Copy link
Member

Apply the error serializer if the error object is top-level. It does not seem to cause any performance regressions from my checks.

Fixes #895

lib/proto.js Show resolved Hide resolved
@YouriT
Copy link

YouriT commented Aug 17, 2020

Be careful that this PR is bringing a breaking change if people were to leverage current behaviour.

@jsumners
Copy link
Member

Be careful that this PR is bringing a breaking change if people were to leverage current behaviour.

Agreed.

@mcollina
Copy link
Member Author

Be careful that this PR is bringing a breaking change if people were to leverage current behaviour.

TBH, I would consider that a bug in anybody codebase :(.


@jsumners I think this is almost good to go. I do not see any other way in which we can fix the change without breaking anybody.

@YouriT
Copy link

YouriT commented Aug 17, 2020

Be careful that this PR is bringing a breaking change if people were to leverage current behaviour.

TBH, I would consider that a bug in anybody codebase :(.

@jsumners I think this is almost good to go. I do not see any other way in which we can fix the change without breaking anybody.

Maybe it deserves a version bump with a breaking change notice in changelog.

Copy link
Member

@jsumners jsumners left a comment

Choose a reason for hiding this comment

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

LGTM, but do we think this is a semver major?

@mcollina
Copy link
Member Author

I'm torn. I don't see why anybody would not want this change, however we have recently bumped major and I do not want this to sit there for a long cycle.

This is be breaking if folks are relying on the difference between things. However this pops every now and then.. and I do not see why somebody would not want this. In fact, it is number 1 reason why I do not recommend logger.info(err).

} else {
obj = Object.assign(mixin ? mixin() : {}, _obj)
if (!msg && objError) {
} else if (_obj instanceof Error) {
Copy link
Member

Choose a reason for hiding this comment

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

what versions did you find there was no slow down? I thought instanceof was expensive? Is that no longer true in 12 and 14?

Copy link

Choose a reason for hiding this comment

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

instanceof was already there. Now there is even a branching being skipped in opposition to the original code.

Copy link
Member

@davidmarkclements davidmarkclements left a comment

Choose a reason for hiding this comment

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

do we need docs for this?

pino/browser.js serializer API needs to be synced with this

@davidmarkclements
Copy link
Member

So the breaking change will be that if someone is using a custom error serializer and then do logger.info(err) the log output will now be different?

@jsumners
Copy link
Member

do we need docs for this?

pino/browser.js serializer API needs to be synced with this

Yes, we need docs. I forgot to block on that 🤦

So the breaking change will be that if someone is using a custom error serializer and then do logger.info(err) the log output will now be different?

The change is that if someone does logger.info(err) they will now potentially get serialized output instead of nothing.

@YouriT
Copy link

YouriT commented Aug 17, 2020

The change is that if someone does logger.info(err) they will now potentially get serialized output instead of nothing.

AFAIK there isn't nothing at the moment, there is the error logged without passing it through the serializer. Hence message, stack, type and all other keys of the Error object are linked to the root of the log entry.

@jsumners
Copy link
Member

The change is that if someone does logger.info(err) they will now potentially get serialized output instead of nothing.

AFAIK there isn't nothing at the moment, there is the error logged without passing it through the serializer. Hence message, stack, type and all other keys of the Error object are linked to the root of the log entry.

Typically, Error.prototype.toString() only returns the message.

@naseemkullah
Copy link
Contributor

There seems to be no documentation with this PR, so I'll just ask here if that is ok:

does this mean we do not have to call the error object err anymore for pino to treat it special and serialize it as an error?

i.e. after this pr is merged:

const foo = new Error('hello');
const bar = {a: 'b'};
logger.error({foo, bar}, foo.message);

will result in foo being serialized?

@jsumners
Copy link
Member

No. This PR addresses log.error(Error('message')).

@mcollina
Copy link
Member Author

@davidmarkclements the browser version requires no changes as far as I understand: https://github.com/pinojs/pino/blob/master/test/browser-serializers.test.js#L47-L66. Please confirm

@davidmarkclements
Copy link
Member

@mcollina 🤣 ok great, yeah confirmed. We've synchronised server pino with browser pino here instead hahaha.

Copy link
Member

@davidmarkclements davidmarkclements left a comment

Choose a reason for hiding this comment

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

👍

@mcollina
Copy link
Member Author

@davidmarkclements @jsumners semver-major or semver-minor?

@jsumners
Copy link
Member

I thought I asked first?
https___i pinimg com_originals_55_0d_2f_550d2f2403def50331d02c031fae22b0

@mcollina
Copy link
Member Author

You did! I'm passing that to @davidmarkclements!

@mcollina
Copy link
Member Author

mcollina commented Sep 6, 2020

Any objection in shipping this in v6? @jsumners @davidmarkclements @delvedor @watson and possibly any others?

@jsumners
Copy link
Member

jsumners commented Sep 6, 2020

If we use the justification that this fixes expected behavior, then we can do a minor release. Ideally, we'd issue a major out of an abundance of caution. But I am okay either way.

@mcollina
Copy link
Member Author

mcollina commented Sep 6, 2020

I'm ok either way. We'll see if we can bump the major in Fastify. Let's do a major.

Copy link
Contributor

@delvedor delvedor left a comment

Choose a reason for hiding this comment

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

I think it can be shipped as a minor, maybe with a note in the docs for showing how to get the old behavior?

@mcollina
Copy link
Member Author

mcollina commented Sep 7, 2020

I think it can be shipped as a minor, maybe with a note in the docs for showing how to get the old behavior?

You can't get the old behavior, that's part of the problem.

@xamgore
Copy link

xamgore commented Oct 14, 2020

When nestedKey is defined and Error is passed to the logger, no fields will be displayed in the output. Does this PR fix it? Do I correctly understand @watson is the only person left to review the code?

export const logger = pino({
  nestedKey: 'payload',
})

process.on('uncaughtException', final(logger, (err, finalLogger) => {
  finalLogger.error(err, 'uncaughtException')
  process.exit()
}))

throw Error('wow') // { level: 50, pid, hostname, payload: {}, message: "uncaughtException"}

@mcollina mcollina added this to the v7.0.0 milestone Oct 22, 2020
@mcollina mcollina added the v7 label Oct 22, 2020
@mcollina mcollina changed the base branch from master to next October 22, 2020 10:25
@mcollina mcollina merged commit 6bc1b93 into next Oct 22, 2020
@mcollina mcollina deleted the apply-err-serializer-everywhere branch October 22, 2020 10:26
@mcollina
Copy link
Member Author

Landed in the next branch, prepping for v7.

davidmarkclements pushed a commit that referenced this pull request Dec 13, 2020
* Apply err serializer everywhere.

* Handle cases where the err serializer is not set

* Added docs

* Typo
mcollina added a commit that referenced this pull request Jan 4, 2021
* Apply err serializer everywhere. (#896)

* Apply err serializer everywhere.

* Handle cases where the err serializer is not set

* Added docs

* Typo

* Merge error flows. (#923)

Merge the 2 error flows:
* if obj is of type Error wrap it in `{ err }`
* if msg not present set to error message (if present)

Update tests. Update API doc

* Check for undefined value instead of falsy ones

Co-authored-by: Matteo Collina <[email protected]>
Co-authored-by: Mihai Voicescu <[email protected]>
@github-actions
Copy link

github-actions bot commented Feb 2, 2022

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error serializer only works on sub err object
7 participants