class Airbrake::Rails::Railties::MiddlewareTie

Ties Airbrake Rails Middleware with Rails (error sending).

Since Rails 3.2 the ActionDispatch::DebugExceptions middleware is responsible for logging exceptions and showing a debugging page in case the request is local. We want to insert our middleware after DebugExceptions, so we don’t notify Airbrake about local requests.

@api private @since v13.0.1

Public Class Methods

new(app) click to toggle source
# File lib/airbrake/rails/railties/middleware_tie.rb, line 16
def initialize(app)
  @app = app
  @middleware = app.config.middleware
end

Public Instance Methods

call() click to toggle source
# File lib/airbrake/rails/railties/middleware_tie.rb, line 21
def call
  return tie_rails_5_or_above if ::Rails.version.to_i >= 5

  if defined?(::ActiveRecord::ConnectionAdapters::ConnectionManagement)
    return tie_rails_4_or_below_with_active_record
  end

  tie_rails_4_or_below_without_active_record
end

Private Instance Methods

tie_rails_4_or_below_with_active_record() click to toggle source

Insert after ConnectionManagement to avoid DB connection leakage: github.com/airbrake/airbrake/pull/568

# File lib/airbrake/rails/railties/middleware_tie.rb, line 45
def tie_rails_4_or_below_with_active_record
  @middleware.insert_after(
    ::ActiveRecord::ConnectionAdapters::ConnectionManagement,
    'Airbrake::Rack::Middleware',
  )
end
tie_rails_4_or_below_without_active_record() click to toggle source

Insert after DebugExceptions for apps without ActiveRecord.

# File lib/airbrake/rails/railties/middleware_tie.rb, line 53
def tie_rails_4_or_below_without_active_record
  @middleware.insert_after(
    ActionDispatch::DebugExceptions,
    'Airbrake::Rack::Middleware',
  )
end
tie_rails_5_or_above() click to toggle source

Avoid the warning about deprecated strings. Insert after DebugExceptions, since ConnectionManagement doesn’t exist in Rails 5 anymore.

# File lib/airbrake/rails/railties/middleware_tie.rb, line 36
def tie_rails_5_or_above
  @middleware.insert_after(
    ActionDispatch::DebugExceptions,
    Airbrake::Rack::Middleware,
  )
end