Module: StackifyRubyAPM::Spies Private

Defined in:
lib/stackify_apm/spies.rb,
lib/stackify_apm/spies/curb.rb,
lib/stackify_apm/spies/tilt.rb,
lib/stackify_apm/spies/mongo.rb,
lib/stackify_apm/spies/redis.rb,
lib/stackify_apm/spies/httprb.rb,
lib/stackify_apm/spies/sequel.rb,
lib/stackify_apm/spies/sinatra.rb,
lib/stackify_apm/spies/net_http.rb,
lib/stackify_apm/spies/curb/easy.rb,
lib/stackify_apm/spies/curb/multi.rb,
lib/stackify_apm/spies/httpclient.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, HTTPClientSpy, HTTPRbSpy, MongoSpy, MysqlAdapterSpy, NetHTTPSpy, PostgresqlAdapterSpy, RedisSpy, Registration, SequelSpy, SinatraSpy, SqliteAdapterSpy, StackifyLoggerSpy, TiltSpy

Class Method Summary collapse

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.

Returns:

  • (Boolean)


82
83
84
85
86
87
# File 'lib/stackify_apm/spies.rb', line 82

def self.class_exists?(class_name)
  klass = Module.const_get(class_name)
  return klass.is_a?(Class)
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.



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/stackify_apm/spies.rb', line 53

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

.installedObject

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.



32
33
34
# File 'lib/stackify_apm/spies.rb', line 32

def self.installed
  @installed ||= {}
end

.m_class(tracked_func, current_class, current_method, tracked_function_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.



12
13
14
15
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
# File 'lib/stackify_apm/spies/custom_instrumenter.rb', line 12

def self.m_class(tracked_func, current_class, current_method, tracked_function_name)
  Module.const_get(current_class.to_s).class_eval <<-RUBY
    alias :"__without_apm_#{current_method}" :"#{current_method}"

    def #{current_method}(*args, &block)
      return __without_apm_#{current_method}(*args, &block) unless StackifyRubyAPM.current_transaction
      name = "Custom Instrument"
      type = "#{current_class}##{current_method}"
      ctx = if "#{tracked_func}" == 'true'
              Span::Context.new(
                CATEGORY: 'Ruby',
                TRACKED_FUNC: "#{tracked_function_name}"
              )
            else
              Span::Context.new(
                CATEGORY: 'Ruby'
              )
            end
      req = __without_apm_#{current_method}(*args, &block)
      StackifyRubyAPM.span name, type, context: ctx do
        req
      end
    end

    def get_class_name
      return self.class.name
    end
  RUBY
end

.m_singleton(tracked_func, current_class, current_method, tracked_function_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.



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
# File 'lib/stackify_apm/spies/custom_instrumenter.rb', line 42

def self.m_singleton(tracked_func, current_class, current_method, tracked_function_name)
  Module.const_get(current_class.to_s).class_eval <<-RUBY
    singleton_class.send(:alias_method, :"__self_without_apm_#{current_method}", :"#{current_method}")

    def self.#{current_method}(*args, &block)
      return __self_without_apm_#{current_method}(*args, &block) unless StackifyRubyAPM.current_transaction

      name = "Custom Instrument"
      type = "#{current_class}##{current_method}"
      ctx = if "#{tracked_func}" == 'true'
              Span::Context.new(
                CATEGORY: 'Ruby',
                TRACKED_FUNC: "#{tracked_function_name}"
              )
            else
              Span::Context.new(
                CATEGORY: 'Ruby'
              )
            end
      req = __self_without_apm_#{current_method}(*args, &block)
      StackifyRubyAPM.span name, type, context: ctx do
        req
      end
    end

    def self.get_class_name
      return self.class.name
    end
  RUBY
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.



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/stackify_apm/spies.rb', line 69

def self.parse_json_config(file)
  jsondata = {}
  if ENV['STACKIFY_RUBY_ENV'] == 'rspec'
    file = 'spec/integration/stackify.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.



36
37
38
39
40
41
42
43
44
45
# File 'lib/stackify_apm/spies.rb', line 36

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.



47
48
49
50
51
# File 'lib/stackify_apm/spies.rb', line 47

def self.register_require_hook(registration)
  registration.require_paths.each do |path|
    require_hooks[path] = registration
  end
end

.require_hooksObject

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.



28
29
30
# File 'lib/stackify_apm/spies.rb', line 28

def self.require_hooks
  @require_hooks ||= {}
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.

Returns:

  • (Boolean)


65
66
67
# File 'lib/stackify_apm/spies.rb', line 65

def self.safe_defined?(const_name)
  Util::Inflector.safe_constantize(const_name)
end