ghazel-newrelic_rpm 3.1.0.1 → 3.4.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. data/CHANGELOG +120 -35
  2. data/LICENSE +29 -2
  3. data/README.rdoc +2 -2
  4. data/bin/mongrel_rpm +0 -0
  5. data/bin/newrelic +0 -0
  6. data/bin/newrelic_cmd +0 -0
  7. data/lib/new_relic/agent.rb +50 -38
  8. data/lib/new_relic/agent/agent.rb +459 -337
  9. data/lib/new_relic/agent/beacon_configuration.rb +71 -11
  10. data/lib/new_relic/agent/browser_monitoring.rb +73 -14
  11. data/lib/new_relic/agent/busy_calculator.rb +11 -3
  12. data/lib/new_relic/agent/chained_call.rb +2 -2
  13. data/lib/new_relic/agent/database.rb +223 -0
  14. data/lib/new_relic/agent/error_collector.rb +231 -183
  15. data/lib/new_relic/agent/instrumentation.rb +2 -2
  16. data/lib/new_relic/agent/instrumentation/active_merchant.rb +10 -2
  17. data/lib/new_relic/agent/instrumentation/active_record.rb +138 -0
  18. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +7 -1
  19. data/lib/new_relic/agent/instrumentation/authlogic.rb +6 -0
  20. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +46 -14
  21. data/lib/new_relic/agent/instrumentation/data_mapper.rb +8 -2
  22. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +11 -3
  23. data/lib/new_relic/agent/instrumentation/memcache.rb +49 -25
  24. data/lib/new_relic/agent/instrumentation/merb/controller.rb +7 -2
  25. data/lib/new_relic/agent/instrumentation/merb/errors.rb +7 -1
  26. data/lib/new_relic/agent/instrumentation/metric_frame.rb +31 -4
  27. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +1 -5
  28. data/lib/new_relic/agent/instrumentation/net.rb +8 -2
  29. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +5 -2
  30. data/lib/new_relic/agent/instrumentation/queue_time.rb +1 -1
  31. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +66 -35
  32. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +7 -1
  33. data/lib/new_relic/agent/instrumentation/rails/errors.rb +7 -1
  34. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +121 -1
  35. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +7 -1
  36. data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +21 -0
  37. data/lib/new_relic/agent/instrumentation/resque.rb +80 -0
  38. data/lib/new_relic/agent/instrumentation/sinatra.rb +46 -20
  39. data/lib/new_relic/agent/instrumentation/sunspot.rb +6 -0
  40. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +7 -2
  41. data/lib/new_relic/agent/method_tracer.rb +205 -99
  42. data/lib/new_relic/agent/new_relic_service.rb +221 -0
  43. data/lib/new_relic/agent/pipe_channel_manager.rb +161 -0
  44. data/lib/new_relic/agent/pipe_service.rb +54 -0
  45. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +89 -0
  46. data/lib/new_relic/agent/samplers/memory_sampler.rb +6 -7
  47. data/lib/new_relic/agent/shim_agent.rb +5 -5
  48. data/lib/new_relic/agent/sql_sampler.rb +282 -0
  49. data/lib/new_relic/agent/stats_engine.rb +2 -0
  50. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +123 -0
  51. data/lib/new_relic/agent/stats_engine/metric_stats.rb +35 -30
  52. data/lib/new_relic/agent/stats_engine/samplers.rb +10 -4
  53. data/lib/new_relic/agent/stats_engine/transactions.rb +28 -87
  54. data/lib/new_relic/agent/transaction_info.rb +74 -0
  55. data/lib/new_relic/agent/transaction_sample_builder.rb +18 -3
  56. data/lib/new_relic/agent/transaction_sampler.rb +108 -20
  57. data/lib/new_relic/agent/worker_loop.rb +14 -6
  58. data/lib/new_relic/collection_helper.rb +19 -11
  59. data/lib/new_relic/command.rb +1 -1
  60. data/lib/new_relic/commands/deployments.rb +2 -2
  61. data/lib/new_relic/commands/install.rb +2 -13
  62. data/lib/new_relic/control.rb +2 -3
  63. data/lib/new_relic/control/class_methods.rb +12 -6
  64. data/lib/new_relic/control/configuration.rb +57 -8
  65. data/lib/new_relic/control/frameworks.rb +10 -0
  66. data/lib/new_relic/control/frameworks/external.rb +4 -4
  67. data/lib/new_relic/control/frameworks/merb.rb +2 -1
  68. data/lib/new_relic/control/frameworks/rails.rb +35 -22
  69. data/lib/new_relic/control/frameworks/rails3.rb +12 -7
  70. data/lib/new_relic/control/frameworks/ruby.rb +5 -5
  71. data/lib/new_relic/control/frameworks/sinatra.rb +1 -4
  72. data/lib/new_relic/control/instance_methods.rb +38 -12
  73. data/lib/new_relic/control/instrumentation.rb +23 -4
  74. data/lib/new_relic/control/logging_methods.rb +70 -15
  75. data/lib/new_relic/control/server_methods.rb +22 -9
  76. data/lib/new_relic/delayed_job_injection.rb +16 -3
  77. data/lib/new_relic/helper.rb +21 -0
  78. data/lib/new_relic/language_support.rb +95 -0
  79. data/lib/new_relic/local_environment.rb +92 -48
  80. data/lib/new_relic/metric_data.rb +7 -2
  81. data/lib/new_relic/metric_spec.rb +12 -9
  82. data/lib/new_relic/noticed_error.rb +6 -1
  83. data/lib/new_relic/rack/browser_monitoring.rb +18 -19
  84. data/lib/new_relic/rack/developer_mode.rb +3 -2
  85. data/lib/new_relic/recipes.rb +8 -4
  86. data/lib/new_relic/stats.rb +17 -60
  87. data/lib/new_relic/transaction_analysis.rb +2 -1
  88. data/lib/new_relic/transaction_analysis/segment_summary.rb +4 -2
  89. data/lib/new_relic/transaction_sample.rb +60 -75
  90. data/lib/new_relic/transaction_sample/segment.rb +31 -79
  91. data/lib/new_relic/version.rb +2 -2
  92. data/lib/newrelic_rpm.rb +1 -1
  93. data/newrelic.yml +2 -2
  94. data/newrelic_rpm.gemspec +46 -54
  95. data/test/active_record_fixtures.rb +3 -3
  96. data/test/config/newrelic.yml +1 -1
  97. data/test/fixtures/proc_cpuinfo.txt +575 -0
  98. data/test/new_relic/agent/agent/connect_test.rb +128 -25
  99. data/test/new_relic/agent/agent/start_test.rb +9 -94
  100. data/test/new_relic/agent/agent/start_worker_thread_test.rb +2 -4
  101. data/test/new_relic/agent/agent_test.rb +51 -78
  102. data/test/new_relic/agent/agent_test_controller.rb +1 -1
  103. data/test/new_relic/agent/agent_test_controller_test.rb +49 -33
  104. data/test/new_relic/agent/beacon_configuration_test.rb +12 -5
  105. data/test/new_relic/agent/browser_monitoring_test.rb +99 -50
  106. data/test/new_relic/agent/database_test.rb +161 -0
  107. data/test/new_relic/agent/error_collector_test.rb +47 -23
  108. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +96 -42
  109. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +0 -2
  110. data/test/new_relic/agent/instrumentation/instrumentation_test.rb +1 -1
  111. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +3 -11
  112. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +9 -9
  113. data/test/new_relic/agent/instrumentation/queue_time_test.rb +6 -11
  114. data/test/new_relic/agent/memcache_instrumentation_test.rb +54 -18
  115. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +1 -1
  116. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +1 -1
  117. data/test/new_relic/agent/method_tracer_test.rb +3 -2
  118. data/test/new_relic/agent/new_relic_service_test.rb +151 -0
  119. data/test/new_relic/agent/pipe_channel_manager_test.rb +114 -0
  120. data/test/new_relic/agent/pipe_service_test.rb +113 -0
  121. data/test/new_relic/agent/rpm_agent_test.rb +4 -31
  122. data/test/new_relic/agent/sql_sampler_test.rb +192 -0
  123. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +19 -18
  124. data/test/new_relic/agent/stats_engine_test.rb +41 -6
  125. data/test/new_relic/agent/transaction_info_test.rb +13 -0
  126. data/test/new_relic/agent/transaction_sample_builder_test.rb +27 -4
  127. data/test/new_relic/agent/transaction_sampler_test.rb +68 -46
  128. data/test/new_relic/agent/worker_loop_test.rb +3 -3
  129. data/test/new_relic/agent_test.rb +242 -0
  130. data/test/new_relic/collection_helper_test.rb +50 -28
  131. data/test/new_relic/control/configuration_test.rb +77 -0
  132. data/test/new_relic/control/logging_methods_test.rb +49 -21
  133. data/test/new_relic/control_test.rb +115 -54
  134. data/test/new_relic/delayed_job_injection_test.rb +21 -0
  135. data/test/new_relic/fake_collector.rb +210 -0
  136. data/test/new_relic/fake_service.rb +44 -0
  137. data/test/new_relic/local_environment_test.rb +14 -1
  138. data/test/new_relic/metric_parser/metric_parser_test.rb +11 -0
  139. data/test/new_relic/rack/browser_monitoring_test.rb +84 -23
  140. data/test/new_relic/rack/developer_mode_helper_test.rb +141 -0
  141. data/test/new_relic/rack/developer_mode_test.rb +31 -0
  142. data/test/new_relic/stats_test.rb +3 -18
  143. data/test/new_relic/transaction_analysis/segment_summary_test.rb +14 -0
  144. data/test/new_relic/transaction_analysis_test.rb +3 -3
  145. data/test/new_relic/transaction_sample/segment_test.rb +15 -80
  146. data/test/new_relic/transaction_sample_test.rb +25 -18
  147. data/test/script/build_test_gem.sh +51 -0
  148. data/test/script/ci.sh +140 -0
  149. data/test/script/ci_agent-tests_runner.sh +82 -0
  150. data/test/script/ci_bench.sh +52 -0
  151. data/test/script/ci_multiverse_runner.sh +63 -0
  152. data/test/test_contexts.rb +1 -0
  153. data/test/test_helper.rb +18 -5
  154. data/ui/helpers/developer_mode_helper.rb +14 -8
  155. data/ui/helpers/google_pie_chart.rb +0 -1
  156. data/ui/views/newrelic/index.rhtml +2 -2
  157. data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +4 -18
  158. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +10 -0
  159. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +11 -11
  160. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +17 -4
  161. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +4 -0
  162. metadata +50 -36
  163. data/lib/new_relic/agent/instrumentation/rails/active_record_instrumentation.rb +0 -108
  164. data/lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb +0 -112
  165. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +0 -40
  166. data/lib/new_relic/data_serialization.rb +0 -84
  167. data/lib/new_relic/histogram.rb +0 -91
  168. data/lib/new_relic/rack/metric_app.rb +0 -65
  169. data/lib/new_relic/rack/mongrel_rpm.ru +0 -28
  170. data/lib/new_relic/rack/newrelic.yml +0 -27
  171. data/lib/new_relic/rack_app.rb +0 -6
  172. data/test/new_relic/data_serialization_test.rb +0 -70
  173. data/vendor/gems/dependency_detection-0.0.1.build/README +0 -0
  174. data/vendor/gems/metric_parser-0.1.0.pre1/LICENSE +0 -0
  175. data/vendor/gems/metric_parser-0.1.0.pre1/README +0 -0
