2
votes

I have rails application and different environment like development , staging and production , RAILS_ENV set that value. I want to add that field in the logstash for filterization of environment, so my question where do I set that variable and how , in logstash config or logstash forwarder

1

1 Answers

2
votes

Both, logstash and logstash forwarder are possible.

1) Logstash Forwarder

From logstash forwarder readme:

Any part of config can use environment variables as $VAR or ${VAR}. They will be evaluated before processing JSON, allowing to pass any structure.

Example forwarder.conf:

"files": [
    {
      "paths": [
        "./example.log"
      ],
      "fields": { 
        "type": "example",
        "env": "$RAILS_ENV"
        }
    }
  ]

Note: Logstash forwarder > 0.4.0 required

You can build the latest version following the instructions on github.


2) Logstash

In logstash you can set fields from environment variables using the environment filter.

Example:

filter {
     environment {
          add_field_from_env => { "ENV" => "RAILS_ENV" }
     }
}