newrelic – undefined method `-’ for nil:NilClass

Using JRuby with trinidad (developer mode) – I was intermittently getting this error. Apparently thrown as estimated_time for the transaction was returning nil. I was also having all sorts of other issues (undefined method `metric_name’ for nil:NilClass) with all newrelics action summaries.

To resolve (following suggestions on the trinidad google group):

{% highlight ruby %}

config/initializers/newrelic.rb

if defined?(JRUBY_VERSION) && Rails.env == “development” require ‘newrelic_rpm’ NewRelic::Agent.manual_start({:dispatcher => :trinidad, :agent_enabled => true}) end

Gemfile

group :development do gem ‘newrelic_rpm’, ‘3.3.0’, :require => false end {% endhighlight %}

According to Nick Sieger’s gist – “NewRelic isn’t detecting Trinidad at the moment” – Although I could see trinidad’s detection mechanism implemented in newrelic’s most recent (3.5.0.1)

I’ve tried it with more recent versions of newrelic – but it seems 3.3.0 is the most stable.
JRuby 1.6.8 (1.9 mode)
trinidad 1.4.4
newrelic_rpm 3.3.0

UPDATE:

Getting another error of “. The error is apparently thrown if the “EXPLAIN” query has failed against the DB engine. Although – I got the transaction_tracing disabled with explain_enabled set to false – yet this release still attempts to fire the “EXPLAIN” against the DB.

Since I’m using the oracle_enhanced_adapter, the current newrelic “EXPLAIN” query wouldn’t work – hence an error is thrown. However, the error consumption by newrelic returns true rather than nil.

Changing “ to return nil instead of the true fixes it.

{% highlight ruby %} def handle_exception_in_explain yield rescue Exception => e begin # guarantees no throw from explain_sql NewRelic::Control.instance.log.error(“Error getting query plan: #{e.message}”) NewRelic::Control.instance.log.debug(e.backtrace.join(“\n”)) # UPDATE: Added to prevent issues when drilling down deep into SQL (explain not working) nil rescue Exception # double exception. throw up your hands end end {% endhighlight %}