# Method to timestamp my logstash events

**URL:** <https://discuss.elastic.co/t/method-to-timestamp-my-logstash-events/135888>\
**Category:** Logstash\
**Created:** [June 14, 2018, 9:46am UTC](https://discuss.elastic.co/t/method-to-timestamp-my-logstash-events/135888 "2018-06-14T09:46:22Z")\
**Posts on this page:** 1\
**Showing post:** 9

<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:** [June 15, 2018, 2:05pm UTC](https://discuss.elastic.co/t/method-to-timestamp-my-logstash-events/135888/9 "2018-06-15T14:05:15Z")

</div>

Sorry about that, I should have tested it before posting. A ruby instance variable is specific to the filter instance, so you cannot set it in one and use it in the other. You have two options. You can use a class variable instead of an instance variable.

```
if [ID2] == "000003" {
    ruby { code => "@@save_the_date = event.get('DATE_BATCH')" }
} else {
    ruby { code => "event.set('DATE_BATCH', @@save_the_date)" }
}

```

Or you can do everything in a single filter instance

```
ruby {
    code => "
        if event.get('ID2') == '000003'
            @save_the_date = event.get('DATE_BATCH')
        else
            event.set('DATE_BATCH', @save_the_date)
        end
    "
}

```

Note that this kind of thing can be fragile. It assumes lines are processed in order. That is why you are restricted to a single pipeline worker. But note that with the new execution engine in 6.3.0 that is no longer true even for a single worker -- stuff gets re-ordered.

---

_[View the full topic](https://discuss.elastic.co/t/method-to-timestamp-my-logstash-events/135888)._
