Class: Callstacking::Rails::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/callstacking/rails/engine.rb

Constant Summary collapse

EXCLUDED_TEST_CLASSES =
%w[test/dummy/app/models/salutation.rb 
test/dummy/app/controllers/application_controller.rb].freeze

Class Method Summary collapse

Class Method Details

.start_tracing(controller) ⇒ Object

Serialize all tracing requests for now.

Can enable parallel tracing later.


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/callstacking/rails/engine.rb', line 51

def self.start_tracing(controller)
  Logger.log("Callstacking::Rails::Engine.start_tracing")
  
  settings.enable!

  lock.synchronize do
    spans[Thread.current.object_id]||=Spans.new
    span = spans[Thread.current.object_id]

    instrumenter.add_span(span)

    if instrumenter.instrumentation_required?
      loader.reset!
      instrumenter.enable!(loader.klasses.to_a)
    end

    traces[Thread.current.object_id] = Trace.new(span)
    trace = traces[Thread.current.object_id]

    trace.begin_trace(controller)
  end

  true
end

.stop_tracing(controller, exception) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/callstacking/rails/engine.rb', line 76

def self.stop_tracing(controller, exception)
  Logger.log("Callstacking::Rails::Engine.stop_tracing")
  
  settings.disable!

  trace = nil
  lock.synchronize do
    trace = traces.delete(Thread.current.object_id)
    if traces.empty?
      instrumenter.disable!
    end
  end

  trace&.end_trace(controller, exception)

  lock.synchronize do
    spans[Thread.current.object_id]&.reset
  end

  true
end