-
Notifications
You must be signed in to change notification settings - Fork 116
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
Pino-http logs a different error from the one sent by express #348
Comments
Please provide a minimal reproducible example. Doing so will help us diagnose your issue. It should be the bare minimum code needed to trigger the issue, and easily runnable without any changes or extra code. You may use a GitHub repository to host the code if it is too much to fit in a code block (or two). |
I'm not sure I understand, the first two line of the issue read like this:
You'll find a minimal reproducible example in that repo |
I would hardly consider that minimal, given the build step, but I was able to reproduce anyway. I've checked the example and pino-http behaves as expected. The "hacky" fix is indeed the correct one. However, I think we could provide an express-specific variant that where the middleware intercept the first, Lines 89 to 93 in a4b581a
In this way we can intercept the error as it's passing through the middleware chain. Would you like to send a PR? |
Not to stray from the issue, but having a build step seems inevitable since pino-http has typescript support? The docs do mention esbuild support too and suggest using the plugin that's setup in the repro. It seems to me the repro is quite "portable" and has two commands that would run without additional setup, what would you guys expect? I'd gladly help with the PR, but I'm not sure what's entailed by |
For me, I want a JavaScript reproduction. I have updated my saved reply to indicate as much as a result of this thread. But I also just didn't see the link originally. I had skimmed the report enough to recognize that we'd need one for clarity, but I missed the link. 🤷♂️ |
A middleware like: const result = (req, res, next) => {
return loggingMiddleware(logger, req, res, next)
}
result.logger = logger
result.express = (err, req, res, next) => {
res.err = err
return loggingMiddleware(logger, req, res, next)
}
return result |
Reproduction
https://github.com/theo-m/repro-pino-http-error
You'll observe that express does send the responses appropriately with the right errors - but, what's logged by Pino is entirely different.
What the client receives (👍 )
What the logger emits (👎 )
I had initially submitted this problem to Sentry as I had messed up my repro and the logger's stack trace pointed to Sentry/OTel - but even without these packages the problem persists.
Looking at this part of the lib, I can get what I want with this patch, but it seems hacky?
It seems this line expects an event, but it doesn't seem to exist on node's Response or OutgoingMessage objects?
The text was updated successfully, but these errors were encountered: