# encoding: utf-8 require 'one_apm/rack/middleware_wrapper' LibraryDetection.defer do named :rails_middleware depends_on do defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i >= 3 end depends_on do !OneApm::Manager.config[:disable_rack_middleware] end executes do OneApm::Manager.logger.info("Installing Rails 3+ middleware instrumentation") module ActionDispatch class MiddlewareStack class Middleware def build_with_one_apm(app) # MiddlewareWrapper.wrap guards against double-wrapping here. # We need to instrument the innermost app (usually a RouteSet), # which will never itself be the return value from #build, but will # instead be the initial value of the app argument. wrapped_app = ::OneApm::Rack::MiddlewareWrapper.wrap(app) result = build_without_one_apm(wrapped_app) ::OneApm::Rack::MiddlewareWrapper.wrap(result) end alias_method :build_without_one_apm, :build alias_method :build, :build_with_one_apm end end end end end