Sha256: 16adbda99f2dda139806f45fb24751b7b89741a428975df2e1f1f234ecae0d57

Contents?: true

Size: 1.35 KB

Versions: 4

Compression:

Stored size: 1.35 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-8.13.1 lib/new_relic/agent/instrumentation/rails_middleware.rb
newrelic_rpm-8.13.0 lib/new_relic/agent/instrumentation/rails_middleware.rb
newrelic_rpm-8.12.0 lib/new_relic/agent/instrumentation/rails_middleware.rb
newrelic_rpm-8.11.0 lib/new_relic/agent/instrumentation/rails_middleware.rb