newrelic_rpm 3.8.0.218 → 3.8.1.221

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +32 -0
  3. data/README.md +4 -7
  4. data/Rakefile +3 -0
  5. data/lib/new_relic/agent.rb +3 -7
  6. data/lib/new_relic/agent/agent.rb +4 -14
  7. data/lib/new_relic/agent/agent_logger.rb +19 -11
  8. data/lib/new_relic/agent/autostart.rb +1 -1
  9. data/lib/new_relic/agent/configuration/default_source.rb +25 -12
  10. data/lib/new_relic/agent/configuration/manager.rb +14 -7
  11. data/lib/new_relic/agent/configuration/yaml_source.rb +39 -8
  12. data/lib/new_relic/agent/cross_app_monitor.rb +9 -7
  13. data/lib/new_relic/agent/cross_app_tracing.rb +6 -6
  14. data/lib/new_relic/agent/datastores/mongo.rb +6 -7
  15. data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +32 -13
  16. data/lib/new_relic/agent/datastores/mongo/statement_formatter.rb +4 -3
  17. data/lib/new_relic/agent/error_collector.rb +2 -2
  18. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +10 -69
  19. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +5 -7
  20. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +2 -2
  21. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +77 -93
  22. data/lib/new_relic/agent/instrumentation/evented_subscriber.rb +1 -1
  23. data/lib/new_relic/agent/instrumentation/mongo.rb +26 -42
  24. data/lib/new_relic/agent/instrumentation/rubyprof.rb +1 -1
  25. data/lib/new_relic/agent/instrumentation/sinatra.rb +4 -1
  26. data/lib/new_relic/agent/javascript_instrumentor.rb +15 -6
  27. data/lib/new_relic/agent/method_tracer.rb +41 -92
  28. data/lib/new_relic/agent/request_sampler.rb +0 -1
  29. data/lib/new_relic/agent/rules_engine.rb +36 -12
  30. data/lib/new_relic/agent/shim_agent.rb +0 -1
  31. data/lib/new_relic/agent/sql_sampler.rb +8 -15
  32. data/lib/new_relic/agent/stats_engine.rb +2 -6
  33. data/lib/new_relic/agent/stats_engine/metric_stats.rb +8 -2
  34. data/lib/new_relic/agent/stats_engine/stats_hash.rb +1 -1
  35. data/lib/new_relic/agent/supported_versions.rb +1 -1
  36. data/lib/new_relic/agent/traced_method_stack.rb +87 -0
  37. data/lib/new_relic/agent/transaction.rb +277 -107
  38. data/lib/new_relic/agent/transaction_sample_builder.rb +2 -2
  39. data/lib/new_relic/agent/transaction_sampler.rb +18 -27
  40. data/lib/new_relic/agent/transaction_state.rb +15 -40
  41. data/lib/new_relic/control/instance_methods.rb +8 -4
  42. data/lib/new_relic/recipes.rb +3 -3
  43. data/lib/new_relic/transaction_sample.rb +3 -7
  44. data/lib/new_relic/version.rb +1 -1
  45. data/lib/sequel/extensions/newrelic_instrumentation.rb +3 -3
  46. data/newrelic_rpm.gemspec +15 -9
  47. data/test/agent_helper.rb +71 -36
  48. data/test/environments/norails/Gemfile +2 -0
  49. data/test/environments/rails21/Gemfile +2 -0
  50. data/test/environments/rails22/Gemfile +2 -0
  51. data/test/environments/rails23/Gemfile +2 -0
  52. data/test/environments/rails30/Gemfile +2 -0
  53. data/test/environments/rails31/Gemfile +2 -0
  54. data/test/environments/rails32/Gemfile +2 -0
  55. data/test/environments/rails40/Gemfile +2 -0
  56. data/test/environments/rails41/Gemfile +1 -0
  57. data/test/helpers/mongo_metric_builder.rb +1 -1
  58. data/test/multiverse/suites/agent_only/audit_log_test.rb +2 -2
  59. data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +9 -1
  60. data/test/multiverse/suites/agent_only/encoding_handling_test.rb +1 -1
  61. data/test/multiverse/suites/agent_only/logging_test.rb +2 -2
  62. data/test/multiverse/suites/agent_only/marshaling_test.rb +8 -9
  63. data/test/multiverse/suites/agent_only/rum_instrumentation_test.rb +14 -1
  64. data/test/multiverse/suites/agent_only/set_transaction_name_test.rb +30 -13
  65. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +9 -8
  66. data/test/multiverse/suites/agent_only/transaction_ignoring_test.rb +43 -0
  67. data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +77 -5
  68. data/test/multiverse/suites/excon/excon_test.rb +1 -1
  69. data/test/multiverse/suites/mongo/Envfile +4 -7
  70. data/test/multiverse/suites/mongo/helpers/mongo_operation_tests.rb +55 -16
  71. data/test/multiverse/suites/mongo/helpers/mongo_server.rb +6 -4
  72. data/test/multiverse/suites/rails/bad_instrumentation_test.rb +2 -2
  73. data/test/multiverse/suites/rails/error_tracing_test.rb +3 -1
  74. data/test/multiverse/suites/rails/request_statistics_test.rb +14 -14
  75. data/test/multiverse/suites/rails/transaction_ignoring_test.rb +45 -0
  76. data/test/multiverse/suites/sequel/sequel_instrumentation_test.rb +1 -1
  77. data/test/new_relic/agent/agent/connect_test.rb +4 -4
  78. data/test/new_relic/agent/agent_logger_test.rb +32 -0
  79. data/test/new_relic/agent/configuration/manager_test.rb +12 -4
  80. data/test/new_relic/agent/configuration/yaml_source_test.rb +2 -2
  81. data/test/new_relic/agent/cross_app_monitor_test.rb +6 -2
  82. data/test/new_relic/agent/cross_app_tracing_test.rb +5 -5
  83. data/test/new_relic/agent/datastores/mongo/statement_formatter_test.rb +7 -6
  84. data/test/new_relic/agent/error_collector_test.rb +1 -2
  85. data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +24 -11
  86. data/test/new_relic/agent/instrumentation/action_view_subscriber_test.rb +2 -2
  87. data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +12 -17
  88. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +43 -32
  89. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +3 -4
  90. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +36 -20
  91. data/test/new_relic/agent/javascript_instrumentor_test.rb +1 -2
  92. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +15 -26
  93. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +66 -103
  94. data/test/new_relic/agent/method_tracer_test.rb +2 -2
  95. data/test/new_relic/agent/mock_scope_listener.rb +3 -6
  96. data/test/new_relic/agent/pipe_channel_manager_test.rb +4 -4
  97. data/test/new_relic/agent/rules_engine_test.rb +13 -0
  98. data/test/new_relic/agent/sql_sampler_test.rb +8 -10
  99. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +18 -0
  100. data/test/new_relic/agent/stats_engine_test.rb +0 -173
  101. data/test/new_relic/agent/threading/agent_thread_test.rb +27 -26
  102. data/test/new_relic/agent/traced_method_stack_test.rb +139 -0
  103. data/test/new_relic/agent/transaction_sample_builder_test.rb +2 -12
  104. data/test/new_relic/agent/transaction_sampler_test.rb +98 -107
  105. data/test/new_relic/agent/transaction_state_test.rb +52 -61
  106. data/test/new_relic/agent/transaction_test.rb +209 -140
  107. data/test/new_relic/agent_test.rb +3 -2
  108. data/test/new_relic/control_test.rb +10 -9
  109. data/test/new_relic/fake_collector.rb +34 -2
  110. data/test/new_relic/http_client_test_cases.rb +0 -5
  111. data/test/new_relic/license_test.rb +4 -2
  112. data/test/new_relic/local_environment_test.rb +14 -28
  113. data/test/new_relic/multiverse_helpers.rb +2 -2
  114. data/test/new_relic/rack/developer_mode_test.rb +4 -5
  115. data/test/new_relic/transaction_ignoring_test_cases.rb +104 -0
  116. data/test/new_relic/transaction_sample_test.rb +14 -7
  117. data/test/performance/lib/performance/instrumentation/gc_stats.rb +6 -3
  118. data/test/performance/suites/transaction_tracing.rb +4 -1
  119. data/test/test_helper.rb +31 -60
  120. data/ui/views/newrelic/show_sample.rhtml +1 -1
  121. metadata +46 -101
  122. metadata.gz.sig +0 -0
  123. data/lib/new_relic/agent/stats_engine/transactions.rb +0 -114
  124. data/lib/new_relic/agent/transaction/pop.rb +0 -52
  125. data/test/new_relic/agent/transaction/pop_test.rb +0 -79
