newrelic_rpm 3.9.5.251 → 3.9.6.257

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +74 -3
  3. data/GUIDELINES_FOR_CONTRIBUTING.md +19 -15
  4. data/README.md +1 -1
  5. data/Rakefile +22 -1
  6. data/lib/new_relic/agent/agent.rb +17 -5
  7. data/lib/new_relic/agent/agent_logger.rb +4 -0
  8. data/lib/new_relic/agent/configuration/default_source.rb +45 -1
  9. data/lib/new_relic/agent/configuration/manager.rb +43 -7
  10. data/lib/new_relic/agent/cross_app_monitor.rb +0 -3
  11. data/lib/new_relic/agent/cross_app_tracing.rb +8 -5
  12. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +4 -1
  13. data/lib/new_relic/agent/instrumentation/active_job.rb +93 -0
  14. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +2 -1
  15. data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +2 -2
  16. data/lib/new_relic/agent/instrumentation/sinatra.rb +1 -2
  17. data/lib/new_relic/agent/new_relic_service.rb +1 -1
  18. data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +20 -1
  19. data/lib/new_relic/agent/new_relic_service/pruby_marshaller.rb +5 -1
  20. data/lib/new_relic/agent/pipe_channel_manager.rb +32 -11
  21. data/lib/new_relic/agent/threading/agent_thread.rb +1 -1
  22. data/lib/new_relic/agent/threading/backtrace_node.rb +4 -3
  23. data/lib/new_relic/agent/transaction.rb +27 -6
  24. data/lib/new_relic/agent/transaction_state.rb +3 -3
  25. data/lib/new_relic/agent/vm/mri_vm.rb +3 -3
  26. data/lib/new_relic/control/frameworks/rails3.rb +1 -16
  27. data/lib/new_relic/control/instance_methods.rb +2 -0
  28. data/lib/new_relic/json_wrapper.rb +18 -3
  29. data/lib/new_relic/rack/browser_monitoring.rb +7 -5
  30. data/lib/new_relic/rack/developer_mode.rb +2 -0
  31. data/lib/new_relic/rack/error_collector.rb +12 -51
  32. data/lib/new_relic/transaction_sample.rb +0 -4
  33. data/lib/new_relic/transaction_sample/segment.rb +0 -4
  34. data/lib/new_relic/version.rb +1 -1
  35. data/newrelic_rpm.gemspec +3 -2
  36. data/test/agent_helper.rb +1 -1
  37. data/test/config/test.cert.crt +16 -12
  38. data/test/config/test.cert.key +13 -13
  39. data/test/environments/lib/environments/runner.rb +3 -0
  40. data/test/environments/rails30/Gemfile +2 -2
  41. data/test/environments/rails31/Gemfile +2 -2
  42. data/test/environments/rails32/Gemfile +2 -2
  43. data/test/environments/rails40/Gemfile +2 -4
  44. data/test/environments/rails41/Gemfile +2 -4
  45. data/test/environments/rails42/Gemfile +2 -4
  46. data/test/fixtures/cross_agent_tests/attribute_configuration.json +349 -0
  47. data/test/fixtures/cross_agent_tests/labels.json +31 -2
  48. data/test/fixtures/cross_agent_tests/postgres_explain_obfuscation/README.md +16 -0
  49. data/test/fixtures/cross_agent_tests/rum_client_config.json +9 -9
  50. data/test/fixtures/cross_agent_tests/rum_loader_insertion_location/empty_head +4 -0
  51. data/test/fixtures/cross_agent_tests/rum_loader_insertion_location/no_end_header.html +6 -0
  52. data/test/fixtures/cross_agent_tests/rum_loader_insertion_location/x_ua_meta_tag_multiple_tags.html +12 -0
  53. data/test/multiverse/lib/multiverse/runner.rb +33 -1
  54. data/test/multiverse/lib/multiverse/suite.rb +79 -7
  55. data/test/multiverse/suites/active_record/Envfile +1 -1
  56. data/test/multiverse/suites/agent_only/encoding_handling_test.rb +1 -1
  57. data/test/multiverse/suites/agent_only/labels_test.rb +2 -1
  58. data/test/multiverse/suites/agent_only/set_transaction_name_test.rb +2 -3
  59. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +6 -6
  60. data/test/multiverse/suites/capistrano/Envfile +2 -2
  61. data/test/multiverse/suites/capistrano2/Envfile +4 -0
  62. data/test/multiverse/suites/curb/Envfile +4 -0
  63. data/test/multiverse/suites/high_security/config/newrelic.yml +5 -2
  64. data/test/multiverse/suites/high_security/high_security_test.rb +10 -8
  65. data/test/multiverse/suites/json/Envfile +23 -0
  66. data/test/multiverse/suites/json/config/newrelic.yml +22 -0
  67. data/test/multiverse/suites/json/json_test.rb +17 -0
  68. data/test/multiverse/suites/marshalling/marshalling_test.rb +2 -45
  69. data/test/multiverse/suites/rails/Envfile +3 -3
  70. data/test/multiverse/suites/rails/activejob_test.rb +137 -0
  71. data/test/multiverse/suites/rails/error_tracing_test.rb +15 -8
  72. data/test/multiverse/suites/rails/parameter_capture_test.rb +39 -19
  73. data/test/multiverse/suites/sequel/Envfile +5 -5
  74. data/test/multiverse/suites/sidekiq/Envfile +2 -2
  75. data/test/multiverse/suites/sinatra/Envfile +2 -1
  76. data/test/multiverse/suites/yajl/Envfile +13 -0
  77. data/test/multiverse/suites/yajl/config/newrelic.yml +21 -0
  78. data/test/multiverse/suites/yajl/yajl_test.rb +19 -0
  79. data/test/new_relic/agent/agent_logger_test.rb +10 -0
  80. data/test/new_relic/agent/agent_test.rb +7 -1
  81. data/test/new_relic/agent/configuration/default_source_test.rb +24 -0
  82. data/test/new_relic/agent/configuration/manager_test.rb +60 -2
  83. data/test/new_relic/agent/configuration/orphan_configuration_test.rb +25 -13
  84. data/test/new_relic/agent/cross_app_tracing_test.rb +10 -1
  85. data/test/new_relic/agent/instrumentation/active_job_test.rb +20 -0
  86. data/test/new_relic/agent/instrumentation/active_record_test.rb +10 -17
  87. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +15 -0
  88. data/test/new_relic/agent/instrumentation/sinatra_test.rb +1 -1
  89. data/test/new_relic/agent/new_relic_service_test.rb +24 -0
  90. data/test/new_relic/agent/pipe_channel_manager_test.rb +44 -2
  91. data/test/new_relic/agent/threading/agent_thread_test.rb +1 -2
  92. data/test/new_relic/agent/threading/backtrace_node_test.rb +12 -0
  93. data/test/new_relic/agent/transaction_state_test.rb +3 -6
  94. data/test/new_relic/agent/transaction_test.rb +163 -0
  95. data/test/new_relic/agent_test.rb +13 -1
  96. data/test/new_relic/fake_collector.rb +5 -5
  97. data/test/new_relic/fake_server.rb +5 -3
  98. data/test/new_relic/http_client_test_cases.rb +0 -4
  99. data/test/new_relic/marshalling_test_cases.rb +54 -0
  100. data/test/new_relic/multiverse_helpers.rb +2 -2
  101. data/test/new_relic/rack/browser_monitoring_test.rb +6 -0
  102. data/test/new_relic/rack/developer_mode_test.rb +8 -0
  103. data/test/new_relic/rack/error_collector_test.rb +0 -41
  104. data/test/new_relic/transaction_sample/segment_test.rb +0 -13
  105. data/test/new_relic/transaction_sample_test.rb +1 -11
  106. data/test/performance/lib/performance/instrumentation/perf_tools.rb +1 -1
  107. data/test/performance/lib/performance/runner.rb +1 -1
  108. data/test/performance/script/runner +2 -1
  109. data/test/performance/suites/rum_autoinsertion.rb +12 -2
  110. metadata +24 -11
  111. metadata.gz.sig +0 -0
  112. data/test/config/test.cert.csr +0 -11
  113. data/test/config/testing-privkey.pem +0 -18
