newrelic_rpm 3.5.4.35.beta → 3.5.5.38

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. data/CHANGELOG +42 -0
  2. data/GUIDELINES_FOR_CONTRIBUTING.md +3 -0
  3. data/Rakefile +8 -0
  4. data/bin/mongrel_rpm +1 -1
  5. data/init.rb +1 -8
  6. data/lib/new_relic/agent.rb +11 -13
  7. data/lib/new_relic/agent/agent.rb +89 -110
  8. data/lib/new_relic/agent/agent_logger.rb +165 -0
  9. data/lib/new_relic/agent/audit_logger.rb +72 -0
  10. data/lib/new_relic/agent/beacon_configuration.rb +4 -4
  11. data/lib/new_relic/agent/browser_monitoring.rb +13 -7
  12. data/lib/new_relic/agent/busy_calculator.rb +2 -2
  13. data/lib/new_relic/agent/configuration.rb +25 -0
  14. data/lib/new_relic/agent/configuration/defaults.rb +45 -8
  15. data/lib/new_relic/agent/configuration/environment_source.rb +8 -15
  16. data/lib/new_relic/agent/configuration/manager.rb +22 -2
  17. data/lib/new_relic/agent/configuration/mask_defaults.rb +10 -0
  18. data/lib/new_relic/agent/configuration/yaml_source.rb +4 -2
  19. data/lib/new_relic/agent/cross_process_monitoring.rb +43 -0
  20. data/lib/new_relic/agent/database.rb +2 -4
  21. data/lib/new_relic/agent/error_collector.rb +4 -9
  22. data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
  23. data/lib/new_relic/agent/instrumentation/active_record.rb +1 -1
  24. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +1 -1
  25. data/lib/new_relic/agent/instrumentation/authlogic.rb +1 -1
  26. data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +41 -0
  27. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +7 -7
  28. data/lib/new_relic/agent/instrumentation/data_mapper.rb +1 -1
  29. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +1 -1
  30. data/lib/new_relic/agent/instrumentation/memcache.rb +4 -4
  31. data/lib/new_relic/agent/instrumentation/merb/controller.rb +1 -1
  32. data/lib/new_relic/agent/instrumentation/merb/errors.rb +1 -1
  33. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +1 -1
  34. data/lib/new_relic/agent/instrumentation/net.rb +1 -1
  35. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +2 -2
  36. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +4 -4
  37. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
  38. data/lib/new_relic/agent/instrumentation/rails/errors.rb +1 -1
  39. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +3 -3
  40. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +1 -1
  41. data/lib/new_relic/agent/instrumentation/resque.rb +3 -2
  42. data/lib/new_relic/agent/instrumentation/sinatra.rb +1 -1
  43. data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
  44. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +2 -2
  45. data/lib/new_relic/agent/method_tracer.rb +6 -8
  46. data/lib/new_relic/agent/new_relic_service.rb +94 -106
  47. data/lib/new_relic/agent/pipe_channel_manager.rb +1 -1
  48. data/lib/new_relic/agent/samplers/memory_sampler.rb +4 -6
  49. data/lib/new_relic/agent/sql_sampler.rb +3 -18
  50. data/lib/new_relic/agent/stats_engine.rb +0 -5
  51. data/lib/new_relic/agent/stats_engine/metric_stats.rb +3 -3
  52. data/lib/new_relic/agent/stats_engine/samplers.rb +2 -4
  53. data/lib/new_relic/agent/thread.rb +8 -3
  54. data/lib/new_relic/agent/thread_profiler.rb +38 -27
  55. data/lib/new_relic/agent/transaction_info.rb +1 -1
  56. data/lib/new_relic/agent/transaction_sample_builder.rb +2 -3
  57. data/lib/new_relic/agent/transaction_sampler.rb +3 -7
  58. data/lib/new_relic/agent/worker_loop.rb +3 -11
  59. data/lib/new_relic/control.rb +0 -2
  60. data/lib/new_relic/control/class_methods.rb +8 -2
  61. data/lib/new_relic/control/frameworks/merb.rb +0 -6
  62. data/lib/new_relic/control/frameworks/rails.rb +8 -29
  63. data/lib/new_relic/control/frameworks/rails3.rb +8 -20
  64. data/lib/new_relic/control/frameworks/rails4.rb +23 -0
  65. data/lib/new_relic/control/frameworks/ruby.rb +1 -22
  66. data/lib/new_relic/control/instance_methods.rb +12 -34
  67. data/lib/new_relic/control/instrumentation.rb +7 -12
  68. data/lib/new_relic/control/server_methods.rb +5 -8
  69. data/lib/new_relic/delayed_job_injection.rb +1 -1
  70. data/lib/new_relic/local_environment.rb +30 -64
  71. data/lib/new_relic/metric_data.rb +1 -1
  72. data/lib/new_relic/metric_spec.rb +1 -1
  73. data/lib/new_relic/noticed_error.rb +1 -1
  74. data/lib/new_relic/rack/browser_monitoring.rb +5 -5
  75. data/lib/new_relic/stats.rb +9 -7
  76. data/lib/new_relic/transaction_sample.rb +2 -7
  77. data/lib/new_relic/version.rb +1 -1
  78. data/lib/newrelic_rpm.rb +1 -1
  79. data/newrelic_rpm.gemspec.erb +15 -17
  80. data/test/config/newrelic.yml +1 -1
  81. data/test/config/test_control.rb +18 -18
  82. data/test/fixtures/gemspec_no_build.rb +0 -2
  83. data/test/fixtures/gemspec_with_build.rb +0 -2
  84. data/test/fixtures/gemspec_with_build_and_stage.rb +0 -2
  85. data/test/multiverse/README.md +3 -8
  86. data/test/multiverse/suites/agent_only/Envfile +1 -0
  87. data/test/multiverse/suites/agent_only/audit_log_test.rb +99 -0
  88. data/test/multiverse/suites/agent_only/marshaling_test.rb +1 -1
  89. data/test/multiverse/suites/config_file_loading/Envfile +7 -0
  90. data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +106 -0
  91. data/test/multiverse/suites/logging/Envfile +4 -0
  92. data/test/multiverse/suites/logging/config/newrelic.yml +22 -0
  93. data/test/multiverse/suites/logging/logging_test.rb +143 -0
  94. data/test/multiverse/suites/no_load/config/newrelic.yml +1 -2
  95. data/test/multiverse/suites/rum_auto_instrumentation/sanity_test.rb +0 -13
  96. data/test/new_relic/agent/agent/connect_test.rb +30 -92
  97. data/test/new_relic/agent/agent/start_test.rb +4 -84
  98. data/test/new_relic/agent/agent/start_worker_thread_test.rb +8 -43
  99. data/test/new_relic/agent/agent_logger_test.rb +153 -0
  100. data/test/new_relic/agent/agent_test.rb +10 -9
  101. data/test/new_relic/agent/audit_logger_test.rb +105 -0
  102. data/test/new_relic/agent/browser_monitoring_test.rb +2 -1
  103. data/test/new_relic/agent/busy_calculator_test.rb +7 -0
  104. data/test/new_relic/agent/configuration/environment_source_test.rb +25 -20
  105. data/test/new_relic/agent/configuration/manager_test.rb +59 -4
  106. data/test/new_relic/agent/configuration/yaml_source_test.rb +20 -1
  107. data/test/new_relic/agent/cross_process_monitoring_test.rb +77 -0
  108. data/test/new_relic/agent/database_test.rb +0 -11
  109. data/test/new_relic/agent/error_collector/notice_error_test.rb +1 -3
  110. data/test/new_relic/agent/error_collector_test.rb +11 -7
  111. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +39 -19
  112. data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +39 -0
  113. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +1 -1
  114. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +0 -6
  115. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +3 -15
  116. data/test/new_relic/agent/new_relic_service_test.rb +48 -8
  117. data/test/new_relic/agent/pipe_channel_manager_test.rb +1 -1
  118. data/test/new_relic/agent/sql_sampler_test.rb +1 -1
  119. data/test/new_relic/agent/thread_profiler_test.rb +46 -45
  120. data/test/new_relic/agent/thread_test.rb +13 -0
  121. data/test/new_relic/agent/transaction_sample_builder_test.rb +1 -1
  122. data/test/new_relic/agent/worker_loop_test.rb +4 -9
  123. data/test/new_relic/agent_test.rb +6 -9
  124. data/test/new_relic/control/class_methods_test.rb +0 -18
  125. data/test/new_relic/control_test.rb +6 -9
  126. data/test/new_relic/dispatcher_test.rb +54 -0
  127. data/test/new_relic/fake_collector.rb +15 -14
  128. data/test/new_relic/fake_service.rb +4 -1
  129. data/test/new_relic/fakes_sending_data.rb +30 -0
  130. data/test/new_relic/framework_test.rb +53 -0
  131. data/test/new_relic/local_environment_test.rb +5 -2
  132. data/test/new_relic/rack/browser_monitoring_test.rb +2 -1
  133. data/test/new_relic/rack/developer_mode_test.rb +1 -1
  134. data/test/new_relic/stats_test.rb +10 -0
  135. data/test/new_relic/transaction_sample_test.rb +2 -2
  136. data/test/script/ci.sh +1 -1
  137. data/test/test_helper.rb +23 -0
  138. data/ui/views/newrelic/file/images/arrow-close.png +0 -0
  139. data/ui/views/newrelic/file/images/arrow-open.png +0 -0
  140. data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
  141. data/ui/views/newrelic/file/images/file_icon.png +0 -0
  142. data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
  143. metadata +47 -41
  144. data/InstallationNotes.md +0 -15
  145. data/lib/new_relic/control/logging_methods.rb +0 -125
  146. data/test/multiverse/Rakefile +0 -17
  147. data/test/multiverse/suites/rum_auto_instrumentation/problem_response.html +0 -422
  148. data/test/new_relic/control/logging_methods_test.rb +0 -211