@@ -1,203 +1,251 @@
1
-
2
1
  module NewRelic
3
2
  module Agent
4
- class ErrorCollector
5
- include NewRelic::CollectionHelper
6
-
7
- # Defined the methods that need to be stubbed out when the
8
- # agent is disabled
9
- module Shim #:nodoc:
10
- def notice_error(*args); end
11
- end
12
-
13
- MAX_ERROR_QUEUE_LENGTH = 20 unless defined? MAX_ERROR_QUEUE_LENGTH
14
-
15
- attr_accessor :enabled
16
- attr_reader :config_enabled
17
-
18
- def initialize
19
- @errors = []
20
- # lookup of exception class names to ignore. Hash for fast access
21
- @ignore = {}
22
- @ignore_filter = nil
23
-
24
- config = NewRelic::Control.instance.fetch('error_collector', {})
25
-
26
- @enabled = @config_enabled = config.fetch('enabled', true)
27
- @capture_source = config.fetch('capture_source', true)
28
-
29
- ignore_errors = config.fetch('ignore_errors', "")
30
- ignore_errors = ignore_errors.split(",") if ignore_errors.is_a? String
31
- ignore_errors.each { |error| error.strip! }
32
- ignore(ignore_errors)
33
- @lock = Mutex.new
34
- end
35
-
36
- def control
37
- NewRelic::Control.instance
38
- end
39
-
40
- def ignore_error_filter(&block)
41
- if block
42
- @ignore_filter = block
43
- else
44
- @ignore_filter
45
- end
46
- end
47
-
48
- # errors is an array of Exception Class Names
49
- #
50
- def ignore(errors)
51
- errors.each { |error| @ignore[error] = true; log.debug("Ignoring errors of type '#{error}'") }
52
- end
53
-
54
- module NoticeError
55
- def disabled?
56
- !@enabled
57
- end
58
-
59
- def filtered_by_error_filter?(error)
60
- return unless @ignore_filter
61
- !@ignore_filter.call(error)
62
- end
63
-
64
- def filtered_error?(error)
65
- @ignore[error.class.name] || filtered_by_error_filter?(error)
66
- end
67
-
68
- def error_is_ignored?(error)
69
- error && filtered_error?(error)
3
+ # This class collects errors from the parent application, storing
4
+ # them until they are harvested and transmitted to the server
5
+ class ErrorCollector
6
+ include NewRelic::CollectionHelper
7
+
8
+ # Defined the methods that need to be stubbed out when the
9
+ # agent is disabled
10
+ module Shim #:nodoc:
11
+ def notice_error(*args); end
12
+ end
13
+
14
+ # Maximum possible length of the queue - defaults to 20, may be
15
+ # made configurable in the future. This is a tradeoff between
16
+ # memory and data retention
17
+ MAX_ERROR_QUEUE_LENGTH = 20 unless defined? MAX_ERROR_QUEUE_LENGTH
18
+
19
+ attr_accessor :enabled, :errors
20
+ attr_reader :config_enabled
21
+
22
+ # Returns a new error collector
23
+ def initialize
24
+ @errors = []
25
+ # lookup of exception class names to ignore. Hash for fast access
26
+ @ignore = {}
27
+
28
+ config = NewRelic::Control.instance.fetch('error_collector', {})
29
+
30
+ @enabled = @config_enabled = config.fetch('enabled', true)
31
+ @capture_source = config.fetch('capture_source', true)
32
+
33
+ ignore_errors = config.fetch('ignore_errors', "")
34
+ ignore_errors = ignore_errors.split(",") if ignore_errors.is_a? String
35
+ ignore_errors.each { |error| error.strip! }
36
+ ignore(ignore_errors)
37
+ @lock = Mutex.new
38
+ end
39
+
40
+ # Helper method to get the NewRelic::Control.instance
41
+ def control
42
+ NewRelic::Control.instance
43
+ end
44
+
45
+ # Returns the error filter proc that is used to check if an
46
+ # error should be reported. When given a block, resets the
47
+ # filter to the provided block. The define_method() is used to
48
+ # wrap the block in a lambda so return statements don't result in a
49
+ # LocalJump exception.
50
+ def ignore_error_filter(&block)
51
+ if block
52
+ self.class.class_eval { define_method(:ignore_filter_proc, &block) }
53
+ @ignore_filter = method(:ignore_filter_proc)
54
+ else
55
+ @ignore_filter
56
+ end
70
57
  end