@@ -21,21 +21,18 @@ module NewRelic::Agent
21
21
 
22
22
  def test_without_transaction_stack_on_thread
23
23
  assert_equal false, state.in_background_transaction?
24
- assert_equal false, state.in_request_transaction?
24
+ assert_equal false, state.in_web_transaction?
25
25
  end
26
26
 
27
27
  def test_in_background_transaction
28
28
  in_transaction(:category => :task) do |txn|
29
- txn.request = nil # this makes it a "background transaction"
30
29
  assert state.in_background_transaction?
31
30
  end
32
31
  end
33
32
 
34
33
  def test_in_request_tranasction
35
- in_transaction do |txn|
36
- txn.request = stub()
37
-
38
- assert state.in_request_transaction?
34
+ in_web_transaction do
35
+ assert state.in_web_transaction?
39
36
  end
40
37
  end
41
38
 
@@ -14,6 +14,8 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
14
14
 
15
15
  def teardown
16
16
  # Failed transactions can leave partial stack, so pave it for next test
17
+
18
+ ::NewRelic::Agent.logger.clear_already_logged
17
19
  cleanup_transaction
18
20
  end
19
21
 
@@ -606,6 +608,102 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
606
608
  end
607
609
  end
608
610
 
611
+ module ::Java
612
+ module JavaLangManagement
613
+ class ManagementFactory
614
+ end
615
+ end
616
+ end
617
+
618
+ def test_jruby_cpu_time_returns_0_for_neg1_java_utime
619
+ in_transaction do |txn|
620
+ with_java_classes_loaded do
621
+ bean = mock(:getCurrentThreadUserTime => -1)
622
+ bean.stubs(:isCurrentThreadCpuTimeSupported).returns(true)
623
+ ::Java::JavaLangManagement::ManagementFactory.stubs(:getThreadMXBean).returns(bean)
624
+ assert_equal 0.0, txn.send(:jruby_cpu_time)
625
+ end
626
+ end
627
+ end
628
+
629
+ def test_jruby_cpu_time_returns_java_utime_over_1e9_if_java_utime_is_1
630
+ java_utime = 1
631
+ in_transaction do |txn|
632
+ with_java_classes_loaded do
633
+ bean = stub(:getCurrentThreadUserTime => java_utime)
634
+ bean.stubs(:isCurrentThreadCpuTimeSupported).returns(true)
635
+ ::Java::JavaLangManagement::ManagementFactory.stubs(:getThreadMXBean).returns(bean)
636
+ assert_equal java_utime/1e9, txn.send(:jruby_cpu_time)
637
+ end
638
+ end
639
+ end
640
+
641
+ def test_jruby_cpu_time_logs_errors_once_at_warn
642
+ in_transaction do |txn|
643
+ with_java_classes_loaded do
644
+ bean = mock
645
+ bean.stubs(:isCurrentThreadCpuTimeSupported).returns(true)
646
+ bean.stubs(:getCurrentThreadUserTime).raises(StandardError, 'Error calculating JRuby CPU Time')
647
+ ::Java::JavaLangManagement::ManagementFactory.stubs(:getThreadMXBean).returns(bean)
648
+
649
+ expects_logging(:warn, includes("Error calculating JRuby CPU Time"), any_parameters)
650
+ txn.send(:jruby_cpu_time)
651
+ expects_no_logging(:warn)
652
+ txn.send(:jruby_cpu_time)
653
+ end
654
+ end
655
+ end
656
+
657
+ def test_jruby_cpu_time_always_logs_errors_at_debug
658
+ in_transaction do |txn|
659
+ with_java_classes_loaded do
660
+ bean = mock
661
+ bean.stubs(:isCurrentThreadCpuTimeSupported).returns(true)
662
+ bean.stubs(:getCurrentThreadUserTime).raises(StandardError, 'Error calculating JRuby CPU Time')
663
+ ::Java::JavaLangManagement::ManagementFactory.stubs(:getThreadMXBean).returns(bean)
664
+
665
+ expects_logging(:warn, includes("Error calculating JRuby CPU Time"), any_parameters)
666
+ txn.send(:jruby_cpu_time)
667
+ expects_logging(:debug, includes("Error calculating JRuby CPU Time"), any_parameters)
668
+ txn.send(:jruby_cpu_time)
669
+ end
670
+ end
671
+ end
672
+
673
+ def test_jruby_cpu_time_returns_nil_if_current_thread_user_time_raises
674
+ in_transaction do |txn|
675
+ with_java_classes_loaded do
676
+ bean = mock
677
+ bean.stubs(:isCurrentThreadCpuTimeSupported).returns(true)
678
+ bean.stubs(:getCurrentThreadUserTime).raises(StandardError, 'Error calculating JRuby CPU Time')
679
+ ::Java::JavaLangManagement::ManagementFactory.stubs(:getThreadMXBean).returns(bean)
680
+
681
+ assert_nil txn.send(:jruby_cpu_time)
682
+ end
683
+ end
684
+ end
685
+
686
+ def test_jruby_cpu_time_does_not_call_get_current_thread_user_time_if_unsupported
687
+ in_transaction do |txn|
688
+ with_java_classes_loaded do
689
+ bean = mock
690
+ bean.stubs(:isCurrentThreadCpuTimeSupported).returns(false)
691
+ ::Java::JavaLangManagement::ManagementFactory.stubs(:getThreadMXBean).returns(bean)
692
+ bean.expects(:getCurrentThreadUserTime).never
693
+
694
+ assert_nil txn.send(:jruby_cpu_time)
695
+ end
696
+ end
697
+ end
698
+
699
+ def with_java_classes_loaded
700
+ # class_variable_set is private on 1.8.7 :(
701
+ ::NewRelic::Agent::Transaction.send(:class_variable_set, :@@java_classes_loaded, true)
702
+ yield
703
+ ensure
704
+ ::NewRelic::Agent::Transaction.send(:class_variable_set, :@@java_classes_loaded, false)
705
+ end
706
+
609
707
  def test_cpu_burn_normal