@@ -16,3 +16,5 @@ platforms :rbx do
16
16
  end
17
17
 
18
18
  gem "newrelic_rpm", :path => "../../.."
19
+
20
+ gem 'pry'
@@ -20,3 +20,5 @@ else
20
20
  gem "mysql", "~>2.9.1"
21
21
  gem "sqlite3-ruby", "1.2.5"
22
22
  end
23
+
24
+ gem 'pry'
@@ -20,3 +20,5 @@ else
20
20
  gem "mysql", "~>2.9.1"
21
21
  gem "sqlite3"
22
22
  end
23
+
24
+ gem 'pry'
@@ -19,3 +19,5 @@ else
19
19
  gem "mysql", "~>2.9.1"
20
20
  gem "sqlite3-ruby", "1.2.5"
21
21
  end
22
+
23
+ gem 'pry'
@@ -18,3 +18,5 @@ else
18
18
  gem "mysql", "~>2.9.1"
19
19
  gem "sqlite3-ruby"
20
20
  end
21
+
22
+ gem 'pry'
@@ -18,3 +18,5 @@ else
18
18
  gem "mysql", "~>2.9.1"
19
19
  gem "sqlite3-ruby"
20
20
  end
21
+
22
+ gem 'pry'
@@ -20,3 +20,5 @@ platforms :ruby, :rbx do
20
20
  gem "mysql", "~>2.9.1"