@@ -0,0 +1,4 @@
1
+ gemfile <<-RB
2
+ gem 'rack'
3
+ gem 'mocha', '< 0.13', :require => false
4
+ RB
@@ -0,0 +1,22 @@
1
+ ---
2
+ development:
3
+ error_collector:
4
+ capture_source: true
5
+ enabled: false
6
+ apdex_t: 0.5
7
+ ssl: false
8
+ monitor_mode: true
9
+ license_key: bootstrap_newrelic_admin_license_key_000
10
+ developer_mode: false
11
+ app_name: test
12
+ host: 127.0.0.1
13
+ api_host: 127.0.0.1
14
+ port: 30303
15
+ transaction_tracer:
16
+ record_sql: obfuscated
17
+ enabled: true
18
+ stack_trace_threshold: 0.5
19
+ transaction_threshold: 1.0
20
+ capture_params: false
21
+ log_level: debug
22
+ disable_serialization: false
@@ -0,0 +1,143 @@
1
+ # RUBY-980 Improve logging
2
+ # This test suite is for checking IMPORTANT conditions that we log rather than
3
+ # trying to do this via brittle unit tests
4
+
5
+ require 'logger'
6
+ require 'newrelic_rpm'
7
+ require 'fake_collector'
8
+ require 'mocha'
9
+
10
+ class LoggingTest < Test::Unit::TestCase
11
+
12
+ def test_logs_app_name
13
+ running_agent_writes_to_log(
14
+ {:app_name => "My App"},
15
+ "Application: My App")
16
+ end
17
+
18
+ def test_logs_error_with_bad_app_name
19
+ running_agent_writes_to_log(
20
+ {:app_name => false},
21
+ "Unable to determine application name.")
22
+ end
23
+
24
+ def test_logs_dispatcher
25
+ dispatcher = "Y U NO SERVER WEBPAGE"
26
+
27
+ running_agent_writes_to_log(
28
+ {:dispatcher => dispatcher},
29
+ dispatcher)
30
+ end
31
+
32
+ def test_logs_missing_dispatcher
33
+ running_agent_writes_to_log(
34
+ {:dispatcher => ''},
35
+ "No dispatcher detected")
36
+ end
37
+
38
+ def test_logs_raw_sql_warning
39
+ NewRelic::Agent.config.apply_config(:'transaction_tracer.record_sql' => 'obfuscated')
40
+
41
+ running_agent_writes_to_log(
42
+ {:'transaction_tracer.record_sql' => 'raw'},
43
+ "Agent is configured to send raw SQL to the service")
44
+ end
45
+
46
+ def test_logs_if_sending_errors_on_change
47
+ NewRelic::Agent.config.apply_config(:'error_collector.enabled' => false)
48
+
49
+ running_agent_writes_to_log(
50
+ {:'error_collector.enabled' => true},
51
+ "Errors will be sent")
52
+ end
53
+
54
+ def test_logs_if_not_sending_errors_on_change
55
+ NewRelic::Agent.config.apply_config(:'error_collector.enabled' => true)
56
+
57
+ running_agent_writes_to_log(
58
+ {:'error_collector.enabled' => false},
59
+ "Errors will not be sent")
60
+ end
61
+
62
+ def test_logs_transaction_tracing_disabled
63
+ running_agent_writes_to_log(
64
+ {:'transaction_tracer.enabled' => false},
65
+ "Transaction traces will not be sent")
66
+ end
67
+
68
+ def test_invalid_license_key
69
+ with_connect_response(401)
70
+ running_agent_writes_to_log({},
71
+ "Visit NewRelic.com to obtain a valid license key")
72
+ end
73
+
74
+ def test_logs_monitor_mode_disabled
75
+ running_agent_writes_to_log(
76
+ {:monitor_mode => false },
77
+ "Agent configured not to send data in this environment.")
78
+ end
79
+
80
+ def test_logs_mising_license_key
81
+ running_agent_writes_to_log(
82
+ { :license_key => false },
83
+ "No license key found in newrelic.yml config.")
84
+ end
85
+
86
+ def test_logs_invalid_license_key
87
+ running_agent_writes_to_log(
88
+ { :license_key => 'a' * 30 },
89
+ "Invalid license key: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
90
+ end
91
+
92
+ def test_logs_forking_workers
93
+ running_agent_writes_to_log(
94
+ { :dispatcher => :passenger },
95
+ "Connecting workers after forking.")
96
+ end
97
+
98
+ # Initialization
99
+ def setup
100
+ $collector ||= NewRelic::FakeCollector.new
101
+ $collector.reset
102
+ $collector.mock['connect'] = [200, {'return_value' => {"agent_run_id" => 666 }}]
103
+ $collector.run
104
+
105
+ NewRelic::Agent.reset_config
106
+ NewRelic::Agent.agent = NewRelic::Agent::Agent.new
107
+ NewRelic::Control.instance(true)
108
+
109
+ @logger = NewRelic::Agent::MemoryLogger.new
110
+ NewRelic::Agent.logger = @logger
111
+ NewRelic::Agent::AgentLogger.stubs(:new).with(any_parameters).returns(@logger)
112
+ end
113
+
114
+ def teardown
115
+ $collector.reset
116
+ end
117
+
118
+ # Helpers
119
+ def running_agent_writes_to_log(options, msg)
120
+ run_agent_with(options) do
121
+ saw?(msg)
122
+ end
123
+ end
124
+
125
+ def with_connect_response(status=200, response={})
126
+ $collector.mock['connect'] = [status, response]
127
+ end
128
+
129
+ def run_agent_with(options = {})
130
+ NewRelic::Agent.manual_start(options)
131
+ NewRelic::Agent.shutdown
132
+ yield
133
+ end
134
+
135
+ def saw?(*expected_messages)
136
+ flattened = @logger.messages.flatten
137
+ expected_messages.each do |expected|
138
+ found = flattened.any? {|msg| msg.to_s.include?(expected)}
139
+ @logger.messages.each {|msg| puts msg.inspect} if !found
140
+ assert(found, "Didn't see message '#{expected}'")
141
+ end
142
+ end
143
+ end
@@ -13,11 +13,10 @@ development:
13
13
  api_host: 127.0.0.1
14
14
  port: 30303
15
15
  transaction_tracer:
16
- record_sql: obfuscated
16
+ record_sql: raw
17
17
  enabled: true
18
18
  stack_trace_threshold: 0.5
19
19
  transaction_threshold: 1.0
20
20
  capture_params: false
21
21
  log_level: debug
22
- #log_file_path: STDOUT
23
22
  disable_serialization: false
@@ -76,19 +76,6 @@ class RumAutoTest < Test::Unit::TestCase
76
76
  assert(!last_response.body.include?(%'NREUMQ'))
77
77
  end
78
78
 
79
- # regression
80
- def test_autoinstrumenation_fails_gracefully_with_js_that_contains_embedded_html_tags
81
- # we got this one from a customer
82
- # https://support.newrelic.com/tickets/14208
83
- MyApp.response = File.read(File.dirname(__FILE__) + '/problem_response.html')
84
- get '/'
85
-
86
- # assert that our js is inserted at the end of the head tag, and not in the
87
- # middle of his script tag.
88
- assert(!last_response.body.include?(%'NREUMQ'))
89
- end
90
-
91
-
92
79
  def test_autoinstrumenation_doesnt_run_for_crazy_shit_like_this
93
80
  MyApp.response = '<html><head <body </body>'
94
81
  get '/'
@@ -12,14 +12,19 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
12
12
  @connect_retry_period = 0
13
13
  @transaction_sampler = NewRelic::Agent::TransactionSampler.new
14
14
  @sql_sampler = NewRelic::Agent::SqlSampler.new
15
+ @error_collector = NewRelic::Agent::ErrorCollector.new
15
16
  server = NewRelic::Control::Server.new('localhost', 30303)
16
17
  @service = NewRelic::Agent::NewRelicService.new('abcdef', server)
17
- log.stubs(:warn => true, :info => true, :debug => true)
18
+ @test_config = { :developer_mode => true }
19
+ NewRelic::Agent.config.apply_config(@test_config)
20
+ end
21
+
22
+ def teardown
23
+ NewRelic::Agent.config.remove_config(@test_config)
18
24
  end
19
25
 
20
26
  def control
21
- fake_control = OpenStruct.new('validate_seed' => false,
22
- 'local_env' => OpenStruct.new('snapshot' => []))
27
+ fake_control = OpenStruct.new('local_env' => OpenStruct.new('snapshot' => []))
23
28
  fake_control.instance_eval do
24
29
  def [](key)
25
30
  return nil
@@ -75,7 +80,6 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
75
80
  def test_should_retry_true
76
81
  @keep_retrying = true
77
82
  @connect_attempts = 1
78
- log.expects(:info).once
79
83
  self.expects(:increment_retry_period!).once
80
84
  assert should_retry?, "should retry in this circumstance"
81
85
  assert_equal 2, @connect_attempts, "should be on the second attempt"
@@ -100,44 +104,25 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
100
104
  end
101
105
 
102
106
  def test_log_error
103
- error = mock('error')
104
- error.expects(:backtrace).once.returns(["line", "secondline"])
105
- error.expects(:message).once.returns("message")
106
- fake_control = mock()
107
- fake_control.expects(:server).returns("server")
108
- self.expects(:control).once.returns(fake_control)
109
- log.expects(:error).with("Error establishing connection with New Relic Service at server: message")
110
- log.expects(:debug).with("line\nsecondline")
107
+ error = StandardError.new("message")
108
+
109
+ expects_logging(:error,
110
+ includes("Error establishing connection with New Relic Service"), \
111
+ instance_of(StandardError))
112
+
111
113
  log_error(error)
112
114
  end
113
115
 
114
116
  def test_handle_license_error
115
- error = mock('error')
117
+ error = mock(:message => "error message")
116
118
  self.expects(:disconnect).once
117
- log.expects(:error).once.with("error message")
118
- log.expects(:info).once.with("Visit NewRelic.com to obtain a valid license key, or to upgrade your account.")
119
- error.expects(:message).returns("error message")
120
119
  handle_license_error(error)
121
120
  end
122
121
 
123
- def test_log_seed_token
124
- with_config(:validate_seed => 'many seeds', :validate_token => 'a token, man') do
125
- log.expects(:debug).with("Connecting with validation seed/token: many seeds/a token, man").once
126
- log_seed_token
127
- end
128
- end
129
-
130
- def test_no_seed_token
131
- with_config(:validate_seed => false) do
132
- log.expects(:debug).never
133
- log_seed_token
134
- end
135
- end
136
-
137
122
  def test_environment_for_connect_positive
138
- fake_env = mock('local_env')
139
- fake_env.expects(:snapshot).once.returns("snapshot")
140
- NewRelic::Control.instance.expects(:local_env).once.returns(fake_env)
123
+ fake_env = stub('local_env', :discovered_dispatcher => nil)
124
+ fake_env.expects(:snapshot).returns("snapshot")
125
+ NewRelic::Control.instance.expects(:local_env).at_least_once.returns(fake_env)
141
126
  with_config(:send_environment_info => true) do
142
127
  assert_equal 'snapshot', environment_for_connect
143
128
  end
@@ -149,62 +134,20 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
149
134
  end
150
135
  end
151
136
 
152
- def test_validate_settings
153
- with_config(:validate_seed => 'seed', :validate_token => 'token') do
154
- assert_equal 'seed', NewRelic::Agent.instance.validate_settings[:seed]
155
- assert_equal 'token', NewRelic::Agent.instance.validate_settings[:token]
156
- end
157
- end
158
-
159
137
  def test_connect_settings
160
138
  control = mocked_control
161
139
  NewRelic::Agent.config.expects(:app_names)
162
- self.expects(:validate_settings)
163
140
  self.expects(:environment_for_connect)
164
- keys = %w(pid host app_name language agent_version environment settings validate)
141
+ keys = %w(pid host app_name language agent_version environment settings)
165
142
  value = connect_settings
166
143
  keys.each do |k|
167
144
  assert(value.has_key?(k.to_sym), "should include the key #{k}")
168
145
  end
169
146
  end
170
147
 
171
- def test_configure_error_collector_base
172
- error_collector = NewRelic::Agent::ErrorCollector.new
173
- NewRelic::Control.instance.log.stubs(:debug)
174
- NewRelic::Control.instance.log.expects(:debug) \
175
- .with("Errors will not be sent to the New Relic service.").at_least_once
176
- with_config(:'error_collector.enabled' => false) do
177
- # noop
178
- end
179
- end
180
-
181
- def test_configure_error_collector_enabled
182
- with_config(:'error_collector.enabled' => false) do
183
- error_collector = NewRelic::Agent::ErrorCollector.new
184
- NewRelic::Control.instance.log.stubs(:debug)
185
- NewRelic::Control.instance.log.expects(:debug) \
186
- .with("Errors will be sent to the New Relic service.").at_least_once
187
- with_config(:'error_collector.enabled' => true) do
188
- # noop
189
- end
190
- end
191
- end
192
-
193
- def test_configure_error_collector_server_disabled
194
- error_collector = NewRelic::Agent::ErrorCollector.new
195
- NewRelic::Control.instance.log.stubs(:debug)
196
- NewRelic::Control.instance.log.expects(:debug) \
197
- .with("Errors will not be sent to the New Relic service.").at_least_once
198
- config = NewRelic::Agent::Configuration::ServerSource.new('collect_errors' => false)
199
- with_config(config) do
200
- # noop
201
- end
202
- end
203
-
204
148
  def test_configure_transaction_tracer_with_random_sampling
205
149
  with_config(:'transaction_tracer.transaction_threshold' => 5,
206
150
  :'transaction_tracer.random_sample' => true) do
207
- log.stubs(:debug)
208
151
  sample = TransactionSampleTestHelper.make_sql_transaction
209
152
  @transaction_sampler.store_sample(sample)
210
153
 
@@ -225,9 +168,6 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
225
168
  end
226
169
 
227
170
  def test_configure_transaction_tracer_server_disabled
228
- @transaction_sampler.stubs(:log).returns(log)
229
- log.stubs(:debug)
230
- log.expects(:debug).with('Transaction traces will not be sent to the New Relic service.')
231
171
  config = NewRelic::Agent::Configuration::ServerSource.new('collect_traces' => false,
232
172
  'developer_mode' => false)
233
173
  with_config(config) do
@@ -302,6 +242,8 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
302
242
  'collect_traces' => true,
303
243
  'collect_errors' => true,
304
244
  'sample_rate' => 10,
245
+ 'cross_process_id' => '1#234',
246
+ 'encoding_key' => 'a' * 30,
305
247
  'agent_config' => { 'transaction_tracer.record_sql' => 'raw' }
306
248
  }
