Sha256: 08b8c037b4b05b29c40bb6a92cd437936c20e616264e59533ab9ae950ae997f4

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

# 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::Agent.config[:disable_rack_middleware]
  end

  executes do
    ::OneApm::Agent.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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
oneapm_rpm-1.1.2 lib/one_apm/inst/rails_middleware.rb
oneapm_rpm-1.1.1 lib/one_apm/inst/rails_middleware.rb
oneapm_rpm-1.1.0 lib/one_apm/inst/rails_middleware.rb