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

Respect config.log_tags configuration option. #126

Open
akhramov opened this issue Dec 22, 2016 · 2 comments
Open

Respect config.log_tags configuration option. #126

akhramov opened this issue Dec 22, 2016 · 2 comments

Comments

@akhramov
Copy link

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

@shadabahmed
Copy link
Owner

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

@akhramov
Copy link
Author

akhramov commented Mar 4, 2017

@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) { ... }]

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

No branches or pull requests

2 participants