307
249
  self.expects(:log_connection!).with(config)
@@ -311,10 +253,17 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
311
253
  with_config(:'transaction_tracer.enabled' => true) do
312
254
  finish_setup(config)
313
255
  assert_equal 'fishsticks', @service.agent_id
256
+ assert_equal '1#234', @cross_process_id
257
+ assert_equal 'a' * 30, @cross_process_encoding_key
258
+ assert_equal [97] * 30, @cross_process_encoding_bytes
314
259
  assert_equal 'raw', NewRelic::Agent.config[:'transaction_tracer.record_sql']
315
260
  end
316
261
  end
317
262
 
263
+ def test_get_bytes_with_nil
264
+ assert_equal [], get_bytes(nil)
265
+ end
266
+
318
267
  def test_logging_collector_messages
319
268
  NewRelic::Agent.manual_start
320
269
  service = NewRelic::FakeService.new
@@ -325,9 +274,8 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
325
274
  { 'message' => 'ha cha cha', 'level' => 'WARN' }]
326
275
  }
327
276
 
328
- NewRelic::Control.instance.log.stubs(:info)
329
- NewRelic::Control.instance.log.expects(:info).with('beep boop')
330
- NewRelic::Control.instance.log.expects(:warn).with('ha cha cha')
277
+ expects_logging(:info, 'beep boop')
278
+ expects_logging(:warn, 'ha cha cha')
331
279
 
