Module: StackifyRubyAPM::Spies Private
- Extended by:
- Log
- Defined in:
- lib/stackify_apm/spies.rb,
lib/stackify_apm/spies/curb.rb,
lib/stackify_apm/spies/tilt.rb,
lib/stackify_apm/spies/yell.rb,
lib/stackify_apm/spies/log4r.rb,
lib/stackify_apm/spies/mongo.rb,
lib/stackify_apm/spies/redis.rb,
lib/stackify_apm/spies/httprb.rb,
lib/stackify_apm/spies/logger.rb,
lib/stackify_apm/spies/sequel.rb,
lib/stackify_apm/spies/faraday.rb,
lib/stackify_apm/spies/logging.rb,
lib/stackify_apm/spies/sidekiq.rb,
lib/stackify_apm/spies/sinatra.rb,
lib/stackify_apm/spies/httparty.rb,
lib/stackify_apm/spies/net_http.rb,
lib/stackify_apm/spies/curb/easy.rb,
lib/stackify_apm/spies/dynamo_db.rb,
lib/stackify_apm/spies/curb/multi.rb,
lib/stackify_apm/spies/httpclient.rb,
lib/stackify_apm/spies/delayed_job.rb,
lib/stackify_apm/spies/sucker_punch.rb,
lib/stackify_apm/spies/action_dispatch.rb,
lib/stackify_apm/spies/stackify_logger.rb,
lib/stackify_apm/spies/custom_instrumenter.rb,
lib/stackify_apm/spies/sinatra_activerecord/mysql_adapter.rb,
lib/stackify_apm/spies/sinatra_activerecord/sqlite_adapter.rb,
lib/stackify_apm/spies/sinatra_activerecord/postgresql_adapter.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Classes: ActionDispatchSpy, CurbEasySpy, CurbMultiSpy, CurbSpy, DelayedJobSpy, DynamoDBSpy, FaradaySpy, HTTPClientSpy, HTTPRbSpy, HTTPartySpy, Log4rSpy, LoggerSpy, LoggingSpy, MongoSpy, MysqlAdapterSpy, NetHTTPSpy, PostgresqlAdapterSpy, RedisSpy, Registration, SequelSpy, SidekiqClientSpy, SinatraSpy, SqliteAdapterSpy, StackifyLoggerSpy, SuckerPunchSpy, TiltSpy, YellSpy
Constant Summary
Constants included from Log
Class Method Summary collapse
- .class_exists?(class_name) ⇒ Boolean private
- .hook_into(name) ⇒ Object private
- .installed ⇒ Object private
-
.ismethod_exists(class_name, current_method) ⇒ Object
private
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity.
- .parse_json_config(file) ⇒ Object private
- .register(*args) ⇒ Object private
- .register_require_hook(registration) ⇒ Object private
- .require_hooks ⇒ Object private
- .run_custom_instrumentation ⇒ Object private
- .safe_defined?(const_name) ⇒ Boolean private
Methods included from Log
debug, error, fatal, info, log, warn
Class Method Details
.class_exists?(class_name) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
87 88 89 90 91 92 93 94 |
# File 'lib/stackify_apm/spies.rb', line 87 def self.class_exists?(class_name) if class_name klass = Module.const_get(class_name) return klass.is_a?(Class) end rescue NameError return false end |
.hook_into(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/stackify_apm/spies.rb', line 58 def self.hook_into(name) return unless (registration = require_hooks[name]) return unless safe_defined?(registration.const_name) installed[registration.const_name] = registration registration.install registration.require_paths.each do |path| require_hooks.delete path end end |
.installed ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
37 38 39 |
# File 'lib/stackify_apm/spies.rb', line 37 def self.installed @installed ||= {} end |
.ismethod_exists(class_name, current_method) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/stackify_apm/spies.rb', line 98 def self.ismethod_exists(class_name, current_method) module_consget = Module.const_get(class_name) current_method_without_apm = "_without_apm_#{current_method}" self_current_method_without_apm = "_self_without_apm_#{current_method}" with_flag = module_consget.instance_methods(false).include?(:"#{current_method_without_apm}") self_with_flag = module_consget.instance_methods(false).include?(:"#{self_current_method_without_apm}") current_method_exists = module_consget.instance_methods(false).include?(:"#{current_method}") self_current_method_exists = module_consget.instance_methods(false).include?(:"self.#{current_method}") exists = false if (self_with_flag == false && with_flag == false) && (current_method_exists == true || self_current_method_exists == true) exists = true end if (module_consget.methods.include?(:"#{current_method_without_apm}") == false && module_consget.methods.include?(:"#{self_current_method_without_apm}") == false) && (module_consget.methods.include?(:"#{current_method}") || module_consget.methods.include?(:"self.#{current_method}")) exists = true end exists end |
.parse_json_config(file) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/stackify_apm/spies.rb', line 74 def self.parse_json_config(file) jsondata = {} if ENV['STACKIFY_RUBY_ENV'] == 'rspec' file = 'spec/integration/stackify_spec.json' end return unless File.exist?(file) File.open(file) do |f| jsondata = JSON.parse(f.read) end jsondata end |
.register(*args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/stackify_apm/spies.rb', line 41 def self.register(*args) registration = Registration.new(*args) if safe_defined?(registration.const_name) registration.install installed[registration.const_name] = registration else register_require_hook registration end end |
.register_require_hook(registration) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
52 53 54 55 56 |
# File 'lib/stackify_apm/spies.rb', line 52 def self.register_require_hook(registration) registration.require_paths.each do |path| require_hooks[path] = registration end end |
.require_hooks ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
33 34 35 |
# File 'lib/stackify_apm/spies.rb', line 33 def self.require_hooks @require_hooks ||= {} end |
.run_custom_instrumentation ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/stackify_apm/spies/custom_instrumenter.rb', line 16 def self.run_custom_instrumentation config = Config.new to_instrument = parse_json_config(config.json_config_file) if config.logger.nil? config.debug_logger config.logger.send(:info, '[StackifyRubyAPM] Error: config/stackify.json does not exist which is required for custom instrumentation!') if to_instrument.nil? end return unless !to_instrument.nil? && !to_instrument.empty? && defined?(to_instrument['instrumentation']) && (to_instrument['instrumentation'].count > 0) to_instrument['instrumentation'].each do |custom_spy| current_class = defined?(custom_spy['class']) ? custom_spy['class'] : nil current_module = defined?(custom_spy['module']) ? custom_spy['module'] : nil current_method = custom_spy['method'] tracked_func = custom_spy['trackedFunction'] tracked_func_name = defined?(custom_spy['trackedFunctionName']) ? custom_spy['trackedFunctionName'] : '' transaction = defined?(custom_spy['transaction']) ? custom_spy['transaction'] : nil file_path = defined?(custom_spy['file_path']) ? custom_spy['file_path'] : nil if current_class tracked_function_tpl = tracked_func_name.nil? ? '{{ClassName}}.{{MethodName}}' : tracked_func_name tracked_function_name = tracked_function_tpl.to_s.sub '{{ClassName}}', current_class tracked_function_name = tracked_function_name.to_s.sub '{{MethodName}}', current_method elsif current_module tracked_function_tpl = tracked_func_name.nil? ? '{{ModuleName}}.{{MethodName}}' : tracked_func_name tracked_function_name = tracked_function_tpl.to_s.sub '{{ModuleName}}', current_module tracked_function_name = tracked_function_name.to_s.sub '{{MethodName}}', current_method end begin if current_module if file_path.nil? config.logger.send(:info, "[StackifyRubyAPM] Error: Missing file_path in module which is required in custom instrumentation.") else require file_path StackifyRubyAPM::InstrumenterHelper.patched_module(tracked_func, current_module, file_path, current_method: current_method, tracked_function_name: tracked_function_name, is_transaction: transaction) end end rescue => e throw e end if !class_exists?(current_class) && !file_path.nil? begin require file_path rescue LoadError => e debug "[StackifyRubyAPM] File path doesn't exist." debug e.inspect end end # rubocop:disable Style/Next if class_exists?(current_class) mod_constant = Module.const_get(current_class.to_s) klass_method_flag = mod_constant.method_defined?(current_method.to_s) singleton_method_flag = mod_constant.respond_to?(current_method.to_s) klass_private_method_flag = mod_constant.private_method_defined?(current_method.to_s) klass_protected_method_flag = mod_constant.protected_method_defined?(current_method.to_s) class_location = mod_constant.instance_methods(false).map do |m| mod_constant.instance_method(m).source_location.first end.uniq class_path = class_location.last if klass_method_flag || klass_private_method_flag StackifyRubyAPM::InstrumenterHelper.m_class( tracked_func, current_class, class_path, current_method: current_method, tracked_function_name: tracked_function_name, is_transaction: transaction, is_private_method: klass_private_method_flag, is_protected_method: klass_protected_method_flag ) elsif singleton_method_flag StackifyRubyAPM::InstrumenterHelper.m_singleton(tracked_func, current_class, class_path, current_method: current_method, tracked_function_name: tracked_function_name, is_transaction: transaction) end end # rubocop:enable Style/Next end end |
.safe_defined?(const_name) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
70 71 72 |
# File 'lib/stackify_apm/spies.rb', line 70 def self.safe_defined?(const_name) Util::Inflector.safe_constantize(const_name) end |