Class: BuilderApm::Methods::Instrumenter
- Inherits:
-
Object
- Object
- BuilderApm::Methods::Instrumenter
- Defined in:
- lib/builder_apm/methods/instrumenter.rb
Instance Method Summary collapse
-
#initialize(root_path: Rails.root.to_s) ⇒ Instrumenter
constructor
A new instance of Instrumenter.
- #process_trace_point(tp) ⇒ Object
- #setup_trace ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #valid_trace_point?(tp) ⇒ Boolean
Constructor Details
#initialize(root_path: Rails.root.to_s) ⇒ Instrumenter
Returns a new instance of Instrumenter.
4 5 6 7 |
# File 'lib/builder_apm/methods/instrumenter.rb', line 4 def initialize(root_path: Rails.root.to_s) @root_path = root_path @call_times = {} end |
Instance Method Details
#process_trace_point(tp) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/builder_apm/methods/instrumenter.rb', line 29 def process_trace_point(tp) if tp.event == :call process_call_event(tp) elsif tp.event == :return process_return_event(tp) end end |
#setup_trace ⇒ Object
18 19 20 21 22 23 |
# File 'lib/builder_apm/methods/instrumenter.rb', line 18 def setup_trace me = self TracePoint.new(:call, :return) do |tp| me.process_trace_point(tp) if me.valid_trace_point?(tp) end end |
#start ⇒ Object
9 10 11 12 |
# File 'lib/builder_apm/methods/instrumenter.rb', line 9 def start @trace = setup_trace @trace.enable end |
#stop ⇒ Object
14 15 16 |
# File 'lib/builder_apm/methods/instrumenter.rb', line 14 def stop @trace.disable unless @trace.nil? end |
#valid_trace_point?(tp) ⇒ Boolean
25 26 27 |
# File 'lib/builder_apm/methods/instrumenter.rb', line 25 def valid_trace_point?(tp) !Thread.current[:request_id].nil? && tp.path.start_with?(@root_path) && !tp.path.include?('controller.rb') end |