oboe 2.7.16.1-java → 2.7.17.1-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,10 +5,12 @@ describe Oboe::Inst do
5
5
  before do
6
6
  clear_all_traces
7
7
  @collect_backtraces = Oboe::Config[:nethttp][:collect_backtraces]
8
+ @log_args = Oboe::Config[:nethttp][:log_args]
8
9
  end
9
10
 
10
11
  after do
11
12
  Oboe::Config[:nethttp][:collect_backtraces] = @collect_backtraces
13
+ Oboe::Config[:nethttp][:log_args] = @log_args
12
14
  end
13
15
 
14
16
  it 'Net::HTTP should be defined and ready' do
@@ -23,7 +25,7 @@ describe Oboe::Inst do
23
25
 
24
26
  it "should trace a Net::HTTP request to an instr'd app" do
25
27
  Oboe::API.start_trace('net-http_test', '', {}) do
26
- uri = URI('http://www.gameface.in/games?q=1')
28
+ uri = URI('http://127.0.0.1:8101/?q=1')
27
29
  http = Net::HTTP.new(uri.host, uri.port)
28
30
  request = Net::HTTP::Get.new(uri.request_uri)
29
31
  response = http.request(request)
@@ -32,52 +34,87 @@ describe Oboe::Inst do
32
34
  end
33
35
 
34
36
  traces = get_all_traces
35
- traces.count.must_equal 5
36
-
37
- # FIXME: We need to switch from making external calls to an internal test
38
- # stack instead so we can validate cross-app traces.
39
- # valid_edges?(traces).must_equal true
40
-
37
+ traces.count.must_equal 8
38
+ valid_edges?(traces).must_equal true
41
39
  validate_outer_layers(traces, 'net-http_test')
42
40
 
43
41
  traces[1]['Layer'].must_equal 'net-http'
44
- traces[2]['IsService'].must_equal 1
45
- traces[2]['RemoteProtocol'].must_equal "HTTP"
46
- traces[2]['RemoteHost'].must_equal "www.gameface.in"
47
- traces[2]['ServiceArg'].must_equal "/games?q=1"
48
- traces[2]['HTTPMethod'].must_equal "GET"
49
- traces[2]['HTTPStatus'].must_equal "200"
50
- traces[2].has_key?('Backtrace').must_equal Oboe::Config[:nethttp][:collect_backtraces]
42
+ traces[1]['Label'].must_equal 'entry'
43
+
44
+ traces[2]['Layer'].must_equal 'rack'
45
+ traces[2]['Label'].must_equal 'entry'
46
+
47
+ traces[3]['Layer'].must_equal 'rack'
48
+ traces[3]['Label'].must_equal 'info'
49
+
50
+ traces[4]['Layer'].must_equal 'rack'
51
+ traces[4]['Label'].must_equal 'exit'
52
+
53
+ traces[5]['IsService'].must_equal 1
54
+ traces[5]['RemoteProtocol'].must_equal "HTTP"
55
+ traces[5]['RemoteHost'].must_equal "127.0.0.1:8101"
56
+ traces[5]['ServiceArg'].must_equal "/?q=1"
57
+ traces[5]['HTTPMethod'].must_equal "GET"
58
+ traces[5]['HTTPStatus'].must_equal "200"
59
+ traces[5].has_key?('Backtrace').must_equal Oboe::Config[:nethttp][:collect_backtraces]
51
60
  end
52
61
 
53
- it "should trace a Net::HTTP request" do
62
+ it "should trace a GET request" do
54
63
  Oboe::API.start_trace('net-http_test', '', {}) do
55
- uri = URI('http://www.curlmyip.de')
64
+ uri = URI('http://127.0.0.1:8101/')
56
65
  http = Net::HTTP.new(uri.host, uri.port)
57
66
  http.get('/?q=1').read_body
58
67
  end
59
68
 
60
69
  traces = get_all_traces
61
- traces.count.must_equal 5
70
+ traces.count.must_equal 8
62
71
  valid_edges?(traces).must_equal true
63
72
 
64
73
  validate_outer_layers(traces, 'net-http_test')
65
74
 
66
75
  traces[1]['Layer'].must_equal 'net-http'