610
708
  in_transaction do |txn|
611
709
  txn.expects(:normal_cpu_burn).twice.returns(1)
@@ -719,6 +817,16 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
719
817
  assert_metrics_not_recorded(['Controller/sinatra', 'Controller/toddler', 'Controller/infant'])
720
818
  end
721
819
 
820
+ def test_nested_other_transaction
821
+ in_transaction('OtherTransaction/outer', :category => :task) do
822
+ in_transaction('OtherTransaction/inner', :category => :task) do
823
+ end
824
+ end
825
+
826
+ assert_metrics_recorded(['OtherTransaction/inner'])
827
+ assert_metrics_not_recorded(['OtherTransaction/outer'])
828
+ end
829
+
722
830
  def test_failure_during_ignore_error_filter_doesnt_prevent_transaction
723
831
  filter = Proc.new do |*_|
724
832
  raise "HAHAHAHAH, error in the filter for ignoring errors!"
@@ -784,6 +892,61 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
784
892
  NewRelic::Agent::Transaction.stop(state)
785
893
  end
786
894
 
895
+ def test_user_defined_rules_ignore_returns_true_for_matched_uri
896
+ rule = 'ignored'
897
+ with_config(:rules => { :ignore_url_regexes => [rule] }) do
898
+ in_transaction do |txn|
899
+ txn.stubs(:uri).returns(rule + '/uri')
900
+ assert txn.user_defined_rules_ignore?, "URIs should be ignored based on user defined rules. Rule: '#{rule}', URI: '#{txn.uri}'."
901
+ end
902
+ end
903
+ end
904
+
905
+ def test_stop_ignores_transactions_from_ignored_uris
906
+ with_config(:rules => { :ignore_url_regexes => ['ignored/uri'] }) do
907
+ in_transaction do |txn|
908
+ txn.stubs(:uri).returns('ignored/uri')
909
+ txn.expects(:ignore!)
910
+ end
911
+ end
912
+ end
913
+
914
+ def test_transactions_are_not_ignored_if_rules_match_http_auth
915
+ with_config(:rules => { :ignore_url_regexes => ['ignored'] }) do
916
+ in_transaction do |txn|
917
+ txn.stubs(:uri).returns('http://ignored_user:ignored_pass@foo.com/bar/baz')
918
+ txn.expects(:ignore!).never
919
+ end
920
+ end
921
+ end
922
+
923
+ def test_transactions_are_not_ignored_if_rules_match_query_string
924
+ with_config(:rules => { :ignore_url_regexes => ['ignored'] }) do
925
+ in_transaction do |txn|
926
+ txn.stubs(:uri).returns('http://foo.com/bar/baz/?ignored=1')
927
+ txn.expects(:ignore!).never
928
+ end
929
+ end
930
+ end
931
+
932
+ def test_user_defined_rules_ignore_does_not_parse_the_uri_if_rules_are_empty
933
+ with_config(:rules => { :ignore_url_regexes => [] }) do
934
+ in_transaction do |txn|
935
+ txn.stubs(:uri).returns('http://foo.com/bar/baz')
936
+ NewRelic::Agent::HTTPClients::URIUtil.expects(:parse_url).never
937
+ end
938
+ end
939
+ end
940
+
941
+ def test_user_defined_rules_ignore_does_not_filter_the_uri_if_rules_are_empty
942
+ with_config(:rules => { :ignore_url_regexes => [] }) do
943
+ in_transaction do |txn|
944
+ txn.stubs(:uri).returns('http://foo.com/bar/baz')
945
+ NewRelic::Agent::HTTPClients::URIUtil.expects(:filter_uri).never
946
+ end
947
+ end
948
+ end
949
+
787
950
  def assert_has_custom_parameter(txn, key, value = key)