71
58
 
72
- def increment_error_count!
73
- NewRelic::Agent.get_stats("Errors/all").increment_count
59
+ # errors is an array of Exception Class Names
60
+ #
61
+ def ignore(errors)
62
+ errors.each { |error| @ignore[error] = true; log.debug("Ignoring errors of type '#{error}'") }
74
63
  end
75
-
76
- def should_exit_notice_error?(exception)
77
- if @enabled
78
- if !error_is_ignored?(exception)
79
- increment_error_count!
80
- return exception.nil?
64
+
65
+ # This module was extracted from the notice_error method - it is
66
+ # internally tested and can be refactored without major issues.
67
+ module NoticeError
68
+ # Whether the error collector is disabled or not
69
+ def disabled?
70
+ !@enabled
71
+ end
72
+
73
+ # Checks the provided error against the error filter, if there
74
+ # is an error filter
75
+ def filtered_by_error_filter?(error)
76
+ return unless @ignore_filter
77
+ !@ignore_filter.call(error)
78
+ end
79
+
80
+ # Checks the array of error names and the error filter against
81
+ # the provided error
82
+ def filtered_error?(error)
83
+ @ignore[error.class.name] || filtered_by_error_filter?(error)
84
+ end
85
+
86
+ # an error is ignored if it is nil or if it is filtered
87
+ def error_is_ignored?(error)
88
+ error && filtered_error?(error)
89
+ end
90
+
91
+ # Increments a statistic that tracks total error rate
92
+ def increment_error_count!
93
+ NewRelic::Agent.get_stats("Errors/all").increment_count
94
+ end
95
+
96
+ # whether we should return early from the notice_error process
97
+ # - based on whether the error is ignored or the error
98
+ # collector is disabled
99
+ def should_exit_notice_error?(exception)
100
+ if @enabled
101
+ if !error_is_ignored?(exception)
102
+ increment_error_count!
103
+ return exception.nil? # exit early if the exception is nil
104
+ end
81
105
  end
