Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to launch a Ruby debugger from within the Logstash Ruby filter plugin?

Is it possible to launch a Ruby debugger from within the Logstash Ruby filter plugin? It would be very handy for debugging.

like image 836
David P Avatar asked Oct 24 '16 19:10

David P


People also ask

How do I use a Logstash ruby filter?

To add inline ruby in your filter, place all code in the code option. This code will be executed for every event the filter receives. You can also place ruby code in the init option. It will be executed only once during the plugin's register phase.

Does Logstash need Ruby?

Logstash has a rich set of filters, and you can even write your own, but often this is not necessary since there is a out-of-the-box filter that allows you to embed Ruby code directly in the configuration file.

What is Logstash filter?

The filters of Logstash measures manipulate and create events like Apache-Access. Many filter plugins used to manage the events in Logstash. Here, in an example of the Logstash Aggregate Filter, we are filtering the duration every SQL transaction in a database and computing the total time.

What is Ruby filter?

Ruby Filter is a filter that is extremely useful in differentiating red stones such as Ruby, Spinel, Tourmaline, and Garnets from others that might look similar in comparison.


1 Answers

The good Logstash folks have thought of this already as they included pry into Logstash core. So all you have to do is to require pry in your ruby filter code as shown in the sample config below:

input { 
  file {
    path => "/tmp/myfile.csv"
    sincedb_path => "/dev/null"
    start_position => "beginning"
  }
}
filter {
  ruby {
    code => "require 'pry'
       ... your code ...

       # start a REPL session
       binding.pry

       ... your code ...
    "
 }
}

When Logstash runs, you'll get a REPL session in your terminal which looks like this and you'll be able to do whatever pry allows you to do.

[1] pry(#<LogStash::Filters::Ruby>)> 
like image 105
Val Avatar answered Jan 27 '23 05:01

Val