newrelic_rpm 3.6.0.83 → 3.6.1.85.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. data/CHANGELOG +27 -0
  2. data/Gemfile +2 -7
  3. data/README.md +1 -1
  4. data/lib/new_relic/agent/agent.rb +3 -2
  5. data/lib/new_relic/agent/autostart.rb +56 -0
  6. data/lib/new_relic/agent/browser_monitoring.rb +19 -14
  7. data/lib/new_relic/agent/configuration/defaults.rb +12 -2
  8. data/lib/new_relic/agent/configuration/environment_source.rb +4 -1
  9. data/lib/new_relic/agent/cross_app_monitor.rb +2 -1
  10. data/lib/new_relic/agent/cross_app_tracing.rb +19 -10
  11. data/lib/new_relic/agent/error_collector.rb +5 -4
  12. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +204 -0
  13. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +88 -0
  14. data/lib/new_relic/agent/instrumentation/active_record.rb +1 -1
  15. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +1 -1
  16. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +84 -0
  17. data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +3 -2
  18. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +104 -87
  19. data/lib/new_relic/agent/instrumentation/evented_subscriber.rb +91 -0
  20. data/lib/new_relic/agent/instrumentation/memcache.rb +4 -4
  21. data/lib/new_relic/agent/instrumentation/merb/errors.rb +4 -4
  22. data/lib/new_relic/agent/instrumentation/rack.rb +1 -1
  23. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +20 -20
  24. data/lib/new_relic/agent/instrumentation/rails/errors.rb +5 -5
  25. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +3 -3
  26. data/lib/new_relic/agent/instrumentation/rails4/action_controller.rb +3 -25
  27. data/lib/new_relic/agent/instrumentation/rails4/action_view.rb +2 -115
  28. data/lib/new_relic/agent/instrumentation/rails4/active_record.rb +2 -82
  29. data/lib/new_relic/agent/instrumentation/rails4/errors.rb +3 -4
  30. data/lib/new_relic/agent/method_tracer.rb +93 -56
  31. data/lib/new_relic/agent/null_logger.rb +6 -0
  32. data/lib/new_relic/agent/samplers/cpu_sampler.rb +9 -4
  33. data/lib/new_relic/agent/sql_sampler.rb +10 -6
  34. data/lib/new_relic/agent/stats_engine/metric_stats.rb +19 -3
  35. data/lib/new_relic/agent/stats_engine/transactions.rb +53 -34
  36. data/lib/new_relic/agent/system_info.rb +54 -0
  37. data/lib/new_relic/agent/thread.rb +2 -2
  38. data/lib/new_relic/agent/transaction/pop.rb +52 -0
  39. data/lib/new_relic/agent/transaction.rb +388 -0
  40. data/lib/new_relic/agent/transaction_info.rb +5 -13
  41. data/lib/new_relic/agent/transaction_sample_builder.rb +13 -20
  42. data/lib/new_relic/agent/transaction_sampler.rb +13 -15
  43. data/lib/new_relic/agent/uri_util.rb +35 -0
  44. data/lib/new_relic/agent.rb +54 -11
  45. data/lib/new_relic/build.rb +2 -2
  46. data/lib/new_relic/control/frameworks/rails.rb +0 -1
  47. data/lib/new_relic/control/frameworks/rails3.rb +2 -0
  48. data/lib/new_relic/control/frameworks/rails4.rb +0 -4
  49. data/lib/new_relic/control/instance_methods.rb +5 -19
  50. data/lib/new_relic/control/server_methods.rb +2 -0
  51. data/lib/new_relic/environment_report.rb +4 -34
  52. data/lib/new_relic/latest_changes.rb +1 -1
  53. data/lib/new_relic/local_environment.rb +0 -6
  54. data/lib/new_relic/metric_spec.rb +2 -2
  55. data/lib/new_relic/rack/error_collector.rb +6 -4
  56. data/lib/new_relic/transaction_sample.rb +7 -1
  57. data/lib/new_relic/version.rb +1 -1
  58. data/lib/newrelic_rpm.rb +2 -2
  59. data/newrelic.yml +20 -20
  60. data/test/config/test_control.rb +2 -2
  61. data/test/multiverse/suites/agent_only/audit_log_test.rb +1 -1
  62. data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +0 -2
  63. data/test/multiverse/suites/agent_only/logging_test.rb +1 -1
  64. data/test/multiverse/suites/agent_only/marshaling_test.rb +5 -3
  65. data/test/multiverse/suites/agent_only/rename_rule_test.rb +2 -0
  66. data/test/multiverse/suites/agent_only/set_transaction_name_test.rb +96 -0
  67. data/test/multiverse/suites/agent_only/testing_app.rb +1 -0
  68. data/test/multiverse/suites/rails/error_tracing_test.rb +17 -29
  69. data/test/multiverse/suites/rails/queue_time_test.rb +8 -2
  70. data/test/multiverse/suites/rails/view_instrumentation_test.rb +6 -3
  71. data/test/multiverse/suites/resque/instrumentation_test.rb +1 -1
  72. data/test/multiverse/suites/sinatra/sinatra_error_tracing_test.rb +8 -0
  73. data/test/new_relic/agent/agent/connect_test.rb +2 -1
  74. data/test/new_relic/agent/agent/start_test.rb +0 -10
  75. data/test/new_relic/agent/agent_logger_test.rb +15 -0
  76. data/test/new_relic/agent/agent_test_controller.rb +6 -2
  77. data/test/new_relic/agent/agent_test_controller_test.rb +20 -69
  78. data/test/new_relic/agent/autostart_test.rb +67 -0
  79. data/test/new_relic/agent/browser_monitoring_test.rb +60 -38
  80. data/test/new_relic/agent/configuration/environment_source_test.rb +19 -17
  81. data/test/new_relic/agent/cross_app_monitor_test.rb +8 -0
  82. data/test/new_relic/agent/error_collector/notice_error_test.rb +0 -5
  83. data/test/new_relic/agent/error_collector_test.rb +8 -9
  84. data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +228 -0
  85. data/test/new_relic/agent/instrumentation/action_view_subscriber_test.rb +18 -34
  86. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +5 -5
  87. data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +8 -9
  88. data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +1 -1
  89. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +24 -38
  90. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +126 -178
  91. data/test/new_relic/agent/instrumentation/rack_test.rb +1 -1
  92. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +135 -151
  93. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +153 -81
  94. data/test/new_relic/agent/method_tracer_test.rb +42 -33
  95. data/test/new_relic/agent/mock_scope_listener.rb +4 -4
  96. data/test/new_relic/agent/pipe_channel_manager_test.rb +4 -2
  97. data/test/new_relic/agent/rpm_agent_test.rb +86 -89
  98. data/test/new_relic/agent/sql_sampler_test.rb +18 -19
  99. data/test/new_relic/agent/stats_engine/gc_profiler_test.rb +5 -8
  100. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +20 -8
  101. data/test/new_relic/agent/stats_engine/samplers_test.rb +31 -14
  102. data/test/new_relic/agent/stats_engine_test.rb +53 -60
  103. data/test/new_relic/agent/thread_test.rb +7 -7
  104. data/test/new_relic/agent/transaction/pop_test.rb +96 -0
  105. data/test/new_relic/agent/transaction_info_test.rb +6 -17
  106. data/test/new_relic/agent/transaction_sample_builder_test.rb +10 -18
  107. data/test/new_relic/agent/transaction_sampler_test.rb +80 -75
  108. data/test/new_relic/agent/{instrumentation/metric_frame_test.rb → transaction_test.rb} +76 -42
  109. data/test/new_relic/agent/uri_util_test.rb +75 -0
  110. data/test/new_relic/agent_test.rb +115 -9
  111. data/test/test_helper.rb +138 -9
  112. data.tar.gz.sig +0 -0
  113. metadata +37 -74
  114. metadata.gz.sig +0 -0
  115. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +0 -84
  116. data/lib/new_relic/agent/instrumentation/metric_frame.rb +0 -353
  117. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +0 -175
  118. data/test/test_contexts.rb +0 -34