788
951
  assert_equal(value, txn.custom_parameters[key])
789
952
  end
@@ -89,6 +89,18 @@ module NewRelic
89
89
  NewRelic::Agent.shutdown
90
90
  end
91
91
 
92
+ def test_manual_start_kicks_dependency_check_again
93
+ with_config(:monitor_mode => true, :license_key => "a" * 40, :sync_startup => true) do
94
+ NewRelic::Agent.manual_start
95
+ assert NewRelic::Agent.instance.started?
96
+
97
+ NewRelic::Control.instance.stubs(:init_config)
98
+ DependencyDetection.expects(:detect!).once
99
+
100
+ NewRelic::Agent.manual_start
101
+ end
102
+ end
103
+
92
104
  def test_get_stats
93
105
  agent = mocked_agent
94
106
  mock_stats_engine = mock('stats_engine')
@@ -266,7 +278,7 @@ module NewRelic
266
278
  Transactor.new.txn do
267
279
  NewRelic::Agent.set_transaction_name('new_name')
268
280
  end
269
- assert engine.lookup_stats('Controller/new_name')
281
+ assert_metrics_recorded(['Controller/new_name'])
270
282
  end
271
283
 
272
284
  def test_get_transaction_name_returns_nil_outside_transaction
@@ -54,8 +54,8 @@ module NewRelic
54
54
 