106
+ # disabled or an ignored error, per above
107
+ true
82
108
  end
83
- # disabled or an ignored error, per above
84
- true
85
- end
86
-
87
- def fetch_from_options(options, key, default=nil)
88
- options.delete(key) || default
89
- end
90
-
91
- def uri_ref_and_root(options)
92
- {
93
- :request_uri => fetch_from_options(options, :uri, ''),
94
- :request_referer => fetch_from_options(options, :referer, ''),
95
- :rails_root => control.root
96
- }
97
- end
98
-
99
- def custom_params_from_opts(options)
100
- # If anything else is left over, treat it like a custom param:
101
- fetch_from_options(options, :custom_params, {}).merge(options)
102
- end
103
-
104
- def request_params_from_opts(options)
105
- value = options.delete(:request_params)
106
- if control.capture_params
107
- value
108
- else
109
- nil
109
+
110
+ # acts just like Hash#fetch, but deletes the key from the hash
111
+ def fetch_from_options(options, key, default=nil)
112
+ options.delete(key) || default
113
+ end
114
+
115
+ # returns some basic option defaults pulled from the provided
116
+ # options hash
117
+ def uri_ref_and_root(options)
118
+ {
119
+ :request_uri => fetch_from_options(options, :uri, ''),
120
+ :request_referer => fetch_from_options(options, :referer, ''),
121
+ :rails_root => control.root
122
+ }
123
+ end
124
+
125
+ # If anything else is left over, we treat it like a custom param
126
+ def custom_params_from_opts(options)
127
+ # If anything else is left over, treat it like a custom param:
128
+ fetch_from_options(options, :custom_params, {}).merge(options)
129
+ end
130
+
131
+ # takes the request parameters out of the options hash, and
132
+ # returns them if we are capturing parameters, otherwise
133
+ # returns nil
134
+ def request_params_from_opts(options)
135
+ value = options.delete(:request_params)
136
+ if control.capture_params
137
+ value
138
+ else
139
+ nil
140
+ end
141
+ end
142
+
143
+ # normalizes the request and custom parameters before attaching
144
+ # them to the error. See NewRelic::CollectionHelper#normalize_params
145
+ def normalized_request_and_custom_params(options)
146
+ {
147
+ :request_params => normalize_params(request_params_from_opts(options)),
148
+ :custom_params => normalize_params(custom_params_from_opts(options))
149
+ }
150
+ end
151
+
152
+ # Merges together many of the options into something that can
153
+ # actually be attached to the error
154
+ def error_params_from_options(options)
155
+ uri_ref_and_root(options).merge(normalized_request_and_custom_params(options))
156
+ end
157
+
158
+ # calls a method on an object, if it responds to it - used for
159
+ # detection and soft fail-safe. Returns nil if the method does
160
+ # not exist
161
+ def sense_method(object, method)
162
+ object.send(method) if object.respond_to?(method)
163
+ end
164
+
165
+ # extracts source from the exception, if the exception supports
166
+ # that method
167
+ def extract_source(exception)
168
+ sense_method(exception, 'source_extract') if @capture_source
169
+ end
170
+
171
+ # extracts a stack trace from the exception for debugging purposes
172
+ def extract_stack_trace(exception)
173
+ actual_exception = sense_method(exception, 'original_exception') || exception
174
+ sense_method(actual_exception, 'backtrace') || '<no stack trace>'
175
+ end
176
+
177
+ # extracts a bunch of information from the exception to include
178
+ # in the noticed error - some may or may not be available, but
179
+ # we try to include all of it
180
+ def exception_info(exception)
181
+ {
182
+ :file_name => sense_method(exception, 'file_name'),
183
+ :line_number => sense_method(exception, 'line_number'),
184
+ :source => extract_source(exception),
185
+ :stack_trace => extract_stack_trace(exception)
186
+ }
187
+ end
188
+
189
+ # checks the size of the error queue to make sure we are under
190
+ # the maximum limit, and logs a warning if we are over the limit.
191
+ def over_queue_limit?(message)
192
+ over_limit = (@errors.length >= MAX_ERROR_QUEUE_LENGTH)
193
+ log.warn("The error reporting queue has reached #{MAX_ERROR_QUEUE_LENGTH}. The error detail for this and subsequent errors will not be transmitted to New Relic until the queued errors have been sent: #{message}") if over_limit
194
+ over_limit
110
195
  end