@@ -2,9 +2,8 @@
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
  require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
5
- require 'new_relic/agent/instrumentation/rails4/active_record'
5
+ require 'new_relic/agent/instrumentation/active_record_subscriber'
6
6
 
7
- if ::Rails::VERSION::MAJOR.to_i >= 4 && !NewRelic::LanguageSupport.using_engine?('jruby')
8
7
  class NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest < Test::Unit::TestCase
9
8
  class Order; end
10
9
 
@@ -42,8 +41,9 @@ class NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest < Test::Unit:
42
41
  t1 = Time.now
43
42
  t0 = t1 - 2
44
43
 
45
- @stats_engine.start_transaction('test_txn')
46
- @subscriber.call('sql.active_record', t0, t1, :id, @params)
44
+ in_transaction('test_txn') do
45
+ @subscriber.call('sql.active_record', t0, t1, :id, @params)
46
+ end
47
47
 
48
48
  metric_name = 'ActiveRecord/NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest::Order/find'
49
49
 
@@ -96,14 +96,14 @@ class NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest < Test::Unit:
96
96
  t0 = t1 - 2
97
97
 
98
98
  NewRelic::Agent.manual_start
99
- @stats_engine.start_transaction('test')
99
+ @stats_engine.start_transaction
100
100
  sampler = NewRelic::Agent.instance.transaction_sampler
101
101
  sampler.notice_first_scope_push(Time.now.to_f)
102
- sampler.notice_transaction('/path', '/path', {})
102
+ sampler.notice_transaction('/path', {})
103
103
  sampler.notice_push_scope('Controller/sandwiches/index')
104
104
  @subscriber.call('sql.active_record', t0, t1, :id, @params)
105
105
  sampler.notice_pop_scope('Controller/sandwiches/index')