21
21
  gem "sqlite3"
22
22
  end
23
+
24
+ gem 'pry'
@@ -40,3 +40,5 @@ platforms :rbx do
40
40
  end
41
41
 
42
42
  gem "newrelic_rpm", :path => "../../.."
43
+
44
+ gem 'pry'
@@ -32,3 +32,4 @@ platforms :rbx do
32
32
  end
33
33
 
34
34
  gem "newrelic_rpm", :path => "../../.."
35
+ gem 'pry'
@@ -19,7 +19,7 @@ module NewRelic
19
19
  metric_attributes = {}
20
20
 
21
21
  metrics.each do |metric|
22
- metric_attributes[metric] = attributes
22
+ metric_attributes[metric] = attributes.dup
23
23
  end
24
24
 
25
25
  metric_attributes
@@ -87,11 +87,11 @@ class AuditLogTest < Minitest::Test
87
87
  def perform_actions
88
88
  reset_collector
89
89
 
90
- NewRelic::Agent.instance.sql_sampler.notice_first_scope_push(nil)
90
+ NewRelic::Agent.instance.sql_sampler.on_start_transaction(nil)
91
91
  NewRelic::Agent.instance.sql_sampler.notice_sql("select * from test",
92
92
  "Database/test/select",
93
93
  nil, 1.5)
94
- NewRelic::Agent.instance.sql_sampler.notice_scope_empty('txn')
94
+ NewRelic::Agent.instance.sql_sampler.on_finishing_transaction('txn')
95
95
  NewRelic::Agent.instance.send(:harvest_and_send_slowest_sql)
96
96
  end
97
97
  end
@@ -18,7 +18,10 @@ class CrossApplicationTracingTest < Minitest::Test
18
18
  :encoding_key => "\0",
19
19
  :trusted_account_ids => [1]) \
20
20
  do |collector|
21
- collector.stub('connect', {"agent_run_id" => 666 })
21
+ collector.stub('connect', {
22
+ 'agent_run_id' => 666,
23
+ 'transaction_name_rules' => [{"match_expression" => "ignored_transaction",
24
+ "ignore" => true}]})
22
25
  end
23
26
 
24
27
  def after_setup
@@ -47,4 +50,9 @@ class CrossApplicationTracingTest < Minitest::Test
47
50
  refute_nil last_response.headers["X-NewRelic-App-Data"]
48
51
  assert_metrics_recorded(['ClientApplication/1#234/all'])
49
52
  end
53
+
54
+ def test_cross_app_doesnt_modify_if_txn_is_ignored
55
+ get '/', {'transaction_name' => 'ignored_transaction'}, {'X-NewRelic-ID' => Base64.encode64('1#234')}
56
+ assert_nil last_response.headers["X-NewRelic-App-Data"]
57
+ end
50
58
  end
