class Mmtrix::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/mmtrix/agent/instrumentation/middleware_proxy.rb, line 40
def self.for_class(target_class)
  Generator.new(target_class)
end
is_sinatra_app?(target) click to toggle source
# File lib/mmtrix/agent/instrumentation/middleware_proxy.rb, line 36
def self.is_sinatra_app?(target)
  defined?(::Sinatra::Base) && target.kind_of?(::Sinatra::Base)
end
needs_wrapping?(target) click to toggle source
# File lib/mmtrix/agent/instrumentation/middleware_proxy.rb, line 44
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/mmtrix/agent/instrumentation/middleware_proxy.rb, line 61
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/mmtrix/agent/instrumentation/middleware_proxy.rb, line 51
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/mmtrix/agent/instrumentation/middleware_proxy.rb, line 98
def class_for_target
  if @target.is_a?(Class)
    @target
  else
    @target.class
  end
end
determine_category() click to toggle source
# File lib/mmtrix/agent/instrumentation/middleware_proxy.rb, line 72
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 the subclass. We need to ensure that we capture the correct name in both cases.

# File lib/mmtrix/agent/instrumentation/middleware_proxy.rb, line 89
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/mmtrix/agent/instrumentation/middleware_proxy.rb, line 80
def determine_prefix
  ControllerInstrumentation::TransactionNamer.prefix_for_category(nil, @category)
end