106
- sampler.notice_scope_empty
106
+ sampler.notice_scope_empty(stub('txn', :name => '/path', :custom_parameters => {}))
107
107
 
108
108
  last_segment = nil
109
109
  sampler.last_sample.root_segment.each_segment{|s| last_segment = s }
@@ -128,5 +128,4 @@ class NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest < Test::Unit:
128
128
  ensure
129
129
  NewRelic::Agent.shutdown
130
130
  end
131
- end
132
- end
131
+ end if ::Rails::VERSION::MAJOR.to_i >= 4 && !NewRelic::LanguageSupport.using_engine?('jruby')
@@ -10,7 +10,7 @@ module NewRelic::Agent::Instrumentation
10
10
  def setup
11
11
  Time.stubs(:now).returns(Time.at(2000))
12
12
  @transaction = stub(
13
- :transaction_name => "Name",
13
+ :transaction => stub(:name => "Name"),
14
14
  :start_time => 0
15
15
  )
16
16
  end
@@ -11,6 +11,8 @@ class NewRelic::Agent::Instrumentation::ControllerInstrumentationTest < Test::Un
11
11
 
12
12
  def setup
13
13
  @object = TestObject.new
14
+ @txn_namer = NewRelic::Agent::Instrumentation:: \
15
+ ControllerInstrumentation::TransactionNamer.new(@object)
14
16
  end
15
17
 
16
18
  def test_detect_upstream_wait_basic
@@ -43,69 +45,53 @@ class NewRelic::Agent::Instrumentation::ControllerInstrumentationTest < Test::Un
43
45
 
44
46
  def test_transaction_name_calls_newrelic_metric_path
45
47
  @object.stubs(:newrelic_metric_path).returns('some/wacky/path')
46
- assert_equal('Controller/some/wacky/path', @object.send(:transaction_name))
48
+ assert_equal('Controller/some/wacky/path', @txn_namer.name)
47
49
  end
48
50
 
49
51
  def test_transaction_name_applies_category_and_path
50
52
  assert_equal('Controller/metric/path',
51
- @object.send(:transaction_name,
52
- :category => :controller,
53
- :path => 'metric/path'))
53
+ @txn_namer.name(:category => :controller,
54
+ :path => 'metric/path'))
54
55
  assert_equal('OtherTransaction/Background/metric/path',
55
- @object.send(:transaction_name,
56
- :category => :task, :path => 'metric/path'))
56
+ @txn_namer.name(:category => :task,
57
+ :path => 'metric/path'))
57
58
  assert_equal('Controller/Rack/metric/path',
58
- @object.send(:transaction_name,
59
- :category => :rack, :path => 'metric/path'))
59
+ @txn_namer.name(:category => :rack,
60
+ :path => 'metric/path'))
60
61
  assert_equal('Controller/metric/path',
61
- @object.send(:transaction_name,
62
- :category => :uri, :path => 'metric/path'))
62
+ @txn_namer.name(:category => :uri,
63
+ :path => 'metric/path'))
63
64
  assert_equal('Controller/Sinatra/metric/path',
64
- @object.send(:transaction_name,
65
- :category => :sinatra,
66
- :path => 'metric/path'))
65
+ @txn_namer.name(:category => :sinatra,
66
+ :path => 'metric/path'))
67
67
  assert_equal('Blarg/metric/path',
68
- @object.send(:transaction_name,
69
- :category => 'Blarg', :path => 'metric/path'))
70
-
68
+ @txn_namer.name(:category => 'Blarg',
69
+ :path => 'metric/path'))
71
70
  end
72
71
 
73
72
  def test_transaction_name_uses_class_name_if_path_not_specified
74
73
  assert_equal('Controller/NewRelic::Agent::Instrumentation::ControllerInstrumentationTest::TestObject',
75
- @object.send(:transaction_name, :category => :controller))
74
+ @txn_namer.name(:category => :controller))
76
75
  end
77
76
 
78
77
  def test_transaction_name_applies_action_name_if_specified_and_not_path
79
78
  assert_equal('Controller/NewRelic::Agent::Instrumentation::ControllerInstrumentationTest::TestObject/action',
80
- @object.send(:transaction_name, :category => :controller,
81
- :name => 'action'))
82
- end
83
-
84
- def test_transaction_name_applies_name_rules
85
- rule = NewRelic::Agent::RulesEngine::Rule.new('match_expression' => '[0-9]+',
86
- 'replacement' => '*',
87
- 'replace_all' => true)
88
- NewRelic::Agent.instance.transaction_rules << rule
89
- assert_equal('foo/*/bar/*',
90
- @object.send(:transaction_name, :category => 'foo',
91
- :path => '1/bar/22'))
92
- ensure
93
- NewRelic::Agent.instance.instance_variable_set(:@transaction_rules,
94
- NewRelic::Agent::RulesEngine.new)
79
+ @txn_namer.name(:category => :controller,
80
+ :name => 'action'))
95
81
  end