55
55
  attr_accessor :agent_data, :mock
56
56
 
57
- def initialize
58
- super
57
+ def initialize(ssl=false)
58
+ super(DEFAULT_PORT, ssl)
59
59
  @id_counter = 0
60
60
  @mock = {
61
61
  'get_redirect_host' => Response.new(200, {'return_value' => 'localhost'}),
@@ -109,7 +109,7 @@ module NewRelic
109
109
  status, body = @mock[method].evaluate
110
110
  res.status = status
111
111
  if format == :json
112
- res.write JSON.dump(body)
112
+ res.write ::NewRelic::JSONWrapper.dump(body)
113
113
  else
114
114
  res.write Marshal.dump(body)
115
115
  end
@@ -125,7 +125,7 @@ module NewRelic
125
125
  raw_body = Zlib::Inflate.inflate(raw_body) if req.env["HTTP_CONTENT_ENCODING"] == "deflate"
126
126
 
127
127
  body = if format == :json
128
- body = JSON.load(raw_body)
128
+ body = ::NewRelic::JSONWrapper.load(raw_body)
129
129
  else
130
130
  body = Marshal.load(raw_body)
131
131
 
@@ -162,7 +162,7 @@ module NewRelic
162
162
  end
163
163
 
164
164
  def calls_for(method)
165
- @agent_data.select {|d| d.action == method }
165
+ @agent_data.select { |d| d.action == method.to_s }
166
166
  end
167
167
 
168
168
  def reported_stats_for_metric(name, scope=nil)
@@ -22,13 +22,15 @@ module NewRelic
22
22
  :AccessLog => [ ['/dev/null', ''] ]
23
23
  }
