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

apply default serializer.req before using configured serializer.req #34

Closed
wants to merge 4 commits into from

Conversation

benib
Copy link
Contributor

@benib benib commented Nov 26, 2017

This serializes the req using the internal asReqValue before passing the result to any configured serializer.req. This is to make it work in combination with pino-noir and a configuration redacting a value in the req object. e.g.

{
    plugin: require('hapi-pino'),
    options: {
      serializers: noir(['req.headers.authorization'])
    }
  }

It is inspired by the discussion in this issue: pinojs/express-pino-logger#14

This change is BC breaking as before any configured serializer got the original req object without being passed through asReqValue. One test case is changed to reflect this.

I am not sure if this makes sense. Another solution would be to do this within a function passed to
options.serializers.req directly. Although this would slightly complicate the usage of pino-noir together with this plugin.

I am also not sure if this should be done for res as well and if you would like to see this as copied code (just for res instead of req) or if you prefer to have it in a separate function called with res or req returning the function.

Let me know if I should change anything.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.08%) to 98.229% when pulling 1fc78ce on benib:overriding-req-serializer into 4d67abf on pinojs:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.08%) to 98.229% when pulling 1fc78ce on benib:overriding-req-serializer into 4d67abf on pinojs:master.

Copy link
Contributor

@jsumners jsumners left a comment

Choose a reason for hiding this comment

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

LGTM

@coveralls
Copy link

coveralls commented Nov 26, 2017

Coverage Status

Coverage increased (+0.06%) to 98.368% when pulling e4c3ece on benib:overriding-req-serializer into 4d67abf on pinojs:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.06%) to 98.368% when pulling e4c3ece on benib:overriding-req-serializer into 4d67abf on pinojs:master.

@felixheck
Copy link
Collaborator

Mhh..I don't know. This results in an issue that the serializes doesn't get the whole information which breaks existing serializers and doesn't feel like best practice.

Perhaps it's better so pass req and additionally asReqValue to the serializer so the dev can decide if he wants the whole request object or just the simplified:

options.serializers.req = (req, asReqValue) => (
  (options.serializers.req | asReqValue)(req, asReqValue)
)

@benib
Copy link
Contributor Author

benib commented Nov 27, 2017

@felixheck Yes, this would break existing serializers that are implemented against the complete request object. This is a problem. I agree.

I'd rather export asReqValue from hapi-pino instead of passing it in though. pino-http does this here: https://github.com/pinojs/pino-http/blob/master/logger.js#L107-L110

As far as I know me as a dev has to apply asReqValue at some point though to stay compatible with https://github.com/pinojs/pino-toke#supports and probably others.
I do not have a lot of experience with pino, so I am not sure what the strategy about keeping these serializers "compatible" as in producing the same req log object. But I guess this should be synced with pinojs/express-pino-logger#14 and others somehow.

I am happy to help with any implementation but would rather leave the decision to people who have more experience with pino and these http-style serializers as it can have quite some implications for the future.

@felixheck
Copy link
Collaborator

Mhh..yeah, exposing asReqValue seems to be the smartest solution. At least in my point of view.

@benib
Copy link
Contributor Author

benib commented Nov 27, 2017

@felixheck so should we go for not overriding but exposing asReqValue and documenting that one should use asReqValue in any custom serializer passed to options.serializers.req? I would send another PR in favor of this one then.
Any opinion from @davidmarkclements? The implementation in this PR is based on your comment here: pinojs/express-pino-logger#14 and handling this in the same way would make a lot of sense imo.

@felixheck
Copy link
Collaborator

@mcollina has the last word ;-)

index.js Outdated
if (options.serializers.req) {
const oriqReqSerializer = options.serializers.req
options.serializers.req = (req) => {
return oriqReqSerializer(asReqValue(req))
Copy link
Contributor

Choose a reason for hiding this comment

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

oriqReqSerializer => origReqSerializer

@jsumners
Copy link
Contributor

How about attaching req.raw as a non-enumerable property when invoking the original serializer?

@coveralls
Copy link

Coverage Status

Coverage increased (+0.06%) to 98.368% when pulling d5fdeef on benib:overriding-req-serializer into 4d67abf on pinojs:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.06%) to 98.368% when pulling d5fdeef on benib:overriding-req-serializer into 4d67abf on pinojs:master.

@jsumners
Copy link
Contributor

jsumners commented Dec 2, 2017

See pinojs/pino-http#43

@benib
Copy link
Contributor Author

benib commented Dec 3, 2017

@jsumners the plan is that hapi-pino could or should wrap around pino-http?

@jsumners
Copy link
Contributor

jsumners commented Dec 3, 2017

@benib unfortunately I don't think so. But I believe whatever solution we settle upon there should be used here.

@jsumners jsumners mentioned this pull request Dec 4, 2017
@davidmarkclements
Copy link
Collaborator

hey guys thanks for all the input here!

@benib - pino-http is the basis for express and koa loggers, but Hapi is too different to integrate with efficiently so it has it's own implementation

@felixheck - the full req serialization is a bug that occurs when adding multiple serializers, which is unfortunate. However it doesn't happen in the main case. To retain the full request behaviour we simply provide a new serializer, let's not change the serializer format as this is more disruptive.

Regarding how we collaborate on Pino and Pino's ecosystem:

@mcollina and I wrote pino core together, @mcollina wrote hapi-pino, I wrote pino-http (express-pino-logger, koa-pino-logger, ...) and as in pretty much all cases when there's a hot topic, the "last word" tends to come from agreement between @mcollina, @jsumners and myself. In this particular case I trust @jsumners judgement (as does @mcollina) on which way to take pino-http, which should tease out a direction for this issue.

@benib
Copy link
Contributor Author

benib commented Dec 4, 2017

thanks for all the explanations. I will leave this PR open and close it once I come up with one fixing the issue along the lines of pino-http once pinojs/pino-http#43 is settled. Or anyone else picks this up. No hard feelings here.

@davidmarkclements
Copy link
Collaborator

davidmarkclements commented Dec 4, 2017

thank you @benib !

@jsumners
Copy link
Contributor

jsumners commented Dec 8, 2017

pino-http has been updated to v3.0.0 which solves this same problem. I recommend looking at how it was solved there and applying that solution to this PR.

@mcollina
Copy link
Collaborator

@benib would you mind updating this PR?

@benib
Copy link
Contributor Author

benib commented Dec 18, 2017

@mcollina sorry was pretty overwhelmed with work the last days. will try to get to that before the end of the year. If someone has the resources to take over, feel free.

@benib benib mentioned this pull request Jan 2, 2018
@benib
Copy link
Contributor Author

benib commented Jan 2, 2018

closed in favor of: #42

@benib benib closed this Jan 2, 2018
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.

6 participants