96
82
 
97
- def test_path_class_and_action
98
- result = @object.send(:path_class_and_action, {})
83
+ def test_transaction_path_name
84
+ result = @txn_namer.path_name
99
85
  assert_equal("NewRelic::Agent::Instrumentation::ControllerInstrumentationTest::TestObject", result)
100
86
  end
101
87
 
102
- def test_path_class_and_action_with_name
103
- result = @object.send(:path_class_and_action, :name => "test")
88
+ def test_transaction_path_name_with_name
89
+ result = @txn_namer.path_name(:name => "test")
104
90
  assert_equal("NewRelic::Agent::Instrumentation::ControllerInstrumentationTest::TestObject/test", result)
105
91
  end
106
92
 
107
- def test_path_class_and_action_with_overridden_class_name
108
- result = @object.send(:path_class_and_action, :name => "perform", :class_name => 'Resque')
93
+ def test_transaction_path_name_with_overridden_class_name
94
+ result = @txn_namer.path_name(:name => "perform", :class_name => 'Resque')
109
95
  assert_equal("Resque/perform", result)
110
96
  end
111
97
  end
@@ -59,26 +59,19 @@ class NewRelic::Agent::Instrumentation::NetInstrumentationTest < Test::Unit::Tes
59
59
  :encoding_key => 'gringletoes'
60
60
  )
61
61
 
62
+ @response = CANNED_RESPONSE.clone
63
+ @socket = fixture_tcp_socket( @response )
64
+
62
65
  # $stderr.puts '', '---', ''
63
66
  # NewRelic::Agent.logger = NewRelic::Agent::AgentLogger.new( {:log_level => 'debug'}, '', Logger.new($stderr) )
64
67
 
65
68
  @engine = NewRelic::Agent.instance.stats_engine
66
69
  @engine.clear_stats
67
70
 
68
- @engine.start_transaction( 'test' )
69
- NewRelic::Agent::TransactionInfo.get.guid = TRANSACTION_GUID
70
71
 
71
72
  @sampler = NewRelic::Agent.instance.transaction_sampler
72
- @sampler.notice_first_scope_push( Time.now.to_f )
73
- @sampler.notice_transaction( '/path', '/path', {} )
74
- @sampler.notice_push_scope "Controller/sandwiches/index"
75
- @sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'wheat'", nil, 0)
76
- @sampler.notice_push_scope "ab"
77
- @sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'white'", nil, 0)
78
- @sampler.notice_push_scope "fetch_external_service"
73
+ NewRelic::Agent::TransactionInfo.get.guid = TRANSACTION_GUID
79
74
 
80
- @response = CANNED_RESPONSE.clone
81
- @socket = fixture_tcp_socket( @response )
82
75
  end
83
76
 
84
77
  def teardown
@@ -92,47 +85,6 @@ class NewRelic::Agent::Instrumentation::NetInstrumentationTest < Test::Unit::Tes
92
85
  # Helpers
93
86
  #
94
87
 
95
- def fixture_tcp_socket( response )
96
-
97
- # Don't actually talk to Google.
98
- socket = stub("socket") do
99
- stubs(:closed?).returns(false)
100
- stubs(:close)
101
-
102
- # Simulate a bunch of socket-ey stuff since Mocha doesn't really
103
- # provide any other way to do it
104
- class << self
105
- attr_accessor :response, :write_checker
106
- end
107
-
108
- def self.check_write
109
- self.write_checker = Proc.new
110
- end
111
-
112
- def self.write( buf )
113
- self.write_checker.call( buf ) if self.write_checker
114
- buf.length
115
- end
116
-
117
- def self.sysread( size, buf='' )
118
- @data ||= response.to_s
119
- raise EOFError if @data.empty?
120
- buf.replace @data.slice!( 0, size )
121
- buf
122
- end
123
- class << self
124
- alias_method :read_nonblock, :sysread
125
- end
126
-
127
- end
128
-
129
- socket.response = response
130
- TCPSocket.stubs( :open ).returns( socket )
131
-
132
- return socket
133
- end
134
-
135
-
136
88
  def make_app_data_payload( *args )
137
89
  return obfuscate_with_key( 'gringletoes', args.to_json ).gsub( /\n/, '' ) + "\n"
138
90
  end
@@ -157,14 +109,14 @@ class NewRelic::Agent::Instrumentation::NetInstrumentationTest < Test::Unit::Tes
157
109
  res = Net::HTTP.start(url.host, url.port) {|http|
158
110
  http.get('/index.html')
159
111
  }
160
-
161
- assert_match %r/<head>/i, res.body
162
- assert_includes @engine.metrics, 'External/all'
163
- assert_includes @engine.metrics, 'External/www.google.com/Net::HTTP/GET'
164
- assert_includes @engine.metrics, 'External/allOther'
165
- assert_includes @engine.metrics, 'External/www.google.com/all'
166
112
 
