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

Fix req object placement #322

Closed
wants to merge 2 commits into from
Closed

Conversation

stychu
Copy link

@stychu stychu commented Jan 19, 2024

Comment on lines +1263 to +1265
customReceivedObject: function (req) {
return { req }
},
Copy link
Author

@stychu stychu Jan 19, 2024

Choose a reason for hiding this comment

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

I am bit skeptical about this test. Not sure if this change is ok or I rather should update the source code to include req at this line https://github.com/pinojs/pino-http/blob/master/logger.js#L191 as const receivedObjectResult = onRequestReceivedObject !== undefined ? onRequestReceivedObject(req, res, undefined) : { [reqKey]: req } and remove the addition in the test?

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

Unfortunately creating a child logger with the given request set is critical to keep attributing all logs to the given request.

@stychu
Copy link
Author

stychu commented Jan 23, 2024

Unfortunately creating a child logger with the given request set is critical to keep attributing all logs to the given request.

Not sure if I follow. I believe it does keep the request set to all logs having it this way. req is present for all logs unless this condition is meet

const receivedObjectResult = onRequestReceivedObject !== undefined ? onRequestReceivedObject(req, res, undefined) : {}

that why Im not sure about that one test. If the req should be added to this false evaluated condition then all logs will contain req/res objects

@mcollina
Copy link
Member

mcollina commented Feb 1, 2024

I've run the example.js file in both master and this PR. It's different.

master

➜  pino-http git:(master) node example.js
{"level":30,"time":1706779462620,"pid":27894,"hostname":"mcl","req":{"id":1,"method":"GET","url":"/","headers":{"host":"localhost:3000","user-agent":"curl/8.4.0","accept":"*/*"},"remoteAddress":"::1","remotePort":56915},"msg":"something else"}
{"level":30,"time":1706779462624,"pid":27894,"hostname":"mcl","req":{"id":1,"method":"GET","url":"/","headers":{"host":"localhost:3000","user-agent":"curl/8.4.0","accept":"*/*"},"remoteAddress":"::1","remotePort":56915},"res":{"statusCode":200,"headers":{}},"responseTime":4,"msg":"request completed"}

This PR:

➜  pino-http git:(fix-nexted-key) node example.js
{"level":30,"time":1706779498790,"pid":28809,"hostname":"mcl","msg":"something else"}
{"level":30,"time":1706779498793,"pid":28809,"hostname":"mcl","req":{"id":1,"method":"GET","url":"/","headers":{"host":"localhost:3000","user-agent":"curl/8.4.0","accept":"*/*"},"remoteAddress":"::1","remotePort":56932},"res":{"statusCode":200,"headers":{}},"responseTime":3,"msg":"request completed"}

@mcollina mcollina closed this Feb 1, 2024
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.

nestedKey now working properly
2 participants