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

Expose req._startAt and req._startTime to be similar to morgan #65

Closed
niftylettuce opened this issue Jun 13, 2019 · 7 comments
Closed

Comments

@niftylettuce
Copy link

https://github.com/expressjs/morgan/blob/master/index.js#L500-L508

@niftylettuce
Copy link
Author

Also https://github.com/pinojs/pino-http/blob/master/logger.js#L63 could probably be changed so that it also sets req[startTime].

@niftylettuce
Copy link
Author

niftylettuce commented Jun 13, 2019

The reason I need this is because I want record the time the request was received in a log, and this is the easiest approach, since this is a timer that starts when it is received and is also the same timer used for calculation of response time.

@davidmarkclements
Copy link
Member

Since we're modifying req objects we wanted to be as least invasive as possible we use a symbol because it's "more private".

The startTime symbol is exposed: https://github.com/pinojs/pino-http/blob/master/logger.js#L108 would that be enough to work with your end?

@niftylettuce
Copy link
Author

niftylettuce commented Jun 13, 2019

This would require me to require the package and install it in my log parser, which I really didn't want to do, since the log parser I'm writing is a library to be published in npm.

Edit: And it's also a parser that works in browsers.

@niftylettuce
Copy link
Author

Prefixing with an underscore as morgan does is probably sufficient enough.

@davidmarkclements
Copy link
Member

We could expose it using Symbol.for, and then you can use Symbol.for('pino-http.startTime')

That way you don't have to require the package, and we don't have add more noise to the req/res objects. I'd be happy to accept a PR for altering to Symbol.for

@niftylettuce
Copy link
Author

Closing in favor of #66 and #67

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

No branches or pull requests

2 participants