167
- assert_not_includes @engine.metrics, 'External/allWeb'
113
+ assert_match %r/<head>/i, res.body
114
+ assert_metrics_recorded_exclusive([
115
+ 'External/all',
116
+ 'External/www.google.com/Net::HTTP/GET',
117
+ 'External/allOther',
118
+ 'External/www.google.com/all'
119
+ ])
168
120
  end
169
121
 
170
122
  def test_background
@@ -178,15 +130,16 @@ class NewRelic::Agent::Instrumentation::NetInstrumentationTest < Test::Unit::Tes
178
130
  end
179
131
 
180
132
  assert_match %r/<head>/i, res.body
181
-
182
- assert_includes @engine.metrics, 'External/all'
183
- assert_includes @engine.metrics, 'External/www.google.com/Net::HTTP/GET'
184
- assert_includes @engine.metrics, 'External/allOther'
185
- assert_includes @engine.metrics, 'External/www.google.com/all'
186
- assert_includes @engine.metrics,
187
- 'OtherTransaction/Background/NewRelic::Agent::Instrumentation::NetInstrumentationTest/task'
188
-
189
- assert_not_includes @engine.metrics, 'External/allWeb'
133
+ assert_metrics_recorded_exclusive([
134
+ 'External/all',
135
+ 'External/allOther',
136
+ 'External/www.google.com/all',
137
+ 'External/www.google.com/Net::HTTP/GET',
138
+ ['External/www.google.com/Net::HTTP/GET', 'OtherTransaction/Background/NewRelic::Agent::Instrumentation::NetInstrumentationTest/task'],
139
+ 'OtherTransaction/Background/NewRelic::Agent::Instrumentation::NetInstrumentationTest/task',
140
+ 'OtherTransaction/Background/all',
141
+ 'OtherTransaction/all'
142
+ ])
190
143
  end
191
144
 
192
145
  def test_transactional
@@ -200,13 +153,13 @@ class NewRelic::Agent::Instrumentation::NetInstrumentationTest < Test::Unit::Tes
200
153
  end
201
154
 
202
155
  assert_match %r/<head>/i, res.body
203
-
204
- assert_includes @engine.metrics, 'External/all'
205
- assert_includes @engine.metrics, 'External/www.google.com/Net::HTTP/GET'
206
- assert_includes @engine.metrics, 'External/allWeb'
207
- assert_includes @engine.metrics, 'External/www.google.com/all'
208
- assert_includes @engine.metrics,
156
+ assert_metrics_recorded([
157
+ 'External/all',
158
+ 'External/www.google.com/Net::HTTP/GET',
159
+ 'External/allWeb',
160
+ 'External/www.google.com/all',
209
161
  'Controller/NewRelic::Agent::Instrumentation::NetInstrumentationTest/task'
162
+ ])
210
163
 
211
164
  assert_not_includes @engine.metrics, 'External/allOther'
212
165
  end
@@ -214,42 +167,39 @@ class NewRelic::Agent::Instrumentation::NetInstrumentationTest < Test::Unit::Tes
214
167
  def test_get__simple
215
168
  Net::HTTP.get URI.parse('http://www.google.com/index.html')
216
169
 
217
- assert_includes @engine.metrics, 'External/all'
218
- assert_includes @engine.metrics, 'External/www.google.com/Net::HTTP/GET'
219
- assert_includes @engine.metrics, 'External/allOther'
220
- assert_includes @engine.metrics, 'External/www.google.com/all'
221
-
222
- assert_not_includes @engine.metrics, 'External/allWeb'
170
+ assert_metrics_recorded_exclusive([
171
+ 'External/all',
172
+ 'External/www.google.com/Net::HTTP/GET',
173
+ 'External/allOther',
174
+ 'External/www.google.com/all'
175
+ ])
223
176
  end
224
177
 
225
178
  def test_ignore
226
- NewRelic::Agent.disable_all_tracing do
227
- url = URI.parse('http://www.google.com/index.html')
228
- res = Net::HTTP.start(url.host, url.port) {|http|
229
- http.post('/index.html','data')
230
- }
179
+ in_transaction do
180
+ NewRelic::Agent.disable_all_tracing do
181
+ url = URI.parse('http://www.google.com/index.html')
182
+ res = Net::HTTP.start(url.host, url.port) {|http|
183
+ http.post('/index.html','data')
184
+ }
185
+ end
231
186
  end
232
187
 
233
- assert_not_includes @engine.metrics, 'External/all'
234
- assert_not_includes @engine.metrics, 'External/www.google.com/Net::HTTP/GET'
235
- assert_not_includes @engine.metrics, 'External/allOther'
236
- assert_not_includes @engine.metrics, 'External/www.google.com/all'
237
-
238
- assert_not_includes @engine.metrics, 'External/allWeb'
188
+ assert_metrics_recorded_exclusive([])
239
189
  end
240
-
190
+
241
191
  def test_head
242
192
  url = URI.parse('http://www.google.com/index.html')