332
280
  NewRelic::Agent.agent.query_server_for_configuration
333
281
  NewRelic::Agent.shutdown
@@ -363,22 +311,12 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
363
311
  fake_control
364
312
  end
365
313
 
366
- def mocked_log
367
- fake_log = mock('log')
368
- self.stubs(:log).returns(fake_log)
369
- fake_log
370
- end
371
-
372
314
  def mocked_error_collector
373
315
  fake_collector = mock('error collector')
374
316
  self.stubs(:error_collector).returns(fake_collector)
375
317
  fake_collector
376
318
  end
377
319
 
378
- def log
379
- @logger ||= Object.new
380
- end
381
-
382
320
  def assert_accessor(sym)
383
321
  var_name = "@#{sym}"
384
322
  instance_variable_set(var_name, 1)
@@ -14,8 +14,7 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
14
14
  end
15
15
 
16
16
  def test_already_started_positive
17
- control = mocked_control
18
- control.expects(:log!).with("Agent Started Already!", :error)
17
+ ::Logger.any_instance.expects(:error).with("Agent Started Already!")
19
18
  self.expects(:started?).returns(true)
20
19
  assert already_started?, "should have already started"
21
20
  end
@@ -37,55 +36,6 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
37
36
  end
38
37
  end
39
38
 
