hapijs / good

hapi process monitoring
Other
525 stars 160 forks source link

Provide request headers in various payload events #557

Closed bodawei closed 7 years ago

bodawei commented 7 years ago

We'd like to be able to access request headers in the various events (RequestError and RequestLog) listed in https://github.com/hapijs/good/blob/master/lib/utils.js that accept a request (similar to RequestSent).

The reason for this is to be able to access certain request headers that we then want to add to our logs.

bodawei commented 7 years ago

Note: I can provide a pull request with this change!

arb commented 7 years ago

Are you sure request headers are always available?

bodawei commented 7 years ago

In our case, yes. But, I think we'd do a conditional check and adding them if they are there.

bodawei commented 7 years ago

@arb I've been thinking about your comment, and wonder if you know something I don't. Is there some reason the request headers wouldn't be there?

arb commented 7 years ago

I don't know, I just am kind of remembering that certain events don't include headers as there wasn't a request associated with the event.

I also feel like this could be a security concern. I think generally you attach some kind of unique ID in headers or body, rather than logging user information.

bodawei commented 7 years ago

Oh, definitely, some events don't have a request. I'm speaking only of the ones that do.

As for the security concern, I agree with you that logging user information isn't desirable! In our particular case, we've got a trace id, that is an id that identifies a particular request that we want to be able to track as it runs across services in our system. That's carried in a particular HTTP header. So, if an error occurs, we'd like to be able to log that ID along with the error information so we know which request it happened with. The problem is just that those headers are not accessible from within the value generated by, say RequestError .

bodawei commented 7 years ago

@arb fwiw, this is roughly what I have in mind (note this is just a draft... no testing or anything yet. so don't take it too seriously. I'm just demonstrating with code something like what I am suggesting:

https://github.com/bodawei/contrib-good/commit/7666ddde8e5c4c2c6ff44c31f23ebdc02b09124a

lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.