@@ -4,7 +4,7 @@
4
4
 
5
5
  if RUBY_VERSION >= '1.9'
6
6
 
7
- class CollectorExceptionHandlingTest < Minitest::Test
7
+ class EncodingHandlingTest < Minitest::Test
8
8
  include MultiverseHelpers
9
9
 
10
10
  setup_and_teardown_agent
@@ -107,13 +107,13 @@ class LoggingTest < Minitest::Test
107
107
  def test_logs_missing_license_key
108
108
  running_agent_writes_to_log(
109
109
  { :license_key => false },
110
- "No license key found in newrelic.yml config.")
110
+ "No license key found.")
111
111
  end
112
112
 
113
113
  def test_logs_blank_license_key
114
114
  running_agent_writes_to_log(
115
115
  { :license_key => '' },
116
- "No license key found in newrelic.yml config.")
116
+ "No license key found.")
117
117
  end
118
118
 
119
119
  def test_logs_invalid_license_key
@@ -18,14 +18,13 @@ class MarshalingTest < Minitest::Test
18
18
  # create fake transaction trace
19
19
  time = freeze_time
20
20
  sampler = agent.transaction_sampler
21
- sampler.notice_first_scope_push time
22
- sampler.notice_transaction nil, {}
23
- sampler.notice_push_scope "a"
24
- sampler.notice_push_scope "ab"
21
+ sampler.on_start_transaction time, nil, {}
22
+ sampler.notice_push_frame "a"
23
+ sampler.notice_push_frame "ab"
25
24
  advance_time 1
