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.
- data/CHANGELOG +120 -35
- data/LICENSE +29 -2
- data/README.rdoc +2 -2
- data/bin/mongrel_rpm +0 -0
- data/bin/newrelic +0 -0
- data/bin/newrelic_cmd +0 -0
- data/lib/new_relic/agent.rb +50 -38
- data/lib/new_relic/agent/agent.rb +459 -337
- data/lib/new_relic/agent/beacon_configuration.rb +71 -11
- data/lib/new_relic/agent/browser_monitoring.rb +73 -14
- data/lib/new_relic/agent/busy_calculator.rb +11 -3
- data/lib/new_relic/agent/chained_call.rb +2 -2
- data/lib/new_relic/agent/database.rb +223 -0
- data/lib/new_relic/agent/error_collector.rb +231 -183
- data/lib/new_relic/agent/instrumentation.rb +2 -2
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +10 -2
- data/lib/new_relic/agent/instrumentation/active_record.rb +138 -0
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +7 -1
- data/lib/new_relic/agent/instrumentation/authlogic.rb +6 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +46 -14
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +8 -2
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +11 -3
- data/lib/new_relic/agent/instrumentation/memcache.rb +49 -25
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +7 -2
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +7 -1
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +31 -4
- data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +1 -5
- data/lib/new_relic/agent/instrumentation/net.rb +8 -2
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +5 -2
- data/lib/new_relic/agent/instrumentation/queue_time.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +66 -35
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +7 -1
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +7 -1
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +121 -1
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +7 -1
- data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +21 -0
- data/lib/new_relic/agent/instrumentation/resque.rb +80 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +46 -20
- data/lib/new_relic/agent/instrumentation/sunspot.rb +6 -0
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +7 -2
- data/lib/new_relic/agent/method_tracer.rb +205 -99
- data/lib/new_relic/agent/new_relic_service.rb +221 -0
- data/lib/new_relic/agent/pipe_channel_manager.rb +161 -0
- data/lib/new_relic/agent/pipe_service.rb +54 -0
- data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +89 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +6 -7
- data/lib/new_relic/agent/shim_agent.rb +5 -5
- data/lib/new_relic/agent/sql_sampler.rb +282 -0
- data/lib/new_relic/agent/stats_engine.rb +2 -0
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +123 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +35 -30
- data/lib/new_relic/agent/stats_engine/samplers.rb +10 -4
- data/lib/new_relic/agent/stats_engine/transactions.rb +28 -87
- data/lib/new_relic/agent/transaction_info.rb +74 -0
- data/lib/new_relic/agent/transaction_sample_builder.rb +18 -3
- data/lib/new_relic/agent/transaction_sampler.rb +108 -20
- data/lib/new_relic/agent/worker_loop.rb +14 -6
- data/lib/new_relic/collection_helper.rb +19 -11
- data/lib/new_relic/command.rb +1 -1
- data/lib/new_relic/commands/deployments.rb +2 -2
- data/lib/new_relic/commands/install.rb +2 -13
- data/lib/new_relic/control.rb +2 -3
- data/lib/new_relic/control/class_methods.rb +12 -6
- data/lib/new_relic/control/configuration.rb +57 -8
- data/lib/new_relic/control/frameworks.rb +10 -0
- data/lib/new_relic/control/frameworks/external.rb +4 -4
- data/lib/new_relic/control/frameworks/merb.rb +2 -1
- data/lib/new_relic/control/frameworks/rails.rb +35 -22
- data/lib/new_relic/control/frameworks/rails3.rb +12 -7
- data/lib/new_relic/control/frameworks/ruby.rb +5 -5
- data/lib/new_relic/control/frameworks/sinatra.rb +1 -4
- data/lib/new_relic/control/instance_methods.rb +38 -12
- data/lib/new_relic/control/instrumentation.rb +23 -4
- data/lib/new_relic/control/logging_methods.rb +70 -15
- data/lib/new_relic/control/server_methods.rb +22 -9
- data/lib/new_relic/delayed_job_injection.rb +16 -3
- data/lib/new_relic/helper.rb +21 -0
- data/lib/new_relic/language_support.rb +95 -0
- data/lib/new_relic/local_environment.rb +92 -48
- data/lib/new_relic/metric_data.rb +7 -2
- data/lib/new_relic/metric_spec.rb +12 -9
- data/lib/new_relic/noticed_error.rb +6 -1
- data/lib/new_relic/rack/browser_monitoring.rb +18 -19
- data/lib/new_relic/rack/developer_mode.rb +3 -2
- data/lib/new_relic/recipes.rb +8 -4
- data/lib/new_relic/stats.rb +17 -60
- data/lib/new_relic/transaction_analysis.rb +2 -1
- data/lib/new_relic/transaction_analysis/segment_summary.rb +4 -2
- data/lib/new_relic/transaction_sample.rb +60 -75
- data/lib/new_relic/transaction_sample/segment.rb +31 -79
- data/lib/new_relic/version.rb +2 -2
- data/lib/newrelic_rpm.rb +1 -1
- data/newrelic.yml +2 -2
- data/newrelic_rpm.gemspec +46 -54
- data/test/active_record_fixtures.rb +3 -3
- data/test/config/newrelic.yml +1 -1
- data/test/fixtures/proc_cpuinfo.txt +575 -0
- data/test/new_relic/agent/agent/connect_test.rb +128 -25
- data/test/new_relic/agent/agent/start_test.rb +9 -94
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +2 -4
- data/test/new_relic/agent/agent_test.rb +51 -78
- data/test/new_relic/agent/agent_test_controller.rb +1 -1
- data/test/new_relic/agent/agent_test_controller_test.rb +49 -33
- data/test/new_relic/agent/beacon_configuration_test.rb +12 -5
- data/test/new_relic/agent/browser_monitoring_test.rb +99 -50
- data/test/new_relic/agent/database_test.rb +161 -0
- data/test/new_relic/agent/error_collector_test.rb +47 -23
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +96 -42
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +0 -2
- data/test/new_relic/agent/instrumentation/instrumentation_test.rb +1 -1
- data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +3 -11
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +9 -9
- data/test/new_relic/agent/instrumentation/queue_time_test.rb +6 -11
- data/test/new_relic/agent/memcache_instrumentation_test.rb +54 -18
- data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +1 -1
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +1 -1
- data/test/new_relic/agent/method_tracer_test.rb +3 -2
- data/test/new_relic/agent/new_relic_service_test.rb +151 -0
- data/test/new_relic/agent/pipe_channel_manager_test.rb +114 -0
- data/test/new_relic/agent/pipe_service_test.rb +113 -0
- data/test/new_relic/agent/rpm_agent_test.rb +4 -31
- data/test/new_relic/agent/sql_sampler_test.rb +192 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +19 -18
- data/test/new_relic/agent/stats_engine_test.rb +41 -6
- data/test/new_relic/agent/transaction_info_test.rb +13 -0
- data/test/new_relic/agent/transaction_sample_builder_test.rb +27 -4
- data/test/new_relic/agent/transaction_sampler_test.rb +68 -46
- data/test/new_relic/agent/worker_loop_test.rb +3 -3
- data/test/new_relic/agent_test.rb +242 -0
- data/test/new_relic/collection_helper_test.rb +50 -28
- data/test/new_relic/control/configuration_test.rb +77 -0
- data/test/new_relic/control/logging_methods_test.rb +49 -21
- data/test/new_relic/control_test.rb +115 -54
- data/test/new_relic/delayed_job_injection_test.rb +21 -0
- data/test/new_relic/fake_collector.rb +210 -0
- data/test/new_relic/fake_service.rb +44 -0
- data/test/new_relic/local_environment_test.rb +14 -1
- data/test/new_relic/metric_parser/metric_parser_test.rb +11 -0
- data/test/new_relic/rack/browser_monitoring_test.rb +84 -23
- data/test/new_relic/rack/developer_mode_helper_test.rb +141 -0
- data/test/new_relic/rack/developer_mode_test.rb +31 -0
- data/test/new_relic/stats_test.rb +3 -18
- data/test/new_relic/transaction_analysis/segment_summary_test.rb +14 -0
- data/test/new_relic/transaction_analysis_test.rb +3 -3
- data/test/new_relic/transaction_sample/segment_test.rb +15 -80
- data/test/new_relic/transaction_sample_test.rb +25 -18
- data/test/script/build_test_gem.sh +51 -0
- data/test/script/ci.sh +140 -0
- data/test/script/ci_agent-tests_runner.sh +82 -0
- data/test/script/ci_bench.sh +52 -0
- data/test/script/ci_multiverse_runner.sh +63 -0
- data/test/test_contexts.rb +1 -0
- data/test/test_helper.rb +18 -5
- data/ui/helpers/developer_mode_helper.rb +14 -8
- data/ui/helpers/google_pie_chart.rb +0 -1
- data/ui/views/newrelic/index.rhtml +2 -2
- data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +4 -18
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +10 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +11 -11
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +17 -4
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +4 -0
- metadata +50 -36
- data/lib/new_relic/agent/instrumentation/rails/active_record_instrumentation.rb +0 -108
- data/lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb +0 -112
- data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +0 -40
- data/lib/new_relic/data_serialization.rb +0 -84
- data/lib/new_relic/histogram.rb +0 -91
- data/lib/new_relic/rack/metric_app.rb +0 -65
- data/lib/new_relic/rack/mongrel_rpm.ru +0 -28
- data/lib/new_relic/rack/newrelic.yml +0 -27
- data/lib/new_relic/rack_app.rb +0 -6
- data/test/new_relic/data_serialization_test.rb +0 -70
- data/vendor/gems/dependency_detection-0.0.1.build/README +0 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/LICENSE +0 -0
- 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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
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
|
-
|
73
|
-
|
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
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
if
|
107
|
-
|
108
|
-
|
109
|
-
|
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
|
-
|
154
|
-
|
155
|
-
|
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
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
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
|
-
|
183
|
-
|
184
|
-
|
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
|
-
|
190
|
-
errors = unsent_errors + errors
|
241
|
+
errors
|
191
242
|
end
|
192
|
-
|
193
|
-
errors
|
194
243
|
end
|
195
|
-
end
|
196
244
|
|
197
|
-
|
198
|
-
|
199
|
-
|
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
|