67
- traces[2]['IsService'].must_equal 1
68
- traces[2]['RemoteProtocol'].must_equal "HTTP"
69
- traces[2]['RemoteHost'].must_equal "www.curlmyip.de"
70
- traces[2]['ServiceArg'].must_equal "/?q=1"
71
- traces[2]['HTTPMethod'].must_equal "GET"
72
- traces[2]['HTTPStatus'].must_equal "200"
73
- traces[2].has_key?('Backtrace').must_equal Oboe::Config[:nethttp][:collect_backtraces]
76
+ traces[5]['IsService'].must_equal 1
77
+ traces[5]['RemoteProtocol'].must_equal "HTTP"
78
+ traces[5]['RemoteHost'].must_equal "127.0.0.1:8101"
79
+ traces[5]['ServiceArg'].must_equal "/?q=1"
80
+ traces[5]['HTTPMethod'].must_equal "GET"
81
+ traces[5]['HTTPStatus'].must_equal "200"
82
+ traces[5].has_key?('Backtrace').must_equal Oboe::Config[:nethttp][:collect_backtraces]
83
+ end
84
+
85
+ it "should obey :log_args setting when true" do
86
+ Oboe::Config[:nethttp][:log_args] = true
87
+
88
+ Oboe::API.start_trace('nethttp_test', '', {}) do
89
+ uri = URI('http://127.0.0.1:8101/')
90
+ http = Net::HTTP.new(uri.host, uri.port)
91
+ http.use_ssl = false
92
+ http.get('/?q=ruby_test_suite').read_body
93
+ end
94
+
95
+ traces = get_all_traces
96
+ traces[5]['ServiceArg'].must_equal '/?q=ruby_test_suite'
97
+ end
98
+
99
+ it "should obey :log_args setting when false" do
100
+ Oboe::Config[:nethttp][:log_args] = false
101
+
102
+ Oboe::API.start_trace('nethttp_test', '', {}) do
103
+ uri = URI('http://127.0.0.1:8101/')
104
+ http = Net::HTTP.new(uri.host, uri.port)
105
+ http.use_ssl = false
106
+ http.get('/?q=ruby_test_suite').read_body
107
+ end
108
+
109
+ traces = get_all_traces
110
+ traces[5]['ServiceArg'].must_equal '/'
74
111
  end
75
112
 
76
113
  it "should obey :collect_backtraces setting when true" do
77
114
  Oboe::Config[:nethttp][:collect_backtraces] = true
78
115
 
79
116
  Oboe::API.start_trace('nethttp_test', '', {}) do
80
- uri = URI('http://www.appneta.com')
117
+ uri = URI('http://127.0.0.1:8101/')
81
118
  http = Net::HTTP.new(uri.host, uri.port)
82
119
  http.use_ssl = false
83
120
  http.get('/?q=ruby_test_suite').read_body
@@ -91,7 +128,7 @@ describe Oboe::Inst do
91
128
  Oboe::Config[:nethttp][:collect_backtraces] = false
92
129
 
93
130
  Oboe::API.start_trace('nethttp_test', '', {}) do
94
- uri = URI('http://www.appneta.com')
131
+ uri = URI('http://127.0.0.1:8101/')
95
132
  http = Net::HTTP.new(uri.host, uri.port)
96
133
  http.use_ssl = false
97
134
  http.get('/?q=ruby_test_suite').read_body
