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
@@ -122,7 +122,7 @@ module NewRelic
|
|
122
122
|
self.expects(:method_defined?).returns(false)
|
123
123
|
assert !traced_method_exists?(nil, nil)
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
126
|
def test_assemble_code_header_forced
|
127
127
|
opts = {:force => true, :code_header => 'CODE HEADER'}
|
128
128
|
assert_equal "CODE HEADER", assemble_code_header('test_method', 'Custom/Test/test_method', opts)
|
@@ -1,14 +1,14 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','..','test_helper'))
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','..','test_helper'))
|
2
2
|
class NewRelic::Agent::MethodTracer::InstanceMethods::TraceExecutionScopedTest < Test::Unit::TestCase
|
3
3
|
require 'new_relic/agent/method_tracer'
|
4
4
|
include NewRelic::Agent::MethodTracer::InstanceMethods::TraceExecutionScoped
|
5
|
-
|
5
|
+
|
6
6
|
def test_trace_disabled_negative
|
7
7
|
self.expects(:traced?).returns(false)
|
8
8
|
options = {:force => false}
|
9
9
|
assert trace_disabled?(options)
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def test_trace_disabled_forced
|
13
13
|
self.expects(:traced?).returns(false)
|
14
14
|
options = {:force => true}
|
@@ -19,7 +19,7 @@ class NewRelic::Agent::MethodTracer::InstanceMethods::TraceExecutionScopedTest <
|
|
19
19
|
self.expects(:traced?).returns(true)
|
20
20
|
options = {:force => false}
|
21
21
|
assert !(trace_disabled?(options))
|
22
|
-
end
|
22
|
+
end
|
23
23
|
|
24
24
|
def test_get_stats_unscoped
|
25
25
|
fake_engine = mocked_object('stat_engine')
|
@@ -28,13 +28,13 @@ class NewRelic::Agent::MethodTracer::InstanceMethods::TraceExecutionScopedTest <
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_get_stats_scoped_scoped_only
|
31
|
-
fake_engine = mocked_object('stat_engine')
|
31
|
+
fake_engine = mocked_object('stat_engine')
|
32
32
|
fake_engine.expects(:get_stats).with('foob', true, true).returns('fakestats')
|
33
33
|
assert_equal 'fakestats', get_stats_scoped('foob', true)
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_get_stats_scoped_no_scoped_only
|
37
|
-
fake_engine = mocked_object('stat_engine')
|
37
|
+
fake_engine = mocked_object('stat_engine')
|
38
38
|
fake_engine.expects(:get_stats).with('foob', true, false).returns('fakestats')
|
39
39
|
assert_equal 'fakestats', get_stats_scoped('foob', false)
|
40
40
|
end
|
@@ -104,7 +104,7 @@ class NewRelic::Agent::MethodTracer::InstanceMethods::TraceExecutionScopedTest <
|
|
104
104
|
end
|
105
105
|
|
106
106
|
def test_log_errors_base
|
107
|
-
|
107
|
+
NewRelic::Control.instance.expects(:log).never
|
108
108
|
ran = false
|
109
109
|
log_errors("name", "metric") do
|
110
110
|
ran = true
|
@@ -113,7 +113,7 @@ class NewRelic::Agent::MethodTracer::InstanceMethods::TraceExecutionScopedTest <
|
|
113
113
|
end
|
114
114
|
|
115
115
|
def test_log_errors_with_return
|
116
|
-
|
116
|
+
NewRelic::Control.instance.expects(:log).never
|
117
117
|
ran = false
|
118
118
|
return_val = log_errors('name', 'metric') do
|
119
119
|
ran = true
|
@@ -125,13 +125,14 @@ class NewRelic::Agent::MethodTracer::InstanceMethods::TraceExecutionScopedTest <
|
|
125
125
|
end
|
126
126
|
|
127
127
|
def test_log_errors_with_error
|
128
|
-
fakelog =
|
128
|
+
fakelog = mock('log')
|
129
|
+
NewRelic::Control.instance.expects(:log).returns(fakelog).at_least_once
|
129
130
|
# normally I don't do this, but we really don't care what the
|
130
131
|
# backtrace looks like, beyond that it actually gets logged. Also,
|
131
132
|
# the mocks are reversed because apparently order matters.
|
132
133
|
fakelog.expects(:error).with(any_parameters)
|
133
134
|
fakelog.expects(:error).with("Caught exception in name. Metric name = metric, exception = should not propagate out of block")
|
134
|
-
|
135
|
+
|
135
136
|
log_errors("name", "metric") do
|
136
137
|
raise "should not propagate out of block"
|
137
138
|
end
|
@@ -162,7 +163,7 @@ class NewRelic::Agent::MethodTracer::InstanceMethods::TraceExecutionScopedTest <
|
|
162
163
|
|
163
164
|
trace_execution_scoped_footer(t0, metric, metric_stats, expected_scope, false, t1)
|
164
165
|
end
|
165
|
-
|
166
|
+
|
166
167
|
def test_trace_execution_scoped_disabled
|
167
168
|
self.expects(:trace_disabled?).returns(true)
|
168
169
|
# make sure the method doesn't beyond the abort
|
@@ -193,7 +194,7 @@ class NewRelic::Agent::MethodTracer::InstanceMethods::TraceExecutionScopedTest <
|
|
193
194
|
assert ran, 'should run contents of the block'
|
194
195
|
assert_equal 1172, value, 'should return the contents of the block'
|
195
196
|
end
|
196
|
-
|
197
|
+
|
197
198
|
def test_trace_execution_scoped_with_error
|
198
199
|
passed_in_opts = {}
|
199
200
|
opts_after_correction = {:metric => true, :deduct_call_time_from_parent => true}
|
@@ -211,7 +212,7 @@ class NewRelic::Agent::MethodTracer::InstanceMethods::TraceExecutionScopedTest <
|
|
211
212
|
|
212
213
|
assert ran, 'should run contents of the block'
|
213
214
|
end
|
214
|
-
|
215
|
+
|
215
216
|
private
|
216
217
|
|
217
218
|
def mocked_object(name)
|
@@ -219,8 +220,8 @@ class NewRelic::Agent::MethodTracer::InstanceMethods::TraceExecutionScopedTest <
|
|
219
220
|
self.stubs(name).returns(object)
|
220
221
|
object
|
221
222
|
end
|
222
|
-
|
223
|
-
|
223
|
+
|
224
|
+
|
224
225
|
def mocked_log
|
225
226
|
mocked_object('log')
|
226
227
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
2
|
require 'new_relic/agent/mock_scope_listener'
|
3
3
|
|
4
4
|
class Module
|
5
5
|
def method_traced?(method_name, metric_name)
|
6
6
|
traced_method_prefix = _traced_method_name(method_name, metric_name)
|
7
|
-
|
7
|
+
|
8
8
|
method_defined? traced_method_prefix
|
9
9
|
end
|
10
|
-
end
|
10
|
+
end
|
11
11
|
|
12
12
|
class Insider
|
13
13
|
def initialize(stats_engine)
|
@@ -47,17 +47,17 @@ module TestModuleWithLog
|
|
47
47
|
#just here to be traced
|
48
48
|
log "12345"
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
def log( msg )
|
52
52
|
msg
|
53
53
|
end
|
54
54
|
include NewRelic::Agent::MethodTracer
|
55
55
|
add_method_tracer :other_method, 'Custom/foo/bar'
|
56
|
-
end
|
56
|
+
end
|
57
57
|
|
58
58
|
class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
59
59
|
attr_reader :stats_engine
|
60
|
-
|
60
|
+
|
61
61
|
def setup
|
62
62
|
NewRelic::Agent.manual_start
|
63
63
|
@stats_engine = NewRelic::Agent.instance.stats_engine
|
@@ -76,7 +76,7 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
76
76
|
rescue RuntimeError
|
77
77
|
# ignore 'no tracer' errors from remove method tracer
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
@metric_name = nil
|
81
81
|
super
|
82
82
|
end
|
@@ -84,7 +84,7 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
84
84
|
def test_preserve_logging
|
85
85
|
assert_equal '12345', TestModuleWithLog.other_method
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
def test_basic
|
89
89
|
metric = "hello"
|
90
90
|
t1 = Time.now
|
@@ -93,12 +93,12 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
93
93
|
assert metric == @stats_engine.peek_scope.name
|
94
94
|
end
|
95
95
|
elapsed = Time.now - t1
|
96
|
-
|
96
|
+
|
97
97
|
stats = @stats_engine.get_stats(metric)
|
98
98
|
check_time stats.total_call_time, elapsed
|
99
99
|
assert stats.call_count == 1
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
def test_basic__original_api
|
103
103
|
metric = "hello"
|
104
104
|
t1 = Time.now
|
@@ -107,17 +107,17 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
107
107
|
assert metric == @stats_engine.peek_scope.name
|
108
108
|
end
|
109
109
|
elapsed = Time.now - t1
|
110
|
-
|
110
|
+
|
111
111
|
stats = @stats_engine.get_stats(metric)
|
112
112
|
check_time stats.total_call_time, elapsed
|
113
113
|
assert stats.call_count == 1
|
114
114
|
end
|
115
|
-
|
115
|
+
|
116
116
|
METRIC = "metric"
|
117
117
|
def test_add_method_tracer
|
118
118
|
@metric_name = METRIC
|
119
119
|
self.class.add_method_tracer :method_to_be_traced, METRIC
|
120
|
-
|
120
|
+
|
121
121
|
t1 = Time.now
|
122
122
|
method_to_be_traced 1,2,3,true,METRIC
|
123
123
|
elapsed = Time.now - t1
|
@@ -126,30 +126,30 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
126
126
|
self.class.remove_method_tracer :method_to_be_traced, METRIC
|
127
127
|
rescue RuntimeError
|
128
128
|
# ignore 'no tracer' errors from remove method tracer
|
129
|
-
end
|
129
|
+
end
|
130
|
+
|
130
131
|
|
131
|
-
|
132
132
|
stats = @stats_engine.get_stats(METRIC)
|
133
133
|
check_time stats.total_call_time, elapsed
|
134
134
|
assert stats.call_count == 1
|
135
135
|
end
|
136
|
-
|
136
|
+
|
137
137
|
def test_add_method_tracer__default
|
138
138
|
self.class.add_method_tracer :simple_method
|
139
|
-
|
139
|
+
|
140
140
|
simple_method
|
141
|
-
|
141
|
+
|
142
142
|
stats = @stats_engine.get_stats("Custom/#{self.class.name}/simple_method")
|
143
143
|
assert stats.call_count == 1
|
144
|
-
|
144
|
+
|
145
145
|
end
|
146
146
|
def test_add_method_tracer__reentry
|
147
147
|
self.class.add_method_tracer :simple_method
|
148
148
|
self.class.add_method_tracer :simple_method
|
149
149
|
self.class.add_method_tracer :simple_method
|
150
|
-
|
150
|
+
|
151
151
|
simple_method
|
152
|
-
|
152
|
+
|
153
153
|
stats = @stats_engine.get_stats("Custom/#{self.class.name}/simple_method")
|
154
154
|
assert stats.call_count == 1
|
155
155
|
end
|
@@ -162,26 +162,26 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
162
162
|
self.class.remove_method_tracer :method_to_be_traced, METRIC
|
163
163
|
rescue RuntimeError
|
164
164
|
# ignore 'no tracer' errors from remove method tracer
|
165
|
-
end
|
165
|
+
end
|
166
166
|
end
|
167
|
-
|
167
|
+
|
168
168
|
def test_tt_only
|
169
|
-
|
169
|
+
|
170
170
|
assert_nil @scope_listener.scope["c2"]
|
171
171
|
self.class.add_method_tracer :method_c1, "c1", :push_scope => true
|
172
|
-
|
172
|
+
|
173
173
|
self.class.add_method_tracer :method_c2, "c2", :metric => false
|
174
174
|
self.class.add_method_tracer :method_c3, "c3", :push_scope => false
|
175
|
-
|
175
|
+
|
176
176
|
method_c1
|
177
|
-
|
177
|
+
|
178
178
|
assert_not_nil @stats_engine.lookup_stat("c1")
|
179
179
|
assert_nil @stats_engine.lookup_stat("c2")
|
180
180
|
assert_not_nil @stats_engine.lookup_stat("c3")
|
181
|
-
|
181
|
+
|
182
182
|
assert_not_nil @scope_listener.scope["c2"]
|
183
183
|
end
|
184
|
-
|
184
|
+
|
185
185
|
def test_nested_scope_tracer
|
186
186
|
Insider.add_method_tracer :catcher, "catcher", :push_scope => true
|
187
187
|
Insider.add_method_tracer :thrower, "thrower", :push_scope => true
|
@@ -196,33 +196,33 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
196
196
|
sample = sampler.harvest
|
197
197
|
assert_not_nil sample
|
198
198
|
end
|
199
|
-
|
199
|
+
|
200
200
|
def test_add_same_tracer_twice
|
201
201
|
@metric_name = METRIC
|
202
202
|
self.class.add_method_tracer :method_to_be_traced, METRIC
|
203
203
|
self.class.add_method_tracer :method_to_be_traced, METRIC
|
204
|
-
|
204
|
+
|
205
205
|
t1 = Time.now
|
206
206
|
method_to_be_traced 1,2,3,true,METRIC
|
207
207
|
elapsed = Time.now - t1
|
208
|
-
|
208
|
+
|
209
209
|
begin
|
210
210
|
self.class.remove_method_tracer :method_to_be_traced, METRIC
|
211
211
|
rescue RuntimeError
|
212
212
|
# ignore 'no tracer' errors from remove method tracer
|
213
|
-
end
|
214
|
-
|
213
|
+
end
|
214
|
+
|
215
215
|
stats = @stats_engine.get_stats(METRIC)
|
216
216
|
check_time stats.total_call_time, elapsed
|
217
217
|
assert stats.call_count == 1
|
218
218
|
end
|
219
|
-
|
219
|
+
|
220
220
|
def test_add_tracer_with_dynamic_metric
|
221
221
|
metric_code = '#{args[0]}.#{args[1]}'
|
222
222
|
@metric_name = metric_code
|
223
223
|
expected_metric = "1.2"
|
224
224
|
self.class.add_method_tracer :method_to_be_traced, metric_code
|
225
|
-
|
225
|
+
|
226
226
|
t1 = Time.now
|
227
227
|
method_to_be_traced 1,2,3,true,expected_metric
|
228
228
|
elapsed = Time.now - t1
|
@@ -231,57 +231,57 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
231
231
|
self.class.remove_method_tracer :method_to_be_traced, metric_code
|
232
232
|
rescue RuntimeError
|
233
233
|
# ignore 'no tracer' errors from remove method tracer
|
234
|
-
end
|
235
|
-
|
234
|
+
end
|
235
|
+
|
236
236
|
stats = @stats_engine.get_stats(expected_metric)
|
237
237
|
check_time stats.total_call_time, elapsed
|
238
238
|
assert stats.call_count == 1
|
239
239
|
end
|
240
|
-
|
240
|
+
|
241
241
|
def test_trace_method_with_block
|
242
242
|
self.class.add_method_tracer :method_with_block, METRIC
|
243
|
-
|
243
|
+
|
244
244
|
t1 = Time.now
|
245
245
|
method_with_block(1,2,3,true,METRIC) do |scope|
|
246
246
|
assert scope == METRIC
|
247
247
|
end
|
248
248
|
elapsed = Time.now - t1
|
249
|
-
|
249
|
+
|
250
250
|
stats = @stats_engine.get_stats(METRIC)
|
251
251
|
check_time stats.total_call_time, elapsed
|
252
252
|
assert stats.call_count == 1
|
253
253
|
end
|
254
|
-
|
254
|
+
|
255
255
|
def test_trace_module_method
|
256
256
|
NewRelic::Agent.add_method_tracer :module_method_to_be_traced, '#{args[0]}'
|
257
257
|
NewRelic::Agent.module_method_to_be_traced "x", self
|
258
258
|
NewRelic::Agent.remove_method_tracer :module_method_to_be_traced, '#{args[0]}'
|
259
259
|
end
|
260
|
-
|
260
|
+
|
261
261
|
def test_remove
|
262
262
|
self.class.add_method_tracer :method_to_be_traced, METRIC
|
263
263
|
self.class.remove_method_tracer :method_to_be_traced, METRIC
|
264
|
-
|
264
|
+
|
265
265
|
t1 = Time.now
|
266
266
|
method_to_be_traced 1,2,3,false,METRIC
|
267
267
|
elapsed = Time.now - t1
|
268
|
-
|
268
|
+
|
269
269
|
stats = @stats_engine.get_stats(METRIC)
|
270
270
|
assert stats.call_count == 0
|
271
271
|
end
|
272
|
-
|
272
|
+
|
273
273
|
def self.static_method(x, testcase, is_traced)
|
274
274
|
testcase.assert x == "x"
|
275
275
|
testcase.assert((testcase.stats_engine.peek_scope.name == "x") == is_traced)
|
276
276
|
end
|
277
|
-
|
277
|
+
|
278
278
|
def trace_trace_static_method
|
279
279
|
self.add_method_tracer :static_method, '#{args[0]}'
|
280
280
|
self.class.static_method "x", self, true
|
281
281
|
self.remove_method_tracer :static_method, '#{args[0]}'
|
282
282
|
self.class.static_method "x", self, false
|
283
283
|
end
|
284
|
-
|
284
|
+
|
285
285
|
def test_multiple_metrics__scoped
|
286
286
|
metrics = %w[first second third]
|
287
287
|
self.class.trace_execution_scoped metrics do
|
@@ -309,19 +309,19 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
309
309
|
metric = "hey"
|
310
310
|
self.class.trace_execution_scoped metric do
|
311
311
|
assert @stats_engine.peek_scope.name == metric
|
312
|
-
throw Exception.new
|
312
|
+
throw Exception.new
|
313
313
|
end
|
314
|
-
|
314
|
+
|
315
315
|
assert false # should never get here
|
316
316
|
rescue Exception
|
317
317
|
# make sure the scope gets popped
|
318
318
|
assert @stats_engine.peek_scope == nil
|
319
319
|
end
|
320
|
-
|
320
|
+
|
321
321
|
stats = @stats_engine.get_stats metric
|
322
322
|
assert stats.call_count == 1
|
323
323
|
end
|
324
|
-
|
324
|
+
|
325
325
|
def test_add_multiple_tracers
|
326
326
|
self.class.add_method_tracer :method_to_be_traced, 'X', :push_scope => false
|
327
327
|
method_to_be_traced 1,2,3,true,nil
|
@@ -332,18 +332,18 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
332
332
|
self.class.remove_method_tracer :method_to_be_traced, 'X'
|
333
333
|
method_to_be_traced 1,2,3,false,'X'
|
334
334
|
end
|
335
|
-
|
335
|
+
|
336
336
|
def trace_no_push_scope
|
337
337
|
self.class.add_method_tracer :method_to_be_traced, 'X', :push_scope => false
|
338
338
|
method_to_be_traced 1,2,3,true,nil
|
339
339
|
self.class.remove_method_tracer :method_to_be_traced, 'X'
|
340
340
|
method_to_be_traced 1,2,3,false,'X'
|
341
341
|
end
|
342
|
-
|
342
|
+
|
343
343
|
def check_time(t1, t2)
|
344
344
|
assert_in_delta t2, t1, 0.02
|
345
345
|
end
|
346
|
-
|
346
|
+
|
347
347
|
# =======================================================
|
348
348
|
# test methods to be traced
|
349
349
|
def method_to_be_traced(x, y, z, is_traced, expected_metric)
|
@@ -358,26 +358,26 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
358
358
|
assert_not_equal expected_metric, scope_name
|
359
359
|
end
|
360
360
|
end
|
361
|
-
|
361
|
+
|
362
362
|
def method_with_block(x, y, z, is_traced, expected_metric, &block)
|
363
363
|
sleep 0.1
|
364
364
|
assert x == 1
|
365
365
|
assert y == 2
|
366
366
|
assert z == 3
|
367
367
|
block.call(@stats_engine.peek_scope.name)
|
368
|
-
|
368
|
+
|
369
369
|
scope_name = @stats_engine.peek_scope ? @stats_engine.peek_scope.name : nil
|
370
370
|
assert((expected_metric == scope_name) == is_traced)
|
371
371
|
end
|
372
|
-
|
372
|
+
|
373
373
|
def method_c1
|
374
374
|
method_c2
|
375
375
|
end
|
376
|
-
|
376
|
+
|
377
377
|
def method_c2
|
378
378
|
method_c3
|
379
379
|
end
|
380
|
-
|
380
|
+
|
381
381
|
def method_c3
|
382
382
|
end
|
383
383
|
|