Genius/heroku-true-relic

Not Threadsafe

Opened this issue · 3 comments

Ironically this gem is not threadsafe, preventing me from using it to compare times pre- and post- puma and threadsafe on my app.

The error is get is:

... .rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.10/lib/action_dispatch/middleware/stack.rb:120:in `assert_index': No such middleware to insert after: "Rack::Lock" (RuntimeError)

Simply uncomment config.threadsafe! in production.rb and bundle this gem and start your server to experience the error.

I've made an adjustment to railtie.rb to not rely on Rack:Lock, will continue to test:

https://github.com/jasonlynes/heroku-true-relic/blob/master/lib/heroku-true-relic/railtie.rb

@jasonlynes I think we should be instrumenting after Rack::Lock if rails is in threadsafe! mode. So I think we need something like:

if Rails.configuration.middleware.include? 'Rack::Lock'
  Rails.configuration.middleware.insert_after 'Rack::Lock', "HerokuTrueRelic::QueueTimeLogger"
else
  Rails.configuration.middleware.insert 0, "HerokuTrueRelic::QueueTimeLogger"
end

obviously this code would be different for rails 3, but the idea is the same

We're using this and it seems to work:

module HerokuTrueRelic
  class Railtie < Rails::Railtie
    initializer 'heroku_true_relic.add_queue_time_logger' do |app|
      app.config.middleware.insert_before "Rack::Runtime", "HerokuTrueRelic::QueueTimeLogger"
    end
  end
end