24
24
 
25
- CONFIG_PATH = File.join(File.dirname(__FILE__), "..", "config")
25
+ CONFIG_PATH = File.join(File.dirname(__FILE__), "..", "config")
26
+ FAKE_SSL_CERT_PATH = File.join(CONFIG_PATH, "test.cert.crt")
27
+ FAKE_SSL_KEY_PATH = File.join(CONFIG_PATH, "test.cert.key")
26
28
 
27
29
  SSL_OPTIONS = {
28
30
  :SSLEnable => true,
29
31
  :SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
30
- :SSLPrivateKey => OpenSSL::PKey::RSA.new(File.open(File.join(CONFIG_PATH, "test.cert.key")).read),
31
- :SSLCertificate => OpenSSL::X509::Certificate.new(File.open(File.join(CONFIG_PATH, "test.cert.crt")).read),
32
+ :SSLPrivateKey => OpenSSL::PKey::RSA.new(File.read(FAKE_SSL_KEY_PATH)),
33
+ :SSLCertificate => OpenSSL::X509::Certificate.new(File.read(FAKE_SSL_CERT_PATH)),
32
34
  :SSLCertName => [["CN", "newrelic.com"]]
33
35
  }
34
36
 
@@ -38,10 +38,6 @@ module HttpClientTestCases
38
38
 
39
39
  # Helpers to support shared tests
40
40
 
41
- def use_ssl
42
- @ssl = true
43
- end
44
-
45
41
  def use_ssl?
46
42
  @ssl
47
43
  end
@@ -0,0 +1,54 @@
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
+ # These tests are intended to exercise the basic marshalling functionality of
6
+ # the agent in it's different permutations (Ruby and JSON)
7
+ module MarshallingTestCases
8
+
9
+ def test_sends_metrics
10
+ NewRelic::Agent.record_metric('Boo', 42)
11
+
12
+ transmit_data
13
+
14
+ result = $collector.calls_for('metric_data')
15
+ assert_equal 1, result.length
16
+ assert_includes result.first.metric_names, 'Boo'
17
+ end
18
+
19
+ def test_sends_errors
20
+ NewRelic::Agent.notice_error(StandardError.new("Boom"))
21
+
22
+ transmit_data
23
+
24
+ result = $collector.calls_for('error_data')
25
+ assert_equal 1, result.length
26
+ assert_equal 1, result.first.errors.length
27
+ assert_equal "StandardError", result.first.errors.first.exception_class_name
28
+ end
29
+
30
+ def test_sends_transaction_traces
31
+ with_config(:'transaction_tracer.transaction_threshold' => -1.0) do
32
+ Transactioner.new.do_it
33
+ end
34
+
35
+ transmit_data
36
+
37
+ result = $collector.calls_for('transaction_sample_data')
38
+ assert_equal 1, result.length
39
+ assert_equal "Controller/MarshallingTestCases::Transactioner/do_it", result.first.metric_name
40
+ end
41
+
42
+ class Transactioner
43
+ include NewRelic::Agent::Instrumentation::ControllerInstrumentation
44
+
45
+ def do_it
46
+ end
47
+
48
+ add_transaction_tracer :do_it
49
+ end
50
+
51
+ def transmit_data
52
+ NewRelic::Agent.instance.send(:transmit_data)
53
+ end
54
+ end
@@ -99,11 +99,11 @@ module MultiverseHelpers
99
99
  # This helps so the runner process can decide before spawning the child