26
- sampler.notice_pop_scope "ab"
27
- sampler.notice_pop_scope "a"
28
- sampler.notice_scope_empty(OpenStruct.new(:name => 'path',
25
+ sampler.notice_pop_frame "ab"
26
+ sampler.notice_pop_frame "a"
27
+ sampler.on_finishing_transaction(OpenStruct.new(:name => 'path',
29
28
  :custom_parameters => {}))
30
29
 
31
30
  expected_sample = sampler.last_sample
@@ -69,11 +68,11 @@ class MarshalingTest < Minitest::Test
69
68
  end
70
69
 
71
70
  def test_sql_trace_data_marshalling
72
- agent.sql_sampler.notice_first_scope_push(nil)
71
+ agent.sql_sampler.on_start_transaction(nil)
73
72
  agent.sql_sampler.notice_sql("select * from test",
74
73
  "Database/test/select",
75
74
  nil, 1.5)
76
- agent.sql_sampler.notice_scope_empty('txn')
75
+ agent.sql_sampler.on_finishing_transaction('txn')
77
76
 
78
77
  agent.service.connect
79
78
  agent.send(:harvest_and_send_slowest_sql)
@@ -22,7 +22,13 @@ class RumAutoTest < Minitest::Test
22
22
  setup_and_teardown_agent(:application_id => 'appId',
23
23
  :beacon => 'beacon',
24
24
  :browser_key => 'browserKey',
25
- :js_agent_loader => JS_AGENT_LOADER)
25
+ :js_agent_loader => JS_AGENT_LOADER) do |collector|
26
+ collector.stub('connect', {
27
+ 'transaction_name_rules' => [{"match_expression" => "ignored_transaction",
28
+ "ignore" => true}],
29
+ 'agent_run_id' => 1,
30
+ })
31
+ end
26
32
 
27
33
  def after_setup
28
34
  @inner_app = TestingApp.new
@@ -76,6 +82,13 @@ class RumAutoTest < Minitest::Test
76
82
  assert_equal(last_response.body, body)
77
83
  end
78
84
 
85
+ def test_rum_headers_are_not_injected_in_ignored_txn
86
+ body = "<html><head><title>W00t!</title></head><body><p>Hello World</p></body></html>"
87
+ @inner_app.response = body
88
+ get '/', 'transaction_name' => 'ignored_transaction'
89
+ assert_equal(last_response.body, body)
90
+ end
91
+
79
92
  def assert_response_includes(*texts)
80
93
  texts.each do |text|
81
94
  assert_match(Regexp.new(text), last_response.body,
@@ -16,15 +16,17 @@ class SetTransactionNameTest < Minitest::Test
16
16
 
17
17
  class TestTransactor
18
18
  include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
19
- def parent_txn
19
+ def parent_txn(child_category=nil)
20
20
  NewRelic::Agent.set_transaction_name('TestTransactor/parent')
21
21
  yield if block_given?
22
- child_txn
22
+ child_txn(child_category)
23
23
  end
24
24
  add_transaction_tracer :parent_txn
25
25
 
26
- def child_txn
27
- NewRelic::Agent.set_transaction_name('TestTransactor/child', :category => :task)
26
+ def child_txn(category)
27
+ opts = {}
28
+ opts[:category] = category if category
29
+ NewRelic::Agent.set_transaction_name('TestTransactor/child', opts)
28
30
  end
29
31
  add_transaction_tracer :child_txn
30
32
 
@@ -34,27 +36,42 @@ class SetTransactionNameTest < Minitest::Test
34
36
  end
35
37
  end
36
38
 
37
- def test_apply_to_metric_names
38
- TestTransactor.new.parent_txn
39
+ def test_metric_names_when_child_has_different_category
40
+ TestTransactor.new.parent_txn(:task)
39
41
 
40
42
  assert_metrics_recorded([
41
43
  'Controller/TestTransactor/parent',
42
44
  'OtherTransaction/Background/TestTransactor/child',
43
- [ 'OtherTransaction/Background/TestTransactor/child', 'Controller/TestTransactor/parent'],
45
+ ['OtherTransaction/Background/TestTransactor/child',
46
+ 'Controller/TestTransactor/parent'],
44
47
  'Apdex/TestTransactor/parent'])
45
48
  end
46
49
 
50
+ def test_apply_to_metric_names
51
+ TestTransactor.new.parent_txn
52
+
53
+ assert_metrics_recorded([
54
+ 'Controller/TestTransactor/child',
55
+ 'Nested/Controller/TestTransactor/child',
56
+ 'Nested/Controller/TestTransactor/parent',
57
+ ['Nested/Controller/TestTransactor/child',
58
+ 'Controller/TestTransactor/child'],
59
+ ['Nested/Controller/TestTransactor/parent',
60
+ 'Controller/TestTransactor/child'],
61
+ 'Apdex/TestTransactor/child'])
62
+ end
63
+
47
64
  def test_apply_to_metric_scopes
48
65
  TestTransactor.new.parent_txn do
49
66
  trace_execution_scoped('Custom/something') {}
50
67
  end
51
68
  assert_metrics_recorded(['Custom/something',
52
- 'Controller/TestTransactor/parent'])
69
+ 'Controller/TestTransactor/child'])
53
70
  end
54
71
 
55
72
  def test_apply_to_traced_transactions
56
73
  TestTransactor.new.parent_txn
