module Datadog::Contrib::Rack::MiddlewareNamePatcher

Provides instrumentation for Rack middleware names

Public Instance Methods

call(env) click to toggle source
# File lib/ddtrace/contrib/rack/patcher.rb, line 51
def call(env)
  env['RESPONSE_MIDDLEWARE'] = self.class.to_s
  __call(env)
end
get_option(option) click to toggle source
# File lib/ddtrace/contrib/rack/patcher.rb, line 62
def get_option(option)
  Datadog.configuration[:rack].get_option(option)
end
patch() click to toggle source
# File lib/ddtrace/contrib/rack/patcher.rb, line 31
def patch
  patch_middleware_names
end
patch_middleware_names() click to toggle source
# File lib/ddtrace/contrib/rack/patcher.rb, line 35
def patch_middleware_names
  retain_middleware_name(get_option(:application))
rescue => e
  # We can safely ignore these exceptions since they happen only in the
  # context of middleware patching outside a Rails server process (eg. a
  # process that doesn't serve HTTP requests but has Rails environment
  # loaded such as a Resque master process)
  Datadog.logger.debug("Error patching middleware stack: #{e}")
end
retain_middleware_name(middleware) click to toggle source
# File lib/ddtrace/contrib/rack/patcher.rb, line 45
def retain_middleware_name(middleware)
  return unless middleware && middleware.respond_to?(:call)

  middleware.singleton_class.class_eval do
    alias_method :__call, :call

    def call(env)
      env['RESPONSE_MIDDLEWARE'] = self.class.to_s
      __call(env)
    end
  end

  following = (middleware.instance_variable_get('@app') if middleware.instance_variable_defined?('@app'))

  retain_middleware_name(following)
end
target_version() click to toggle source
# File lib/ddtrace/contrib/rack/patcher.rb, line 27
def target_version
  Integration.version
end