# Logstash errors while executing ruby code (Ruby exception occurred: allocator undefined for Floa)

**URL:** <https://discuss.elastic.co/t/logstash-errors-while-executing-ruby-code-ruby-exception-occurred-allocator-undefined-for-floa/151939>\
**Category:** Logstash\
**Created:** [October 10, 2018, 9:10pm UTC](https://discuss.elastic.co/t/logstash-errors-while-executing-ruby-code-ruby-exception-occurred-allocator-undefined-for-floa/151939 "2018-10-10T21:10:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dawn\_Okem](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dawn_okem/32/58264_2.png) [@Dawn\_Okem](https://discuss.elastic.co/u/Dawn_Okem)\
**Post date:** [October 10, 2018, 9:10pm UTC](https://discuss.elastic.co/t/logstash-errors-while-executing-ruby-code-ruby-exception-occurred-allocator-undefined-for-floa/151939/1 "2018-10-10T21:10:16Z")

</div>

Was trying to execute below code. but logstash keeps spitting an error out.

```
if [received_at] and [sent_at] {
	ruby {
	  init => "require 'time'"
	  code => "
		received_by_finacle = (Time.parse(event.get('received_at').to_f)*1000).round(2);
		sent_out_by_finacle = (Time.parse(event.get('sent_at').to_f)*1000).round(2);
		event.set('delta', (sent_out_by_finacle - received_by_finacle)).to_s;
		event.set('epoch_received_at_in_milliseconds', received_by_finacle);
		event.set('epoch_sent_at_in_milliseconds', sent_out_by_finacle);
		"
	  add_tag => ["calculated_time_difference"]
	}
}  

```

Error is  
[2018-10-10T22:01:05,631][ERROR][logstash.filters.ruby] Ruby exception occurred: allocator undefined for Float  
[2018-10-10T22:01:05,640][ERROR][logstash.filters.ruby] Ruby exception occurred: allocator undefined for Float  
[2018-10-10T22:01:05,643][ERROR][logstash.filters.ruby] Ruby exception occurred: allocator undefined for Float  
[2018-10-10T22:01:05,646][ERROR][logstash.filters.ruby] Ruby exception occurred: allocator undefined for Float  
[2018-10-10T22:01:05,649][ERROR][logstash.filters.ruby] Ruby exception occurred: allocator undefined for Float

Any help will be appreciated please. I am logstash version. 6.2.3

---

<div class="post-metadata">

**Author:** ![Dawn\_Okem](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dawn_okem/32/58264_2.png) [@Dawn\_Okem](https://discuss.elastic.co/u/Dawn_Okem)\
**Post date:** [October 11, 2018, 11:07pm UTC](https://discuss.elastic.co/t/logstash-errors-while-executing-ruby-code-ruby-exception-occurred-allocator-undefined-for-floa/151939/2 "2018-10-11T23:07:26Z")

</div>

Thanks to @Ganesh_Venkataraman. I was able to resolve this by adding "rescue nil" to the time difference. Here's what finally worked.

```
	date {
		match => ["received_at", "dd/mm/yyyy HH:mm:ss.SSS"]
		timezone => "UTC"
		target => "receivedlogtime"
	  }
	  
	date {
		match => ["sent_at", "dd/mm/yyyy HH:mm:ss.SSS"]
		timezone => "UTC"
		target => "sentlogtime"
	  }
	  
	  
	if [received_at] and [sent_at] {
		ruby {
			init => "require 'time'"
			code => "
				received_by_finacle = (Time.parse(event.get('received_at')).to_f)*1000;
				sent_out_by_finacle = (Time.parse(event.get('sent_at')).to_f)*1000;
				timetaken = (sent_out_by_finacle - received_by_finacle) rescue nil;
				event.set('time_delta',timetaken);
				event.set('epoch_received_at_in_milliseconds',received_by_finacle);
				event.set('epoch_sent_at_in_milliseconds',sent_out_by_finacle);
				"
				add_tag => ["calculated_time_difference"]
		}
	}
```

---

<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:** [November 8, 2018, 11:07pm UTC](https://discuss.elastic.co/t/logstash-errors-while-executing-ruby-code-ruby-exception-occurred-allocator-undefined-for-floa/151939/3 "2018-11-08T23:07:28Z")

</div>

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