243
193
  res = Net::HTTP.start(url.host, url.port) {|http|
244
194
  http.head('/index.html')
245
195
  }
246
196
 
247
- assert_includes @engine.metrics, 'External/all'
248
- assert_includes @engine.metrics, 'External/www.google.com/Net::HTTP/HEAD'
249
- assert_includes @engine.metrics, 'External/allOther'
250
- assert_includes @engine.metrics, 'External/www.google.com/all'
251
-
252
- assert_not_includes @engine.metrics, 'External/allWeb'
197
+ assert_metrics_recorded_exclusive([
198
+ 'External/all',
199
+ 'External/www.google.com/Net::HTTP/HEAD',
200
+ 'External/allOther',
201
+ 'External/www.google.com/all'
202
+ ])
253
203
  end
254
204
 
255
205
  def test_post
@@ -258,12 +208,12 @@ class NewRelic::Agent::Instrumentation::NetInstrumentationTest < Test::Unit::Tes
258
208
  http.post('/index.html','data')
259
209
  }
260
210
 
261
- assert_includes @engine.metrics, 'External/all'
262
- assert_includes @engine.metrics, 'External/www.google.com/Net::HTTP/POST'
263
- assert_includes @engine.metrics, 'External/allOther'
264
- assert_includes @engine.metrics, 'External/www.google.com/all'
265
-
266
- assert_not_includes @engine.metrics, 'External/allWeb'
211
+ assert_metrics_recorded_exclusive([
212
+ 'External/all',
213
+ 'External/www.google.com/Net::HTTP/POST',
214
+ 'External/allOther',
215
+ 'External/www.google.com/all'
216
+ ])
267
217
  end
268
218
 
269
219
  # When an http call is made, the agent should add a request header named
@@ -276,7 +226,7 @@ class NewRelic::Agent::Instrumentation::NetInstrumentationTest < Test::Unit::Tes
276
226
  # The above assertion won't work in Ruby 2.0.0-p0 because of a bug in the
277
227
  # regexp engine. Until that's fixed we'll check the header name case
278
228
  # sensitively.
279
- assert_match /X-Newrelic-Id: VURQV1BZRkZdXUFT/, data
229
+ assert_match(/X-Newrelic-Id: VURQV1BZRkZdXUFT/, data)
280
230
  end
281
231
 
282
232
  with_config(:"cross_application_tracer.enabled" => true) do
@@ -290,7 +240,7 @@ class NewRelic::Agent::Instrumentation::NetInstrumentationTest < Test::Unit::Tes
290
240
  # The above assertion won't work in Ruby 2.0.0-p0 because of a bug in the
291
241
  # regexp engine. Until that's fixed we'll check the header name case
292
242
  # sensitively.
293
- assert_match /X-Newrelic-Id: VURQV1BZRkZdXUFT/, data
243
+ assert_match(/X-Newrelic-Id: VURQV1BZRkZdXUFT/, data)
294
244
  end
295
245
 
296
246
  with_config(:cross_application_tracing => true) do
@@ -304,7 +254,7 @@ class NewRelic::Agent::Instrumentation::NetInstrumentationTest < Test::Unit::Tes
304
254
  # The above assertion won't work in Ruby 2.0.0-p0 because of a bug in the
305
255
  # regexp engine. Until that's fixed we'll check the header name case
306
256
  # sensitively.
307
- assert_no_match /X-Newrelic-Id: VURQV1BZRkZdXUFT/, data
257
+ assert_no_match(/X-Newrelic-Id: VURQV1BZRkZdXUFT/, data)
308
258
  end
309
259
 
310
260
  Net::HTTP.get URI.parse('http://www.google.com/index.html')
@@ -313,40 +263,35 @@ class NewRelic::Agent::Instrumentation::NetInstrumentationTest < Test::Unit::Tes
313
263
 
314
264
  def test_instrumentation_with_crossapp_enabled_records_normal_metrics_if_no_header_present
315
265
  with_config(:"cross_application_tracer.enabled" => true) do
316
- Net::HTTP.get URI.parse('http://www.google.com/index.html')
266
+ in_transaction('test') do
267
+ Net::HTTP.get URI.parse('http://www.google.com/index.html')
268
+ end
317
269
  end
318
270
 
319
- assert_equal 5, @engine.metrics.length
320
-
321
- assert_includes @engine.metrics, 'External/all'
322
- assert_includes @engine.metrics, 'External/allOther'
323
- assert_includes @engine.metrics, 'External/www.google.com/Net::HTTP/GET'
324
- assert_includes @engine.metrics, 'External/www.google.com/all'
325
- assert_includes @engine.metrics, 'External/www.google.com/Net::HTTP/GET:test'
326
-
327
- assert_not_includes @engine.metrics, 'ExternalApp/www.google.com/18#1884/all'
328
- assert_not_includes @engine.metrics, 'ExternalTransaction/www.google.com/18#1884/txn-name'
329
- assert_not_includes @engine.metrics, 'External/allWeb'
271
+ assert_metrics_recorded_exclusive([
272
+ 'External/all',
273
+ 'External/allOther',
274
+ 'External/www.google.com/all',
275
+ 'External/www.google.com/Net::HTTP/GET',
276
+ ['External/www.google.com/Net::HTTP/GET', 'test']
277
+ ])
330
278
  end
