# encoding: utf-8 module OneApm module Configuration module Autostart extend self def agent_should_start? !blacklisted_constants? && !blacklisted_executables? && !in_blacklisted_rake_task? end def blacklisted_constants? blacklisted?(OneApm::Manager.config[:'autostart.blacklisted_constants']) do |name| OneApm::LanguageSupport.constant_is_defined?(name) end end def blacklisted_executables? blacklisted?(OneApm::Manager.config[:'autostart.blacklisted_executables']) do |bin| File.basename($0) == bin end end def blacklisted?(value, &block) value.split(/\s*,\s*/).any?(&block) end def in_blacklisted_rake_task? tasks = begin ::Rake.application.top_level_tasks rescue => e OneApm::Manager.logger.debug("Not in Rake environment so skipping blacklisted_rake_tasks check: #{e}") [] end !(tasks & OneApm::Manager.config[:'autostart.blacklisted_rake_tasks'].split(/\s*,\s*/)).empty? end end end end