newrelic_rpm 2.14.1 → 3.0.0.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/README.rdoc +2 -0
- data/install.rb +2 -2
- data/lib/new_relic/agent.rb +34 -1
- data/lib/new_relic/agent/agent.rb +34 -25
- data/lib/new_relic/agent/browser_monitoring.rb +111 -0
- data/lib/new_relic/agent/error_collector.rb +4 -4
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +3 -3
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +5 -7
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +8 -8
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/memcache.rb +1 -1
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +1 -1
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +1 -1
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +1 -0
- data/lib/new_relic/agent/instrumentation/queue_time.rb +26 -26
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +2 -2
- data/lib/new_relic/agent/instrumentation/sinatra.rb +1 -1
- data/lib/new_relic/agent/method_tracer.rb +15 -15
- data/lib/new_relic/agent/shim_agent.rb +2 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +3 -3
- data/lib/new_relic/agent/stats_engine/samplers.rb +2 -2
- data/lib/new_relic/agent/stats_engine/transactions.rb +2 -1
- data/lib/new_relic/agent/transaction_sample_builder.rb +101 -0
- data/lib/new_relic/agent/transaction_sampler.rb +299 -251
- data/lib/new_relic/control.rb +2 -2
- data/lib/new_relic/control/class_methods.rb +0 -5
- data/lib/new_relic/control/configuration.rb +4 -3
- data/lib/new_relic/control/frameworks/rails.rb +9 -12
- data/lib/new_relic/control/instance_methods.rb +2 -2
- data/lib/new_relic/control/instrumentation.rb +1 -1
- data/lib/new_relic/control/server_methods.rb +2 -2
- data/lib/new_relic/delayed_job_injection.rb +1 -1
- data/lib/new_relic/local_environment.rb +7 -7
- data/lib/new_relic/rack/browser_monitoring.rb +61 -0
- data/lib/new_relic/stats.rb +6 -6
- data/lib/new_relic/version.rb +4 -4
- data/newrelic.yml +19 -0
- data/newrelic_rpm.gemspec +9 -4
- data/test/active_record_fixtures.rb +5 -5
- data/test/config/test_control.rb +3 -3
- data/test/new_relic/agent/agent/connect_test.rb +27 -6
- data/test/new_relic/agent/agent/start_test.rb +13 -13
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +8 -8
- data/test/new_relic/agent/agent_test.rb +85 -0
- data/test/new_relic/agent/agent_test_controller.rb +9 -9
- data/test/new_relic/agent/agent_test_controller_test.rb +37 -37
- data/test/new_relic/agent/browser_monitoring_test.rb +124 -0
- data/test/new_relic/agent/busy_calculator_test.rb +7 -7
- data/test/new_relic/agent/error_collector/notice_error_test.rb +9 -9
- data/test/new_relic/agent/error_collector_test.rb +54 -54
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +69 -69
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +36 -0
- data/test/new_relic/agent/instrumentation/metric_frame_test.rb +3 -3
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +11 -11
- data/test/new_relic/agent/instrumentation/queue_time_test.rb +38 -35
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +18 -18
- data/test/new_relic/agent/memcache_instrumentation_test.rb +12 -12
- 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 +16 -15
- data/test/new_relic/agent/method_tracer_test.rb +60 -60
- data/test/new_relic/agent/mock_scope_listener.rb +8 -8
- data/test/new_relic/agent/rpm_agent_test.rb +26 -26
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +17 -17
- data/test/new_relic/agent/stats_engine/samplers_test.rb +4 -4
- data/test/new_relic/agent/stats_engine/stats_engine_test.rb +51 -51
- data/test/new_relic/agent/transaction_sample_builder_test.rb +36 -36
- data/test/new_relic/agent/transaction_sampler_test.rb +727 -178
- data/test/new_relic/agent/worker_loop_test.rb +4 -4
- data/test/new_relic/collection_helper_test.rb +15 -15
- data/test/new_relic/command/deployments_test.rb +5 -5
- data/test/new_relic/control_test.rb +25 -25
- data/test/new_relic/local_environment_test.rb +11 -11
- data/test/new_relic/metric_spec_test.rb +21 -21
- data/test/new_relic/rack/episodes_test.rb +35 -35
- data/test/new_relic/stats_test.rb +61 -43
- data/test/new_relic/transaction_sample_subtest_test.rb +15 -15
- data/test/new_relic/transaction_sample_test.rb +25 -25
- data/test/new_relic/version_number_test.rb +11 -11
- data/test/test_contexts.rb +7 -7
- data/test/test_helper.rb +6 -6
- data/ui/helpers/developer_mode_helper.rb +67 -67
- data/ui/helpers/google_pie_chart.rb +4 -4
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +4 -4
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/action_mailer.rb +3 -3
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_merchant.rb +7 -7
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_record.rb +1 -1
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/apdex.rb +9 -9
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/background_transaction.rb +1 -1
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/client.rb +8 -8
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller.rb +9 -9
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_cpu.rb +4 -4
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_ext.rb +2 -2
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database.rb +8 -8
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database_pool.rb +3 -3
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net.rb +6 -6
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net_parser.rb +3 -3
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/external.rb +2 -2
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/frontend.rb +6 -6
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/gc.rb +2 -2
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/hibernate_session.rb +1 -1
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java.rb +4 -4
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java_parser.rb +3 -3
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp.rb +4 -4
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp_tag.rb +1 -1
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +1 -1
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +21 -21
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/orm.rb +2 -2
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/other_transaction.rb +6 -6
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet.rb +2 -2
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_context_listener.rb +1 -1
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_filter.rb +1 -1
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr.rb +3 -3
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr_request_handler.rb +1 -1
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring.rb +8 -8
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_action.rb +3 -3
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_result.rb +3 -3
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +5 -5
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_transaction.rb +20 -20
- metadata +15 -9
- data/lib/new_relic/agent/instrumentation/sequel.rb +0 -109
@@ -25,7 +25,7 @@ DependencyDetection.defer do
|
|
25
25
|
depends_on do
|
26
26
|
defined?(ActsAsSolr::ParserMethods)
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
depends_on do
|
30
30
|
defined?(ActsAsSolr::ClassMethods)
|
31
31
|
end
|
@@ -33,7 +33,7 @@ DependencyDetection.defer do
|
|
33
33
|
depends_on do
|
34
34
|
defined?(ActsAsSolr::CommonMethods)
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
executes do
|
38
38
|
ActsAsSolr::ParserMethods.module_eval do
|
39
39
|
include NewRelic::Instrumentation::ActsAsSolrInstrumentation::ParserMethodsInstrumentation
|
@@ -41,7 +41,7 @@ DependencyDetection.defer do
|
|
41
41
|
alias :parse_query :parse_query_with_newrelic
|
42
42
|
end
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
executes do
|
46
46
|
ActsAsSolr::ClassMethods.module_eval do
|
47
47
|
%w[find_by_solr find_id_by_solr multi_solr_search count_by_solr].each do |method|
|
@@ -264,11 +264,7 @@ module NewRelic
|
|
264
264
|
# Look for a metric frame in the thread local and process it.
|
265
265
|
# Clear the thread local when finished to ensure it only gets called once.
|
266
266
|
frame_data.record_apdex unless _is_filtered?('ignore_apdex')
|
267
|
-
|
268
|
-
if Thread::current[:browser_request]
|
269
|
-
NewRelic::Agent.instance.stats_engine.get_stats_no_scope("HttpDispatcherWithBrowser").record_data_point(Time.now - frame_data.start)
|
270
|
-
end
|
271
|
-
|
267
|
+
|
272
268
|
frame_data.pop
|
273
269
|
end
|
274
270
|
end
|
@@ -387,10 +383,12 @@ module NewRelic
|
|
387
383
|
# now is a Time instance to fall back on if no other candidate
|
388
384
|
# for the start time is found.
|
389
385
|
def _detect_upstream_wait(now)
|
386
|
+
queue_start = nil
|
390
387
|
if newrelic_request_headers
|
391
|
-
parse_frontend_headers(newrelic_request_headers)
|
388
|
+
queue_start = parse_frontend_headers(newrelic_request_headers)
|
389
|
+
Thread.current[:newrelic_queue_time] = (now.to_f - queue_start.to_f) if queue_start
|
392
390
|
end
|
393
|
-
now
|
391
|
+
queue_start || now
|
394
392
|
rescue Exception => e
|
395
393
|
NewRelic::Control.instance.log.error("Error detecting upstream wait time: #{e}")
|
396
394
|
NewRelic::Control.instance.log.debug("#{e.backtrace[0..20]}")
|
@@ -53,7 +53,7 @@ DependencyDetection.defer do
|
|
53
53
|
depends_on do
|
54
54
|
defined?(DataMapper::Collection)
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
executes do
|
58
58
|
DataMapper::Model.class_eval do
|
59
59
|
add_method_tracer :get, 'ActiveRecord/#{self.name}/get'
|
@@ -117,13 +117,13 @@ DependencyDetection.defer do
|
|
117
117
|
end
|
118
118
|
|
119
119
|
DependencyDetection.defer do
|
120
|
-
|
120
|
+
|
121
121
|
depends_on do
|
122
122
|
defined?(DataMapper) && defined?(DataMapper::Adapters) && defined?(DataMapper::Adapters::DataObjectsAdapter)
|
123
123
|
end
|
124
|
-
|
124
|
+
|
125
125
|
executes do
|
126
|
-
|
126
|
+
|
127
127
|
# Catch the two entry points into DM::Repository::Adapter that bypass CRUD
|
128
128
|
# (for when SQL is run directly).
|
129
129
|
DataMapper::Adapters::DataObjectsAdapter.class_eval do
|
@@ -140,7 +140,7 @@ DependencyDetection.defer do
|
|
140
140
|
depends_on do
|
141
141
|
defined?(DataMapper) && defined?(DataMapper::Validations) && defined?(DataMapper::Validations::ClassMethods)
|
142
142
|
end
|
143
|
-
|
143
|
+
|
144
144
|
# DM::Validations overrides Model#create, but currently in a way that makes it
|
145
145
|
# impossible to instrument from one place. I've got a patch pending inclusion
|
146
146
|
# to make it instrumentable by putting the create method inside ClassMethods.
|
@@ -158,7 +158,7 @@ DependencyDetection.defer do
|
|
158
158
|
depends_on do
|
159
159
|
defined?(DataMapper) && defined?(DataMapper::Transaction)
|
160
160
|
end
|
161
|
-
|
161
|
+
|
162
162
|
# NOTE: DM::Transaction basically calls commit() twice, so as-is it will show
|
163
163
|
# up in traces twice -- second time subordinate to the first's scope. Works
|
164
164
|
# well enough.
|
@@ -219,11 +219,11 @@ module NewRelic
|
|
219
219
|
end # NewRelic
|
220
220
|
|
221
221
|
DependencyDetection.defer do
|
222
|
-
|
222
|
+
|
223
223
|
depends_on do
|
224
224
|
defined?(DataObjects) && defined?(DataObjects::Connection)
|
225
225
|
end
|
226
|
-
|
226
|
+
|
227
227
|
executes do
|
228
228
|
DataObjects::Connection.class_eval do
|
229
229
|
include ::NewRelic::Agent::Instrumentation::DataMapperInstrumentation
|
@@ -11,7 +11,7 @@ module NewRelic
|
|
11
11
|
module Memcache
|
12
12
|
module_function
|
13
13
|
def instrument_method(the_class, method_name)
|
14
|
-
return unless the_class.method_defined? method_name.to_sym
|
14
|
+
return unless the_class.method_defined? method_name.to_sym
|
15
15
|
the_class.class_eval <<-EOD
|
16
16
|
def #{method_name}_with_newrelic_trace(*args)
|
17
17
|
metrics = ["MemCache/#{method_name}",
|
@@ -138,6 +138,7 @@ module NewRelic
|
|
138
138
|
NewRelic::Agent.instance.transaction_sampler.notice_scope_empty
|
139
139
|
end
|
140
140
|
NewRelic::Agent.instance.stats_engine.end_transaction
|
141
|
+
Thread.current[:newrelic_start_time] = (Thread.current[:newrelic_metric_frame].start rescue nil)
|
141
142
|
Thread.current[:newrelic_metric_frame] = nil
|
142
143
|
else # path stack not empty
|
143
144
|
# change the transaction name back to whatever was on the stack.
|
@@ -9,7 +9,7 @@ module NewRelic
|
|
9
9
|
ALT_QUEUE_HEADER = 'HTTP_X_QUEUE_TIME'
|
10
10
|
HEROKU_QUEUE_HEADER = 'HTTP_X_HEROKU_QUEUE_WAIT_TIME'
|
11
11
|
APP_HEADER = 'HTTP_X_APPLICATION_START'
|
12
|
-
|
12
|
+
|
13
13
|
HEADER_REGEX = /([^\s\/,(t=)]+)? ?t=([0-9]+)/
|
14
14
|
SERVER_METRIC = 'WebFrontend/WebServer/'
|
15
15
|
MIDDLEWARE_METRIC = 'Middleware/'
|
@@ -24,24 +24,22 @@ module NewRelic
|
|
24
24
|
# of the app don't have to worry about it.
|
25
25
|
# May have performance implications with very large env hashes
|
26
26
|
env = headers.dup
|
27
|
-
add_end_time_header(
|
28
|
-
parse_middleware_time_from(env)
|
29
|
-
parse_queue_time_from(env)
|
30
|
-
parse_server_time_from(env)
|
27
|
+
add_end_time_header(Time.now, env)
|
28
|
+
middleware_start = parse_middleware_time_from(env)
|
29
|
+
queue_start = parse_queue_time_from(env)
|
30
|
+
server_start = parse_server_time_from(env)
|
31
|
+
# returned for the controller instrumentation
|
32
|
+
[middleware_start, queue_start, server_start].min
|
31
33
|
end
|
32
|
-
|
34
|
+
|
33
35
|
private
|
34
|
-
|
35
|
-
def current_time
|
36
|
-
Time.now
|
37
|
-
end
|
38
|
-
|
36
|
+
|
39
37
|
# main method to extract server time info from env hash,
|
40
38
|
# records individual server metrics and one roll-up for all servers
|
41
39
|
def parse_server_time_from(env)
|
42
40
|
end_time = parse_end_time(env)
|
43
41
|
matches = get_matches_from_header(MAIN_HEADER, env)
|
44
|
-
|
42
|
+
|
45
43
|
record_individual_server_stats(end_time, matches)
|
46
44
|
record_rollup_server_stat(end_time, matches)
|
47
45
|
end
|
@@ -51,30 +49,31 @@ module NewRelic
|
|
51
49
|
matches = get_matches_from_header(MIDDLEWARE_HEADER, env)
|
52
50
|
|
53
51
|
record_individual_middleware_stats(end_time, matches)
|
54
|
-
record_rollup_middleware_stat(end_time, matches)
|
52
|
+
oldest_time = record_rollup_middleware_stat(end_time, matches)
|
55
53
|
# notice this bit: we reset the end time to the earliest
|
56
54
|
# middleware tag so that other frontend metrics don't
|
57
55
|
# include this time.
|
58
|
-
add_end_time_header(
|
56
|
+
add_end_time_header(oldest_time, env)
|
57
|
+
oldest_time
|
59
58
|
end
|
60
59
|
|
61
60
|
def parse_queue_time_from(env)
|
62
|
-
|
61
|
+
oldest_time = nil
|
63
62
|
end_time = parse_end_time(env)
|
64
63
|
alternate_length = check_for_alternate_queue_length(env)
|
65
64
|
if alternate_length
|
66
65
|
# skip all that fancy-dan stuff
|
67
66
|
NewRelic::Agent.get_stats(ALL_QUEUE_METRIC).trace_call(alternate_length)
|
68
|
-
|
67
|
+
oldest_time = (end_time - alternate_length) # should be a time
|
69
68
|
else
|
70
69
|
matches = get_matches_from_header(QUEUE_HEADER, env)
|
71
|
-
record_rollup_queue_stat(end_time, matches)
|
72
|
-
first_time = find_oldest_time(matches)
|
70
|
+
oldest_time = record_rollup_queue_stat(end_time, matches)
|
73
71
|
end
|
74
72
|
# notice this bit: we reset the end time to the earliest
|
75
73
|
# queue tag or the start time minus the queue time so that
|
76
74
|
# other frontend metrics don't include this time.
|
77
|
-
add_end_time_header(
|
75
|
+
add_end_time_header(oldest_time, env)
|
76
|
+
oldest_time
|
78
77
|
end
|
79
78
|
|
80
79
|
def check_for_alternate_queue_length(env)
|
@@ -115,7 +114,7 @@ module NewRelic
|
|
115
114
|
time
|
116
115
|
}
|
117
116
|
end
|
118
|
-
|
117
|
+
|
119
118
|
# goes through the list of servers and records each one in
|
120
119
|
# reverse order, subtracting the time for each successive
|
121
120
|
# server from the earlier ones in the list.
|
@@ -132,7 +131,7 @@ module NewRelic
|
|
132
131
|
def record_individual_middleware_stats(end_time, matches)
|
133
132
|
record_individual_stat_of_type(:record_middleware_time_for, end_time, matches)
|
134
133
|
end
|
135
|
-
|
134
|
+
|
136
135
|
# records the total time for all servers in a rollup metric
|
137
136
|
def record_rollup_server_stat(end_time, matches) # (Time, [String, Time]) -> nil
|
138
137
|
record_rollup_stat_of_type(ALL_SERVER_METRIC, end_time, matches)
|
@@ -147,17 +146,18 @@ module NewRelic
|
|
147
146
|
end
|
148
147
|
|
149
148
|
def record_rollup_stat_of_type(metric, end_time, matches)
|
150
|
-
|
151
|
-
record_time_stat(metric,
|
149
|
+
oldest_time = find_oldest_time(matches) || end_time
|
150
|
+
record_time_stat(metric, oldest_time, end_time)
|
151
|
+
oldest_time
|
152
152
|
end
|
153
|
-
|
153
|
+
|
154
154
|
# searches for the first server to touch a request
|
155
155
|
def find_oldest_time(matches) # [[String, Time]] -> Time
|
156
156
|
matches.map do |name, time|
|
157
157
|
time
|
158
158
|
end.min
|
159
159
|
end
|
160
|
-
|
160
|
+
|
161
161
|
# basically just assembles the metric name
|
162
162
|
def record_server_time_for(name, start_time, end_time) # (Maybe String, Time, Time) -> nil
|
163
163
|
record_time_stat(SERVER_METRIC + name, start_time, end_time) if name
|
@@ -195,7 +195,7 @@ module NewRelic
|
|
195
195
|
return time if time.is_a?(Numeric)
|
196
196
|
(time.to_f * 1_000_000).to_i
|
197
197
|
end
|
198
|
-
|
198
|
+
|
199
199
|
# convert a time from the header value (time in microseconds)
|
200
200
|
# into a ruby time object
|
201
201
|
def convert_from_microseconds(int) # Int -> Time
|
@@ -24,7 +24,7 @@ DependencyDetection.defer do
|
|
24
24
|
add_method_tracer :decode_response, "WebService/Soap/XML Decode"
|
25
25
|
add_method_tracer :encode_response, "WebService/Soap/XML Encode"
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
if defined?(ActionController) && defined?(ActionController::Base)
|
29
29
|
ActionController::Base.class_eval do
|
30
30
|
if method_defined? :perform_invocation
|
@@ -45,11 +45,11 @@ DependencyDetection.defer do
|
|
45
45
|
depends_on do
|
46
46
|
defined?(Rails) && Rails::VERSION::MAJOR.to_i == 3
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
depends_on do
|
50
50
|
defined?(ActionController) && defined?(ActionController::Base)
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
executes do
|
54
54
|
class ActionController::Base
|
55
55
|
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
@@ -92,7 +92,7 @@ module NewRelic
|
|
92
92
|
end
|
93
93
|
|
94
94
|
alias trace_method_execution_no_scope trace_execution_unscoped #:nodoc:
|
95
|
-
|
95
|
+
|
96
96
|
module TraceExecutionScoped
|
97
97
|
def agent_instance
|
98
98
|
NewRelic::Agent.instance
|
@@ -101,7 +101,7 @@ module NewRelic
|
|
101
101
|
def traced?
|
102
102
|
NewRelic::Agent.is_execution_traced?
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
def trace_disabled?(options)
|
106
106
|
!(traced? || options[:force])
|
107
107
|
end
|
@@ -120,7 +120,7 @@ module NewRelic
|
|
120
120
|
def main_stat(metric, options)
|
121
121
|
get_stats_scoped(metric, options[:scoped_metric_only])
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
def get_metric_stats(metrics, options)
|
125
125
|
metrics = Array(metrics)
|
126
126
|
first_name = metrics.shift
|
@@ -146,8 +146,8 @@ module NewRelic
|
|
146
146
|
def log_errors(code_area, metric)
|
147
147
|
yield
|
148
148
|
rescue => e
|
149
|
-
log.error("Caught exception in #{code_area}. Metric name = #{metric}, exception = #{e}")
|
150
|
-
log.error(e.backtrace.join("\n"))
|
149
|
+
NewRelic::Control.instance.log.error("Caught exception in #{code_area}. Metric name = #{metric}, exception = #{e}")
|
150
|
+
NewRelic::Control.instance.log.error(e.backtrace.join("\n"))
|
151
151
|
end
|
152
152
|
|
153
153
|
def trace_execution_scoped_header(metric, options, t0=Time.now.to_f)
|
@@ -163,7 +163,7 @@ module NewRelic
|
|
163
163
|
def trace_execution_scoped_footer(t0, first_name, metric_stats, expected_scope, forced, t1=Time.now.to_f)
|
164
164
|
log_errors("trace_method_execution footer", first_name) do
|
165
165
|
duration = t1 - t0
|
166
|
-
|
166
|
+
|
167
167
|
pop_flag!(forced)
|
168
168
|
if expected_scope
|
169
169
|
scope = stat_engine.pop_scope(expected_scope, duration, t1)
|
@@ -195,7 +195,7 @@ module NewRelic
|
|
195
195
|
trace_execution_scoped_footer(start_time, first_name, metric_stats, expected_scope, options[:force])
|
196
196
|
end
|
197
197
|
end
|
198
|
-
|
198
|
+
|
199
199
|
end
|
200
200
|
include TraceExecutionScoped
|
201
201
|
|
@@ -274,11 +274,11 @@ module NewRelic
|
|
274
274
|
|
275
275
|
module AddMethodTracer
|
276
276
|
ALLOWED_KEYS = [:force, :metric, :push_scope, :deduct_call_time_from_parent, :code_header, :code_footer, :scoped_metric_only].freeze
|
277
|
-
|
277
|
+
|
278
278
|
def unrecognized_keys(expected, given)
|
279
279
|
given.keys - expected
|
280
280
|
end
|
281
|
-
|
281
|
+
|
282
282
|
def any_unrecognized_keys?(expected, given)
|
283
283
|
unrecognized_keys(expected, given).any?
|
284
284
|
end
|
@@ -288,7 +288,7 @@ module NewRelic
|
|
288
288
|
raise "Unrecognized options in add_method_tracer_call: #{unrecognized_keys(ALLOWED_KEYS, options).join(', ')}"
|
289
289
|
end
|
290
290
|
end
|
291
|
-
|
291
|
+
|
292
292
|
def set_deduct_call_time_based_on_metric(options)
|
293
293
|
{:deduct_call_time_from_parent => !!options[:metric]}.merge(options)
|
294
294
|
end
|
@@ -300,7 +300,7 @@ module NewRelic
|
|
300
300
|
end
|
301
301
|
|
302
302
|
DEFAULT_SETTINGS = {:push_scope => true, :metric => true, :force => false, :code_header => "", :code_footer => "", :scoped_metric_only => false}.freeze
|
303
|
-
|
303
|
+
|
304
304
|
def validate_options(options)
|
305
305
|
raise TypeError.new("provided options must be a Hash") unless options.is_a?(Hash)
|
306
306
|
check_for_illegal_keys!(options)
|
@@ -308,12 +308,12 @@ module NewRelic
|
|
308
308
|
check_for_push_scope_and_metric(options)
|
309
309
|
options
|
310
310
|
end
|
311
|
-
|
311
|
+
|
312
312
|
# Default to the class where the method is defined.
|
313
313
|
def default_metric_name_code(method_name)
|
314
314
|
"Custom/#{self.name}/#{method_name.to_s}"
|
315
315
|
end
|
316
|
-
|
316
|
+
|
317
317
|
def method_exists?(method_name)
|
318
318
|
exists = method_defined?(method_name) || private_method_defined?(method_name)
|
319
319
|
NewRelic::Control.instance.log.warn("Did not trace #{self.name}##{method_name} because that method does not exist") unless exists
|
@@ -380,10 +380,10 @@ module NewRelic
|
|
380
380
|
def add_method_tracer(method_name, metric_name_code=nil, options = {})
|
381
381
|
return unless method_exists?(method_name)
|
382
382
|
metric_name_code ||= default_metric_name_code(method_name)
|
383
|
-
return if traced_method_exists?(method_name, metric_name_code)
|
383
|
+
return if traced_method_exists?(method_name, metric_name_code)
|
384
384
|
|
385
385
|
traced_method = code_to_eval(method_name, metric_name_code, options)
|
386
|
-
|
386
|
+
|
387
387
|
class_eval traced_method, __FILE__, __LINE__
|
388
388
|
alias_method _untraced_method_name(method_name, metric_name_code), method_name
|
389
389
|
alias_method method_name, _traced_method_name(method_name, metric_name_code)
|