57
- assert_equal('Controller/TestTransactor/parent',
74
+ assert_equal('Controller/TestTransactor/child',
58
75
  NewRelic::Agent.instance.transaction_sampler.last_sample \
59
76
  .params[:path])
60
77
  end
@@ -63,16 +80,16 @@ class SetTransactionNameTest < Minitest::Test
63
80
  TestTransactor.new.parent_txn do
64
81
  NewRelic::Agent.notice_error(RuntimeError.new('toot'))
65
82
  end
66
- assert_equal('Controller/TestTransactor/parent',
83
+ assert_equal('Controller/TestTransactor/child',
67
84
  NewRelic::Agent.instance.error_collector.errors.last.path)
68
85
  end
69
86
 
70
87
  def test_set_name_is_subject_to_txn_name_rules
71
- rule = NewRelic::Agent::RulesEngine::Rule.new('match_expression' => 'parent',
72
- 'replacement' => 'dad')
88
+ rule = NewRelic::Agent::RulesEngine::Rule.new('match_expression' => 'child',
89
+ 'replacement' => 'kid')
73
90
  NewRelic::Agent.instance.transaction_rules << rule
74
91
  TestTransactor.new.parent_txn
75
- assert_metrics_recorded(['Controller/TestTransactor/dad'])
92
+ assert_metrics_recorded(['Controller/TestTransactor/kid'])
76
93
  end
77
94
 
78
95
  def test_does_not_overwrite_name_when_set_by_RUM
@@ -61,8 +61,8 @@ class ThreadProfilingTest < Minitest::Test
61
61
  # go only let a few cycles through, so we check less than 10
62
62
 
63
63
  def test_thread_profiling
64
- run_thread { NewRelic::Agent::Transaction.start(:controller, :request => stub) }
65
- run_thread { NewRelic::Agent::Transaction.start(:task) }
64
+ run_transaction_in_thread(:type => :controller, :request => stub)
65
+ run_transaction_in_thread(:type => :task)
66
66
 
67
67
  issue_command(START_COMMAND)
68
68
 
@@ -80,8 +80,8 @@ class ThreadProfilingTest < Minitest::Test
80
80
 
81
81
  def test_thread_profiling_with_pruby_marshaller
82
82
  with_config(:marshaller => 'pruby') do
83
- run_thread { NewRelic::Agent::Transaction.start(:controller, :request => stub) }
84
- run_thread { NewRelic::Agent::Transaction.start(:task) }
83
+ run_transaction_in_thread(:type => :controller, :request => stub)
84
+ run_transaction_in_thread(:type => :task)
85
85
 
86
86
  issue_command(START_COMMAND)
87
87
 
@@ -118,13 +118,14 @@ class ThreadProfilingTest < Minitest::Test
118
118
  end
119
119
 
120
120
  # Runs a thread we expect to span entire test and be killed at the end
121
- def run_thread
121
+ def run_transaction_in_thread(opts)
122
122
  q = Queue.new
123
123
  @threads ||= []
124
124
  @threads << Thread.new do
125
- yield
126
- q.push('.')
127
- sleep # sleep until explicitly woken in join_background_threads
125
+ in_transaction(opts) do
126
+ q.push('.')
127
+ sleep # sleep until explicitly woken in join_background_threads
128
+ end
128
129
  end
129
130
  q.pop # block until the thread has had a chance to start up
130
131
  end
@@ -0,0 +1,43 @@
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.join(File.dirname(__FILE__), '..', '..', '..', 'agent_helper')
6
+ require 'multiverse_helpers'
7
+ require 'transaction_ignoring_test_cases'
8
+
9
+ class TransactionIgnoringTest < Minitest::Test
10
+
11
+ include MultiverseHelpers
12
+ include TransactionIgnoringTestCases
13
+
14
+ def trigger_transaction(txn_name)
15
+ TestWidget.new.run_transaction(txn_name)
16
+ end
17
+
18
+ def trigger_transaction_with_error(txn_name, error_msg)
19
+ TestWidget.new.run_transaction(txn_name) do
20
+ NewRelic::Agent.notice_error(error_msg)
21
+ end
22
+ end
23
+
24
+ def trigger_transaction_with_slow_sql(txn_name)
25
+ TestWidget.new.run_transaction(txn_name) do
26
+ NewRelic::Agent.instance.sql_sampler.notice_sql("select * from test",
27
+ "Database/test/select",
28
+ nil, 1.5)
29
+ end
30
+ end
31
+
32
+ class TestWidget
33
+ include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
34
+
35
+ def run_transaction(txn_name)
36
+ NewRelic::Agent.set_transaction_name(txn_name)
37
+ yield if block_given?
38
+ end
39
+
40
+ add_transaction_tracer :run_transaction
41
+ end
42
+
43
+ end
@@ -49,26 +49,31 @@ class ConfigFileLoadingTest < Minitest::Test
49
49
  FakeFS.deactivate!
50
50
  end
51
51
 
52
- def setup_config(path, manual_config_options = {})
52
+ def setup_config(path, manual_config_options = {}, config_file_content=nil)
53
53
  teardown_agent
54
54
 
55
55
  FileUtils.mkdir_p(File.dirname(path))
56
56
  Dir.chdir @cwd
57
57
  File.open(path, 'w') do |f|
58
- f.print <<-YAML
58
+ if config_file_content
59
+ f.write(config_file_content)
60
+ else
61
+ f.print <<-YAML
59
62
  development:
60
63
  foo: "success!!"
61
64
  test:
62
65
  foo: "success!!"
63
66
  bazbangbarn:
64
67
  i_am: "bazbangbarn"
65
- YAML
68
+ YAML
69
+ end
66
70
  end
71
+
67
72
  setup_agent(manual_config_options)
68
73
  end
69
74
 
70
- def assert_config_read_from(path)
71
- setup_config(path)
75
+ def assert_config_read_from(path, manual_config_options={})
76
+ setup_config(path, manual_config_options)
72
77
  assert NewRelic::Agent.config[:foo] == "success!!", "Failed to read yaml config from #{path.inspect[0..100]}\n\n#{NewRelic::Agent.config.inspect[0..100]}"
73
78
  end
74
79
 
@@ -93,6 +98,67 @@ bazbangbarn:
93
98
  assert_config_read_from(ENV['HOME'] + "/.newrelic/newrelic.yml")
94
99
  end
95
100
 
101
+ def test_config_loads_from_config_path_option_to_manual_start
102
+ path = File.join(File.dirname(__FILE__), 'otherplace', 'newrelic.yml')
103
+ assert_config_read_from(path, :config_path => path)
104
+ end
105
+
106
+ def test_warning_logged_when_no_config_file
107
+ teardown_agent
108
+ setup_agent
109
+
110
+ log = with_array_logger { NewRelic::Agent.manual_start }
111
+
112
+ assert_log_contains(log, /WARN.*No configuration file found/)
113
+ assert_log_contains(log, /WARN.*Looked in these locations.*based on defaults/)
114
+ end
115
+
116
+ def test_warning_logged_when_no_config_file_manual_config
117
+ teardown_agent
118
+ setup_agent
119
+
120
+ log = with_array_logger do
121
+ NewRelic::Agent.manual_start(:config_path => 'otherplace/newrelic.yml')
122
+ end
123
+
124
+ assert_log_contains(log, /WARN.*No configuration file found/)
125
+ assert_log_contains(log, /WARN.*Looked in these locations.*based on API call.*otherplace\/newrelic\.yml/)
126
+ end
127
+
128
+ def test_warning_logged_when_no_config_file_environment_variable
129
+ ENV['NRCONFIG'] = 'otherplace/newrelic.yml'
130
+ teardown_agent
131
+ setup_agent
132
+
133
+ log = with_array_logger { NewRelic::Agent.manual_start }
134
+
135
+ assert_log_contains(log, /WARN.*No configuration file found/)
136
+ assert_log_contains(log, /WARN.*Looked in these locations.*based on environment variable.*otherplace\/newrelic\.yml/)
137
+ ensure
138
+ ENV['NRCONFIG'] = nil
139
+ end
140
+
141
+ def test_warning_logged_when_config_file_yaml_parsing_error
142
+ path = File.join(File.dirname(__FILE__), 'config', 'newrelic.yml')
143
+ setup_config(path, {}, '<< bogus junk')
144
+ setup_agent
145
+
146
+ log = with_array_logger { NewRelic::Agent.manual_start }
147
+
148
+ assert_log_contains(log, /ERROR.*Failed to read or parse configuration file at config\/newrelic\.yml/)
149
+ end
150
+
151
+ def test_warning_logged_when_config_file_erb_error
152
+ path = File.join(File.dirname(__FILE__), 'config', 'newrelic.yml')
153
+ setup_config(path, {}, "\n\n\n<%= this is not ruby %>") # the error is on line 4
154
+ setup_agent
155
+
156
+ log = with_array_logger { NewRelic::Agent.manual_start }
157
+
158
+ assert_log_contains(log, /ERROR.*Failed to read or parse configuration file at config\/newrelic\.yml/)
159
+ assert_log_contains(log, /\(erb\):4/)
160
+ end
161
+
96
162
  def test_config_loads_from_env_NRCONFIG
97
163
  ENV["NRCONFIG"] = "/tmp/foo/bar.yml"
98
164
  assert_config_read_from("/tmp/foo/bar.yml")
@@ -112,4 +178,10 @@ bazbangbarn:
112
178
  setup_config(path, {:env => 'bazbangbarn'} )
113
179
  assert_equal 'bazbangbarn', NewRelic::Agent.config[:i_am], "Agent.config did not load bazbangbarn config as requested"
114
180
  end
181
+
182
+ def assert_log_contains(log, message)
183
+ lines = log.array
184
+ failure_message = "Did not find '#{message}' in log. Log contained:\n#{lines.join('')}"
185
+ assert (lines.any? { |line| line.match(message) }), failure_message
186
+ end
115
187
  end