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.

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