100
100
  # whether we want the collector running or not.
101
101
 
102
- def setup_collector
102
+ def setup_collector(use_ssl=false)
103
103
  return if omit_collector?
104
104
 
105
105
  require 'fake_collector'
106
- $collector ||= NewRelic::FakeCollector.new
106
+ $collector ||= NewRelic::FakeCollector.new(use_ssl)
107
107
  $collector.reset
108
108
  $collector.run
109
109
 
@@ -97,6 +97,12 @@ EOL
97
97
  assert !app.should_instrument?({NewRelic::Rack::BrowserMonitoring::ALREADY_INSTRUMENTED_KEY => true}, 200, {'Content-Type' => 'text/html'})
98
98
  end
99
99
 
100
+ def test_should_not_instrument_when_disabled_by_config
101
+ with_config(:'browser_monitoring.auto_instrument' => false) do
102
+ refute app.should_instrument?({}, 200, {'Content-Type' => 'text/html'})
103
+ end
104
+ end
105
+
100
106
  def test_insert_header_should_mark_environment
101
107
  get '/'
102
108
  assert last_request.env.key?(NewRelic::Rack::BrowserMonitoring::ALREADY_INSTRUMENTED_KEY)
@@ -64,6 +64,14 @@ class DeveloperModeTest < Minitest::Test
64
64
  assert last_response.body.include?('Key Length')
65
65
  assert last_response.body.include?('Using index')
66
66
  end
67
+
68
+ def test_doesnt_record_transaction
69
+ NewRelic::Agent.instance.transaction_sampler.dev_mode_sample_buffer.reset!
70
+
71
+ get "/newrelic"
72
+
73
+ assert_empty NewRelic::Agent.instance.transaction_sampler.dev_mode_sample_buffer.samples
74
+ end
67
75
  end
68
76
 
69
77
  else
@@ -54,25 +54,6 @@ module NewRelic::Rack
54
54
  'noticed an error that should have been ignored')
55
55
  end
56
56
 
57
- def test_handles_parameter_parsing_exceptions
58
- if defined?(ActionDispatch::Request)
59
- bad_request = stub.stubs(:filtered_params).raises(TypeError, "can't convert nil into Hash")
60
- ActionDispatch::Request.stubs(:new).returns(bad_request)
61
- else
62
- bad_request = stub(:env => {}, :path => '/', :referer => '', :cookies => {})
63
- bad_request.stubs(:params).raises(TypeError, "whatever, man")
64
- Rack::Request.stubs(:new).returns(bad_request)
65
- end
66
-
67
- assert_raises RuntimeError do
68
- get '/'
69
- end
70
-
71
- assert_equal('unhandled error', last_error.message)
72
- assert_match(/failed to capture request parameters/i,
73
- last_error.params[:request_params]['error'])
74
- end
75
-
76
57
  # Ideally we'd test this for failures to create Rack::Request as well,
77
58
  # but unfortunately rack-test, which we're using to drive, creates
78
59
  # Rack::Request objects internally, so there's not an easy way to.
@@ -89,28 +70,6 @@ module NewRelic::Rack
89
70
  end
90
71
  end
91
72
 
92
- def test_captures_parameters_with_rails
93
- assert_raises RuntimeError do
94
- get '/?foo=bar&baz=qux'
95
- end
96
-
97
- expected_params = { 'foo' => 'bar', 'baz' => 'qux' }
98
- assert_equal('unhandled error', last_error.message)
99
- assert_equal(expected_params, last_error.params[:request_params])
100
- end
101
-
102
- def test_captures_parameters_without_rails
103
- undefine_constant(:'ActionDispatch::Request') do
104
- assert_raises RuntimeError do
105
- get '/?foo=bar&baz=qux'
106
- end
107
- end
108
-
109
- expected_params = { 'foo' => 'bar', 'baz' => 'qux' }
110
- assert_equal('unhandled error', last_error.message)
111
- assert_equal(expected_params, last_error.params[:request_params])
112
- end
113
-
114
73
  def last_error
115
74
  NewRelic::Agent.instance.error_collector.errors[0]
116
75
  end