40
- def test_log_dispatcher_positive
41
- log = mocked_log
42
- with_config(:dispatcher => 'Y U NO SERVE WEBPAGE') do
43
- log.expects(:info).with("Dispatcher: Y U NO SERVE WEBPAGE")
44
- log_dispatcher
45
- end
46
- end
47
-
48
- def test_log_dispatcher_negative
49
- log = mocked_log
50
- with_config(:dispatcher => '') do
51
- log.expects(:info).with("No dispatcher detected.")
52
- log_dispatcher
53
- end
54
- end
55
-
56
- def test_log_app_names_string
57
- with_config(:app_name => 'zam;zam;zabam') do
58
- log = mocked_log
59
- log.expects(:info).with("Application: zam, zam, zabam")
60
- log_app_names
61
- end
62
- end
63
-
64
- def test_log_app_names_array
65
- with_config(:app_name => ['zam', 'zam', 'zabam']) do
66
- log = mocked_log
67
- log.expects(:info).with("Application: zam, zam, zabam")
68
- log_app_names
69
- end
70
- end
71
-
72
- def test_log_app_names_with_env_var
73
- # bad app name after env - used to cover the yaml config
74
- with_config({:app_name => false}, 1) do
75
- log = mocked_log
76
- log.expects(:info).with("Application: start_test") # set in setup
77
- log_app_names
78
- end
79
- end
80
-
81
- def test_log_app_names_with_unknown
82
- with_config(:app_name => false) do
83
- log = mocked_log
84
- log.expects(:error).with('Unable to determine application name. Please set the application name in your newrelic.yml or in a NEW_RELIC_APP_NAME environment variable.')
85
- log_app_names
86
- end
87
- end
88
-
89
39
  def test_check_config_and_start_agent_disabled
