hapijs / good

hapi process monitoring
Other
525 stars 161 forks source link

Custom Data With Good 7 #493

Closed thadclay closed 8 years ago

thadclay commented 8 years ago

I'm using Good 7, but I'm having a hard time figuring out how to pass additional data to an event. I want to add the request params and the users login but not sure how to do this. Here is my reporter setup.

file: [
      { module: 'good-squeeze', name: 'Squeeze', args: [{ response: '*' }] },
      {
        module: 'my-transform',
        name: 'DataFilters'
      },
      { module: 'good-squeeze', name: 'SafeJson' },
      { module: 'good-file', args: ['./logs/my_log.log'] }
    ]

Any help would be great.

vdeturckheim commented 8 years ago

Within the handler, you can call request.log (see doc here) Or do you want a more automated way to do this ?

thadclay commented 8 years ago

@vdeturckheim Thanks for the link to the docs. Ideally I would like a more automated way of doing it. I was trying to avoid doing it in each handler.

arb commented 8 years ago

The path, query parameters, and request body are available. See [https://github.com/hapijs/good/blob/master/lib/utils.js#L69-L70] and [https://github.com/hapijs/good/blob/master/lib/utils.js#L88-L90].

As far as the user credentials... that us unlikely unless they are somewhere in the query parameters or request body. What kind of auth are you using?

thadclay commented 8 years ago

I'm using hapi-auth-cookie for authentication.

arb commented 8 years ago

So that stuff is in request.auth.credentials and not exposed in any event payloads generated by good.

I am reluctant to include it as it is secure information and once it leaves good, I can't vouch for the security of anything else in the reporting pipeline. Plus then everything would have to strip that stuff off before logging for security reasons.

You may be able to do what you're looking for by adding "onPostAuth" or "onPreResponse" to the good extensions option. That might have what you're looking for since they expose the entire request object.

thadclay commented 8 years ago

Great. Thanks for the suggestions. I will look into the good extensions.

DuriDuri commented 6 years ago

@thadclay @vdeturckheim Did you guys figure out how to add data to the response event to be logged? I want to add userID information and can't seem to be able to have it passed through to the logs

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.