111
- end
112
-
113
- def normalized_request_and_custom_params(options)
114
- {
115
- :request_params => normalize_params(request_params_from_opts(options)),
116
- :custom_params => normalize_params(custom_params_from_opts(options))
117
- }
118
- end
119
-
120
- def error_params_from_options(options)
121
- uri_ref_and_root(options).merge(normalized_request_and_custom_params(options))
122
- end
123
-
124
- def sense_method(object, method)
125
- object.send(method) if object.respond_to?(method)
126
- end
127
-
128
- def extract_source(exception)
129
- sense_method(exception, 'source_extract') if @capture_source
130
- end
131
-
132
- def extract_stack_trace(exception)
133
- actual_exception = sense_method(exception, 'original_exception') || exception
134
- sense_method(actual_exception, 'backtrace') || '<no stack trace>'
135
- end
136
-
137
- def exception_info(exception)
138
- {
139
- :file_name => sense_method(exception, 'file_name'),
140
- :line_number => sense_method(exception, 'line_number'),
141
- :source => extract_source(exception),
142
- :stack_trace => extract_stack_trace(exception)
143
- }
144
- end
145
-
146
- def over_queue_limit?(message)
147
- over_limit = (@errors.length >= MAX_ERROR_QUEUE_LENGTH)
148
- log.warn("The error reporting queue has reached #{MAX_ERROR_QUEUE_LENGTH}. The error detail for this and subsequent errors will not be transmitted to New Relic until the queued errors have been sent: #{message}") if over_limit
149
- over_limit
150
- end
151
-
152
196
 
