newrelic_rpm 2.13.5.beta4 → 2.13.6.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of newrelic_rpm might be problematic. Click here for more details.
- data/CHANGELOG +8 -0
- data/cert/cacert.pem +21 -0
- data/lib/conditional_vendored_dependency_detection.rb +3 -0
- data/lib/new_relic/agent/agent.rb +14 -1
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +15 -12
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +38 -21
- data/lib/new_relic/agent/instrumentation/authlogic.rb +9 -4
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +364 -364
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +142 -121
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +17 -16
- data/lib/new_relic/agent/instrumentation/memcache.rb +40 -26
- data/lib/new_relic/agent/instrumentation/net.rb +19 -13
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +27 -15
- data/lib/new_relic/agent/instrumentation/rails/active_record_instrumentation.rb +80 -71
- data/lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb +84 -72
- data/lib/new_relic/agent/instrumentation/sequel.rb +84 -70
- data/lib/new_relic/agent/instrumentation/sinatra.rb +44 -37
- data/lib/new_relic/agent/instrumentation/sunspot.rb +18 -12
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +13 -7
- data/lib/new_relic/agent/method_tracer.rb +1 -1
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +2 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +1 -1
- data/lib/new_relic/control.rb +1 -0
- data/lib/new_relic/control/instrumentation.rb +1 -0
- data/lib/new_relic/delayed_job_injection.rb +23 -14
- data/lib/new_relic/version.rb +2 -2
- data/lib/newrelic_rpm.rb +5 -0
- data/newrelic_rpm.gemspec +25 -23
- data/test/new_relic/agent/{agent_connect_test.rb → agent/connect_test.rb} +2 -2
- data/test/new_relic/agent/{agent_start_test.rb → agent/start_test.rb} +17 -3
- data/test/new_relic/agent/{agent_start_worker_thread_test.rb → agent/start_worker_thread_test.rb} +2 -2
- data/test/new_relic/agent/{agent_controller_test.rb → agent_test_controller_test.rb} +6 -3
- data/test/new_relic/agent/{error_collector_notice_error_test.rb → error_collector/notice_error_test.rb} +2 -2
- data/test/new_relic/agent/{active_record_instrumentation_test.rb → instrumentation/active_record_instrumentation_test.rb} +2 -2
- data/test/new_relic/agent/{metric_frame_test.rb → instrumentation/metric_frame_test.rb} +2 -3
- data/test/new_relic/agent/{net_instrumentation_test.rb → instrumentation/net_instrumentation_test.rb} +4 -4
- data/test/new_relic/agent/{queue_time_test.rb → instrumentation/queue_time_test.rb} +1 -1
- data/test/new_relic/agent/{task_instrumentation_test.rb → instrumentation/task_instrumentation_test.rb} +29 -32
- data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +165 -0
- data/test/new_relic/agent/{method_tracer_trace_execution_scoped_test.rb → method_tracer/instance_methods/trace_execution_scoped_test.rb} +2 -2
- data/test/new_relic/agent/method_tracer_test.rb +31 -3
- data/test/new_relic/agent/rpm_agent_test.rb +8 -3
- data/test/new_relic/{agent/collection_helper_test.rb → collection_helper_test.rb} +4 -4
- data/test/new_relic/{deployments_api_test.rb → command/deployments_test.rb} +3 -5
- data/test/new_relic/control_test.rb +3 -3
- data/test/new_relic/{environment_test.rb → local_environment_test.rb} +2 -5
- data/test/new_relic/metric_spec_test.rb +32 -122
- data/test/new_relic/stats_test.rb +0 -1
- data/test/new_relic/{agent/transaction_sample_subtest_test.rb → transaction_sample_subtest_test.rb} +0 -0
- data/test/new_relic/{agent/transaction_sample_test.rb → transaction_sample_test.rb} +1 -2
- data/test/test_helper.rb +1 -0
- data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +19 -0
- data/vendor/gems/dependency_detection-0.0.1.build/README +0 -0
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +57 -0
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection/version.rb +3 -0
- metadata +29 -27
- data/test/new_relic/agent/add_method_tracer_test.rb +0 -158
- data/test/new_relic/agent/metric_data_test.rb +0 -53
- data/test/new_relic/agent/testable_agent.rb +0 -13
- data/test/new_relic/shim_agent_test.rb +0 -9
@@ -1,91 +1,100 @@
|
|
1
|
+
module NewRelic
|
2
|
+
module Agent
|
3
|
+
module Instrumentation
|
4
|
+
module ActiveRecordInstrumentation
|
1
5
|
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
module Instrumentation
|
8
|
-
module ActiveRecordInstrumentation
|
9
|
-
|
10
|
-
def self.included(instrumented_class)
|
11
|
-
instrumented_class.class_eval do
|
12
|
-
alias_method :log_without_newrelic_instrumentation, :log
|
13
|
-
alias_method :log, :log_with_newrelic_instrumentation
|
14
|
-
protected :log
|
15
|
-
end
|
6
|
+
def self.included(instrumented_class)
|
7
|
+
instrumented_class.class_eval do
|
8
|
+
alias_method :log_without_newrelic_instrumentation, :log
|
9
|
+
alias_method :log, :log_with_newrelic_instrumentation
|
10
|
+
protected :log
|
16
11
|
end
|
12
|
+
end
|
17
13
|
|
18
|
-
|
14
|
+
def log_with_newrelic_instrumentation(sql, name, &block)
|
19
15
|
|
20
|
-
|
16
|
+
return log_without_newrelic_instrumentation(sql, name, &block) unless NewRelic::Agent.is_execution_traced?
|
21
17
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
18
|
+
# Capture db config if we are going to try to get the explain plans
|
19
|
+
if (defined?(ActiveRecord::ConnectionAdapters::MysqlAdapter) && self.is_a?(ActiveRecord::ConnectionAdapters::MysqlAdapter)) ||
|
20
|
+
(defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && self.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter))
|
21
|
+
supported_config = @config
|
22
|
+
end
|
23
|
+
if name && (parts = name.split " ") && parts.size == 2
|
24
|
+
model = parts.first
|
25
|
+
operation = parts.last.downcase
|
26
|
+
metric_name = case operation
|
27
|
+
when 'load' then 'find'
|
28
|
+
when 'indexes', 'columns' then nil # fall back to DirectSQL
|
29
|
+
when 'destroy', 'find', 'save', 'create' then operation
|
30
|
+
when 'update' then 'save'
|
31
|
+
else
|
32
|
+
if model == 'Join'
|
33
|
+
operation
|
39
34
|
end
|
40
|
-
|
41
|
-
|
35
|
+
end
|
36
|
+
metric = "ActiveRecord/#{model}/#{metric_name}" if metric_name
|
37
|
+
end
|
42
38
|
|
39
|
+
if metric.nil?
|
40
|
+
metric = NewRelic::Agent::Instrumentation::MetricFrame.database_metric_name
|
43
41
|
if metric.nil?
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
else
|
52
|
-
metric = "Database/SQL/other"
|
53
|
-
end
|
42
|
+
if sql =~ /^(select|update|insert|delete|show)/i
|
43
|
+
# Could not determine the model/operation so let's find a better
|
44
|
+
# metric. If it doesn't match the regex, it's probably a show
|
45
|
+
# command or some DDL which we'll ignore.
|
46
|
+
metric = "Database/SQL/#{$1.downcase}"
|
47
|
+
else
|
48
|
+
metric = "Database/SQL/other"
|
54
49
|
end
|
55
50
|
end
|
51
|
+
end
|
56
52
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
53
|
+
if !metric
|
54
|
+
log_without_newrelic_instrumentation(sql, name, &block)
|
55
|
+
else
|
56
|
+
metrics = [metric, "ActiveRecord/all"]
|
57
|
+
metrics << "ActiveRecord/#{metric_name}" if metric_name
|
58
|
+
self.class.trace_execution_scoped(metrics) do
|
59
|
+
t0 = Time.now
|
60
|
+
begin
|
61
|
+
log_without_newrelic_instrumentation(sql, name, &block)
|
62
|
+
ensure
|
63
|
+
NewRelic::Agent.instance.transaction_sampler.notice_sql(sql, supported_config, (Time.now - t0).to_f)
|
69
64
|
end
|
70
65
|
end
|
71
66
|
end
|
72
|
-
|
73
67
|
end
|
74
68
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
79
73
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
74
|
+
DependencyDetection.defer do
|
75
|
+
depends_on do
|
76
|
+
defined?(ActiveRecord) && defined?(ActiveRecord::Base)
|
77
|
+
end
|
78
|
+
|
79
|
+
depends_on do
|
80
|
+
!NewRelic::Control.instance['skip_ar_instrumentation']
|
81
|
+
end
|
82
|
+
|
83
|
+
depends_on do
|
84
|
+
!NewRelic::Control.instance['disable_activerecord_instrumentation']
|
85
|
+
end
|
86
|
+
|
87
|
+
executes do
|
88
|
+
ActiveRecord::ConnectionAdapters::AbstractAdapter.module_eval do
|
89
|
+
include ::NewRelic::Agent::Instrumentation::ActiveRecordInstrumentation
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
executes do
|
94
|
+
ActiveRecord::Base.class_eval do
|
95
|
+
class << self
|
96
|
+
add_method_tracer :find_by_sql, 'ActiveRecord/#{self.name}/find_by_sql', :metric => false
|
97
|
+
add_method_tracer :transaction, 'ActiveRecord/#{self.name}/transaction', :metric => false
|
89
98
|
end
|
90
99
|
end
|
91
100
|
end
|
@@ -1,92 +1,104 @@
|
|
1
|
+
module NewRelic
|
2
|
+
module Agent
|
3
|
+
module Instrumentation
|
4
|
+
module ActiveRecordInstrumentation
|
1
5
|
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
module Instrumentation
|
8
|
-
module ActiveRecordInstrumentation
|
9
|
-
|
10
|
-
def self.included(instrumented_class)
|
11
|
-
instrumented_class.class_eval do
|
12
|
-
alias_method :log_without_newrelic_instrumentation, :log
|
13
|
-
alias_method :log, :log_with_newrelic_instrumentation
|
14
|
-
protected :log
|
15
|
-
end
|
6
|
+
def self.included(instrumented_class)
|
7
|
+
instrumented_class.class_eval do
|
8
|
+
alias_method :log_without_newrelic_instrumentation, :log
|
9
|
+
alias_method :log, :log_with_newrelic_instrumentation
|
10
|
+
protected :log
|
16
11
|
end
|
12
|
+
end
|
17
13
|
|
18
|
-
|
14
|
+
def log_with_newrelic_instrumentation(sql, name, &block)
|
19
15
|
|
20
|
-
|
16
|
+
return log_without_newrelic_instrumentation(sql, name, &block) unless NewRelic::Agent.is_execution_traced?
|
21
17
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
18
|
+
# Capture db config if we are going to try to get the explain plans
|
19
|
+
if (defined?(ActiveRecord::ConnectionAdapters::MysqlAdapter) && self.is_a?(ActiveRecord::ConnectionAdapters::MysqlAdapter)) ||
|
20
|
+
(defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && self.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter))
|
21
|
+
supported_config = @config
|
22
|
+
end
|
23
|
+
if name && (parts = name.split " ") && parts.size == 2
|
24
|
+
model = parts.first
|
25
|
+
operation = parts.last.downcase
|
26
|
+
metric_name = case operation
|
27
|
+
when 'load' then 'find'
|
28
|
+
when 'indexes', 'columns' then nil # fall back to DirectSQL
|
29
|
+
when 'destroy', 'find', 'save', 'create' then operation
|
30
|
+
when 'update' then 'save'
|
31
|
+
else
|
32
|
+
if model == 'Join'
|
33
|
+
operation
|
39
34
|
end
|
40
|
-
|
41
|
-
|
35
|
+
end
|
36
|
+
metric = "ActiveRecord/#{model}/#{metric_name}" if metric_name
|
37
|
+
end
|
42
38
|
|
39
|
+
if metric.nil?
|
40
|
+
metric = NewRelic::Agent::Instrumentation::MetricFrame.database_metric_name
|
43
41
|
if metric.nil?
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
else
|
52
|
-
metric = "Database/SQL/other"
|
53
|
-
end
|
42
|
+
if sql =~ /^(select|update|insert|delete|show)/i
|
43
|
+
# Could not determine the model/operation so let's find a better
|
44
|
+
# metric. If it doesn't match the regex, it's probably a show
|
45
|
+
# command or some DDL which we'll ignore.
|
46
|
+
metric = "Database/SQL/#{$1.downcase}"
|
47
|
+
else
|
48
|
+
metric = "Database/SQL/other"
|
54
49
|
end
|
55
50
|
end
|
51
|
+
end
|
56
52
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
53
|
+
if !metric
|
54
|
+
log_without_newrelic_instrumentation(sql, name, &block)
|
55
|
+
else
|
56
|
+
metrics = [metric, "ActiveRecord/all"]
|
57
|
+
metrics << "ActiveRecord/#{metric_name}" if metric_name
|
58
|
+
self.class.trace_execution_scoped(metrics) do
|
59
|
+
t0 = Time.now
|
60
|
+
begin
|
61
|
+
log_without_newrelic_instrumentation(sql, name, &block)
|
62
|
+
ensure
|
63
|
+
NewRelic::Agent.instance.transaction_sampler.notice_sql(sql, supported_config, (Time.now - t0).to_f)
|
69
64
|
end
|
70
65
|
end
|
71
66
|
end
|
72
|
-
|
73
67
|
end
|
74
68
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
80
73
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
74
|
+
DependencyDetection.defer do
|
75
|
+
depends_on do
|
76
|
+
defined?(ActiveRecord) && defined?(ActiveRecord::Base)
|
77
|
+
end
|
78
|
+
|
79
|
+
depends_on do
|
80
|
+
!NewRelic::Control.instance['skip_ar_instrumentation']
|
81
|
+
end
|
82
|
+
|
83
|
+
depends_on do
|
84
|
+
!NewRelic::Control.instance['disable_activerecord_instrumentation']
|
85
|
+
end
|
86
|
+
|
87
|
+
executes do
|
88
|
+
Rails.configuration.after_initialize do
|
89
|
+
ActiveRecord::ConnectionAdapters::AbstractAdapter.module_eval do
|
90
|
+
include ::NewRelic::Agent::Instrumentation::ActiveRecordInstrumentation
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
executes do
|
96
|
+
Rails.configuration.after_initialize do
|
97
|
+
ActiveRecord::Base.class_eval do
|
98
|
+
class << self
|
99
|
+
add_method_tracer :find_by_sql, 'ActiveRecord/#{self.name}/find_by_sql', :metric => false
|
100
|
+
add_method_tracer :transaction, 'ActiveRecord/#{self.name}/transaction', :metric => false
|
101
|
+
end
|
90
102
|
end
|
91
103
|
end
|
92
104
|
end
|
@@ -4,92 +4,106 @@
|
|
4
4
|
# See data_mapper.rb for major differences compared to the ActiveRecord instrumentation.
|
5
5
|
#
|
6
6
|
|
7
|
-
|
7
|
+
DependencyDetection.defer do
|
8
|
+
depends_on do
|
9
|
+
defined?(::Sequel)
|
10
|
+
end
|
8
11
|
|
9
|
-
|
10
|
-
|
12
|
+
executes do
|
13
|
+
# Sequel::Model class methods
|
14
|
+
::Sequel::Model::ClassMethods.class_eval do
|
11
15
|
|
12
|
-
|
16
|
+
add_method_tracer :[], 'ActiveRecord/#{self.name}/find'
|
13
17
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
add_method_tracer :all, 'ActiveRecord/#{self.name}/find'
|
19
|
+
add_method_tracer :each, 'ActiveRecord/#{self.name}/find'
|
20
|
+
add_method_tracer :create, 'ActiveRecord/#{self.name}/create'
|
21
|
+
add_method_tracer :insert, 'ActiveRecord/#{self.name}/create'
|
22
|
+
add_method_tracer :insert_multiple, 'ActiveRecord/#{self.name}/create'
|
23
|
+
add_method_tracer :import, 'ActiveRecord/#{self.name}/create'
|
24
|
+
add_method_tracer :update, 'ActiveRecord/#{self.name}/update'
|
25
|
+
add_method_tracer :delete, 'ActiveRecord/#{self.name}/delete'
|
22
26
|
|
23
|
-
|
27
|
+
end
|
24
28
|
|
25
|
-
|
26
|
-
|
29
|
+
# Sequel's Model instance methods
|
30
|
+
::Sequel::Model::InstanceMethods.class_eval do
|
27
31
|
|
28
|
-
|
29
|
-
|
30
|
-
|
32
|
+
add_method_tracer :_insert, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/create'
|
33
|
+
add_method_tracer :_update, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/update'
|
34
|
+
add_method_tracer :_delete, 'ActiveRecord/#{self.class.name[/[^:]*$/]}/destroy'
|
31
35
|
|
32
|
-
|
36
|
+
end
|
33
37
|
|
34
|
-
|
35
|
-
|
38
|
+
# Sequel's Dataset instance methods
|
39
|
+
::Sequel::Dataset.class_eval do
|
36
40
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
+
add_method_tracer :execute, 'ActiveRecord/#{model ? model.name : "Dataset#{first_source}"}/find'
|
42
|
+
add_method_tracer :execute_insert, 'ActiveRecord/#{model ? model.name : "Dataset#{first_source}"}/create'
|
43
|
+
add_method_tracer :execute_dui, 'ActiveRecord/#{model ? model.name : "Dataset#{first_source}"}/update'
|
44
|
+
add_method_tracer :execute_ddl, 'ActiveRecord/#{model ? model.name : "Dataset#{first_source}"}/all'
|
41
45
|
|
42
|
-
|
46
|
+
end
|
43
47
|
|
44
|
-
|
45
|
-
|
48
|
+
# Sequel's Database methods
|
49
|
+
::Sequel::Database.class_eval do
|
46
50
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
+
add_method_tracer :execute, 'ActiveRecord/Database/find'
|
52
|
+
add_method_tracer :execute_insert, 'ActiveRecord/Database/create'
|
53
|
+
add_method_tracer :execute_dui, 'ActiveRecord/Database/update'
|
54
|
+
add_method_tracer :execute_ddl, 'ActiveRecord/Database/all'
|
51
55
|
|
56
|
+
end
|
52
57
|
end
|
58
|
+
end
|
53
59
|
|
54
|
-
module NewRelic
|
55
|
-
module Agent
|
56
|
-
module Instrumentation
|
57
|
-
module SequelInstrumentation
|
58
|
-
def self.included(klass)
|
59
|
-
klass.class_eval do
|
60
|
-
alias_method :log_duration_without_newrelic_instrumentation, :log_duration
|
61
|
-
alias_method :log_duration, :log_duration_with_newrelic_instrumentation
|
62
|
-
end
|
63
|
-
end
|
64
60
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
# Attach SQL to current segment/scope.
|
75
|
-
NewRelic::Agent.instance.transaction_sampler.notice_sql(sql, nil, duration)
|
76
|
-
|
77
|
-
# Record query duration associated with each of the desired metrics.
|
78
|
-
metrics = [ "ActiveRecord/#{operation}", 'ActiveRecord/all' ]
|
79
|
-
metrics.each do |metric|
|
80
|
-
NewRelic::Agent.instance.stats_engine.get_stats_no_scope(metric).trace_call(duration)
|
81
|
-
end
|
82
|
-
ensure
|
83
|
-
log_duration_without_newrelic_instrumentation(duration, sql)
|
61
|
+
module NewRelic
|
62
|
+
module Agent
|
63
|
+
module Instrumentation
|
64
|
+
module SequelInstrumentation
|
65
|
+
def self.included(klass)
|
66
|
+
klass.class_eval do
|
67
|
+
alias_method :log_duration_without_newrelic_instrumentation, :log_duration
|
68
|
+
alias_method :log_duration, :log_duration_with_newrelic_instrumentation
|
84
69
|
end
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
70
|
+
end
|
71
|
+
|
72
|
+
def log_duration_with_newrelic_instrumentation(duration, sql)
|
73
|
+
return unless NewRelic::Agent.is_execution_traced?
|
74
|
+
return unless operation = case sql
|
75
|
+
when /^\s*select/i then 'find'
|
76
|
+
when /^\s*(update|insert)/i then 'save'
|
77
|
+
when /^\s*delete/i then 'destroy'
|
78
|
+
else nil
|
79
|
+
end
|
80
|
+
|
81
|
+
# Attach SQL to current segment/scope.
|
82
|
+
NewRelic::Agent.instance.transaction_sampler.notice_sql(sql, nil, duration)
|
83
|
+
|
84
|
+
# Record query duration associated with each of the desired metrics.
|
85
|
+
metrics = [ "ActiveRecord/#{operation}", 'ActiveRecord/all' ]
|
86
|
+
metrics.each do |metric|
|
87
|
+
NewRelic::Agent.instance.stats_engine.get_stats_no_scope(metric).trace_call(duration)
|
88
|
+
end
|
89
|
+
ensure
|
90
|
+
log_duration_without_newrelic_instrumentation(duration, sql)
|
91
|
+
end
|
92
|
+
|
93
|
+
end # SequelInstrumentation
|
94
|
+
end # Instrumentation
|
95
|
+
end # Agent
|
96
|
+
end # NewRelic
|
97
|
+
|
98
|
+
DependencyDetection.defer do
|
99
|
+
depends_on do
|
100
|
+
defined?(::Sequel) && defined?(::Sequel::Database)
|
101
|
+
end
|
102
|
+
|
103
|
+
executes do
|
104
|
+
::Sequel::Database.class_eval do
|
105
|
+
include ::NewRelic::Agent::Instrumentation::SequelInstrumentation
|
106
|
+
end
|
93
107
|
end
|
108
|
+
end
|
94
109
|
|
95
|
-
end # if defined? Sequel
|