90
40
  self.expects(:monitoring?).returns(false)
91
41
  check_config_and_start_agent
@@ -165,30 +115,14 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
165
115
  end
166
116
  end
167
117
 
168
- def test_notify_log_file_location_positive
169
- log = mocked_log
170
- NewRelic::Control.instance.expects(:log_file).returns('./')
171
- log.expects(:send).with(:info, "Agent Log at ./")
172
- notify_log_file_location
173
- end
174
-
175
- def test_notify_log_file_location_negative
176
- log = mocked_log
177
- NewRelic::Control.instance.expects(:log_file).returns(nil)
178
- notify_log_file_location
179
- end
180
-
181
118
  def test_monitoring_positive
182
119
  with_config(:monitor_mode => true) do
183
- log = mocked_log
184
120
  assert monitoring?
185
121
  end
186
122
  end
187
123
 
188
124
  def test_monitoring_negative
189
- log = mocked_log
190
125
  with_config(:monitor_mode => false) do
191
- log.expects(:send).with(:warn, "Agent configured not to send data in this environment.")
192
126
  assert !monitoring?
193
127
  end
194
128
  end
@@ -201,8 +135,6 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
201
135
 
202
136
  def test_has_license_key_negative
203
137
  with_config(:license_key => false) do
204
- log = mocked_log
205
- log.expects(:send).with(:warn, 'No license key found in newrelic.yml config.')
206
138
  assert !has_license_key?
