class NewRelic::Agent::Instrumentation::MiddlewareProxy
Constants
- ANONYMOUS_CLASS
- OBJECT_CLASS_NAME
Attributes
Public Class Methods
Source
# File lib/new_relic/agent/instrumentation/middleware_proxy.rb, line 42 def self.for_class(target_class) Generator.new(target_class) end
Source
# File lib/new_relic/agent/instrumentation/middleware_proxy.rb, line 38 def self.is_sinatra_app?(target) defined?(::Sinatra::Base) && target.kind_of?(::Sinatra::Base) end
Source
# File lib/new_relic/agent/instrumentation/middleware_proxy.rb, line 46 def self.needs_wrapping?(target) ( !target.respond_to?(:_nr_has_middleware_tracing) && !is_sinatra_app?(target) ) end
Source
# File lib/new_relic/agent/instrumentation/middleware_proxy.rb, line 63 def initialize(target, is_app = false) @target = target @is_app = is_app @category = determine_category @target_class_name = determine_class_name @transaction_name = "#{determine_prefix}#{@target_class_name}/call" @transaction_options = { :transaction_name => @transaction_name } end
Source
# File lib/new_relic/agent/instrumentation/middleware_proxy.rb, line 53 def self.wrap(target, is_app = false) if needs_wrapping?(target) self.new(target, is_app) else target end end
Public Instance Methods
Source
# File lib/new_relic/agent/instrumentation/middleware_proxy.rb, line 100 def class_for_target if @target.is_a?(Class) @target else @target.class end end
Source
# File lib/new_relic/agent/instrumentation/middleware_proxy.rb, line 74 def determine_category if @is_app :rack else :middleware end end
Source
# File lib/new_relic/agent/instrumentation/middleware_proxy.rb, line 91 def determine_class_name clazz = class_for_target name = clazz.name name = clazz.superclass.name if name.nil? || name == '' name = ANONYMOUS_CLASS if name.nil? || name == OBJECT_CLASS_NAME name end
In ‘normal’ usage, the target will be an application instance that responds to call
. With Rails, however, the target may be a subclass of Rails::Application that defines a method_missing that proxies call
to a singleton instance of the subclass. We need to ensure that we capture the correct name in both cases.
Source
# File lib/new_relic/agent/instrumentation/middleware_proxy.rb, line 82 def determine_prefix ControllerInstrumentation::TransactionNamer.prefix_for_category(nil, @category) end