newrelic_rpm 3.9.4.245 → 3.9.5.251
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/CHANGELOG +57 -0
- data/Guardfile +1 -0
- data/lib/new_relic/agent/agent.rb +3 -3
- data/lib/new_relic/agent/audit_logger.rb +5 -2
- data/lib/new_relic/agent/configuration/default_source.rb +11 -5
- data/lib/new_relic/agent/error_collector.rb +14 -1
- data/lib/new_relic/agent/hostname.rb +22 -1
- data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +8 -2
- data/lib/new_relic/agent/instrumentation/queue_time.rb +9 -6
- data/lib/new_relic/agent/method_tracer.rb +51 -172
- data/lib/new_relic/agent/method_tracer_helpers.rb +90 -0
- data/lib/new_relic/agent/new_relic_service.rb +33 -11
- data/lib/new_relic/agent/new_relic_service/encoders.rb +9 -5
- data/lib/new_relic/agent/request_sampler.rb +20 -12
- data/lib/new_relic/agent/rules_engine.rb +31 -78
- data/lib/new_relic/agent/rules_engine/replacement_rule.rb +76 -0
- data/lib/new_relic/agent/rules_engine/segment_terms_rule.rb +48 -0
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +1 -1
- data/lib/new_relic/agent/sql_sampler.rb +39 -10
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +1 -0
- data/lib/new_relic/agent/stats_engine/stats_hash.rb +7 -13
- data/lib/new_relic/agent/system_info.rb +96 -10
- data/lib/new_relic/agent/threading/agent_thread.rb +4 -1
- data/lib/new_relic/agent/threading/backtrace_node.rb +67 -57
- data/lib/new_relic/agent/threading/thread_profile.rb +30 -15
- data/lib/new_relic/agent/transaction.rb +11 -4
- data/lib/new_relic/environment_report.rb +21 -20
- data/lib/new_relic/version.rb +1 -1
- data/test/agent_helper.rb +12 -0
- data/test/fixtures/cross_agent_tests/README.md +1 -0
- data/test/fixtures/cross_agent_tests/proc_cpuinfo/1pack_1core_1logical.txt +3 -0
- data/test/fixtures/cross_agent_tests/proc_cpuinfo/1pack_1core_2logical.txt +14 -0
- data/test/fixtures/cross_agent_tests/proc_cpuinfo/1pack_2core_2logical.txt +14 -0
- data/test/fixtures/cross_agent_tests/proc_cpuinfo/1pack_4core_4logical.txt +28 -0
- data/test/fixtures/{proc_cpuinfo.txt → cross_agent_tests/proc_cpuinfo/2pack_12core_24logical.txt} +0 -0
- data/test/fixtures/cross_agent_tests/proc_cpuinfo/2pack_20core_40logical.txt +999 -0
- data/test/fixtures/cross_agent_tests/proc_cpuinfo/2pack_2core_2logical.txt +51 -0
- data/test/fixtures/cross_agent_tests/proc_cpuinfo/2pack_2core_4logical.txt +28 -0
- data/test/fixtures/cross_agent_tests/proc_cpuinfo/2pack_4core_4logical.txt +28 -0
- data/test/fixtures/cross_agent_tests/proc_cpuinfo/4pack_4core_4logical.txt +103 -0
- data/test/fixtures/cross_agent_tests/proc_cpuinfo/8pack_8core_8logical.txt +199 -0
- data/test/fixtures/cross_agent_tests/proc_cpuinfo/README.md +24 -0
- data/test/fixtures/cross_agent_tests/proc_cpuinfo/Xpack_Xcore_2logical.txt +43 -0
- data/test/fixtures/cross_agent_tests/transaction_segment_terms.json +101 -0
- data/test/multiverse/lib/multiverse/suite.rb +1 -1
- data/test/multiverse/suites/agent_only/agent_run_id_handling_test.rb +40 -0
- data/test/multiverse/suites/agent_only/labels_test.rb +9 -14
- data/test/multiverse/suites/agent_only/marshaling_test.rb +4 -6
- data/test/multiverse/suites/agent_only/rename_rule_test.rb +41 -4
- data/test/multiverse/suites/agent_only/set_transaction_name_test.rb +11 -3
- data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +8 -8
- data/test/multiverse/suites/rack/example_app.rb +20 -0
- data/test/multiverse/suites/rack/http_response_code_test.rb +51 -0
- data/test/multiverse/suites/sidekiq/Envfile +13 -6
- data/test/multiverse/suites/sidekiq/sidekiq_server.rb +4 -3
- data/test/new_relic/agent/audit_logger_test.rb +27 -0
- data/test/new_relic/agent/error_collector_test.rb +26 -5
- data/test/new_relic/agent/hostname_test.rb +66 -14
- data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +8 -12
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +7 -45
- data/test/new_relic/agent/method_tracer_test.rb +52 -1
- data/test/new_relic/agent/new_relic_service_test.rb +76 -0
- data/test/new_relic/agent/request_sampler_test.rb +7 -0
- data/test/new_relic/agent/rules_engine_test.rb +87 -56
- data/test/new_relic/agent/sql_sampler_test.rb +50 -14
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +2 -2
- data/test/new_relic/agent/stats_engine/samplers_test.rb +1 -1
- data/test/new_relic/agent/{stats_hash_test.rb → stats_engine/stats_hash_test.rb} +1 -38
- data/test/new_relic/agent/system_info_test.rb +45 -0
- data/test/new_relic/agent/threading/agent_thread_test.rb +30 -0
- data/test/new_relic/agent/threading/backtrace_node_test.rb +27 -44
- data/test/new_relic/agent/threading/thread_profile_test.rb +35 -14
- data/test/new_relic/agent/transaction_test.rb +13 -10
- data/test/new_relic/environment_report_test.rb +7 -6
- data/test/new_relic/fake_collector.rb +10 -6
- data/test/new_relic/multiverse_helpers.rb +4 -11
- data/test/new_relic/rack/agent_hooks_test.rb +1 -1
- data/test/performance/lib/performance/baseline_compare_reporter.rb +24 -7
- data/test/performance/lib/performance/result.rb +3 -1
- data/test/performance/lib/performance/runner.rb +10 -0
- data/test/performance/lib/performance/timer.rb +6 -10
- data/test/performance/script/runner +18 -1
- data/test/performance/suites/queue_time.rb +21 -0
- data/test/performance/suites/stats_hash.rb +34 -0
- data/test/performance/suites/thread_profiling.rb +26 -0
- metadata +25 -4
- metadata.gz.sig +0 -0
@@ -0,0 +1,101 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"testname": "basic",
|
4
|
+
"transaction_segment_terms": [
|
5
|
+
{
|
6
|
+
"prefix": "WebTransaction/Custom",
|
7
|
+
"terms": ["one", "two", "three"]
|
8
|
+
},
|
9
|
+
{
|
10
|
+
"prefix": "WebTransaction/Uri",
|
11
|
+
"terms": ["seven", "eight", "nine"]
|
12
|
+
}
|
13
|
+
],
|
14
|
+
"tests": [
|
15
|
+
{
|
16
|
+
"input": "WebTransaction/Uri/one/two/seven/user/nine/account",
|
17
|
+
"expected": "WebTransaction/Uri/*/seven/*/nine/*"
|
18
|
+
},
|
19
|
+
{
|
20
|
+
"input": "WebTransaction/Custom/one/two/seven/user/nine/account",
|
21
|
+
"expected": "WebTransaction/Custom/one/two/*"
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"input": "WebTransaction/Other/one/two/foo/bar",
|
25
|
+
"expected": "WebTransaction/Other/one/two/foo/bar"
|
26
|
+
}
|
27
|
+
]
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"testname": "prefix_with_trailing_slash",
|
31
|
+
"transaction_segment_terms": [
|
32
|
+
{
|
33
|
+
"prefix": "WebTransaction/Custom/",
|
34
|
+
"terms": ["a", "b"]
|
35
|
+
}
|
36
|
+
],
|
37
|
+
"tests": [
|
38
|
+
{
|
39
|
+
"input": "WebTransaction/Custom/a/b/c",
|
40
|
+
"expected": "WebTransaction/Custom/a/b/*"
|
41
|
+
},
|
42
|
+
{
|
43
|
+
"input": "WebTransaction/Customer/a/b/c",
|
44
|
+
"expected": "WebTransaction/Customer/a/b/c"
|
45
|
+
}
|
46
|
+
]
|
47
|
+
},
|
48
|
+
{
|
49
|
+
"testname": "rule_chaining",
|
50
|
+
"transaction_segment_terms": [
|
51
|
+
{
|
52
|
+
"prefix": "WebTransaction/Foo",
|
53
|
+
"terms": ["one", "two", "three"]
|
54
|
+
},
|
55
|
+
{
|
56
|
+
"prefix": "WebTransaction/Foo/one",
|
57
|
+
"terms": ["one", "two"]
|
58
|
+
}
|
59
|
+
],
|
60
|
+
"tests": [
|
61
|
+
{
|
62
|
+
"input": "WebTransaction/Foo/one/two/three/four",
|
63
|
+
"expected": "WebTransaction/Foo/one/two/three/*"
|
64
|
+
}
|
65
|
+
]
|
66
|
+
},
|
67
|
+
{
|
68
|
+
"testname": "rule_with_prefix_not_ending_in_segment_boundary",
|
69
|
+
"transaction_segment_terms": [
|
70
|
+
{
|
71
|
+
"prefix": "WebTrans",
|
72
|
+
"terms": ["one", "two"]
|
73
|
+
}
|
74
|
+
],
|
75
|
+
"tests": [
|
76
|
+
{
|
77
|
+
"input": "WebTransaction/Foo/one/two",
|
78
|
+
"expected": "WebTrans*/one/two"
|
79
|
+
}
|
80
|
+
]
|
81
|
+
},
|
82
|
+
{
|
83
|
+
"testname": "terms_are_order_independent",
|
84
|
+
"transaction_segment_terms": [
|
85
|
+
{
|
86
|
+
"prefix": "Foo",
|
87
|
+
"terms": ["one", "two", "three"]
|
88
|
+
}
|
89
|
+
],
|
90
|
+
"tests": [
|
91
|
+
{
|
92
|
+
"input": "Foo/bar/one/three/two",
|
93
|
+
"expected": "Foo/*/one/three/two"
|
94
|
+
},
|
95
|
+
{
|
96
|
+
"input": "Foo/three/one/one/two/three",
|
97
|
+
"expected": "Foo/three/one/one/two/three"
|
98
|
+
}
|
99
|
+
]
|
100
|
+
}
|
101
|
+
]
|
@@ -0,0 +1,40 @@
|
|
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 'newrelic_rpm'
|
6
|
+
require 'multiverse_helpers'
|
7
|
+
|
8
|
+
class AgentRunIdHandlingTest < Minitest::Test
|
9
|
+
include MultiverseHelpers
|
10
|
+
|
11
|
+
NON_NUMERIC_RUN_ID = 'some-crazy-non-integer-thing'
|
12
|
+
|
13
|
+
setup_and_teardown_agent do
|
14
|
+
$collector.stub('connect', { "agent_run_id" => NON_NUMERIC_RUN_ID })
|
15
|
+
end
|
16
|
+
|
17
|
+
# This test verifies that the Ruby agent is able to accept non-numeric values
|
18
|
+
# of the agent run ID handed down by the collector in response to the connect
|
19
|
+
# method. This is required for agent protocol version 14.
|
20
|
+
def test_handles_non_numeric_agent_run_ids
|
21
|
+
NewRelic::Agent.agent.send(:transmit_data)
|
22
|
+
metric_data_post = $collector.calls_for('metric_data').last
|
23
|
+
assert_equal(NON_NUMERIC_RUN_ID, metric_data_post[0])
|
24
|
+
end
|
25
|
+
|
26
|
+
# The sql_data endpoint sends the agent run ID as a query string parameter,
|
27
|
+
# rather than embedded within the body, so make sure we handle that.
|
28
|
+
def test_handles_non_numeric_agent_run_id_on_slow_sql_traces
|
29
|
+
simulate_slow_sql_trace
|
30
|
+
sql_data_post = $collector.calls_for('sql_trace_data').last
|
31
|
+
assert_equal(NON_NUMERIC_RUN_ID, sql_data_post.query_params['run_id'])
|
32
|
+
end
|
33
|
+
|
34
|
+
def simulate_slow_sql_trace
|
35
|
+
in_transaction do
|
36
|
+
agent.sql_sampler.notice_sql("select * from test", "Database/test/select", nil, 1.5)
|
37
|
+
end
|
38
|
+
NewRelic::Agent.agent.send(:harvest_and_send_slowest_sql)
|
39
|
+
end
|
40
|
+
end
|
@@ -14,31 +14,26 @@ class LabelsTest < Minitest::Test
|
|
14
14
|
EXPECTED = [{'label_type' => 'Server', 'label_value' => 'East'}]
|
15
15
|
YML_EXPECTED = [{'label_type' => 'Server', 'label_value' => 'Yaml'}]
|
16
16
|
|
17
|
-
def after_setup
|
18
|
-
$collector.reset
|
19
|
-
make_sure_agent_reconnects({})
|
20
|
-
end
|
21
|
-
|
22
17
|
def test_yaml_makes_it_to_the_collector
|
23
18
|
# Relies on the agent_only/config/newrelic.yml!
|
24
|
-
|
19
|
+
trigger_agent_reconnect
|
25
20
|
assert_connect_had_labels(YML_EXPECTED)
|
26
21
|
end
|
27
22
|
|
28
23
|
def test_labels_from_config_hash_make_it_to_the_collector
|
29
24
|
with_config("labels" => { "Server" => "East" }) do
|
30
|
-
|
25
|
+
trigger_agent_reconnect
|
31
26
|
assert_connect_had_labels(EXPECTED)
|
32
27
|
end
|
33
28
|
end
|
34
29
|
|
35
30
|
def test_labels_from_manual_start_hash_make_it_to_the_collector
|
36
|
-
|
31
|
+
trigger_agent_reconnect(:labels => { "Server" => "East" })
|
37
32
|
assert_connect_had_labels(EXPECTED)
|
38
33
|
end
|
39
34
|
|
40
35
|
def test_numeric_values_for_labels
|
41
|
-
|
36
|
+
trigger_agent_reconnect(:labels => { "Server" => 42 })
|
42
37
|
expected = [
|
43
38
|
{ 'label_type' => 'Server', 'label_value' => '42' }
|
44
39
|
]
|
@@ -46,7 +41,7 @@ class LabelsTest < Minitest::Test
|
|
46
41
|
end
|
47
42
|
|
48
43
|
def test_boolean_values_for_labels
|
49
|
-
|
44
|
+
trigger_agent_reconnect(:labels => { "Server" => true })
|
50
45
|
expected = [
|
51
46
|
{ 'label_type' => 'Server', 'label_value' => 'true' }
|
52
47
|
]
|
@@ -58,13 +53,13 @@ class LabelsTest < Minitest::Test
|
|
58
53
|
load_cross_agent_test("labels").each do |testcase|
|
59
54
|
define_method("test_#{testcase['name']}_from_config_string") do
|
60
55
|
with_config("labels" => testcase["labelString"]) do
|
61
|
-
|
56
|
+
trigger_agent_reconnect
|
62
57
|
assert_connect_had_labels(testcase["expected"])
|
63
58
|
end
|
64
59
|
end
|
65
60
|
|
66
61
|
define_method("test_#{testcase['name']}_from_manual_start") do
|
67
|
-
|
62
|
+
trigger_agent_reconnect(:labels => testcase["labelString"])
|
68
63
|
assert_connect_had_labels(testcase["expected"])
|
69
64
|
end
|
70
65
|
|
@@ -74,7 +69,7 @@ class LabelsTest < Minitest::Test
|
|
74
69
|
ENV['NEW_RELIC_LABELS'] = testcase["labelString"]
|
75
70
|
NewRelic::Agent.config.reset_to_defaults
|
76
71
|
|
77
|
-
|
72
|
+
trigger_agent_reconnect
|
78
73
|
assert_connect_had_labels(testcase["expected"])
|
79
74
|
ensure
|
80
75
|
ENV['NEW_RELIC_LABELS'] = nil
|
@@ -83,7 +78,7 @@ class LabelsTest < Minitest::Test
|
|
83
78
|
end
|
84
79
|
|
85
80
|
def assert_connect_had_labels(expected)
|
86
|
-
result = $collector.calls_for('connect').
|
81
|
+
result = $collector.calls_for('connect').last['labels']
|
87
82
|
assert_equal expected, result
|
88
83
|
end
|
89
84
|
end
|
@@ -67,12 +67,10 @@ class MarshalingTest < Minitest::Test
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def test_sql_trace_data_marshalling
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
nil, 1.5, state)
|
75
|
-
agent.sql_sampler.on_finishing_transaction(state, 'txn')
|
70
|
+
in_transaction do
|
71
|
+
agent.sql_sampler.notice_sql("select * from test", "Database/test/select",
|
72
|
+
nil, 1.5)
|
73
|
+
end
|
76
74
|
|
77
75
|
agent.service.connect
|
78
76
|
agent.send(:harvest_and_send_slowest_sql)
|
@@ -9,11 +9,18 @@ class RenameRuleTest < Minitest::Test
|
|
9
9
|
include MultiverseHelpers
|
10
10
|
|
11
11
|
setup_and_teardown_agent do |collector|
|
12
|
-
rules = [
|
12
|
+
rules = [
|
13
|
+
{ 'match_expression' => 'RenameRuleTest', 'replacement' => 'Class' },
|
14
|
+
{ 'match_expression' => 'Nothing', 'replacement' => 'Something' }
|
15
|
+
]
|
16
|
+
segment_terms_rules = [
|
17
|
+
{ 'prefix' => 'other', 'terms' => ['Nothing', 'one', 'two'] }
|
18
|
+
]
|
13
19
|
collector.stub('connect', {
|
14
|
-
'agent_run_id'
|
15
|
-
'transaction_name_rules'
|
16
|
-
'metric_name_rules'
|
20
|
+
'agent_run_id' => 666,
|
21
|
+
'transaction_name_rules' => rules,
|
22
|
+
'metric_name_rules' => rules,
|
23
|
+
'transaction_segment_terms' => segment_terms_rules
|
17
24
|
})
|
18
25
|
end
|
19
26
|
|
@@ -53,4 +60,34 @@ class RenameRuleTest < Minitest::Test
|
|
53
60
|
assert_not_includes(metric_names, 'Custom/RenameRuleTest::TestWidget/mthd')
|
54
61
|
end
|
55
62
|
|
63
|
+
def test_transaction_segment_terms_do_not_apply_to_metrics
|
64
|
+
in_transaction do
|
65
|
+
NewRelic::Agent.record_metric("other/foo/bar", 42)
|
66
|
+
end
|
67
|
+
|
68
|
+
assert_metrics_recorded(['other/foo/bar'])
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_transaction_segment_terms_do_apply_to_transaction_names
|
72
|
+
in_transaction do
|
73
|
+
NewRelic::Agent.set_transaction_name('one/two/three/four')
|
74
|
+
end
|
75
|
+
|
76
|
+
assert_metrics_recorded(['other/one/two/*'])
|
77
|
+
assert_metrics_not_recorded(['other/one/two/three/four'])
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_transaction_segment_terms_applied_after_other_rules
|
81
|
+
in_transaction do
|
82
|
+
NewRelic::Agent.set_transaction_name('Nothing/one/two/three')
|
83
|
+
end
|
84
|
+
|
85
|
+
assert_metrics_recorded(['other/*/one/two/*'])
|
86
|
+
assert_metrics_not_recorded([
|
87
|
+
'other/Something/one/two/*',
|
88
|
+
'other/Something/one/two/three',
|
89
|
+
'other/Nothing/one/two/*',
|
90
|
+
'other/Nothing/one/two/three'
|
91
|
+
])
|
92
|
+
end
|
56
93
|
end
|
@@ -85,9 +85,17 @@ class SetTransactionNameTest < Minitest::Test
|
|
85
85
|
end
|
86
86
|
|
87
87
|
def test_set_name_is_subject_to_txn_name_rules
|
88
|
-
|
89
|
-
|
90
|
-
|
88
|
+
connect_response = {
|
89
|
+
'agent_run_id' => 1,
|
90
|
+
'transaction_name_rules' => [
|
91
|
+
{ 'match_expression' => 'child', 'replacement' => 'kid' }
|
92
|
+
]
|
93
|
+
}
|
94
|
+
|
95
|
+
$collector.stub('connect', connect_response)
|
96
|
+
|
97
|
+
trigger_agent_reconnect
|
98
|
+
|
91
99
|
TestTransactor.new.parent_txn
|
92
100
|
assert_metrics_recorded(['Controller/TestTransactor/kid'])
|
93
101
|
end
|
@@ -83,11 +83,11 @@ bazbangbarn:
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def test_config_loads_from_config_newrelic_yml
|
86
|
-
assert_config_read_from(File.
|
86
|
+
assert_config_read_from(File.join(@cwd, "config/newrelic.yml"))
|
87
87
|
end
|
88
88
|
|
89
89
|
def test_config_loads_from_newrelic_yml
|
90
|
-
assert_config_read_from(File.
|
90
|
+
assert_config_read_from(File.join(@cwd, "newrelic.yml"))
|
91
91
|
end
|
92
92
|
|
93
93
|
def test_config_loads_from_home_newrelic_yml
|
@@ -99,7 +99,7 @@ bazbangbarn:
|
|
99
99
|
end
|
100
100
|
|
101
101
|
def test_config_loads_from_config_path_option_to_manual_start
|
102
|
-
path = File.join(
|
102
|
+
path = File.join(@cwd, 'otherplace', 'newrelic.yml')
|
103
103
|
assert_config_read_from(path, :config_path => path)
|
104
104
|
end
|
105
105
|
|
@@ -139,7 +139,7 @@ bazbangbarn:
|
|
139
139
|
end
|
140
140
|
|
141
141
|
def test_warning_logged_when_config_file_yaml_parsing_error
|
142
|
-
path = File.join(
|
142
|
+
path = File.join(@cwd, 'config', 'newrelic.yml')
|
143
143
|
setup_config(path, {}, '<< bogus junk')
|
144
144
|
setup_agent
|
145
145
|
|
@@ -149,7 +149,7 @@ bazbangbarn:
|
|
149
149
|
end
|
150
150
|
|
151
151
|
def test_warning_logged_when_config_file_erb_error
|
152
|
-
path = File.join(
|
152
|
+
path = File.join(@cwd, 'config', 'newrelic.yml')
|
153
153
|
setup_config(path, {}, "\n\n\n<%= this is not ruby %>") # the error is on line 4
|
154
154
|
setup_agent
|
155
155
|
|
@@ -169,7 +169,7 @@ boom:
|
|
169
169
|
# <%= this is not ruby %>
|
170
170
|
YAML
|
171
171
|
|
172
|
-
path = File.join(
|
172
|
+
path = File.join(@cwd, 'config', 'newrelic.yml')
|
173
173
|
setup_config(path, {}, config_contents)
|
174
174
|
setup_agent
|
175
175
|
|
@@ -189,11 +189,11 @@ boom:
|
|
189
189
|
end
|
190
190
|
|
191
191
|
def test_config_isnt_loaded_from_somewhere_crazy
|
192
|
-
assert_config_not_read_from(File.
|
192
|
+
assert_config_not_read_from(File.join(@cwd, "somewhere/crazy/newrelic.yml"))
|
193
193
|
end
|
194
194
|
|
195
195
|
def test_config_will_load_settings_for_environment_passed_manual_start
|
196
|
-
path = File.
|
196
|
+
path = File.join(@cwd, "config/newrelic.yml")
|
197
197
|
|
198
198
|
# pass an env key to NewRelic::Agent.manual_start which should cause it to
|
199
199
|
# load that section of newrelic.yml
|
@@ -48,3 +48,23 @@ class MiddlewareTwo
|
|
48
48
|
[status, headers, body]
|
49
49
|
end
|
50
50
|
end
|
51
|
+
|
52
|
+
class ResponseCodeMiddleware
|
53
|
+
def initialize(app)
|
54
|
+
@app = app
|
55
|
+
end
|
56
|
+
|
57
|
+
def call(env)
|
58
|
+
req = Rack::Request.new(env)
|
59
|
+
|
60
|
+
result = @app.call(env)
|
61
|
+
|
62
|
+
if req.params['override-response-code']
|
63
|
+
response_code = req.params['override-response-code'].to_i
|
64
|
+
else
|
65
|
+
response_code = result[0]
|
66
|
+
end
|
67
|
+
|
68
|
+
[response_code, result[1], result[2]]
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,51 @@
|
|
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
|
+
require File.join(File.dirname(__FILE__), 'example_app')
|
7
|
+
require 'new_relic/rack/browser_monitoring'
|
8
|
+
require 'new_relic/rack/agent_hooks'
|
9
|
+
require 'new_relic/rack/error_collector'
|
10
|
+
|
11
|
+
if NewRelic::Agent::Instrumentation::RackHelpers.rack_version_supported?
|
12
|
+
|
13
|
+
class HttpResponseCodeTest < Minitest::Test
|
14
|
+
include MultiverseHelpers
|
15
|
+
|
16
|
+
setup_and_teardown_agent
|
17
|
+
|
18
|
+
include Rack::Test::Methods
|
19
|
+
|
20
|
+
def app
|
21
|
+
Rack::Builder.app do
|
22
|
+
use ResponseCodeMiddleware
|
23
|
+
use NewRelic::Rack::AgentHooks
|
24
|
+
run ExampleApp.new
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_records_http_response_code_on_analytics_events
|
29
|
+
rsp = get '/', { 'override-response-code' => 404 }
|
30
|
+
assert_equal(404, rsp.status)
|
31
|
+
assert_equal('404', get_last_analytics_event[0]['httpResponseCode'])
|
32
|
+
|
33
|
+
rsp = get '/', { 'override-response-code' => 302 }
|
34
|
+
assert_equal(302, rsp.status)
|
35
|
+
assert_equal('302', get_last_analytics_event[0]['httpResponseCode'])
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_skips_http_response_code_if_middleware_tracing_disabled
|
39
|
+
with_config(:disable_middleware_instrumentation => true) do
|
40
|
+
rsp = get '/', { 'override-response-code' => 404 }
|
41
|
+
assert_equal(404, rsp.status)
|
42
|
+
assert_nil get_last_analytics_event[0]['httpResponseCode']
|
43
|
+
|
44
|
+
rsp = get '/', { 'override-response-code' => 302 }
|
45
|
+
assert_equal(302, rsp.status)
|
46
|
+
assert_nil get_last_analytics_event[0]['httpResponseCode']
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|