331
279
 
332
-
333
280
  def test_instrumentation_with_crossapp_disabled_records_normal_metrics_even_if_header_is_present
334
281
  @response[ NR_APPDATA_HEADER ] =
335
282
  make_app_data_payload( '18#1884', 'txn-name', 2, 8, 0, TRANSACTION_GUID )
336
283
 
337
- Net::HTTP.get URI.parse('http://www.google.com/index.html')
338
-
339
- assert_equal 5, @engine.metrics.length
340
-
341
- assert_includes @engine.metrics, 'External/all'
342
- assert_includes @engine.metrics, 'External/allOther'
343
- assert_includes @engine.metrics, 'External/www.google.com/Net::HTTP/GET'
344
- assert_includes @engine.metrics, 'External/www.google.com/all'
345
- assert_includes @engine.metrics, 'External/www.google.com/Net::HTTP/GET:test'
284
+ in_transaction('test') do
285
+ Net::HTTP.get URI.parse('http://www.google.com/index.html')
286
+ end
346
287
 
347
- assert_not_includes @engine.metrics, 'ExternalApp/www.google.com/18#1884/all'
348
- assert_not_includes @engine.metrics, 'ExternalTransaction/www.google.com/18#1884/txn-name'
349
- assert_not_includes @engine.metrics, 'External/allWeb'
288
+ assert_metrics_recorded_exclusive([
289
+ 'External/all',
290
+ 'External/allOther',
291
+ 'External/www.google.com/all',
292
+ 'External/www.google.com/Net::HTTP/GET',
293
+ ['External/www.google.com/Net::HTTP/GET', 'test']
294
+ ])
350
295
  end
351
296
 
352
297
 
@@ -355,25 +300,23 @@ class NewRelic::Agent::Instrumentation::NetInstrumentationTest < Test::Unit::Tes
355
300
  make_app_data_payload( '18#1884', 'txn-name', 2, 8, 0, TRANSACTION_GUID )
356
301
 
357
302
  with_config(:"cross_application_tracer.enabled" => true) do
358
- Net::HTTP.get URI.parse('http://www.google.com/index.html')
359
- end
360
-
361
- assert_equal 6, @engine.metrics.length
303
+ in_transaction('test') do
304
+ Net::HTTP.get URI.parse('http://www.google.com/index.html')
362
305
 
363
- assert_includes @engine.metrics, 'External/all'
364
- assert_includes @engine.metrics, 'External/allOther'
365
- assert_includes @engine.metrics, 'ExternalApp/www.google.com/18#1884/all'
366
- assert_includes @engine.metrics, 'ExternalTransaction/www.google.com/18#1884/txn-name'
367
- assert_includes @engine.metrics, 'External/www.google.com/all'
368
- assert_includes @engine.metrics, 'ExternalTransaction/www.google.com/18#1884/txn-name:test'
369
-
370
- assert_not_includes @engine.metrics, 'External/www.google.com/Net::HTTP/GET'
371
- assert_not_includes @engine.metrics, 'External/allWeb'
372
-
373
- last_segment = find_last_segment()
306
+ last_segment = find_last_segment()
307
+ assert_includes last_segment.params.keys, :transaction_guid
308
+ assert_equal TRANSACTION_GUID, last_segment.params[:transaction_guid]
309
+ end
310
+ end
374
311
 
375
- assert_includes last_segment.params.keys, :transaction_guid
376
- assert_equal TRANSACTION_GUID, last_segment.params[:transaction_guid]
312
+ assert_metrics_recorded_exclusive([
313
+ 'External/all',
314
+ 'External/allOther',
315
+ 'ExternalApp/www.google.com/18#1884/all',
316
+ 'ExternalTransaction/www.google.com/18#1884/txn-name',
317
+ 'External/www.google.com/all',
318
+ ['ExternalTransaction/www.google.com/18#1884/txn-name', 'test']
319
+ ])
377
320
  end
378
321
 
379
322
  def test_crossapp_metrics_allow_valid_utf8_characters
@@ -381,25 +324,23 @@ class NewRelic::Agent::Instrumentation::NetInstrumentationTest < Test::Unit::Tes
381
324
  make_app_data_payload( '12#1114', '世界線航跡蔵', 18.0, 88.1, 4096, TRANSACTION_GUID )
382
325
 
383
326
  with_config(:"cross_application_tracer.enabled" => true) do
