29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/scout_apm/instruments/active_record.rb', line 29
def add_instruments
if Utils::KlassHelper.defined?("ActiveRecord::Base")
::ActiveRecord::Base.class_eval do
include ::ScoutApm::Tracer
end
end
if Utils::KlassHelper.defined?("ActiveRecord::ConnectionAdapters::AbstractAdapter")
::ActiveRecord::ConnectionAdapters::AbstractAdapter.module_eval do
include ::ScoutApm::Instruments::ActiveRecordInstruments
include ::ScoutApm::Tracer
end
end
if Utils::KlassHelper.defined?("ActiveRecord::Querying")
::ActiveRecord::Querying.module_eval do
include ::ScoutApm::Tracer
include ::ScoutApm::Instruments::ActiveRecordQueryingInstruments
end
end
if Utils::KlassHelper.defined?("ActiveRecord::FinderMethods")
::ActiveRecord::FinderMethods.module_eval do
include ::ScoutApm::Tracer
include ::ScoutApm::Instruments::ActiveRecordFinderMethodsInstruments
end
end
if Utils::KlassHelper.defined?("ActiveSupport::Notifications")
ActiveSupport::Notifications.subscribe("instantiation.active_record") do |event_name, start, stop, uuid, payload|
req = ScoutApm::RequestManager.lookup
layer = req.current_layer
if layer && layer.type == "ActiveRecord"
layer.annotate_layer(payload)
else
ScoutApm::Agent.instance.logger.debug("Expected layer type: ActiveRecord, got #{layer && layer.type}")
end
end
end
rescue
ScoutApm::Agent.instance.logger.warn "ActiveRecord instrumentation exception: #{$!.message}"
end
|