Module: APMInsight::API::CustomTracker::CustomMethodTracker
- Defined in:
- lib/agent/api/custom_tracker.rb
Instance Method Summary collapse
-
#get_instrumentation_code(method_name) ⇒ Object
TODO: Capture exception, attach tracker TODO: Create agent handler and call respective methods like in java agent.
- #is_instrumented?(method_name) ⇒ Boolean
- #track_method(method_name) ⇒ Object
Instance Method Details
#get_instrumentation_code(method_name) ⇒ Object
TODO: Capture exception, attach tracker TODO: Create agent handler and call respective methods like in java agent
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/agent/api/custom_tracker.rb', line 42 def get_instrumentation_code(method_name) "def apminsight_#{method_name}(*args, &block) tracker = ::APMInsight::API::CustomAPIHandler.invokeTracker \"\#{self.class.name}.#{method_name}\" begin original_#{method_name}(*args, &block) rescue Exception=>e if tracker != nil tracker.setError e end raise e ensure ::APMInsight::API::CustomAPIHandler.exitTracker tracker end end" end |
#is_instrumented?(method_name) ⇒ Boolean
35 36 37 38 |
# File 'lib/agent/api/custom_tracker.rb', line 35 def is_instrumented?(method_name) method_name = "apminsight_#{method_name}" return method_defined?(method_name) end |
#track_method(method_name) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/agent/api/custom_tracker.rb', line 13 def track_method(method_name) # Check whether the method exists return unless method_defined?(method_name) || private_method_defined?(method_name) # Check whether the method is already instrumented return if is_instrumented?(method_name) # Injecting code into the class class_eval(get_instrumentation_code(method_name), __FILE__, __LINE__) # Setting alias to invoke agent methods alias_method "original_#{method_name}", "#{method_name}" alias_method "#{method_name}", "apminsight_#{method_name}" # TODO: set visibility # visibility = instance_method_visibility(self, method_name) # send visibility, method_name # send visibility, "apminsight_#{method_name}" end |