153
- def add_to_error_queue(noticed_error)
154
- @lock.synchronize do
155
- @errors << noticed_error unless over_queue_limit?(noticed_error.message)
197
+
198
+ # Synchronizes adding an error to the error queue, and checks if
199
+ # the error queue is too long - if so, we drop the error on the
200
+ # floor after logging a warning.
201
+ def add_to_error_queue(noticed_error)
202
+ @lock.synchronize do
203
+ @errors << noticed_error unless over_queue_limit?(noticed_error.message)
204
+ end
156
205
  end
157
206
  end
158
- end
159
-
160
- include NoticeError
161
207
 
162
- # Notice the error with the given available options:
163
- #
164
- # * <tt>:uri</tt> => The request path, minus any request params or query string.
165
- # * <tt>:referer</tt> => The URI of the referer
166
- # * <tt>:metric</tt> => The metric name associated with the transaction
167
- # * <tt>:request_params</tt> => Request parameters, already filtered if necessary
168
- # * <tt>:custom_params</tt> => Custom parameters
169
- #
170
- # If anything is left over, it's added to custom params
171
- # If exception is nil, the error count is bumped and no traced error is recorded
172
- def notice_error(exception, options={})
173
- return if should_exit_notice_error?(exception)
174
- action_path = fetch_from_options(options, :metric, (NewRelic::Agent.instance.stats_engine.scope_name || ''))
175
- exception_options = error_params_from_options(options).merge(exception_info(exception))
176
- add_to_error_queue(NewRelic::NoticedError.new(action_path, exception_options, exception))
177
- exception
178
- rescue Exception => e
179
- log.error("Error capturing an error, yodawg. #{e}")
180
- end
208
+ include NoticeError
209
+
210
+ # Notice the error with the given available options:
211
+ #
212
+ # * <tt>:uri</tt> => The request path, minus any request params or query string.
213
+ # * <tt>:referer</tt> => The URI of the referer
214
+ # * <tt>:metric</tt> => The metric name associated with the transaction
215
+ # * <tt>:request_params</tt> => Request parameters, already filtered if necessary
216
+ # * <tt>:custom_params</tt> => Custom parameters
217
+ #
218
+ # If anything is left over, it's added to custom params
219
+ # If exception is nil, the error count is bumped and no traced error is recorded
220
+ def notice_error(exception, options={})
221
+ return if should_exit_notice_error?(exception)
222
+ action_path = fetch_from_options(options, :metric, (NewRelic::Agent.instance.stats_engine.scope_name || ''))
223
+ exception_options = error_params_from_options(options).merge(exception_info(exception))
224
+ add_to_error_queue(NewRelic::NoticedError.new(action_path, exception_options, exception))
225
+ exception
226
+ rescue => e
227
+ log.error("Error capturing an error, yodawg. #{e}")
228
+ end
229
+
230
+ # Get the errors currently queued up. Unsent errors are left
231
+ # over from a previous unsuccessful attempt to send them to the server.
232
+ def harvest_errors(unsent_errors)
233
+ @lock.synchronize do
234
+ errors = @errors
235
+ @errors = []
181
236
 