384
- Net::HTTP.get URI.parse('http://www.google.com/index.html')
385
- end
386
-
387
- assert_equal 6, @engine.metrics.length
388
-
389
- assert_includes @engine.metrics, 'External/all'
390
- assert_includes @engine.metrics, 'External/allOther'
391
- assert_includes @engine.metrics, 'ExternalApp/www.google.com/12#1114/all'
392
- assert_includes @engine.metrics, 'ExternalTransaction/www.google.com/12#1114/世界線航跡蔵'
393
- assert_includes @engine.metrics, 'External/www.google.com/all'
394
- assert_includes @engine.metrics, 'ExternalTransaction/www.google.com/12#1114/世界線航跡蔵:test'
395
-
396
- assert_not_includes @engine.metrics, 'External/www.google.com/Net::HTTP/GET'
397
- assert_not_includes @engine.metrics, 'External/allWeb'
327
+ in_transaction('test') do
328
+ Net::HTTP.get URI.parse('http://www.google.com/index.html')
398
329
 
399
- last_segment = find_last_segment()
330
+ last_segment = find_last_segment()
331
+ assert_includes last_segment.params.keys, :transaction_guid
332
+ assert_equal TRANSACTION_GUID, last_segment.params[:transaction_guid]
333
+ end
334
+ end
400
335
 
401
- assert_includes last_segment.params.keys, :transaction_guid
402
- assert_equal TRANSACTION_GUID, last_segment.params[:transaction_guid]
336
+ assert_metrics_recorded_exclusive([
337
+ 'External/all',
338
+ 'External/allOther',
339
+ 'ExternalApp/www.google.com/12#1114/all',
340
+ 'External/www.google.com/all',
341
+ 'ExternalTransaction/www.google.com/12#1114/世界線航跡蔵',
342
+ ['ExternalTransaction/www.google.com/12#1114/世界線航跡蔵', 'test']
343
+ ])
403
344
  end
404
345
 
405
346
  def test_crossapp_metrics_ignores_crossapp_header_with_malformed_crossprocess_id
@@ -407,20 +348,18 @@ class NewRelic::Agent::Instrumentation::NetInstrumentationTest < Test::Unit::Tes
407
348
  make_app_data_payload( '88#88#88', 'invalid', 1, 2, 4096, TRANSACTION_GUID )
408
349
 
409
350
  with_config(:"cross_application_tracer.enabled" => true) do
410
- Net::HTTP.get URI.parse('http://www.google.com/index.html')
351
+ in_transaction('test') do
352
+ Net::HTTP.get URI.parse('http://www.google.com/index.html')
353
+ end
411
354
  end
412
355
 
413
- assert_equal 5, @engine.metrics.length
414
-
415
- assert_includes @engine.metrics, 'External/all'
416
- assert_includes @engine.metrics, 'External/allOther'
417
- assert_includes @engine.metrics, 'External/www.google.com/Net::HTTP/GET'
418
- assert_includes @engine.metrics, 'External/www.google.com/all'
419
- assert_includes @engine.metrics, 'External/www.google.com/Net::HTTP/GET:test'
420
-
421
- assert_not_includes @engine.metrics, 'ExternalApp/www.google.com/88#88#88/all'
422
- assert_not_includes @engine.metrics, 'ExternalTransaction/www.google.com/88#88#88/invalid'
423
- assert_not_includes @engine.metrics, 'External/allWeb'
356
+ assert_metrics_recorded_exclusive([
357
+ 'External/all',
358
+ 'External/allOther',
359
+ 'External/www.google.com/Net::HTTP/GET',
360
+ 'External/www.google.com/all',
361
+ ['External/www.google.com/Net::HTTP/GET', 'test']
362
+ ])
424
363
  end
425
364
 
426
365
  def test_doesnt_affect_the_request_if_an_exception_is_raised_while_setting_up_tracing
@@ -481,4 +420,13 @@ class NewRelic::Agent::Instrumentation::NetInstrumentationTest < Test::Unit::Tes
481
420
  @engine.transaction_sampler = NewRelic::Agent.agent.transaction_sampler
482
421
  end
483
422
 
423
+ def test_includes_full_url_in_transaction_trace
424
+ uri = 'http://www.google.com/index.html?foo=bar#fragment'
425
+ in_transaction do
426
+ Net::HTTP.get URI.parse(uri)
427
+ last_segment = find_last_segment()
428
+ filtered_uri = 'http://www.google.com/index.html'
429
+ assert_equal filtered_uri, last_segment.params[:uri]
430
+ end
431
+ end
484
432
  end
@@ -31,7 +31,7 @@ class NewRelic::Agent::Instrumentation::RackTest < Test::Unit::TestCase
31
31
  end
32
32
 
33
33
  def test_basic_rack_app_ignores_404
34
- NewRelic::Agent::Instrumentation::MetricFrame.expects(:abort_transaction!)
34
+ NewRelic::Agent::Transaction.expects(:abort_transaction!)
35
35
  x = MinimalRackApp.new([404, {}, ["whee"]])
36
36
  assert_equal [404, {}, ["whee"]], x.call({})
37
37
  end