@@ -0,0 +1,296 @@
1
+ require 'minitest_helper'
2
+ require 'oboe/inst/rack'
3
+ require File.expand_path(File.dirname(__FILE__) + '../../frameworks/apps/sinatra_simple')
4
+
5
+ class HTTPClientTest < Minitest::Test
6
+ include Rack::Test::Methods
7
+
8
+ def app
9
+ SinatraSimple
10
+ end
11
+
12
+ def test_reports_version_init
13
+ init_kvs = ::Oboe::Util.build_init_report
14
+ assert init_kvs.key?('Ruby.HTTPClient.Version')
15
+ assert_equal init_kvs['Ruby.HTTPClient.Version'], "HTTPClient-#{::HTTPClient::VERSION}"
16
+ end
17
+
18
+ def test_get_request
19
+ clear_all_traces
20
+
21
+ response = nil
22
+
23
+ Oboe::API.start_trace('httpclient_tests') do
24
+ clnt = HTTPClient.new
25
+ response = clnt.get('http://127.0.0.1:8101/', :query => { :keyword => 'ruby', :lang => 'en' })
26
+ end
27
+
28
+ traces = get_all_traces
29
+
30
+ # Validate returned xtrace
31
+ assert response.headers.key?("X-Trace")
32
+ assert Oboe::XTrace.valid?(response.headers["X-Trace"])
33
+
34
+ assert_equal traces.count, 7
35
+ valid_edges?(traces)
36
+ validate_outer_layers(traces, "httpclient_tests")
37
+
38
+ assert_equal traces[1]['IsService'], 1
39
+ assert_equal traces[1]['RemoteURL'], 'http://127.0.0.1:8101/?keyword=ruby&lang=en'
40
+ assert_equal traces[1]['HTTPMethod'], 'GET'
41
+ assert traces[1].key?('Backtrace')
42
+
43
+ assert_equal traces[5]['Layer'], 'httpclient'
44
+ assert_equal traces[5]['Label'], 'exit'
45
+ assert_equal traces[5]['HTTPStatus'], 200
46
+ end
47
+
48
+ def test_get_with_header_hash
49
+ clear_all_traces
50
+
51
+ response = nil
52
+
53
+ Oboe::API.start_trace('httpclient_tests') do
54
+ clnt = HTTPClient.new
55
+ response = clnt.get('http://127.0.0.1:8101/', nil, { "SOAPAction" => "HelloWorld" })
56
+ end
57
+
58
+ traces = get_all_traces
59
+
60
+ xtrace = response.headers['X-Trace']
61
+ assert xtrace
62
+ assert Oboe::XTrace.valid?(xtrace)
63
+
64
+ assert_equal traces.count, 7
65
+ valid_edges?(traces)
66
+ validate_outer_layers(traces, "httpclient_tests")
67
+
68
+ assert_equal traces[1]['IsService'], 1
69
+ assert_equal traces[1]['RemoteURL'], 'http://127.0.0.1:8101/'
70
+ assert_equal traces[1]['HTTPMethod'], 'GET'
71
+ assert traces[1].key?('Backtrace')
72
+
73
+ assert_equal traces[5]['Layer'], 'httpclient'
74
+ assert_equal traces[5]['Label'], 'exit'
75
+ assert_equal traces[5]['HTTPStatus'], 200
76
+ end
77
+
78
+ def test_get_with_header_array
79
+ clear_all_traces
80
+
81
+ response = nil
82
+
83
+ Oboe::API.start_trace('httpclient_tests') do
84
+ clnt = HTTPClient.new
85
+ response = clnt.get('http://127.0.0.1:8101/', nil, [["Accept", "text/plain"], ["Accept", "text/html"]])
86
+ end
87
+
88
+ traces = get_all_traces
89
+
90
+ xtrace = response.headers['X-Trace']
91
+ assert xtrace
92
+ assert Oboe::XTrace.valid?(xtrace)
93
+
94
+ assert_equal traces.count, 7
95
+ valid_edges?(traces)
96
+ validate_outer_layers(traces, "httpclient_tests")
97
+
98
+ assert_equal traces[1]['IsService'], 1
99
+ assert_equal traces[1]['RemoteURL'], 'http://127.0.0.1:8101/'
100
+ assert_equal traces[1]['HTTPMethod'], 'GET'
101
+ assert traces[1].key?('Backtrace')
102
+
103
+ assert_equal traces[5]['Layer'], 'httpclient'
104
+ assert_equal traces[5]['Label'], 'exit'
105
+ assert_equal traces[5]['HTTPStatus'], 200
106
+ end
107
+
108
+ def test_post_request
109
+ clear_all_traces
110
+
111
+ response = nil
112
+
113
+ Oboe::API.start_trace('httpclient_tests') do
114
+ clnt = HTTPClient.new
115
+ response = clnt.post('http://127.0.0.1:8101/')
116
+ end
117
+
118
+ traces = get_all_traces
119
+
120
+ xtrace = response.headers['X-Trace']
121
+ assert xtrace
122
+ assert Oboe::XTrace.valid?(xtrace)
123
+
124
+ assert_equal traces.count, 7
125
+ valid_edges?(traces)
126
+ validate_outer_layers(traces, "httpclient_tests")
127
+
128
+ assert_equal traces[1]['IsService'], 1
129
+ assert_equal traces[1]['RemoteURL'], 'http://127.0.0.1:8101/'
130
+ assert_equal traces[1]['HTTPMethod'], 'POST'
131
+ assert traces[1].key?('Backtrace')
132
+
133
+ assert_equal traces[5]['Layer'], 'httpclient'
134
+ assert_equal traces[5]['Label'], 'exit'
135
+ assert_equal traces[5]['HTTPStatus'], 200
136
+ end
137
+
138
+ def test_async_get
139
+ skip if RUBY_VERSION < '1.9.2'
140
+
141
+ clear_all_traces
142
+
143
+ conn = nil
144
+
145
+ Oboe::API.start_trace('httpclient_tests') do
146
+ clnt = HTTPClient.new
147
+ conn = clnt.get_async('http://127.0.0.1:8101/?blah=1')
148
+ end
149
+
150
+ # Allow async request to finish
151
+ Thread.pass until conn.finished?
152
+
153
+ traces = get_all_traces
154
+ #require 'byebug'; debugger
155
+ assert_equal traces.count, 7
156
+ valid_edges?(traces)
157
+
158
+ # FIXME: validate_outer_layers assumes that the traces
159
+ # are ordered which in the case of async, they aren't
160
+ # validate_outer_layers(traces, "httpclient_tests")
161
+
162
+ assert_equal traces[2]['Async'], 1
163
+ assert_equal traces[2]['IsService'], 1
164
+ assert_equal traces[2]['RemoteURL'], 'http://127.0.0.1:8101/?blah=1'
165
+ assert_equal traces[2]['HTTPMethod'], 'GET'
166
+ assert traces[2].key?('Backtrace')
167
+
168
+ assert_equal traces[6]['Layer'], 'httpclient'
169
+ assert_equal traces[6]['Label'], 'exit'
170
+ assert_equal traces[6]['HTTPStatus'], 200
171
+ end
172
+
173
+ def test_cross_app_tracing
174
+ clear_all_traces
175
+
176
+ response = nil
177
+
178
+ Oboe::API.start_trace('httpclient_tests') do
179
+ clnt = HTTPClient.new
180
+ response = clnt.get('http://127.0.0.1:8101/', :query => { :keyword => 'ruby', :lang => 'en' })
181
+ end
182
+
183
+ xtrace = response.headers['X-Trace']
184
+ assert xtrace
185
+ assert Oboe::XTrace.valid?(xtrace)
186
+
187
+ traces = get_all_traces
188
+
189
+ assert_equal traces.count, 7
190
+ valid_edges?(traces)
191
+ validate_outer_layers(traces, "httpclient_tests")
192
+
193
+ assert_equal traces[1]['IsService'], 1
194
+ assert_equal traces[1]['RemoteURL'], 'http://127.0.0.1:8101/?keyword=ruby&lang=en'
195
+ assert_equal traces[1]['HTTPMethod'], 'GET'
196
+ assert traces[1].key?('Backtrace')
197
+
198
+ assert_equal traces[2]['Layer'], 'rack'
199
+ assert_equal traces[2]['Label'], 'entry'
200
+ assert_equal traces[3]['Layer'], 'rack'
201
+ assert_equal traces[3]['Label'], 'info'
202
+ assert_equal traces[4]['Layer'], 'rack'
203
+ assert_equal traces[4]['Label'], 'exit'
204
+
205
+ assert_equal traces[5]['Layer'], 'httpclient'
206
+ assert_equal traces[5]['Label'], 'exit'
207
+ assert_equal traces[5]['HTTPStatus'], 200
208
+ end
209
+
210
+ def test_requests_with_errors
211
+ clear_all_traces
212
+
213
+ result = nil
214
+ begin
215
+ Oboe::API.start_trace('httpclient_tests') do
216
+ clnt = HTTPClient.new
217
+ result = clnt.get('http://asfjalkfjlajfljkaljf/')
218
+ end
219
+ rescue
220
+ end
221
+
222
+ traces = get_all_traces
223
+ assert_equal traces.count, 5
224
+ valid_edges?(traces)
225
+ validate_outer_layers(traces, "httpclient_tests")
226
+
227
+ assert_equal traces[1]['IsService'], 1
228
+ assert_equal traces[1]['RemoteURL'], 'http://asfjalkfjlajfljkaljf/'
229
+ assert_equal traces[1]['HTTPMethod'], 'GET'
230
+ assert traces[1].key?('Backtrace')
231
+
232
+ assert_equal traces[2]['Layer'], 'httpclient'
233
+ assert_equal traces[2]['Label'], 'error'
234
+ assert_equal traces[2]['ErrorClass'], "SocketError"
235
+ assert traces[2].key?('ErrorMsg')
236
+ assert traces[2].key?('Backtrace')
237
+
238
+ assert_equal traces[3]['Layer'], 'httpclient'
239
+ assert_equal traces[3]['Label'], 'exit'
240
+ end
241
+
242
+ def test_log_args_when_true
243
+ clear_all_traces
244
+
245
+ @log_args = Oboe::Config[:httpclient][:log_args]
246
+ Oboe::Config[:httpclient][:log_args] = true
247
+
248
+ response = nil
249
+
250
+ Oboe::API.start_trace('httpclient_tests') do
251
+ clnt = HTTPClient.new
252
+ response = clnt.get('http://127.0.0.1:8101/', :query => { :keyword => 'ruby', :lang => 'en' })
253
+ end
254
+
255
+ traces = get_all_traces
256
+
257
+ xtrace = response.headers['X-Trace']
258
+ assert xtrace
259
+ assert Oboe::XTrace.valid?(xtrace)
260
+
261
+ assert_equal traces.count, 7
262
+ valid_edges?(traces)
263
+
264
+ assert_equal traces[1]['RemoteURL'], 'http://127.0.0.1:8101/?keyword=ruby&lang=en'
265
+
266
+ Oboe::Config[:httpclient][:log_args] = @log_args
267
+ end
268
+
269
+ def test_log_args_when_false
270
+ clear_all_traces
271
+
272
+ @log_args = Oboe::Config[:httpclient][:log_args]
273
+ Oboe::Config[:httpclient][:log_args] = false
274
+
275
+ response = nil
276
+
277
+ Oboe::API.start_trace('httpclient_tests') do
278
+ clnt = HTTPClient.new
279
+ response = clnt.get('http://127.0.0.1:8101/', :query => { :keyword => 'ruby', :lang => 'en' })
280
+ end
281
+
282
+ traces = get_all_traces
283
+
284
+ xtrace = response.headers['X-Trace']
285
+ assert xtrace
286
+ assert Oboe::XTrace.valid?(xtrace)
287
+
288
+ assert_equal traces.count, 7
289
+ valid_edges?(traces)
290
+
291
+ assert_equal traces[1]['RemoteURL'], 'http://127.0.0.1:8101/'
292
+
293
+ Oboe::Config[:httpclient][:log_args] = @log_args
294
+ end
295
+ end
296
+
@@ -30,14 +30,15 @@ class RackTestApp < Minitest::Test
30
30
 
