class NewRelic::Agent::Instrumentation::MiddlewareProxy

Constants

ANONYMOUS_CLASS
OBJECT_CLASS_NAME

Attributes

category[R]
target[R]
transaction_options[R]

Public Class Methods

for_class(target_class) click to toggle source
# File lib/new_relic/agent/instrumentation/middleware_proxy.rb, line 42
def self.for_class(target_class)
  Generator.new(target_class)
end
is_sinatra_app?(target) click to toggle 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
needs_wrapping?(target) click to toggle 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
new(target, is_app = false) click to toggle 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
wrap(target, is_app = false) click to toggle 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

class_for_target() click to toggle 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
determine_category() click to toggle source
# File lib/new_relic/agent/instrumentation/middleware_proxy.rb, line 74
def determine_category
  if @is_app
    :rack
  else
    :middleware
  end
end
determine_class_name() click to toggle source

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.

# 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
determine_prefix() click to toggle source
# File lib/new_relic/agent/instrumentation/middleware_proxy.rb, line 82
def determine_prefix
  ControllerInstrumentation::TransactionNamer.prefix_for_category(nil, @category)
end