207
139
  end
208
140
  end
@@ -226,16 +158,12 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
226
158
 
227
159
  def test_correct_license_length_negative
228
160
  with_config(:license_key => 'a' * 30) do
229
- log = mocked_log
230
- log.expects(:send).with(:error, "Invalid license key: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
231
161
  assert !correct_license_length
232
162
  end
233
163
  end
234
164
 
235
165
  def test_using_forking_dispatcher_positive
236
166
  with_config(:dispatcher => :passenger) do
237
- log = mocked_log
238
- log.expects(:send).with(:info, "Connecting workers after forking.")
239
167
  assert using_forking_dispatcher?
240
168
  end
241
169
  end
@@ -250,16 +178,15 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
250
178
  # should not log
251
179
  assert log_unless(true, :warn, "DURRR")
252
180
  end
181
+
253
182
  def test_log_unless_negative
254
183
  # should log
255
- log = mocked_log
256
- log.expects(:send).with(:warn, "DURRR")
184
+ expects_logging(:warn, "DURRR")
257
185
  assert !log_unless(false, :warn, "DURRR")
258
186
  end
259
187
 
260
188
  def test_log_if_positive
261
- log = mocked_log
262
- log.expects(:send).with(:warn, "WHEE")
189
+ expects_logging(:warn, "WHEE")
263
190
  assert log_if(true, :warn, "WHEE")
264
191
  end
265
192
 
@@ -269,13 +196,6 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
269
196
 
270
197
  private
271
198
 
272
- def mocked_log
273
- fake_log = mock('log')
274
- self.stubs(:log).returns(fake_log)
275
- fake_log
276
- end
277
-
278
-
279
199
  def mocked_control
280
200
  fake_control = mock('control')
281
201
  self.stubs(:control).returns(fake_control)