How to troubleshoot "undefined method `+' for nil:NilClass"

Hi
Maybe You have some idea how to troubleshoot in the long pipeline the bug referring to

[2022-12-28T19:47:41,016][ERROR][logstash.filters.ruby ][main][1b91d552e5ff1ebff261eab8e51449b8aba605255321bb2b70376384a2493180] Ruby exception occurred: undefined method +' for nil:NilClass {:class=>"NoMethodError", :backtrace=>["(ruby filter code):4:in block in filter_method'", "/usr/share/logstash/vendor/bundle/jruby/2.6.0/gems/logstash-filter-ruby-3.1.8/lib/logstash/filters/ruby.rb:96:in inline_script'", "/usr/share/logstash/vendor/bundle/jruby/2.6.0/gems/logstash-filter-ruby-3.1.8/lib/logstash/filters/ruby.rb:89:in filter'", "/usr/share/logstash/logstash-core/lib/logstash/filters/base.rb:159:in do_filter'", "/usr/share/logstash/logstash-core/lib/logstash/filters/base.rb:178:in block in multi_filter'", "org/jruby/RubyArray.java:1865:in each'", "/usr/share/logstash/logstash-core/lib/logstash/filters/base.rb:175:in multi_filter'", "org/logstash/config/ir/compiler/AbstractFilterDelegatorExt.java:134:in multi_filter'", "/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:300:in block in start_workers'"]}

You have a ruby filter with a code block.

    ruby {
        code => ' a = b + 1 '
    }

will report that exception with :backtrace=>["(ruby filter code):2:in, so you should be looking at the third line of your ruby code.

	ruby {
		code => "
			event_millisecond = ('000' + event.get('millisecond').to_s).split(//).last(3).join
			event.set('event_timestamp', event.get('date') + ' ' + event.get('time') + '.' + event_millisecond)
		"
	}

OK, so that is the third line of your code. It is processing an event that does not have [date] and/or [time] fields.

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