shadabahmed / logstasher

Awesome rails logs
MIT License
821 stars 136 forks source link

Custom Fields only works when an Exception is handled #120

Closed mtuckerb closed 8 years ago

mtuckerb commented 8 years ago

My add_custom_fields

LogStasher.add_custom_fields do |fields|
  fields[:request_params] = request.filtered_parameters.to_json
  fields[:environment] = Rails.env
  fields[:app] = "Farkwar"
  # fields[:user] = current_user && current_user.try(:email)
end

Output under normal operation

{"method":"GET","path":"/profile","format":"html","controller":"users","action":"edit","status":200,"duration":3680.81,"view":3571.64,"db":14.5,"source":"farkwar.dev","tags":["request"],"@timestamp":"2016-08-11T13:54:57.888Z","@version":"1"}

Output under exception

{"method":"GET","path":"/waypoints/1/edit","format":"html","controller":"waypoints","action":"edit","status":404,"duration":9.71,"error": ,"request_params":"{\"controller\":\"waypoints\",\"action\":\"edit\",\"id\":\"1\"}","environment":"development","app":"Farkwar","source":"farkwar.dev","tags":["request","exception"],"@timestamp":"2016-08-11T13:58:17.214Z","@version":"1"}

I have tried enabling and disabling every combination of _enabled in the configs. Have tried yaml and environments configs. Nothing seems to change this behavior.

notpad commented 8 years ago

Try to remove this line:

LogStasher::CustomFields.clear

in https://github.com/shadabahmed/logstasher/blob/master/lib/logstasher/rails_ext/action_controller/metal/instrumentation.rb

mtuckerb commented 8 years ago

Yup that worked. To use in production, will I have to run off my own branch, or will this be added to this repo soon?

MarcGrimme commented 8 years ago

Should be fixed now upstream with #119 . I'll close this issue.