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
@@ -0,0 +1,64 @@
|
|
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 'multiverse_helpers'
|
6
|
+
|
7
|
+
# These tests are designed to work in conjunction with a local newrelic.yml
|
8
|
+
# file set with "insecure" settings and the server returning "insecure" values,
|
9
|
+
# and confirm that high security changes the actual agent behavior, not just
|
10
|
+
# the settings in question.
|
11
|
+
class HighSecurityTest < Minitest::Test
|
12
|
+
|
13
|
+
include MultiverseHelpers
|
14
|
+
|
15
|
+
setup_and_teardown_agent do |collector|
|
16
|
+
# Because our tests will default to using SSL, we need to stub that out
|
17
|
+
# on our HTTP connects to the fake collector which doesn't have SSL...
|
18
|
+
Net::HTTPSession.any_instance.expects('use_ssl=').with(true).at_least_once
|
19
|
+
|
20
|
+
collector.stub('connect', {
|
21
|
+
"agent_run_id" => 1,
|
22
|
+
"listen_to_server_config" => true,
|
23
|
+
|
24
|
+
"agent_config" => {
|
25
|
+
"capture_params" => true,
|
26
|
+
}
|
27
|
+
}, 200)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_connects_via_ssl_no_matter_what
|
31
|
+
# Expectation is set in setup since we all need to sidestep the use_ssl=
|
32
|
+
# setting, and mocking gets weird if we call `stubs` then try to `expects`
|
33
|
+
NewRelic::Agent.manual_start(:ssl => false)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_sends_high_security_flag_in_connect
|
37
|
+
data = $collector.calls_for('connect')
|
38
|
+
assert data.first.body["high_security"]
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_disallows_server_config_from_overriding_high_security
|
42
|
+
refute NewRelic::Agent.config[:capture_params]
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_doesnt_capture_params
|
46
|
+
in_transaction(:filtered_params => { "loose" => "params" }) do
|
47
|
+
# no-op
|
48
|
+
end
|
49
|
+
assert_empty last_transaction_trace_request_params
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_doesnt_record_custom_parameters
|
53
|
+
in_transaction do
|
54
|
+
NewRelic::Agent::TransactionState.tl_get.is_cross_app_caller = true
|
55
|
+
NewRelic::Agent.add_custom_parameters(:not => "allowed")
|
56
|
+
end
|
57
|
+
|
58
|
+
assert_nil last_transaction_trace.params[:custom_params][:not]
|
59
|
+
refute_nil last_transaction_trace.params[:custom_params][:cpu_time]
|
60
|
+
refute_nil last_transaction_trace.params[:custom_params][:'nr.trip_id']
|
61
|
+
refute_nil last_transaction_trace.params[:custom_params][:'nr.path_hash']
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,39 @@
|
|
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 './app'
|
6
|
+
|
7
|
+
if defined?(ActionController::Live)
|
8
|
+
|
9
|
+
class UndeadController < ApplicationController
|
10
|
+
RESPONSE_BODY = "<html><head></head><body>Brains!</body></html>"
|
11
|
+
|
12
|
+
def brains
|
13
|
+
render :inline => RESPONSE_BODY
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class LiveController < UndeadController
|
18
|
+
include ActionController::Live
|
19
|
+
end
|
20
|
+
|
21
|
+
class ActionControllerLiveRumTest < RailsMultiverseTest
|
22
|
+
include MultiverseHelpers
|
23
|
+
|
24
|
+
JS_LOADER = "JS LOADER IN DA HOUSE"
|
25
|
+
|
26
|
+
setup_and_teardown_agent(:js_agent_loader => JS_LOADER, :beacon => "beacon", :browser_key => "key")
|
27
|
+
|
28
|
+
def test_rum_instrumentation_when_not_streaming
|
29
|
+
get '/undead/brains'
|
30
|
+
assert_includes(response.body, JS_LOADER)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_excludes_rum_instrumentation_when_streaming_with_action_controller_live
|
34
|
+
get '/live/brains'
|
35
|
+
assert_equal(LiveController::RESPONSE_BODY, response.body)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -11,7 +11,9 @@ class BadInstrumentationController < ApplicationController
|
|
11
11
|
# to fail.
|
12
12
|
# https://newrelic.atlassian.net/browse/RUBY-1158
|
13
13
|
def failwhale
|
14
|
-
NewRelic::Agent::
|
14
|
+
state = NewRelic::Agent::TransactionState.tl_get
|
15
|
+
stack = state.traced_method_stack
|
16
|
+
stack.push_frame(state, 'failwhale')
|
15
17
|
render :text => 'everything went great'
|
16
18
|
end
|
17
19
|
end
|
@@ -146,24 +146,4 @@ class ParameterCaptureTest < RailsMultiverseTest
|
|
146
146
|
end
|
147
147
|
assert_equal('/parameter_capture/sql', last_sql_trace.url)
|
148
148
|
end
|
149
|
-
|
150
|
-
def last_traced_error
|
151
|
-
NewRelic::Agent.agent.error_collector.errors.last
|
152
|
-
end
|
153
|
-
|
154
|
-
def last_traced_error_request_params
|
155
|
-
last_traced_error.params[:request_params]
|
156
|
-
end
|
157
|
-
|
158
|
-
def last_transaction_trace
|
159
|
-
NewRelic::Agent.agent.transaction_sampler.last_sample
|
160
|
-
end
|
161
|
-
|
162
|
-
def last_transaction_trace_request_params
|
163
|
-
last_transaction_trace.params[:request_params]
|
164
|
-
end
|
165
|
-
|
166
|
-
def last_sql_trace
|
167
|
-
NewRelic::Agent.agent.sql_sampler.sql_traces.values.last
|
168
|
-
end
|
169
149
|
end
|
@@ -149,36 +149,31 @@ class NewRelic::Agent::Agent::ConnectTest < Minitest::Test
|
|
149
149
|
|
150
150
|
def test_set_sql_recording_default
|
151
151
|
with_config(:'transaction_tracer.record_sql' => 'obfuscated') do
|
152
|
-
assert_equal(:obfuscated, NewRelic::Agent::Database.record_sql_method
|
153
|
-
"should default to :obfuscated, was #{NewRelic::Agent::Database.record_sql_method}")
|
152
|
+
assert_equal(:obfuscated, NewRelic::Agent::Database.record_sql_method)
|
154
153
|
end
|
155
154
|
end
|
156
155
|
|
157
156
|
def test_set_sql_recording_off
|
158
157
|
with_config(:'transaction_tracer.record_sql' => 'off') do
|
159
|
-
assert_equal(:off, NewRelic::Agent::Database.record_sql_method
|
160
|
-
"should be set to :off, was #{NewRelic::Agent::Database.record_sql_method}")
|
158
|
+
assert_equal(:off, NewRelic::Agent::Database.record_sql_method)
|
161
159
|
end
|
162
160
|
end
|
163
161
|
|
164
162
|
def test_set_sql_recording_none
|
165
163
|
with_config(:'transaction_tracer.record_sql' => 'none') do
|
166
|
-
assert_equal(:off, NewRelic::Agent::Database.record_sql_method
|
167
|
-
"should be set to :off, was #{NewRelic::Agent::Database.record_sql_method}")
|
164
|
+
assert_equal(:off, NewRelic::Agent::Database.record_sql_method)
|
168
165
|
end
|
169
166
|
end
|
170
167
|
|
171
168
|
def test_set_sql_recording_raw
|
172
169
|
with_config(:'transaction_tracer.record_sql' => 'raw') do
|
173
|
-
assert_equal(:raw, NewRelic::Agent::Database.record_sql_method
|
174
|
-
"should be set to :raw, was #{NewRelic::Agent::Database.record_sql_method}")
|
170
|
+
assert_equal(:raw, NewRelic::Agent::Database.record_sql_method)
|
175
171
|
end
|
176
172
|
end
|
177
173
|
|
178
174
|
def test_set_sql_recording_falsy
|
179
175
|
with_config(:'transaction_tracer.record_sql' => false) do
|
180
|
-
assert_equal(:off, NewRelic::Agent::Database.record_sql_method
|
181
|
-
"should be set to :off, was #{NewRelic::Agent::Database.record_sql_method}")
|
176
|
+
assert_equal(:off, NewRelic::Agent::Database.record_sql_method)
|
182
177
|
end
|
183
178
|
end
|
184
179
|
|
@@ -300,6 +300,16 @@ module NewRelic
|
|
300
300
|
@agent.send(:connect, :force_reconnect => true)
|
301
301
|
end
|
302
302
|
|
303
|
+
def test_connect_logs_error_for_all_exceptions
|
304
|
+
bad = Class.new(Exception)
|
305
|
+
@agent.stubs(:should_connect?).raises(bad)
|
306
|
+
::NewRelic::Agent.logger.expects(:error).once
|
307
|
+
|
308
|
+
assert_raises(bad) do
|
309
|
+
@agent.send(:connect)
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
303
313
|
def test_connect_settings
|
304
314
|
settings = @agent.connect_settings
|
305
315
|
assert settings.include?(:pid)
|
@@ -309,6 +319,7 @@ module NewRelic
|
|
309
319
|
assert settings.include?(:agent_version)
|
310
320
|
assert settings.include?(:environment)
|
311
321
|
assert settings.include?(:settings)
|
322
|
+
assert settings.include?(:high_security)
|
312
323
|
end
|
313
324
|
|
314
325
|
def test_connect_settings_checks_environment_report_can_marshal
|
@@ -17,27 +17,31 @@ module NewRelic::Agent
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_get_token_with_embedded_tags_sanitized
|
20
|
-
assert_token(
|
20
|
+
assert_token(nil, 'NRAGENT' => 'tk=1234<tag>evil</tag>5678')
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_get_token_with_embedded_utf8_js_sanitized
|
24
|
-
assert_token(
|
24
|
+
assert_token(nil, 'NRAGENT' => "tk=1234"])򑛞")
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_get_token_with_embedded_utf7_js_sanitized
|
28
|
+
assert_token(nil, 'NRAGENT' => 'tk=+ADw-SCRIPT+AD4-alert(1)+ADw-/SCRIPT+AD4-')
|
25
29
|
end
|
26
30
|
|
27
31
|
def test_get_token_replaces_double_quoted_token_with_empty_string
|
28
|
-
assert_token(
|
32
|
+
assert_token(nil, 'NRAGENT' => 'tk="""deadbeef"""')
|
29
33
|
end
|
30
34
|
|
31
35
|
def test_get_token_replaces_single_quoted_token_with_empty_string
|
32
|
-
assert_token(
|
36
|
+
assert_token(nil, 'NRAGENT' => "tk='''deadbeef'''")
|
33
37
|
end
|
34
38
|
|
35
39
|
def test_get_token_replaces_token_started_with_multiple_Lt_with_empty_string
|
36
|
-
assert_token(
|
40
|
+
assert_token(nil, 'NRAGENT' => 'tk=<<<deadbeef')
|
37
41
|
end
|
38
42
|
|
39
43
|
def test_get_token_replaces_token_started_with_multiple_gt_with_empty_string
|
40
|
-
assert_token(
|
44
|
+
assert_token(nil, 'NRAGENT' => 'tk=>>>deadbeef')
|
41
45
|
end
|
42
46
|
|
43
47
|
def test_get_token_bare_value_replaced_with_nil
|
@@ -54,6 +54,12 @@ module NewRelic::Agent::Configuration
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
def test_config_search_paths_include_application_root
|
58
|
+
NewRelic::Control.instance.stubs(:root).returns('app_root')
|
59
|
+
paths = DefaultSource.config_search_paths.call
|
60
|
+
assert paths.any? { |p| p.include? 'app_root' }
|
61
|
+
end
|
62
|
+
|
57
63
|
def fetch_config_value(key)
|
58
64
|
accessor = key.to_sym
|
59
65
|
config = @default_source
|
@@ -0,0 +1,83 @@
|
|
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/configuration/high_security_source'
|
7
|
+
|
8
|
+
module NewRelic::Agent::Configuration
|
9
|
+
class HighSecuritySourceTest < Minitest::Test
|
10
|
+
def test_leaves_obfuscated_record_sql_parameters
|
11
|
+
local_settings = {
|
12
|
+
:'transaction_tracer.record_sql' => 'obfuscated',
|
13
|
+
:'slow_sql.record_sql' => 'obfuscated'
|
14
|
+
}
|
15
|
+
|
16
|
+
source = HighSecuritySource.new(local_settings)
|
17
|
+
|
18
|
+
assert_equal('obfuscated', source[:'transaction_tracer.record_sql'])
|
19
|
+
assert_equal('obfuscated', source[:'slow_sql.record_sql'])
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_leaves_off_record_sql_parameters
|
23
|
+
local_settings = {
|
24
|
+
:'transaction_tracer.record_sql' => 'off',
|
25
|
+
:'slow_sql.record_sql' => 'off'
|
26
|
+
}
|
27
|
+
|
28
|
+
source = HighSecuritySource.new(local_settings)
|
29
|
+
|
30
|
+
assert_equal('off', source[:'transaction_tracer.record_sql'])
|
31
|
+
assert_equal('off', source[:'slow_sql.record_sql'])
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_changes_raw_record_sql_to_obfuscated
|
35
|
+
local_settings = {
|
36
|
+
:'transaction_tracer.record_sql' => 'raw',
|
37
|
+
:'slow_sql.record_sql' => 'raw'
|
38
|
+
}
|
39
|
+
|
40
|
+
source = HighSecuritySource.new(local_settings)
|
41
|
+
|
42
|
+
assert_equal('obfuscated', source[:'transaction_tracer.record_sql'])
|
43
|
+
assert_equal('obfuscated', source[:'slow_sql.record_sql'])
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_forces_unrecognized_values_to_off
|
47
|
+
local_settings = {
|
48
|
+
:'transaction_tracer.record_sql' => 'jibberish',
|
49
|
+
:'slow_sql.record_sql' => 'junk'
|
50
|
+
}
|
51
|
+
|
52
|
+
expects_logging(:info, includes('jibberish'))
|
53
|
+
|
54
|
+
source = HighSecuritySource.new(local_settings)
|
55
|
+
|
56
|
+
assert_equal('off', source[:'transaction_tracer.record_sql'])
|
57
|
+
assert_equal('off', source[:'slow_sql.record_sql'])
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_logs_when_changing_raw_to_obfuscated
|
61
|
+
local_settings = {
|
62
|
+
:'transaction_tracer.record_sql' => 'raw',
|
63
|
+
:'slow_sql.record_sql' => 'raw'
|
64
|
+
}
|
65
|
+
|
66
|
+
expects_logging(:info, all_of(includes('raw'), includes('obfuscated')))
|
67
|
+
|
68
|
+
HighSecuritySource.new(local_settings)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_no_logging_when_allowed_values
|
72
|
+
local_settings = {
|
73
|
+
:'transaction_tracer.record_sql' => 'off',
|
74
|
+
:'slow_sql.record_sql' => 'obfuscated'
|
75
|
+
}
|
76
|
+
|
77
|
+
expects_no_logging(:info)
|
78
|
+
|
79
|
+
HighSecuritySource.new(local_settings)
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
@@ -45,16 +45,20 @@ module NewRelic::Agent::Configuration
|
|
45
45
|
|
46
46
|
def test_sources_applied_in_correct_order
|
47
47
|
# in order of precedence
|
48
|
-
|
49
|
-
|
48
|
+
high_security = HighSecuritySource.new({})
|
49
|
+
server_source = ServerSource.new(:foo => 'foo', :capture_params => true)
|
50
|
+
manual_source = ManualSource.new(:foo => 'bad', :bar => 'bar',
|
51
|
+
:capture_params => true)
|
50
52
|
|
51
53
|
# load them out of order, just to prove that load order
|
52
54
|
# doesn't determine precedence
|
53
55
|
@manager.replace_or_add_config(manual_source)
|
54
56
|
@manager.replace_or_add_config(server_source)
|
57
|
+
@manager.replace_or_add_config(high_security)
|
55
58
|
|
56
59
|
assert_equal 'foo', @manager['foo']
|
57
60
|
assert_equal 'bar', @manager['bar']
|
61
|
+
assert_equal false, @manager['capture_params']
|
58
62
|
end
|
59
63
|
|
60
64
|
def test_identifying_config_source
|
@@ -276,6 +280,7 @@ module NewRelic::Agent::Configuration
|
|
276
280
|
refute @manager.config_classes_for_testing.include?(ManualSource)
|
277
281
|
refute @manager.config_classes_for_testing.include?(ServerSource)
|
278
282
|
refute @manager.config_classes_for_testing.include?(YamlSource)
|
283
|
+
refute @manager.config_classes_for_testing.include?(HighSecuritySource)
|
279
284
|
end
|
280
285
|
end
|
281
286
|
end
|
@@ -208,6 +208,22 @@ module NewRelic::Agent
|
|
208
208
|
assert_metrics_recorded(["ClientApplication/#{REQUEST_CROSS_APP_ID}/all"])
|
209
209
|
end
|
210
210
|
|
211
|
+
def test_path_hash
|
212
|
+
with_config(:app_name => 'test') do
|
213
|
+
h0 = @monitor.path_hash('23547', 0)
|
214
|
+
h1 = @monitor.path_hash('step1', 0)
|
215
|
+
h2 = @monitor.path_hash('step2', h1.to_i(16))
|
216
|
+
h3 = @monitor.path_hash('step3', h2.to_i(16))
|
217
|
+
h4 = @monitor.path_hash('step4', h3.to_i(16))
|
218
|
+
|
219
|
+
assert_equal("eaaec1df", h0)
|
220
|
+
assert_equal("2e9a0b02", h1)
|
221
|
+
assert_equal("01d3f0eb", h2)
|
222
|
+
assert_equal("9a1b45e5", h3)
|
223
|
+
assert_equal("e9eecfee", h4)
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
211
227
|
#
|
212
228
|
# Helpers
|
213
229
|
#
|
@@ -241,7 +257,7 @@ module NewRelic::Agent
|
|
241
257
|
|
242
258
|
def for_id(id)
|
243
259
|
encoded_id = id == "" ? "" : Base64.encode64(id)
|
244
|
-
encoded_txn_info =
|
260
|
+
encoded_txn_info = json_dump_and_encode([ REF_TRANSACTION_GUID, false ])
|
245
261
|
|
246
262
|
return {
|
247
263
|
NEWRELIC_ID_HEADER => encoded_id,
|
@@ -17,18 +17,19 @@ module NewRelic
|
|
17
17
|
:type => "Fake",
|
18
18
|
:method => "GET")
|
19
19
|
@response = stub_everything
|
20
|
+
@state = NewRelic::Agent::TransactionState.tl_get
|
20
21
|
end
|
21
22
|
|
22
23
|
def test_start_trace
|
23
|
-
t0
|
24
|
-
|
24
|
+
t0 = Time.now
|
25
|
+
segment = CrossAppTracing.start_trace(@state, t0, request)
|
25
26
|
refute_nil segment
|
26
27
|
end
|
27
28
|
|
28
|
-
def
|
29
|
-
|
30
|
-
t0
|
31
|
-
|
29
|
+
def test_start_trace_has_nil_segment_on_agent_failure
|
30
|
+
@state.traced_method_stack.stubs(:push_frame).raises("Boom!")
|
31
|
+
t0 = Time.now
|
32
|
+
segment = CrossAppTracing.start_trace(@state, t0, request)
|
32
33
|
assert_nil segment
|
33
34
|
end
|
34
35
|
|
@@ -37,24 +38,24 @@ module NewRelic
|
|
37
38
|
|
38
39
|
def test_finish_trace_allows_nil_segment
|
39
40
|
expects_no_logging(:error)
|
40
|
-
CrossAppTracing.finish_trace(Time.now, nil, request, response)
|
41
|
+
CrossAppTracing.finish_trace(@state, Time.now, nil, request, response)
|
41
42
|
end
|
42
43
|
|
43
44
|
def test_finish_trace_allows_nil_request
|
44
45
|
expects_no_logging(:error)
|
45
46
|
expects_pop_frame
|
46
|
-
CrossAppTracing.finish_trace(Time.now, segment, nil, response)
|
47
|
+
CrossAppTracing.finish_trace(@state, Time.now, segment, nil, response)
|
47
48
|
end
|
48
49
|
|
49
50
|
def test_finish_trace_allows_nil_response
|
50
51
|
expects_no_logging(:error)
|
51
52
|
expects_pop_frame
|
52
|
-
CrossAppTracing.finish_trace(Time.now, segment, request, nil)
|
53
|
+
CrossAppTracing.finish_trace(@state, Time.now, segment, request, nil)
|
53
54
|
end
|
54
55
|
|
55
56
|
|
56
57
|
def expects_pop_frame
|
57
|
-
|
58
|
+
@state.traced_method_stack.stubs(:pop_frame).once
|
58
59
|
end
|
59
60
|
end
|
60
61
|
end
|