newrelic_rpm 3.9.0.229 → 3.9.1.236
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +4 -1
- data/CHANGELOG +73 -0
- data/install.rb +2 -2
- data/lib/new_relic/agent/agent.rb +8 -1
- data/lib/new_relic/agent/browser_token.rb +10 -7
- data/lib/new_relic/agent/configuration/default_source.rb +8 -1
- data/lib/new_relic/agent/configuration/high_security_source.rb +56 -0
- data/lib/new_relic/agent/configuration/manager.rb +35 -28
- data/lib/new_relic/agent/cross_app_monitor.rb +23 -0
- data/lib/new_relic/agent/cross_app_tracing.rb +34 -26
- data/lib/new_relic/agent/database.rb +7 -6
- data/lib/new_relic/agent/instrumentation/active_record.rb +18 -18
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/curb.rb +18 -15
- data/lib/new_relic/agent/instrumentation/excon/connection.rb +1 -1
- data/lib/new_relic/agent/instrumentation/excon/middleware.rb +7 -4
- data/lib/new_relic/agent/instrumentation/httpclient.rb +1 -1
- data/lib/new_relic/agent/instrumentation/memcache.rb +9 -2
- data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +1 -1
- data/lib/new_relic/agent/instrumentation/net.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails4/errors.rb +1 -1
- data/lib/new_relic/agent/instrumentation/typhoeus.rb +6 -4
- data/lib/new_relic/agent/javascript_instrumentor.rb +9 -1
- data/lib/new_relic/agent/new_relic_service.rb +7 -0
- data/lib/new_relic/agent/obfuscator.rb +3 -2
- data/lib/new_relic/agent/request_sampler.rb +17 -1
- data/lib/new_relic/agent/sql_sampler.rb +10 -6
- data/lib/new_relic/agent/traced_method_stack.rb +0 -12
- data/lib/new_relic/agent/transaction.rb +98 -10
- data/lib/new_relic/agent/transaction_sampler.rb +10 -3
- data/lib/new_relic/agent/transaction_state.rb +2 -12
- data/lib/new_relic/control/frameworks/sinatra.rb +0 -3
- data/lib/new_relic/control/instance_methods.rb +5 -0
- data/lib/new_relic/json_wrapper.rb +7 -1
- data/lib/new_relic/rack/browser_monitoring.rb +25 -4
- data/lib/new_relic/version.rb +1 -1
- data/newrelic_rpm.gemspec +0 -1
- data/test/agent_helper.rb +76 -0
- data/test/fixtures/cross_agent_tests/cat_map.json +299 -0
- data/test/multiverse/suites/agent_only/collector_exception_handling_test.rb +16 -0
- data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +30 -0
- data/test/multiverse/suites/agent_only/marshaling_test.rb +17 -17
- data/test/multiverse/suites/agent_only/testing_app.rb +10 -1
- data/test/multiverse/suites/deferred_instrumentation/config/newrelic.yml +0 -1
- data/test/multiverse/suites/high_security/Envfile +3 -0
- data/test/multiverse/suites/high_security/config/newrelic.yml +27 -0
- data/test/multiverse/suites/high_security/high_security_test.rb +64 -0
- data/test/multiverse/suites/rails/action_controller_live_rum_test.rb +39 -0
- data/test/multiverse/suites/rails/bad_instrumentation_test.rb +3 -1
- data/test/multiverse/suites/rails/parameter_capture_test.rb +0 -20
- data/test/new_relic/agent/agent/connect_test.rb +5 -10
- data/test/new_relic/agent/agent_test.rb +11 -0
- data/test/new_relic/agent/browser_token_test.rb +10 -6
- data/test/new_relic/agent/configuration/default_source_test.rb +6 -0
- data/test/new_relic/agent/configuration/high_security_source_test.rb +83 -0
- data/test/new_relic/agent/configuration/manager_test.rb +7 -2
- data/test/new_relic/agent/cross_app_monitor_test.rb +17 -1
- data/test/new_relic/agent/cross_app_tracing_test.rb +11 -10
- data/test/new_relic/agent/hostname_test.rb +1 -1
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +22 -0
- data/test/new_relic/agent/instrumentation/middleware_tracing_test.rb +37 -0
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +4 -2
- data/test/new_relic/agent/javascript_instrumentor_test.rb +42 -0
- data/test/new_relic/agent/memcache_instrumentation_test.rb +11 -5
- data/test/new_relic/agent/request_sampler_test.rb +9 -0
- data/test/new_relic/agent/sql_sampler_test.rb +46 -0
- data/test/new_relic/agent/stats_engine/gc_profiler_test.rb +1 -0
- data/test/new_relic/agent/transaction_sampler_test.rb +64 -4
- data/test/new_relic/agent/transaction_state_test.rb +0 -75
- data/test/new_relic/agent/transaction_test.rb +142 -0
- data/test/new_relic/control/instance_methods_test.rb +24 -4
- data/test/new_relic/fake_collector.rb +6 -13
- data/test/new_relic/fake_external_server.rb +14 -1
- data/test/new_relic/http_client_test_cases.rb +69 -21
- data/test/new_relic/json_wrapper_test.rb +10 -5
- data/test/performance/suites/rack_middleware.rb +2 -1
- data/test/performance/suites/rum_autoinsertion.rb +17 -3
- data/test/script/path_hash.rb +49 -0
- data/test/test_helper.rb +0 -10
- metadata +12 -52
- metadata.gz.sig +0 -0
@@ -7,7 +7,7 @@ require 'new_relic/agent/hostname'
|
|
7
7
|
|
8
8
|
module NewRelic
|
9
9
|
module Agent
|
10
|
-
class HostnameTest <
|
10
|
+
class HostnameTest < Minitest::Test
|
11
11
|
def test_get_returns_socket_hostname
|
12
12
|
Socket.stubs(:gethostname).returns('Rivendell')
|
13
13
|
assert_equal 'Rivendell', NewRelic::Agent::Hostname.get
|
@@ -219,4 +219,26 @@ class NewRelic::Agent::Instrumentation::ControllerInstrumentationTest < Minitest
|
|
219
219
|
host.doit
|
220
220
|
assert host.params_called
|
221
221
|
end
|
222
|
+
|
223
|
+
class UserError < StandardError
|
224
|
+
end
|
225
|
+
|
226
|
+
def test_failure_during_starting_shouldnt_override_error_raised
|
227
|
+
host_class = Class.new do
|
228
|
+
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
229
|
+
|
230
|
+
def doit
|
231
|
+
perform_action_with_newrelic_trace do
|
232
|
+
raise UserError.new
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
NewRelic::Agent::Transaction.stubs(:start).returns(nil)
|
238
|
+
|
239
|
+
host = host_class.new
|
240
|
+
assert_raises(UserError) do
|
241
|
+
host.doit
|
242
|
+
end
|
243
|
+
end
|
222
244
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under New Relic's license terms.
|
3
|
+
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
|
+
|
5
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper'))
|
6
|
+
require 'new_relic/agent/instrumentation/middleware_tracing'
|
7
|
+
|
8
|
+
class NewRelic::Agent::Instrumentation::MiddlewareTracingTest < Minitest::Test
|
9
|
+
class UserError < StandardError
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_dont_block_errors_during_malfunctioning_transaction
|
13
|
+
middleware_class = Class.new do
|
14
|
+
include NewRelic::Agent::Instrumentation::MiddlewareTracing
|
15
|
+
|
16
|
+
attr_reader :category
|
17
|
+
|
18
|
+
def target
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def transaction_options
|
23
|
+
{}
|
24
|
+
end
|
25
|
+
|
26
|
+
def traced_call(env)
|
27
|
+
raise UserError.new
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
NewRelic::Agent::Transaction.stubs(:start).returns(nil)
|
32
|
+
|
33
|
+
assert_raises(UserError) do
|
34
|
+
middleware_class.new.call({})
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -24,9 +24,11 @@ class NewRelic::Agent::Instrumentation::NetInstrumentationTest < Minitest::Test
|
|
24
24
|
def test_scope_stack_integrity_maintained_on_request_failure
|
25
25
|
@socket.stubs(:write).raises('fake network error')
|
26
26
|
with_config(:"cross_application_tracer.enabled" => true) do
|
27
|
-
|
27
|
+
state = NewRelic::Agent::TransactionState.tl_get
|
28
|
+
stack = state.traced_method_stack
|
29
|
+
expected = stack.push_frame(state, 'dummy')
|
28
30
|
Net::HTTP.get(URI.parse('http://www.google.com/index.html')) rescue nil
|
29
|
-
|
31
|
+
stack.pop_frame(state, expected, 42, Time.now.to_f)
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
@@ -274,6 +274,48 @@ class NewRelic::Agent::JavascriptInstrumentorTest < Minitest::Test
|
|
274
274
|
assert_equal(string, instrumentor.html_safe_if_needed(string))
|
275
275
|
end
|
276
276
|
|
277
|
+
def test_request_guid_to_include
|
278
|
+
state = NewRelic::Agent::TransactionState.tl_get
|
279
|
+
with_config(:apdex_t => 2.0) do
|
280
|
+
freeze_time
|
281
|
+
in_transaction do |txn|
|
282
|
+
state.request_token = "token"
|
283
|
+
advance_time(4.0)
|
284
|
+
|
285
|
+
data = instrumentor.data_for_js_agent(state)
|
286
|
+
assert_equal(state.current_transaction.guid, data['ttGuid'])
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
def test_request_guid_excluded_if_request_fast_enough
|
292
|
+
state = NewRelic::Agent::TransactionState.tl_get
|
293
|
+
with_config(:apdex_t => 2.0) do
|
294
|
+
freeze_time
|
295
|
+
|
296
|
+
state.request_token = "token"
|
297
|
+
in_transaction do |txn|
|
298
|
+
advance_time(1.0)
|
299
|
+
data = instrumentor.data_for_js_agent(state)
|
300
|
+
assert_nil(data['ttGuid'])
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
def test_request_guid_excluded_if_no_token
|
306
|
+
state = NewRelic::Agent::TransactionState.tl_get
|
307
|
+
with_config(:apdex_t => 2.0) do
|
308
|
+
freeze_time
|
309
|
+
|
310
|
+
state.request_token = nil
|
311
|
+
in_transaction do |txn|
|
312
|
+
advance_time(4.0)
|
313
|
+
data = instrumentor.data_for_js_agent(state)
|
314
|
+
assert_nil(data['ttGuid'])
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
277
319
|
# Helpers
|
278
320
|
|
279
321
|
BEGINNING_OF_FOOTER = '<script type="text/javascript">window.NREUM||(NREUM={});NREUM.info='
|
@@ -75,10 +75,12 @@ if memcached_ready
|
|
75
75
|
def test_reads__web
|
76
76
|
commands = ['get']
|
77
77
|
commands << 'get_multi' unless MEMCACHED_CLASS.name == 'Spymemcached'
|
78
|
-
|
78
|
+
expected_metrics = commands
|
79
|
+
expected_metrics = ['single_get', 'multi_get'] if MEMCACHED_CLASS.name == 'Memcached' && Memcached::VERSION >= '1.8.0'
|
80
|
+
commands.zip(expected_metrics) do |method, metric|
|
79
81
|
if @cache.class.method_defined?(method)
|
80
82
|
_call_test_method_in_web_transaction(method)
|
81
|
-
compare_metrics ["Memcache/#{
|
83
|
+
compare_metrics ["Memcache/#{metric}", "Memcache/allWeb", "Memcache/#{metric}:Controller/NewRelic::Agent::MemcacheInstrumentationTest/action"],
|
82
84
|
@engine.metrics.select{|m| m =~ /^memcache.*/i}
|
83
85
|
end
|
84
86
|
end
|
@@ -106,10 +108,12 @@ if memcached_ready
|
|
106
108
|
def test_reads__background
|
107
109
|
commands = ['get']
|
108
110
|
commands << 'get_multi' unless MEMCACHED_CLASS.name == 'Spymemcached'
|
109
|
-
|
111
|
+
expected_metrics = commands
|
112
|
+
expected_metrics = ['single_get', 'multi_get'] if MEMCACHED_CLASS.name == 'Memcached' && Memcached::VERSION >= '1.8.0'
|
113
|
+
commands.zip(expected_metrics) do |method, metric|
|
110
114
|
if @cache.class.method_defined?(method)
|
111
115
|
_call_test_method_in_background_task(method)
|
112
|
-
compare_metrics ["Memcache/#{
|
116
|
+
compare_metrics ["Memcache/#{metric}", "Memcache/allOther", "Memcache/#{metric}:OtherTransaction/Background/NewRelic::Agent::MemcacheInstrumentationTest/bg_task"],
|
113
117
|
@engine.metrics.select{|m| m =~ /^memcache.*/i}
|
114
118
|
end
|
115
119
|
end
|
@@ -135,7 +139,9 @@ if memcached_ready
|
|
135
139
|
end
|
136
140
|
|
137
141
|
def test_handles_cas
|
138
|
-
expected_metrics = ["
|
142
|
+
expected_metrics = ["cas"]
|
143
|
+
expected_metrics = ["single_get", "single_cas"] if MEMCACHED_CLASS.name == 'Memcached' && Memcached::VERSION >= '1.8.0'
|
144
|
+
expected_metrics = ["Memcache/allOther"] + expected_metrics.flat_map {|m| ["Memcache/#{m}", "Memcache/#{m}:OtherTransaction/Background/NewRelic::Agent::MemcacheInstrumentationTest/bg_task"] }
|
139
145
|
if @cache.class.method_defined?(:cas)
|
140
146
|
@engine.clear_stats
|
141
147
|
perform_action_with_newrelic_trace(:name => 'bg_task', :category => :task) do
|
@@ -128,6 +128,15 @@ class NewRelic::Agent::RequestSamplerTest < Minitest::Test
|
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
|
+
def test_samples_on_transaction_finished_event_include_apdex_perf_zone
|
132
|
+
with_sampler_config do
|
133
|
+
generate_request('name', :apdex_perf_zone => 'S')
|
134
|
+
|
135
|
+
event_data = single_sample[EVENT_DATA_INDEX]
|
136
|
+
assert_equal 'S', event_data['nr.apdexPerfZone']
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
131
140
|
def test_samples_on_transaction_finished_event_includes_guid
|
132
141
|
with_sampler_config do
|
133
142
|
generate_request('name', :guid => "GUID")
|
@@ -205,6 +205,26 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
|
|
205
205
|
end
|
206
206
|
end
|
207
207
|
|
208
|
+
def test_should_not_collect_anything_when_record_sql_is_off
|
209
|
+
sampler = NewRelic::Agent.agent.sql_sampler
|
210
|
+
|
211
|
+
settings = {
|
212
|
+
:'slow_sql.enabled' => true,
|
213
|
+
:'slow_sql.record_sql' => 'off'
|
214
|
+
}
|
215
|
+
|
216
|
+
with_config(settings) do
|
217
|
+
in_transaction do
|
218
|
+
sql = "SELECT * FROM test"
|
219
|
+
metric_name = "Database/test/select"
|
220
|
+
sampler.notice_sql(sql, metric_name, {}, 10)
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
traces = sampler.harvest!
|
225
|
+
assert_empty(traces)
|
226
|
+
end
|
227
|
+
|
208
228
|
def test_sql_id_fits_in_a_mysql_int_11
|
209
229
|
sql_trace = NewRelic::Agent::SqlTrace.new("select * from test",
|
210
230
|
NewRelic::Agent::SlowSql.new("select * from test",
|
@@ -232,6 +252,27 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
|
|
232
252
|
end
|
233
253
|
end
|
234
254
|
|
255
|
+
def test_sends_obfuscated_queries_when_configured_via_slow_sql_settings
|
256
|
+
settings = {
|
257
|
+
:'slow_sql.record_sql' => 'obfuscated',
|
258
|
+
:'transaction_tracer.record_sql' => 'raw'
|
259
|
+
}
|
260
|
+
with_config(settings) do
|
261
|
+
data = NewRelic::Agent::TransactionSqlData.new
|
262
|
+
data.set_transaction_info("/c/a", 'guid')
|
263
|
+
data.set_transaction_name("WebTransaction/Controller/c/a")
|
264
|
+
data.sql_data.concat([NewRelic::Agent::SlowSql.new("select * from test where foo = 'bar'",
|
265
|
+
"Database/test/select", {}, 1.5),
|
266
|
+
NewRelic::Agent::SlowSql.new("select * from test where foo in (1,2,3,4,5)",
|
267
|
+
"Database/test/select", {}, 1.2)])
|
268
|
+
@sampler.harvest_slow_sql(data)
|
269
|
+
sql_traces = @sampler.harvest!
|
270
|
+
|
271
|
+
assert_equal('select * from test where foo = ?', sql_traces[0].sql)
|
272
|
+
assert_equal('select * from test where foo in (?,?,?,?,?)', sql_traces[1].sql)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
235
276
|
def test_can_directly_marshal_traces_for_pipe_transmittal
|
236
277
|
with_config(:'transaction_tracer.explain_enabled' => false) do
|
237
278
|
data = NewRelic::Agent::TransactionSqlData.new
|
@@ -316,4 +357,9 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
|
|
316
357
|
assert_equal(2, aggregated_trace.call_count)
|
317
358
|
assert_equal(3, aggregated_trace.total_call_time)
|
318
359
|
end
|
360
|
+
|
361
|
+
def test_on_finishing_transaction_with_busted_transaction_state_does_not_crash
|
362
|
+
state = NewRelic::Agent::TransactionState.tl_get
|
363
|
+
@sampler.on_finishing_transaction(state, "whatever", Time.now)
|
364
|
+
end
|
319
365
|
end
|
@@ -36,8 +36,13 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
|
|
36
36
|
NewRelic::Agent.instance.instance_variable_set(:@transaction_sampler, @sampler)
|
37
37
|
@test_config = { :'transaction_tracer.enabled' => true }
|
38
38
|
NewRelic::Agent.config.add_config_for_testing(@test_config)
|
39
|
-
@txn = stub('txn',
|
40
|
-
:
|
39
|
+
@txn = stub('txn',
|
40
|
+
:best_name => '/path',
|
41
|
+
:guid => 'a guid',
|
42
|
+
:custom_parameters => {},
|
43
|
+
:cat_trip_id => '',
|
44
|
+
:cat_path_hash => '',
|
45
|
+
:filtered_params => {} )
|
41
46
|
end
|
42
47
|
|
43
48
|
def teardown
|
@@ -779,11 +784,61 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
|
|
779
784
|
NewRelic::Agent.add_custom_parameters(:foo => 'bar')
|
780
785
|
end
|
781
786
|
end
|
782
|
-
|
783
|
-
custom_params = sample.params[:custom_params]
|
787
|
+
custom_params = custom_params_from_last_sample
|
784
788
|
assert_includes custom_params.keys, :foo
|
785
789
|
end
|
786
790
|
|
791
|
+
def test_custom_params_include_gc_time
|
792
|
+
with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
793
|
+
in_transaction do
|
794
|
+
NewRelic::Agent::StatsEngine::GCProfiler.stubs(:record_delta).returns(10.0)
|
795
|
+
end
|
796
|
+
end
|
797
|
+
|
798
|
+
assert_equal 10.0, custom_params_from_last_sample[:gc_time]
|
799
|
+
end
|
800
|
+
|
801
|
+
def test_custom_params_include_tripid
|
802
|
+
guid = nil
|
803
|
+
|
804
|
+
NewRelic::Agent.instance.cross_app_monitor.stubs(:client_referring_transaction_trip_id).returns('PDX-NRT')
|
805
|
+
|
806
|
+
with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
807
|
+
in_transaction do |transaction|
|
808
|
+
NewRelic::Agent::TransactionState.tl_get.is_cross_app_caller = true
|
809
|
+
guid = transaction.guid
|
810
|
+
end
|
811
|
+
end
|
812
|
+
|
813
|
+
assert_equal 'PDX-NRT', custom_params_from_last_sample[:'nr.trip_id']
|
814
|
+
end
|
815
|
+
|
816
|
+
def test_custom_params_dont_include_tripid_if_not_cross_app_transaction
|
817
|
+
NewRelic::Agent.instance.cross_app_monitor.stubs(:client_referring_transaction_trip_id).returns('PDX-NRT')
|
818
|
+
|
819
|
+
with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
820
|
+
in_transaction do |transaction|
|
821
|
+
NewRelic::Agent::TransactionState.tl_get.is_cross_app_caller = false
|
822
|
+
end
|
823
|
+
end
|
824
|
+
|
825
|
+
assert_nil custom_params_from_last_sample[:'nr.trip_id']
|
826
|
+
end
|
827
|
+
|
828
|
+
def test_custom_params_include_path_hash
|
829
|
+
path_hash = nil
|
830
|
+
|
831
|
+
with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
832
|
+
in_transaction do |transaction|
|
833
|
+
state = NewRelic::Agent::TransactionState.tl_get
|
834
|
+
state.is_cross_app_caller = true
|
835
|
+
path_hash = transaction.cat_path_hash(state)
|
836
|
+
end
|
837
|
+
end
|
838
|
+
|
839
|
+
assert_equal path_hash, custom_params_from_last_sample[:'nr.path_hash']
|
840
|
+
end
|
841
|
+
|
787
842
|
class Dummy
|
788
843
|
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
789
844
|
def run(n)
|
@@ -873,4 +928,9 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
|
|
873
928
|
@sampler.notice_pop_frame(state, "a")
|
874
929
|
@sampler.on_finishing_transaction(state, @txn, (stop || Time.now.to_f))
|
875
930
|
end
|
931
|
+
|
932
|
+
def custom_params_from_last_sample
|
933
|
+
sample = NewRelic::Agent.agent.transaction_sampler.harvest!.first
|
934
|
+
sample.params[:custom_params]
|
935
|
+
end
|
876
936
|
end
|
@@ -61,81 +61,6 @@ module NewRelic::Agent
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
GUID = "goo-id"
|
65
|
-
|
66
|
-
def test_request_guid_to_include
|
67
|
-
with_config(:apdex_t => 2.0) do
|
68
|
-
freeze_time
|
69
|
-
in_transaction do |txn|
|
70
|
-
state.request_token = "token"
|
71
|
-
advance_time(4.0)
|
72
|
-
assert_equal state.current_transaction.guid, state.request_guid_to_include
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_requst_guid_excluded_if_request_fast_enough
|
78
|
-
with_config(:apdex_t => 2.0) do
|
79
|
-
freeze_time
|
80
|
-
|
81
|
-
state.request_token = "token"
|
82
|
-
in_transaction do |txn|
|
83
|
-
advance_time(1.0)
|
84
|
-
assert_equal "", state.request_guid_to_include
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_request_guid_excluded_if_no_token
|
90
|
-
with_config(:apdex_t => 2.0) do
|
91
|
-
freeze_time
|
92
|
-
|
93
|
-
state.request_token = nil
|
94
|
-
in_transaction do |txn|
|
95
|
-
advance_time(4.0)
|
96
|
-
assert_equal "", state.request_guid_to_include
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_no_request_guid_for_event
|
102
|
-
state.request_token = nil
|
103
|
-
state.is_cross_app_caller = false
|
104
|
-
state.referring_transaction_info = nil
|
105
|
-
in_transaction do
|
106
|
-
assert_nil state.request_guid_for_event
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_request_guid_for_event
|
111
|
-
in_transaction do
|
112
|
-
state.request_token = nil
|
113
|
-
state.is_cross_app_caller = true
|
114
|
-
state.referring_transaction_info = nil
|
115
|
-
assert_equal state.current_transaction.guid, state.request_guid_for_event
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_request_guid_for_event_if_referring_transaction
|
120
|
-
in_transaction do
|
121
|
-
state.request_token = nil
|
122
|
-
state.is_cross_app_caller = false
|
123
|
-
state.referring_transaction_info = ["another"]
|
124
|
-
assert_equal state.current_transaction.guid, state.request_guid_for_event
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def test_request_guid_for_event_if_there_for_rum
|
129
|
-
with_config(:apdex_t => 2.0) do
|
130
|
-
in_transaction do
|
131
|
-
state.request_token = "token"
|
132
|
-
state.is_cross_app_caller = false
|
133
|
-
advance_time(10.0)
|
134
|
-
assert_equal state.current_transaction.guid, state.request_guid_for_event
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
64
|
def test_reset_should_reset_cat_state
|
140
65
|
state.is_cross_app_caller = true
|
141
66
|
state.referring_transaction_info = ['foo', 'bar']
|
@@ -338,6 +338,40 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
|
|
338
338
|
refute found_guid
|
339
339
|
end
|
340
340
|
|
341
|
+
def test_end_fires_a_transaction_finished_event_with_guid_if_request_token_and_too_long
|
342
|
+
guid = nil
|
343
|
+
NewRelic::Agent.subscribe(:transaction_finished) do |payload|
|
344
|
+
guid = payload[:guid]
|
345
|
+
end
|
346
|
+
|
347
|
+
with_config(:apdex_t => 2.0) do
|
348
|
+
freeze_time
|
349
|
+
in_transaction do
|
350
|
+
state = NewRelic::Agent::TransactionState.tl_get
|
351
|
+
state.request_token = 'token'
|
352
|
+
advance_time 4.0
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
refute_empty guid
|
357
|
+
end
|
358
|
+
|
359
|
+
def test_end_fires_a_transaction_finished_event_with_guid_if_referring_transaction
|
360
|
+
guid = nil
|
361
|
+
NewRelic::Agent.subscribe(:transaction_finished) do |payload|
|
362
|
+
guid = payload[:guid]
|
363
|
+
end
|
364
|
+
|
365
|
+
with_config(:apdex_t => 2.0) do
|
366
|
+
in_transaction do
|
367
|
+
state = NewRelic::Agent::TransactionState.tl_get
|
368
|
+
state.referring_transaction_info = ["another"]
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
refute_empty guid
|
373
|
+
end
|
374
|
+
|
341
375
|
def test_end_fires_a_transaction_finished_event_with_referring_transaction_guid
|
342
376
|
referring_guid = nil
|
343
377
|
NewRelic::Agent.subscribe(:transaction_finished) do |payload|
|
@@ -365,6 +399,74 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
|
|
365
399
|
refute found_referring_guid
|
366
400
|
end
|
367
401
|
|
402
|
+
def test_end_fires_a_transaction_finished_event_with_apdex_perf_zone
|
403
|
+
apdex = nil
|
404
|
+
NewRelic::Agent.subscribe(:transaction_finished) do |payload|
|
405
|
+
apdex = payload[:apdex_perf_zone]
|
406
|
+
end
|
407
|
+
|
408
|
+
freeze_time
|
409
|
+
|
410
|
+
with_config(:apdex_t => 1.0) do
|
411
|
+
in_web_transaction { advance_time 0.5 }
|
412
|
+
assert_equal('S', apdex)
|
413
|
+
|
414
|
+
in_web_transaction { advance_time 1.5 }
|
415
|
+
assert_equal('T', apdex)
|
416
|
+
|
417
|
+
in_web_transaction { advance_time 4.5 }
|
418
|
+
assert_equal('F', apdex)
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
422
|
+
def test_background_transaction_event_doesnt_include_apdex_perf_zone
|
423
|
+
apdex = nil
|
424
|
+
NewRelic::Agent.subscribe(:transaction_finished) do |payload|
|
425
|
+
apdex = payload[:apdex_perf_zone]
|
426
|
+
end
|
427
|
+
|
428
|
+
freeze_time
|
429
|
+
|
430
|
+
with_config(:apdex_t => 1.0) do
|
431
|
+
in_background_transaction { advance_time 0.5 }
|
432
|
+
assert_nil apdex
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
def test_cross_app_fields_in_finish_event_payload
|
437
|
+
keys = []
|
438
|
+
NewRelic::Agent.subscribe(:transaction_finished) do |payload|
|
439
|
+
keys = payload.keys
|
440
|
+
end
|
441
|
+
|
442
|
+
in_transaction do
|
443
|
+
NewRelic::Agent::TransactionState.tl_get.is_cross_app_caller = true
|
444
|
+
end
|
445
|
+
|
446
|
+
assert_includes keys, :cat_trip_id
|
447
|
+
assert_includes keys, :cat_path_hash
|
448
|
+
end
|
449
|
+
|
450
|
+
def test_cross_app_fields_not_in_finish_event_payload_if_no_cross_app_calls
|
451
|
+
keys = []
|
452
|
+
NewRelic::Agent.subscribe(:transaction_finished) do |payload|
|
453
|
+
keys = payload.keys
|
454
|
+
end
|
455
|
+
|
456
|
+
freeze_time
|
457
|
+
|
458
|
+
in_transaction do
|
459
|
+
advance_time(10)
|
460
|
+
|
461
|
+
state = NewRelic::Agent::TransactionState.tl_get
|
462
|
+
state.request_token = 'token'
|
463
|
+
state.is_cross_app_caller = false
|
464
|
+
end
|
465
|
+
|
466
|
+
refute_includes keys, :cat_trip_id
|
467
|
+
refute_includes keys, :cat_path_hash
|
468
|
+
end
|
469
|
+
|
368
470
|
def test_logs_warning_if_a_non_hash_arg_is_passed_to_add_custom_params
|
369
471
|
expects_logging(:warn, includes("add_custom_parameters"))
|
370
472
|
in_transaction do
|
@@ -372,6 +474,15 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
|
|
372
474
|
end
|
373
475
|
end
|
374
476
|
|
477
|
+
def test_ignores_custom_parameters_when_in_high_security
|
478
|
+
with_config(:high_security => true) do
|
479
|
+
in_transaction do |txn|
|
480
|
+
NewRelic::Agent.add_custom_parameters(:failure => "is an option")
|
481
|
+
assert_empty txn.custom_parameters
|
482
|
+
end
|
483
|
+
end
|
484
|
+
end
|
485
|
+
|
375
486
|
def test_user_attributes_alias_to_custom_parameters
|
376
487
|
in_transaction('user_attributes') do |txn|
|
377
488
|
txn.set_user_attributes(:set_instance => :set_instance)
|
@@ -639,6 +750,37 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
|
|
639
750
|
assert_metrics_recorded('Errors/all' => { :call_count => 2 })
|
640
751
|
end
|
641
752
|
|
753
|
+
def test_start_safe_from_exceptions
|
754
|
+
NewRelic::Agent::Transaction.any_instance.stubs(:start).raises("Haha")
|
755
|
+
expects_logging(:error, any_parameters)
|
756
|
+
|
757
|
+
in_transaction("Controller/boom") do
|
758
|
+
# nope
|
759
|
+
end
|
760
|
+
|
761
|
+
# We expect our transaction to fail, but no exception should surface
|
762
|
+
assert_metrics_not_recorded(['Controller/boom'])
|
763
|
+
end
|
764
|
+
|
765
|
+
def test_stop_safe_from_exceptions
|
766
|
+
NewRelic::Agent::Transaction.any_instance.stubs(:stop).raises("Haha")
|
767
|
+
expects_logging(:error, any_parameters)
|
768
|
+
|
769
|
+
in_transaction("Controller/boom") do
|
770
|
+
# nope
|
771
|
+
end
|
772
|
+
|
773
|
+
# We expect our transaction to fail, but no exception should surface
|
774
|
+
assert_metrics_not_recorded(['Controller/boom'])
|
775
|
+
end
|
776
|
+
|
777
|
+
def test_stop_safe_when_no_transaction_available
|
778
|
+
expects_logging(:error, includes(NewRelic::Agent::Transaction::FAILED_TO_STOP_MESSAGE))
|
779
|
+
|
780
|
+
state = NewRelic::Agent::TransactionState.new
|
781
|
+
NewRelic::Agent::Transaction.stop(state)
|
782
|
+
end
|
783
|
+
|
642
784
|
def assert_has_custom_parameter(txn, key, value = key)
|
643
785
|
assert_equal(value, txn.custom_parameters[key])
|
644
786
|
end
|