Method: StackifyRubyAPM::InstrumenterHelper.patched_module
- Defined in:
- lib/stackify_apm/instrumenter_helper.rb
.patched_module(tracked_func, current_module, 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.
Monkey patch the single ruby module file.
tracked_func - trackedFunction variable in stackify.json current_module - module variable in stackify.json class_path - file_path variable in stackify.json options - other options such as trackedFunctionName
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/stackify_apm/instrumenter_helper.rb', line 199 def self.patched_module(tracked_func, current_module, class_path, **) current_method = [:current_method] || nil tracked_function_name = [:tracked_function_name] || nil transaction = [:is_transaction] || nil mod_spy = "#{current_module}Spy" unless @custom_instrumented[current_module.to_s] @custom_instrumented[current_module.to_s] = {} end unless @custom_instrumented[current_module.to_s][current_method.to_s] @custom_instrumented[current_module.to_s][current_method.to_s] = false end unless @custom_class_info[current_module.to_s] @custom_class_info[current_module.to_s] = {} end unless @custom_class_info[current_module.to_s]['controller'] @custom_class_info[current_module.to_s]['controller'] = false end unless @custom_class_info[current_module.to_s]['model'] @custom_class_info[current_module.to_s]['model'] = false end return unless @custom_instrumented[current_module.to_s][current_method.to_s] == false eval " module \#{mod_spy}\n def self.install\n \#{current_module}.class_eval do\n class<< self\n alias_method \"\#{current_method}_without_apm\", \"\#{current_method}\"\n\n def \#{current_method}(*args, &block)\n if StackifyRubyAPM.current_transaction.nil? && \#{!transaction.nil?}\n t = StackifyRubyAPM.transaction(\"custom.\#{current_module}.\#{current_method}\", TRACETYPE)\n begin\n req = \#{current_method}_without_apm(*args, &block)\n rescue Exception => e\n StackifyRubyAPM.report(e)\n raise e\n ensure\n t.submit\n end\n return req\n elsif StackifyRubyAPM.current_transaction\n name = \"Custom Instrument\"\n type = \"\#{current_module}#\#{current_method}\"\n ctx = if \"\#{tracked_func}\" == 'true'\n Span::Context.new(\n CATEGORY: 'Ruby',\n TRACKED_FUNC: \"\#{tracked_function_name}\"\n )\n else\n Span::Context.new(\n CATEGORY: 'Ruby'\n )\n end\n\n StackifyRubyAPM.span name, type, context: ctx do\n \#{current_method}_without_apm(*args, &block)\n end\n else\n return \#{current_method}_without_apm(*args, &block)\n end\n end\n end\n end\n end\n end\n\n StackifyRubyAPM::Spies.register current_module.to_s, class_path.to_s, \#{mod_spy}, true, \"\#{current_method}\", \"\#{tracked_func}\", \"\#{tracked_function_name}\"\n RUBY\n @custom_instrumented[current_module.to_s][current_method.to_s] = true\n @custom_class_info[current_module.to_s]['controller'] = true if class_path && class_path.include?('controllers')\n @custom_class_info[current_module.to_s]['model'] = true if class_path && class_path.include?('models')\nend\n" |