Class: StackifyRubyAPM::InstrumenterHelper Private

Inherits:
Object
  • Object
show all
Defined in:
lib/stackify_apm/instrumenter_helper.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

TRACETYPE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'TASK'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#custom_class_infoObject

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 rubocop:disable Lint/UselessAssignment rubocop:disable Security/Eval



12
13
14
# File 'lib/stackify_apm/instrumenter_helper.rb', line 12

def custom_class_info
  @custom_class_info
end

#custom_instrumentedObject

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 rubocop:disable Lint/UselessAssignment rubocop:disable Security/Eval



12
13
14
# File 'lib/stackify_apm/instrumenter_helper.rb', line 12

def custom_instrumented
  @custom_instrumented
end

Class Method Details

.custom_instrumented_resetObject

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.



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/stackify_apm/instrumenter_helper.rb', line 17

def self.custom_instrumented_reset
  @custom_instrumented.each do |custom_instrument, values|
    current_class = custom_instrument
    module_consget = Module.const_get(current_class)
    values.each_key do |current_method|
      is_method_exists = StackifyRubyAPM::Spies.ismethod_exists(current_class, current_method)
      if is_method_exists
        @custom_instrumented[current_class.to_s][current_method.to_s] = false
      end
    end
  end
end

.m_class(tracked_func, current_class, class_path, **options) ⇒ 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.



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
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/stackify_apm/instrumenter_helper.rb', line 30

def self.m_class(tracked_func, current_class, class_path, **options)
  current_method = options[:current_method] || nil
  tracked_function_name = options[:tracked_function_name] || nil
  transaction = options[:is_transaction] || nil
  module_consget = Module.const_get(current_class)
  classspyitem = "#{current_class}Spy"
  module_consget_spy = Module.const_get(current_class)
  current_method_without = "_without_apm_#{current_method}"

  unless @custom_instrumented[current_class.to_s]
    @custom_instrumented[current_class.to_s] = {}
  end

  unless @custom_instrumented[current_class.to_s][current_method.to_s]
    @custom_instrumented[current_class.to_s][current_method.to_s] = false
  end

  unless @custom_class_info[current_class.to_s]
    @custom_class_info[current_class.to_s] = {}
  end

  unless @custom_class_info[current_class.to_s]['controller']
    @custom_class_info[current_class.to_s]['controller'] = false
  end

  unless @custom_class_info[current_class.to_s]['model']
    @custom_class_info[current_class.to_s]['model'] = false
  end

  return unless @custom_instrumented[current_class.to_s][current_method.to_s] == false

  eval <<-RUBY
    class #{classspyitem}
      def install
        #{current_class}.class_eval do
          alias_method "#{current_method_without}", "#{current_method}"

          def #{current_method}(*args, &block)
            if StackifyRubyAPM.current_transaction.nil? && #{!transaction.nil?}
              t = StackifyRubyAPM.transaction("custom.#{current_class}.#{current_method}", TRACETYPE)
              begin
                req = #{current_method_without}(*args, &block)
              rescue Exception => e
                StackifyRubyAPM.report(e)
                raise e
              ensure
                t.submit
              end
              return req
            elsif 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 = #{current_method_without}(*args, &block)
              StackifyRubyAPM.span name, type, context: ctx do
                req
              end
            else
              return #{current_method_without}(*args, &block)
            end
          end
        end
      end
    end
    StackifyRubyAPM::Spies.register current_class.to_s, class_path.to_s, #{classspyitem}.new, true, "#{current_method}", "#{tracked_func}", "#{tracked_function_name}"
  RUBY

  @custom_instrumented[current_class.to_s][current_method.to_s] = true
  @custom_class_info[current_class.to_s]['controller'] = true if class_path && class_path.include?('controllers')
  @custom_class_info[current_class.to_s]['model'] = true if class_path && class_path.include?('models')
end

.m_singleton(tracked_func, current_class, class_path, **options) ⇒ 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.



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/stackify_apm/instrumenter_helper.rb', line 112

def self.m_singleton(tracked_func, current_class, class_path, **options)
  current_method = options[:current_method] || nil
  tracked_function_name = options[:tracked_function_name] || nil
  transaction = options[:is_transaction] || nil
  module_consget = Module.const_get(current_class)
  classspyitem = "#{current_class}Spy"

  unless @custom_instrumented[current_class.to_s]
    @custom_instrumented[current_class.to_s] = {}
  end

  unless @custom_instrumented[current_class.to_s][current_method.to_s]
    @custom_instrumented[current_class.to_s][current_method.to_s] = false
  end

  unless @custom_class_info[current_class.to_s]
    @custom_class_info[current_class.to_s] = {}
  end

  unless @custom_class_info[current_class.to_s]['controller']
    @custom_class_info[current_class.to_s]['controller'] = false
  end

  unless @custom_class_info[current_class.to_s]['model']
    @custom_class_info[current_class.to_s]['model'] = false
  end

  return unless @custom_instrumented[current_class.to_s][current_method.to_s] == false

  eval <<-RUBY
    class #{classspyitem}
      def install
        #{current_class}.class_eval do
          singleton_class.send(:alias_method, :"_self_without_apm_#{current_method}", :"#{current_method}")

          def self.#{current_method}(*args, &block)
            if StackifyRubyAPM.current_transaction.nil? && #{!transaction.nil?}
              t = StackifyRubyAPM.transaction("custom.#{current_class}.#{current_method}", TRACETYPE)
              begin
                req = _self_without_apm_#{current_method}(*args, &block)
              rescue Exception => e
                StackifyRubyAPM.report(e)
                raise e
              ensure
                t.submit
              end
              return req
            elsif 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
            else
              return _self_without_apm_#{current_method}(*args, &block)
            end
          end

          def self.get_class_name
            return self.class.name
          end
        end
      end
    end
    StackifyRubyAPM::Spies.register current_class.to_s, class_path.to_s, #{classspyitem}.new, true, "#{current_method}", "#{tracked_func}", "#{tracked_function_name}"
  RUBY
  @custom_instrumented[current_class.to_s][current_method.to_s] = true
  @custom_class_info[current_class.to_s]['controller'] = true if class_path && class_path.include?('controllers')
  @custom_class_info[current_class.to_s]['model'] = true if class_path && class_path.include?('models')
end