logstasher icon indicating copy to clipboard operation
logstasher copied to clipboard

Respect config.log_tags configuration option.

Open akhramov opened this issue 8 years ago • 2 comments

Rails has a logger configuration option: .log_tags:

config.log_tags accepts a list of: methods that the request object responds to, a Proc that accepts the request object, or something that responds to to_s. This makes it easy to tag log lines with debug information like subdomain and request id - both very helpful in debugging multi-user production applications.

Is it a good Idea to include entries specified in config.log_tags to logstash log as well? If so I will be happy to create a PR.

http://guides.rubyonrails.org/configuring.html#rails-general-configuration

akhramov avatar Dec 22 '16 07:12 akhramov

Hey @akhramov .. I haven't used log_tags much. Could you reply back with an example ?

shadabahmed avatar Mar 01 '17 19:03 shadabahmed

@shadabahmed

Sure! Log tags are configured this way:

# config/application.rb
config.log_tags = [:remote_ip, ->(request) { request.headers["Content-Type"] }]

Then Rails will log something like this:

[10.69.37.58] [text/plain] Rendered app/views/users/index.erb

It would be nice to have these tags appearing in logstash logs as well. I.e. given the previous example, the corresponding logstash log entry would be as following:

{
  "@version": "1",
  "@timestamp": "2017-03-04T13:20:17.749Z",
  "source": "unknown",
  "tags": [
    "request",
    "10.69.37.58",
    "text/plain"
  ],
  "request_id": "e4bc8364-d0b6-410f-b05c-151fd9ef9ab4",
  "route": "users#index",
  "ip": "10.69.37.58",
  "duration": 0.89,
  "status": 200,
  "action": "index",
  "controller": "users",
  "format": "*\/*",
  "path": "\/users",
  "method": "GET"
}

The only thing I'm concerned of is we might break existing applications if they use log_tags, but do not expect them to appear in Kibana. :) How about introducing new configuration option, like:

config.logstasher.log_tags = [:remote_ip, ->(request) { ... }]

akhramov avatar Mar 04 '17 08:03 akhramov