Sha256: 26867726b2d9d1104d56374a135db3d310915035d4a5e2ad905d64c95c9e6134

Contents?: true

Size: 1.34 KB

Versions: 4

Compression:

Stored size: 1.34 KB

Contents

# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
# frozen_string_literal: true

require 'new_relic/agent/instrumentation/middleware_proxy'

DependencyDetection.defer do
  named :rails_middleware

  depends_on do
    !NewRelic::Agent.config[:disable_middleware_instrumentation]
  end

  depends_on do
    defined?(Rails::VERSION::MAJOR) && Rails::VERSION::MAJOR.to_i >= 3
  end

  executes do
    NewRelic::Agent.logger.info("Installing Rails 3+ middleware instrumentation")
    module ActionDispatch
      class MiddlewareStack
        class Middleware
          def build_with_new_relic(app)
            # MiddlewareProxy.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 = ::NewRelic::Agent::Instrumentation::MiddlewareProxy.wrap(app)
            result = build_without_new_relic(wrapped_app)
            ::NewRelic::Agent::Instrumentation::MiddlewareProxy.wrap(result)
          end

          alias_method :build_without_new_relic, :build
          alias_method :build, :build_with_new_relic
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
newrelic_rpm-9.0.0 lib/new_relic/agent/instrumentation/rails_middleware.rb
newrelic_rpm-8.16.0 lib/new_relic/agent/instrumentation/rails_middleware.rb
newrelic_rpm-8.15.0 lib/new_relic/agent/instrumentation/rails_middleware.rb
newrelic_rpm-8.14.0 lib/new_relic/agent/instrumentation/rails_middleware.rb