31
31
  kvs = {}
32
32
  kvs["Label"] = "entry"
33
+ kvs["URL"] = "/lobster"
33
34
  validate_event_keys(traces[0], kvs)
34
35
 
35
36
  kvs.clear
37
+ kvs["Layer"] = "rack"
36
38
  kvs["Label"] = "info"
37
39
  kvs["HTTP-Host"] = "example.org"
38
40
  kvs["Port"] = 80
39
41
  kvs["Proto"] = "http"
40
- kvs["URL"] = "/lobster"
41
42
  kvs["Method"] = "GET"
42
43
  kvs["ClientIP"] = "127.0.0.1"
43
44
  validate_event_keys(traces[1], kvs)
@@ -73,5 +74,43 @@ class RackTestApp < Minitest::Test
73
74
  assert xtrace
74
75
  assert Oboe::XTrace.valid?(xtrace)
75
76
  end
77
+
78
+ def test_log_args_when_false
79
+ clear_all_traces
80
+
81
+ @log_args = Oboe::Config[:rack][:log_args]
82
+ Oboe::Config[:rack][:log_args] = false
83
+
84
+ get "/lobster?blah=1"
85
+
86
+ traces = get_all_traces
87
+
88
+ xtrace = last_response['X-Trace']
89
+ assert xtrace
90
+ assert Oboe::XTrace.valid?(xtrace)
91
+
92
+ traces[0]['URL'].must_equal "/lobster"
93
+
94
+ Oboe::Config[:rack][:log_args] = @log_args
95
+ end
96
+
97
+ def test_log_args_when_true
98
+ clear_all_traces
99
+
100
+ @log_args = Oboe::Config[:rack][:log_args]
101
+ Oboe::Config[:rack][:log_args] = true
102
+
103
+ get "/lobster?blah=1"
104
+
105
+ traces = get_all_traces
106
+
107
+ xtrace = last_response['X-Trace']
108
+ assert xtrace
109
+ assert Oboe::XTrace.valid?(xtrace)
110
+
111
+ traces[0]['URL'].must_equal "/lobster?blah=1"
112
+
113
+ Oboe::Config[:rack][:log_args] = @log_args
114
+ end
76
115
  end
77
116