lib/contrast/framework/manager.rb in contrast-agent-4.13.1 vs lib/contrast/framework/manager.rb in contrast-agent-4.14.0

- old
+ new

@@ -7,16 +7,18 @@ require 'contrast/framework/rack/support' require 'contrast/framework/rails/support' require 'contrast/framework/grape/support' require 'contrast/framework/sinatra/support' require 'contrast/utils/class_util' +require 'contrast/framework/manager_extend' module Contrast module Framework # Allows access to framework specific information class Manager include Contrast::Components::Logger::InstanceMethods + include Contrast::Framework::ManagerExtend # Order here does matter as the first framework listed will be the first one we pull information from Rack will # be a special case that may involve updating some logic to handle only applying Rack if Rails/Sinatra do not # exist SUPPORTED_FRAMEWORKS = [ @@ -63,10 +65,14 @@ framework_version = first_framework_result :version, '' Contrast::Framework::PlatformVersion.from_string(framework_version) end + def platform_version_string + first_framework_result :version, '' + end + def server_type first_framework_result :server_type, 'rack' end def app_name @@ -114,11 +120,12 @@ # result. # # @param request [Contrast::Agent::Request] the current request. # @return [Contrast::Api::Dtm::RouteCoverage] the current route as a Dtm. def get_route_dtm request - @_frameworks.lazy.map { |framework_support| framework_support.current_route(request) }.reject(&:nil?).first + @_frameworks.lazy.map { |framework_support| framework_support.current_route(request) }. + reject(&:nil?).first end # Sometimes the framework we want to instrument is loaded after our agent code. To catch that case, we'll detect # if the loaded_module is the marker class for any of our supported frameworks. If it is, and we don't already # have support enabled, we'll enable it now. We'll also need to catch up on any other startup actions that we've @@ -146,40 +153,9 @@ frameworks: @_frameworks) break end rescue StandardError => e logger.warn('Unable to register a late framework', e, module: mod.cs__name) - end - - private - - def enable_framework_support? klass - Contrast::Utils::ClassUtil.truly_defined?(klass) - end - - def routes_for_all_frameworks - data_for_all_frameworks :collect_routes - end - - # This returns an array of all data from each framework in a flat, no-nil values array - # - # @param method_name [Symbol] the method to call on each FrameworkSupport class - # @return [Array] - def data_for_all_frameworks method_name - @_frameworks.flat_map { |framework| framework.send(method_name) }.compact - end - - # This returns a single object from the first framework to successfully respond - # - # @param method_name [Symbol] the method to call on each FrameworkSupport class - # @return [Object] - Determined by method to be invoked - def first_framework_result method_name, default_value - result = nil - @_frameworks.each do |framework| - result = framework.send(method_name) - break if result - end - result || default_value end end end end