Skip to content

Commit

Permalink
Now filtering properly previously loaded classes
Browse files Browse the repository at this point in the history
  • Loading branch information
aantix committed May 15, 2023
1 parent 1b1eb60 commit a10bdd0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
2 changes: 0 additions & 2 deletions lib/callstacking/rails/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ def self.start_tracing(controller)
instrumenter.add_span(span)

if instrumenter.instrumentation_required?
Logger.log("Callstacking::Rails::Engine instrumenter.instrumentation_required? #{instrumenter.instrumentation_required?} #{loader.klasses.to_a}")

loader.reset!
instrumenter.enable!(loader.klasses.to_a)
end
Expand Down
8 changes: 4 additions & 4 deletions lib/callstacking/rails/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ def initialize(instrumenter, excluded: [])
def instrument_existing
objs = []
ObjectSpace.each_object(Module){|ob| objs << [ob, ((Object.const_source_location(ob.to_s) rescue nil))].flatten}
objs.each{|o| filter_klass(o.first, o.last)}
objs.each{|o| filter_klass(o.first, o.second)}
end

def on_load
trace = TracePoint.new(:end) do |tp|
klass = tp.self
path = tp.path

Logger.log("Callstacking::Rails::Loader.on_load #{klass} #{path}")
Logger.log("English defined? #{Object.const_defined?('English')}")

filter_klass(klass, path)
end

Expand All @@ -38,6 +35,9 @@ def reset!

private
def filter_klass(klass, path)
return if klass.nil? || path.nil?
return if path == false

excluded_klass = excluded.any? { |ex| path =~ /#{ex}/ }

if path =~ /#{::Rails.root.to_s}/ &&
Expand Down
4 changes: 1 addition & 3 deletions test/integration/thread_safety_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ class ThreadSafetyTest < ActionDispatch::IntegrationTest
response = client.show('xxxx', url: "#{TEST_URL}#{url}")
json = response.body

STDERR.puts "Trace response: -- #{response.inspect} -- json #{json.inspect}"

sleep 5
sleep 20

json['trace_entries'][1..10].each do |trace_entry|
assert_equal klass, trace_entry['klass']
Expand Down

0 comments on commit a10bdd0

Please sign in to comment.