Last week I updated a legacy Rails application from 3.2 to 4.0. I wanted to quickly address as many Rails deprecation warnings as I could, because we are planing to upgrade to Rails 4.1 and 4.2 in the near future. The test suite identified the majority of the deprecation warnings, but I suspected there was more outdated code off the beaten path of my development environment.
I decided to let production use of the upgraded application identify the remaining deprecations for me. I added this Rails initializer to report production Rails deprecation warnings to Airbrake, our error monitoring service:
if Rails.env.staging? || Rails.env.production? ActiveSupport::Notifications.subscribe("deprecation.rails") do |name, start, finish, id, payload| Airbrake.delay.notify( error_class: "Rails Deprecation Warning", error_message: payload[:message], backtrace: payload[:callstack], environment_name: Rails.env ) end end
Within 24 hours, I had identified and addressed several deprecation warnings that had lingered in those dark crannies of the application. If you’re familiar with Delayed::Job, you’ll notice that those notifications are sent in the background so that the application is minimally impacted by this reporting.
N.B. I ran into a small snag when deploying this: Airbrake was flooded with deprecation warnings coming out of New Relic’s RPM gem. Their Delayed::Job instrumentation contained some deprecated ActiveRecord queries. This has since been fixed in version 18.104.22.1686 of the NewRelic gem. Update the NewRelic gem to that version or later if you are using it. If you can’t upgrade the gem, turn off NewRelic’s DJ monitoring by setting disable_dj to true in newrelic.yml.