-
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
Fix setting request id #44
Conversation
2 similar comments
logger.js
Outdated
@@ -121,7 +121,7 @@ function wrapReqSerializer (serializer) { | |||
function asReqValue (req) { | |||
var connection = req.connection | |||
const _req = Object.create(pinoReqProto) | |||
_req.id = req.id | |||
_req.id = Function.prototype.isPrototypeOf(req.id) ? req.id() : req.id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not typeof req.id === 'function'
? Which one is faster?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unless there's a speed benefit.. definitely go with typeof
here...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/shrug, I prefer using the actual API. I haven't tested for any difference in speed.
test.js
Outdated
logger: pino(dest), | ||
serializers: { | ||
req: function (req) { | ||
t.is(Function.isPrototypeOf(req.id), false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer typeof
- unless there's some really awesome reasons
test.js
Outdated
server.unref() | ||
server.listen(0, () => { | ||
const port = server.address().port | ||
http.get(`http://127.0.0.1:${port}`, () => {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pointless pedantry: you could just do http.get(server.address(), () => {})
1 similar comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
While updating
restify-pino-logger
I learned that the request id property was not getting set properly. I'm don't know how it ever was. Consider:First it's set to a function and then that function is assigned to the property.
This PR simply invokes the
req.id
function in the serializer if it is actually a function. Otherwise it assigns whatever that value is to the property.