182
- # Get the errors currently queued up. Unsent errors are left
183
- # over from a previous unsuccessful attempt to send them to the server.
184
- def harvest_errors(unsent_errors)
185
- @lock.synchronize do
186
- errors = @errors
187
- @errors = []
237
+ if unsent_errors && !unsent_errors.empty?
238
+ errors = unsent_errors + errors
239
+ end
188
240
 
189
- if unsent_errors && !unsent_errors.empty?
190
- errors = unsent_errors + errors
241
+ errors
191
242
  end
192
-
193
- errors
194
243
  end
195
- end
196
244
 
197
- private
198
- def log
199
- NewRelic::Agent.logger
245
+ private
246
+ def log
247
+ NewRelic::Agent.logger
248
+ end
200
249
  end
201
250
  end
202
251
  end
203
- end
@@ -1,8 +1,8 @@
1
1
  require 'new_relic/agent'
2
- # stub module that contains instrumentation defined in the
3
- # instrumentation directory
4
2
  module NewRelic
5
3
  module Agent
4
+ # stub module that contains instrumentation defined in the
5
+ # instrumentation directory
6
6
  module Instrumentation
7
7
  end
8
8
  end
@@ -1,8 +1,16 @@
1
1
  DependencyDetection.defer do
2
+ @name = :active_merchant
3
+
2
4
  depends_on do
3
- defined?(ActiveMerchant)
5
+ defined?(ActiveMerchant) && defined?(ActiveMerchant::Billing) &&
6
+ defined?(ActiveMerchant::Billing::Gateway) &&
7
+ ActiveMerchant::Billing::Gateway.respond_to?(:implementations)
4
8
  end
5
-
9
+
10
+ executes do
11
+ NewRelic::Agent.logger.debug 'Installing ActiveMerchant instrumentation'
12
+ end
13
+
6
14
  executes do
7
15
  ActiveMerchant::Billing::Gateway.implementations.each do |gateway|
8
16
  gateway.class_eval do