# Logstash Ruby filter - init not working

**URL:** <https://discuss.elastic.co/t/logstash-ruby-filter-init-not-working/309670>\
**Category:** Logstash\
**Created:** [July 14, 2022, 4:02pm UTC](https://discuss.elastic.co/t/logstash-ruby-filter-init-not-working/309670 "2022-07-14T16:02:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hichem](https://avatars.discourse-cdn.com/v4/letter/h/c67d28/32.png) [@Hichem](https://discuss.elastic.co/u/Hichem)\
**Post date:** [July 14, 2022, 4:02pm UTC](https://discuss.elastic.co/t/logstash-ruby-filter-init-not-working/309670/1 "2022-07-14T16:02:20Z")

</div>

I'm trying to initialize a variable in a ruby filter. It works properly with the code tag, but not when using a ruby file.  
Here is my code:  
pipeline.conf

```auto
  ruby {
    init => "@val = 5 "
    path => "script.rb"
     }

```

script.rb

```auto
def register(params)
end

def filter(event)
    puts @val
    return [event]
end   

```

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [July 14, 2022, 6:01pm UTC](https://discuss.elastic.co/t/logstash-ruby-filter-init-not-working/309670/2 "2022-07-14T18:01:16Z")

</div>

> [@Hichem](#):
>
> I'm trying to initialize a variable in a ruby filter. It works properly with the code tag, but not when using a ruby file.

That is correct. The filter [avoids](https://github.com/logstash-plugins/logstash-filter-ruby/blob/32c5f6c9efeaa041dd98ffbc4b7665204c88e2dd/lib/logstash/filters/ruby.rb#L62) evaluating the init option if the path option is set.

Once you know that it becomes clear that the documentation does imply it. The init option supplies inline code, not script code.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 11, 2022, 6:01pm UTC](https://discuss.elastic.co/t/logstash-ruby-filter-init-not-working/309670/3 "2022-08-11T18:01:58Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
