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

feat: add support for request-received middleware (closes #66) #67

Closed
wants to merge 1 commit into from
Closed

feat: add support for request-received middleware (closes #66) #67

wants to merge 1 commit into from

Conversation

niftylettuce
Copy link

No description provided.

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.

when we expose symbols in pino we prefix with the pino namespace, see https://github.com/pinojs/pino/blob/master/lib/symbols.js#L30

@@ -4,6 +4,7 @@ var pino = require('pino')
var serializers = require('pino-std-serializers')

var startTime = Symbol('startTime')
var requestReceivedStartTime = Symbol.for('request-received.startTime')
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var requestReceivedStartTime = Symbol.for('request-received.startTime')
var startTime = Symbol.for('pino-http.startTime')

@@ -4,6 +4,7 @@ var pino = require('pino')
var serializers = require('pino-std-serializers')

var startTime = Symbol('startTime')
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var startTime = Symbol('startTime')

@@ -60,7 +61,7 @@ function pinoLogger (opts, stream) {
function loggingMiddleware (req, res, next) {
req.id = genReqId(req)
req.log = res.log = logger.child({req: req})
res[startTime] = res[startTime] || Date.now()
res[startTime] = res[startTime] || req[requestReceivedStartTime] ? req[requestReceivedStartTime].getTime() : Date.now()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
res[startTime] = res[startTime] || req[requestReceivedStartTime] ? req[requestReceivedStartTime].getTime() : Date.now()
res[startTime] = res[startTime] || Date.now()

@niftylettuce
Copy link
Author

@davidmarkclements these aren't symbols being exposed by pino, they're exposed by request-received, which I created as a standard for Koa and Express communities

@davidmarkclements
Copy link
Member

davidmarkclements commented Jun 13, 2019

cool, since you pushed it two hours ago and don't have anyone depending on it yet it'll be super easy to update. If one module consumes another, the consuming module integrates using consumed modules API's - rarely the other way round.

@niftylettuce
Copy link
Author

The point of the package is to simply expose these as Symbols for any package to consume - I didn't want to prefix it with pino-http since it's not related to pino-http, it simply adds to the request object a process.hrtime() and new Date() object using the Symbol.

@niftylettuce
Copy link
Author

I guess I could however update the package so that it also defines req[pinoHttpStartTimeSymbol] in addition.

@davidmarkclements
Copy link
Member

I get what you're trying to do with your package but this isn't the way to do, you'll have to think of another way. Closing - feel free to reopen if it becomes useful to you in the requested form

@niftylettuce niftylettuce deleted the patch-1 branch June 13, 2019 23:18
@davidmarkclements
Copy link
Member

sorry I didn't see #67 (comment) before closing - that could work.

@niftylettuce
Copy link
Author

The purpose of this isn't so people use Cabin, it's so people that don't want to use Cabin's middleware and simply want to use parse-request can do so.

https://github.com/cabinjs/parse-request (major update coming soon)

@davidmarkclements
Copy link
Member

feel free to reopen if plan is to consume the pino symbol

@niftylettuce
Copy link
Author

def will do

niftylettuce added a commit to cabinjs/request-received that referenced this pull request Jun 14, 2019
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