traceview 3.0.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rubocop.yml +5 -0
  4. data/.travis.yml +58 -0
  5. data/Appraisals +10 -0
  6. data/CHANGELOG.md +490 -0
  7. data/CONFIG.md +16 -0
  8. data/Gemfile +95 -0
  9. data/LICENSE +199 -0
  10. data/README.md +380 -0
  11. data/Rakefile +109 -0
  12. data/examples/DNT.md +35 -0
  13. data/examples/carrying_context.rb +225 -0
  14. data/examples/instrumenting_metal_controller.rb +8 -0
  15. data/examples/puma_on_heroku_config.rb +17 -0
  16. data/examples/tracing_async_threads.rb +125 -0
  17. data/examples/tracing_background_jobs.rb +52 -0
  18. data/examples/tracing_forked_processes.rb +100 -0
  19. data/examples/unicorn_on_heroku_config.rb +28 -0
  20. data/ext/oboe_metal/extconf.rb +61 -0
  21. data/ext/oboe_metal/noop/noop.c +7 -0
  22. data/ext/oboe_metal/src/bson/bson.h +221 -0
  23. data/ext/oboe_metal/src/bson/platform_hacks.h +91 -0
  24. data/ext/oboe_metal/src/oboe.h +275 -0
  25. data/ext/oboe_metal/src/oboe.hpp +352 -0
  26. data/ext/oboe_metal/src/oboe_wrap.cxx +3886 -0
  27. data/ext/oboe_metal/tests/test.rb +11 -0
  28. data/gemfiles/mongo.gemfile +33 -0
  29. data/gemfiles/moped.gemfile +33 -0
  30. data/get_version.rb +5 -0
  31. data/init.rb +4 -0
  32. data/lib/joboe_metal.rb +206 -0
  33. data/lib/oboe/README +2 -0
  34. data/lib/oboe/backward_compatibility.rb +59 -0
  35. data/lib/oboe/inst/rack.rb +11 -0
  36. data/lib/oboe.rb +7 -0
  37. data/lib/oboe_metal.rb +151 -0
  38. data/lib/rails/generators/traceview/install_generator.rb +76 -0
  39. data/lib/rails/generators/traceview/templates/traceview_initializer.rb +159 -0
  40. data/lib/traceview/api/layerinit.rb +51 -0
  41. data/lib/traceview/api/logging.rb +209 -0
  42. data/lib/traceview/api/memcache.rb +31 -0
  43. data/lib/traceview/api/profiling.rb +50 -0
  44. data/lib/traceview/api/tracing.rb +135 -0
  45. data/lib/traceview/api/util.rb +121 -0
  46. data/lib/traceview/api.rb +18 -0
  47. data/lib/traceview/base.rb +225 -0
  48. data/lib/traceview/config.rb +238 -0
  49. data/lib/traceview/frameworks/grape.rb +97 -0
  50. data/lib/traceview/frameworks/padrino/templates.rb +58 -0
  51. data/lib/traceview/frameworks/padrino.rb +64 -0
  52. data/lib/traceview/frameworks/rails/helpers/rum/rum_ajax_header.js.erb +5 -0
  53. data/lib/traceview/frameworks/rails/helpers/rum/rum_footer.js.erb +1 -0
  54. data/lib/traceview/frameworks/rails/helpers/rum/rum_header.js.erb +3 -0
  55. data/lib/traceview/frameworks/rails/inst/action_controller.rb +216 -0
  56. data/lib/traceview/frameworks/rails/inst/action_view.rb +56 -0
  57. data/lib/traceview/frameworks/rails/inst/action_view_2x.rb +54 -0
  58. data/lib/traceview/frameworks/rails/inst/action_view_30.rb +48 -0
  59. data/lib/traceview/frameworks/rails/inst/active_record.rb +24 -0
  60. data/lib/traceview/frameworks/rails/inst/connection_adapters/mysql.rb +43 -0
  61. data/lib/traceview/frameworks/rails/inst/connection_adapters/mysql2.rb +28 -0
  62. data/lib/traceview/frameworks/rails/inst/connection_adapters/oracle.rb +18 -0
  63. data/lib/traceview/frameworks/rails/inst/connection_adapters/postgresql.rb +30 -0
  64. data/lib/traceview/frameworks/rails/inst/connection_adapters/utils.rb +117 -0
  65. data/lib/traceview/frameworks/rails.rb +145 -0
  66. data/lib/traceview/frameworks/sinatra/templates.rb +56 -0
  67. data/lib/traceview/frameworks/sinatra.rb +95 -0
  68. data/lib/traceview/inst/cassandra.rb +279 -0
  69. data/lib/traceview/inst/dalli.rb +86 -0
  70. data/lib/traceview/inst/em-http-request.rb +99 -0
  71. data/lib/traceview/inst/excon.rb +111 -0
  72. data/lib/traceview/inst/faraday.rb +73 -0
  73. data/lib/traceview/inst/http.rb +87 -0
  74. data/lib/traceview/inst/httpclient.rb +173 -0
  75. data/lib/traceview/inst/memcache.rb +102 -0
  76. data/lib/traceview/inst/memcached.rb +94 -0
  77. data/lib/traceview/inst/mongo.rb +238 -0
  78. data/lib/traceview/inst/moped.rb +474 -0
  79. data/lib/traceview/inst/rack.rb +122 -0
  80. data/lib/traceview/inst/redis.rb +271 -0
  81. data/lib/traceview/inst/resque.rb +192 -0
  82. data/lib/traceview/inst/rest-client.rb +38 -0
  83. data/lib/traceview/inst/sequel.rb +162 -0
  84. data/lib/traceview/inst/typhoeus.rb +102 -0
  85. data/lib/traceview/instrumentation.rb +21 -0
  86. data/lib/traceview/loading.rb +94 -0
  87. data/lib/traceview/logger.rb +41 -0
  88. data/lib/traceview/method_profiling.rb +84 -0
  89. data/lib/traceview/ruby.rb +36 -0
  90. data/lib/traceview/support.rb +113 -0
  91. data/lib/traceview/thread_local.rb +26 -0
  92. data/lib/traceview/util.rb +250 -0
  93. data/lib/traceview/version.rb +16 -0
  94. data/lib/traceview/xtrace.rb +90 -0
  95. data/lib/traceview.rb +62 -0
  96. data/test/frameworks/apps/grape_nested.rb +30 -0
  97. data/test/frameworks/apps/grape_simple.rb +24 -0
  98. data/test/frameworks/apps/padrino_simple.rb +45 -0
  99. data/test/frameworks/apps/sinatra_simple.rb +24 -0
  100. data/test/frameworks/grape_test.rb +142 -0
  101. data/test/frameworks/padrino_test.rb +30 -0
  102. data/test/frameworks/sinatra_test.rb +30 -0
  103. data/test/instrumentation/cassandra_test.rb +380 -0
  104. data/test/instrumentation/dalli_test.rb +171 -0
  105. data/test/instrumentation/em_http_request_test.rb +86 -0
  106. data/test/instrumentation/excon_test.rb +207 -0
  107. data/test/instrumentation/faraday_test.rb +235 -0
  108. data/test/instrumentation/http_test.rb +140 -0
  109. data/test/instrumentation/httpclient_test.rb +296 -0
  110. data/test/instrumentation/memcache_test.rb +251 -0
  111. data/test/instrumentation/memcached_test.rb +226 -0
  112. data/test/instrumentation/mongo_test.rb +462 -0
  113. data/test/instrumentation/moped_test.rb +496 -0
  114. data/test/instrumentation/rack_test.rb +116 -0
  115. data/test/instrumentation/redis_hashes_test.rb +265 -0
  116. data/test/instrumentation/redis_keys_test.rb +318 -0
  117. data/test/instrumentation/redis_lists_test.rb +310 -0
  118. data/test/instrumentation/redis_misc_test.rb +160 -0
  119. data/test/instrumentation/redis_sets_test.rb +293 -0
  120. data/test/instrumentation/redis_sortedsets_test.rb +325 -0
  121. data/test/instrumentation/redis_strings_test.rb +333 -0
  122. data/test/instrumentation/resque_test.rb +62 -0
  123. data/test/instrumentation/rest-client_test.rb +294 -0
  124. data/test/instrumentation/sequel_mysql2_test.rb +326 -0
  125. data/test/instrumentation/sequel_mysql_test.rb +326 -0
  126. data/test/instrumentation/sequel_pg_test.rb +330 -0
  127. data/test/instrumentation/typhoeus_test.rb +285 -0
  128. data/test/minitest_helper.rb +187 -0
  129. data/test/profiling/method_test.rb +198 -0
  130. data/test/servers/rackapp_8101.rb +22 -0
  131. data/test/support/backcompat_test.rb +269 -0
  132. data/test/support/config_test.rb +128 -0
  133. data/test/support/dnt_test.rb +73 -0
  134. data/test/support/liboboe_settings_test.rb +104 -0
  135. data/test/support/xtrace_test.rb +35 -0
  136. data/traceview.gemspec +29 -0
  137. metadata +248 -0
@@ -0,0 +1,333 @@
1
+ require 'minitest_helper'
2
+ require "redis"
3
+
4
+ describe "Redis Strings" do
5
+ attr_reader :entry_kvs, :exit_kvs, :redis, :redis_version
6
+
7
+ def min_server_version(version)
8
+ unless Gem::Version.new(@redis_version) >= Gem::Version.new(version.to_s)
9
+ skip "supported only on redis-server #{version} or greater"
10
+ end
11
+ end
12
+
13
+ before do
14
+ clear_all_traces
15
+
16
+ @redis ||= Redis.new
17
+
18
+ @redis_version ||= @redis.info["redis_version"]
19
+
20
+ # These are standard entry/exit KVs that are passed up with all moped operations
21
+ @entry_kvs ||= { 'Layer' => 'redis_test', 'Label' => 'entry' }
22
+ @exit_kvs ||= { 'Layer' => 'redis_test', 'Label' => 'exit' }
23
+ end
24
+
25
+ it "should trace append" do
26
+ @redis.set("yourkey", "test")
27
+
28
+ TraceView::API.start_trace('redis_test', '', {}) do
29
+ @redis.append("yourkey", "blah")
30
+ end
31
+
32
+ traces = get_all_traces
33
+ traces.count.must_equal 4
34
+ traces[2]['KVOp'].must_equal "append"
35
+ traces[2]['KVKey'].must_equal "yourkey"
36
+ end
37
+
38
+ it "should trace bitcount (>=2.6)" do
39
+
40
+ min_server_version("2.6")
41
+
42
+ TraceView::API.start_trace('redis_test', '', {}) do
43
+ @redis.bitcount("yourkey")
44
+ end
45
+
46
+ traces = get_all_traces
47
+ traces.count.must_equal 4
48
+ traces[2]['KVOp'].must_equal "bitcount"
49
+ traces[2]['start'].must_equal 0
50
+ traces[2]['stop'].must_equal -1
51
+ end
52
+
53
+ it "should trace bitop (>=2.6)" do
54
+
55
+ min_server_version("2.6")
56
+
57
+ TraceView::API.start_trace('redis_test', '', {}) do
58
+ @redis.bitop("not", "bitopkey", "yourkey")
59
+ end
60
+
61
+ traces = get_all_traces
62
+ traces.count.must_equal 4
63
+ traces[2]['KVOp'].must_equal "bitop"
64
+ traces[2]['operation'].must_equal "not"
65
+ traces[2]['destkey'].must_equal "bitopkey"
66
+ end
67
+
68
+ it "should trace decr" do
69
+ @redis.setex("decr", 60, 0)
70
+
71
+ TraceView::API.start_trace('redis_test', '', {}) do
72
+ @redis.decr("decr")
73
+ end
74
+
75
+ traces = get_all_traces
76
+ traces.count.must_equal 4
77
+ traces[2]['KVOp'].must_equal "decr"
78
+ traces[2]['KVKey'].must_equal "decr"
79
+ end
80
+
81
+ it "should trace decrby" do
82
+ @redis.setex("decr", 60, 0)
83
+
84
+ TraceView::API.start_trace('redis_test', '', {}) do
85
+ @redis.decrby("decr", 1)
86
+ end
87
+
88
+ traces = get_all_traces
89
+ traces.count.must_equal 4
90
+ traces[2]['KVOp'].must_equal "decrby"
91
+ traces[2]['KVKey'].must_equal "decr"
92
+ traces[2]['decrement'].must_equal 1
93
+ end
94
+
95
+ it "should trace get" do
96
+ @redis.setex("diwore", 60, "okokok")
97
+
98
+ TraceView::API.start_trace('redis_test', '', {}) do
99
+ @rv = @redis.get("diwore")
100
+ end
101
+
102
+ @rv.must_equal "okokok"
103
+
104
+ traces = get_all_traces
105
+ traces.count.must_equal 4
106
+ traces[2]['KVOp'].must_equal "get"
107
+ traces[2]['KVKey'].must_equal "diwore"
108
+ end
109
+
110
+ it "should trace getbit" do
111
+ min_server_version(2.2)
112
+
113
+ @redis.setex("diwore", 60, "okokok")
114
+
115
+ TraceView::API.start_trace('redis_test', '', {}) do
116
+ @redis.getbit("diwore", 3)
117
+ end
118
+
119
+ traces = get_all_traces
120
+ traces.count.must_equal 4
121
+ traces[2]['KVOp'].must_equal "getbit"
122
+ traces[2]['KVKey'].must_equal "diwore"
123
+ traces[2]['offset'].must_equal 3
124
+ end
125
+
126
+ it "should trace getrange" do
127
+ min_server_version(2.2)
128
+
129
+ TraceView::API.start_trace('redis_test', '', {}) do
130
+ @redis.getrange("yourkey", 0, 3)
131
+ end
132
+
133
+ traces = get_all_traces
134
+ traces.count.must_equal 4
135
+ traces[2]['KVOp'].must_equal "getrange"
136
+ traces[2]['KVKey'].must_equal "yourkey"
137
+ traces[2]['start'].must_equal 0
138
+ traces[2]['end'].must_equal 3
139
+ end
140
+
141
+ it "should trace getset" do
142
+ min_server_version(2.2)
143
+
144
+ TraceView::API.start_trace('redis_test', '', {}) do
145
+ @redis.getset("dollar", 0)
146
+ end
147
+
148
+ traces = get_all_traces
149
+ traces.count.must_equal 4
150
+ traces[2]['KVOp'].must_equal "getset"
151
+ traces[2]['KVKey'].must_equal "dollar"
152
+ traces[2]['value'].must_equal "0"
153
+ end
154
+
155
+ it "should trace incr" do
156
+ @redis.setex("dotcom", 60, 0)
157
+
158
+ TraceView::API.start_trace('redis_test', '', {}) do
159
+ @redis.incr("dotcom")
160
+ end
161
+
162
+ traces = get_all_traces
163
+ traces.count.must_equal 4
164
+ traces[2]['KVOp'].must_equal "incr"
165
+ traces[2]['KVKey'].must_equal "dotcom"
166
+ end
167
+
168
+ it "should trace incrby" do
169
+ @redis.setex("incr", 60, 0)
170
+
171
+ TraceView::API.start_trace('redis_test', '', {}) do
172
+ @redis.incrby("incr", 1)
173
+ end
174
+
175
+ traces = get_all_traces
176
+ traces.count.must_equal 4
177
+ traces[2]['KVOp'].must_equal "incrby"
178
+ traces[2]['KVKey'].must_equal "incr"
179
+ traces[2]['increment'].must_equal 1
180
+ end
181
+
182
+ it "should trace incrbyfloat" do
183
+ min_server_version(2.6)
184
+
185
+ @redis.setex("incrfloat", 60, 0.0)
186
+
187
+ TraceView::API.start_trace('redis_test', '', {}) do
188
+ @redis.incrbyfloat("incrfloat", 1.01)
189
+ end
190
+
191
+ traces = get_all_traces
192
+ traces.count.must_equal 4
193
+ traces[2]['KVOp'].must_equal "incrbyfloat"
194
+ traces[2]['KVKey'].must_equal "incrfloat"
195
+ traces[2]['increment'].must_equal 1.01
196
+ end
197
+
198
+ it "should trace mget" do
199
+ @redis.setex("france", 60, "ok")
200
+ @redis.setex("denmark", 60, "ok")
201
+ @redis.setex("germany", 60, "ok")
202
+
203
+ TraceView::API.start_trace('redis_test', '', {}) do
204
+ @redis.mget(["france", "nothing", "denmark"])
205
+ @redis.mget("germany")
206
+ end
207
+
208
+ traces = get_all_traces
209
+ traces.count.must_equal 6
210
+ traces[2]['KVOp'].must_equal "mget"
211
+ traces[2]['KVKeyCount'].must_equal 3
212
+ traces[2]['KVHitCount'].must_equal 2
213
+ traces[4]['KVOp'].must_equal "mget"
214
+ traces[4]['KVKeyCount'].must_equal 1
215
+ traces[4]['KVHitCount'].must_equal 1
216
+ end
217
+
218
+ it "should trace mset" do
219
+ TraceView::API.start_trace('redis_test', '', {}) do
220
+ @redis.mset(["one", 1, "two", 2, "three", 3])
221
+ @redis.mset("one", 1)
222
+ end
223
+
224
+ traces = get_all_traces
225
+ traces.count.must_equal 6
226
+ traces[2]['KVOp'].must_equal "mset"
227
+ traces[2]['KVKeyCount'].must_equal 3
228
+ traces[4]['KVOp'].must_equal "mset"
229
+ traces[4]['KVKeyCount'].must_equal 1
230
+ end
231
+
232
+ it "should trace msetnx" do
233
+ TraceView::API.start_trace('redis_test', '', {}) do
234
+ @redis.msetnx(["one", 1, "two", 2, "three", 3])
235
+ end
236
+
237
+ traces = get_all_traces
238
+ traces.count.must_equal 4
239
+ traces[2]['KVOp'].must_equal "msetnx"
240
+ end
241
+
242
+ it "should trace psetex (>= v2.6)" do
243
+
244
+ TraceView::API.start_trace('redis_test', '', {}) do
245
+ @redis.psetex("one", 60, "hello")
246
+ end
247
+
248
+ traces = get_all_traces
249
+ traces.count.must_equal 4
250
+ traces[2]['KVOp'].must_equal "psetex"
251
+ traces[2]['KVKey'].must_equal "one"
252
+ traces[2]['ttl'].must_equal 60
253
+ end
254
+
255
+ it "should trace basic set" do
256
+ TraceView::API.start_trace('redis_test', '', {}) do
257
+ @redis.set("one", "hello")
258
+ end
259
+
260
+ traces = get_all_traces
261
+ traces.count.must_equal 4
262
+ traces[2]['KVOp'].must_equal "set"
263
+ traces[2]['KVKey'].must_equal "one"
264
+ end
265
+
266
+ it "should trace setbit" do
267
+ min_server_version(2.2)
268
+
269
+ TraceView::API.start_trace('redis_test', '', {}) do
270
+ @redis.setbit("yourkey", 3, 0)
271
+ end
272
+
273
+ traces = get_all_traces
274
+ traces.count.must_equal 4
275
+ traces[2]['KVOp'].must_equal "setbit"
276
+ traces[2]['KVKey'].must_equal "yourkey"
277
+ traces[2]['offset'].must_equal 3
278
+ end
279
+
280
+ it "should trace setex" do
281
+ TraceView::API.start_trace('redis_test', '', {}) do
282
+ @redis.setex("one", 60, "hello")
283
+ end
284
+
285
+ traces = get_all_traces
286
+ traces.count.must_equal 4
287
+ traces[2]['KVOp'].must_equal "setex"
288
+ traces[2]['KVKey'].must_equal "one"
289
+ traces[2]['ttl'].must_equal 60
290
+ end
291
+
292
+ it "should trace setnx" do
293
+ TraceView::API.start_trace('redis_test', '', {}) do
294
+ @redis.setnx("one", "hello")
295
+ end
296
+
297
+ traces = get_all_traces
298
+ traces.count.must_equal 4
299
+ traces[2]['KVOp'].must_equal "setnx"
300
+ traces[2]['KVKey'].must_equal "one"
301
+ end
302
+
303
+ it "should trace setrange" do
304
+ min_server_version(2.2)
305
+
306
+ @redis.setex("spandau_ballet", 60, "XXXXXXXXXXXXXXX")
307
+
308
+ TraceView::API.start_trace('redis_test', '', {}) do
309
+ @redis.setrange("yourkey", 2, "ok")
310
+ end
311
+
312
+ traces = get_all_traces
313
+ traces.count.must_equal 4
314
+ traces[2]['KVOp'].must_equal "setrange"
315
+ traces[2]['KVKey'].must_equal "yourkey"
316
+ traces[2]['offset'].must_equal 2
317
+ end
318
+
319
+ it "should trace strlen" do
320
+ min_server_version(2.2)
321
+
322
+ @redis.setex("talking_heads", 60, "burning down the house")
323
+
324
+ TraceView::API.start_trace('redis_test', '', {}) do
325
+ @redis.strlen("talking_heads")
326
+ end
327
+
328
+ traces = get_all_traces
329
+ traces.count.must_equal 4
330
+ traces[2]['KVOp'].must_equal "strlen"
331
+ traces[2]['KVKey'].must_equal "talking_heads"
332
+ end
333
+ end
@@ -0,0 +1,62 @@
1
+ require 'minitest_helper'
2
+
3
+ describe "Resque" do
4
+ before do
5
+ clear_all_traces
6
+
7
+ # These are standard entry/exit KVs that are passed up with all moped operations
8
+ @entry_kvs = {
9
+ 'Layer' => 'resque',
10
+ 'Label' => 'entry' }
11
+
12
+ @exit_kvs = { 'Layer' => 'resque', 'Label' => 'exit' }
13
+ end
14
+
15
+ it 'Stock Resque should be loaded, defined and ready' do
16
+ defined?(::Resque).wont_match nil
17
+ defined?(::Resque::Worker).wont_match nil
18
+ defined?(::Resque::Job).wont_match nil
19
+ end
20
+
21
+ it 'Resque should have traceview methods defined' do
22
+ [ :enqueue, :enqueue_to, :dequeue ].each do |m|
23
+ ::Resque.method_defined?("#{m}_with_traceview").must_equal true
24
+ end
25
+
26
+ ::Resque::Worker.method_defined?("perform_with_traceview").must_equal true
27
+ ::Resque::Job.method_defined?("fail_with_traceview").must_equal true
28
+ end
29
+
30
+ it "should trace enqueue" do
31
+ skip
32
+ TraceView::API.start_trace('resque-client_test', '', {}) do
33
+ Resque.enqueue(TraceViewResqueJob, { :generate => :activerecord, :delay => rand(5..30).to_f })
34
+ Resque.enqueue(TraceViewResqueJobThatFails)
35
+ Resque.dequeue(TraceViewResqueJob, { :generate => :moped })
36
+ end
37
+
38
+ traces = get_all_traces
39
+
40
+ traces.count.must_equal 4
41
+ validate_outer_layers(traces, 'resque-client_test')
42
+
43
+ validate_event_keys(traces[1], @entry_kvs)
44
+ validate_event_keys(traces[2], @exit_kvs)
45
+ end
46
+
47
+ it "should trace dequeue" do
48
+ skip
49
+ TraceView::API.start_trace('resque-client_test', '', {}) do
50
+ Resque.dequeue(TraceViewResqueJob, { :generate => :moped })
51
+ end
52
+
53
+ traces = get_all_traces
54
+
55
+ traces.count.must_equal 4
56
+ validate_outer_layers(traces, 'resque-client_test')
57
+
58
+ validate_event_keys(traces[1], @entry_kvs)
59
+ validate_event_keys(traces[2], @exit_kvs)
60
+ end
61
+ end
62
+
@@ -0,0 +1,294 @@
1
+ require 'minitest_helper'
2
+
3
+ if RUBY_VERSION >= '1.9.3'
4
+ describe "RestClient" do
5
+ before do
6
+ clear_all_traces
7
+ @collect_backtraces = TraceView::Config[:rest_client][:collect_backtraces]
8
+ end
9
+
10
+ after do
11
+ TraceView::Config[:rest_client][:collect_backtraces] = @collect_backtraces
12
+ end
13
+
14
+ it 'RestClient should be defined and ready' do
15
+ defined?(::RestClient).wont_match nil
16
+ end
17
+
18
+ it 'RestClient should have traceview methods defined' do
19
+ [ :execute_with_traceview ].each do |m|
20
+ ::RestClient::Request.method_defined?(m).must_equal true
21
+ end
22
+ end
23
+
24
+ it "should report rest-client version in __Init" do
25
+ init_kvs = ::TraceView::Util.build_init_report
26
+
27
+ init_kvs.key?('Ruby.RestClient.Version').must_equal true
28
+ init_kvs['Ruby.RestClient.Version'].must_equal "RestClient-#{::RestClient::VERSION}"
29
+ end
30
+
31
+ it "should trace a request to an instr'd app" do
32
+ response = nil
33
+
34
+ TraceView::API.start_trace('rest_client_test') do
35
+ response = RestClient.get 'http://127.0.0.1:8101/'
36
+ end
37
+
38
+ traces = get_all_traces
39
+ traces.count.must_equal 10
40
+
41
+ valid_edges?(traces).must_equal true
42
+ validate_outer_layers(traces, 'rest_client_test')
43
+
44
+ traces[1]['Layer'].must_equal 'rest-client'
45
+ traces[1]['Label'].must_equal 'entry'
46
+
47
+ traces[2]['Layer'].must_equal 'net-http'
48
+ traces[2]['Label'].must_equal 'entry'
49
+
50
+ traces[6]['Layer'].must_equal 'net-http'
51
+ traces[6]['Label'].must_equal 'info'
52
+ traces[6]['IsService'].must_equal 1
53
+ traces[6]['RemoteProtocol'].must_equal 'HTTP'
54
+ traces[6]['RemoteHost'].must_equal '127.0.0.1:8101'
55
+ traces[6]['ServiceArg'].must_equal '/'
56
+ traces[6]['HTTPMethod'].must_equal 'GET'
57
+ traces[6]['HTTPStatus'].must_equal "200"
58
+ traces[6].key?('Backtrace').must_equal TraceView::Config[:nethttp][:collect_backtraces]
59
+
60
+ traces[7]['Layer'].must_equal 'net-http'
61
+ traces[7]['Label'].must_equal 'exit'
62
+
63
+ traces[8]['Layer'].must_equal 'rest-client'
64
+ traces[8]['Label'].must_equal 'exit'
65
+
66
+ response.headers.key?(:x_trace).wont_equal nil
67
+ xtrace = response.headers[:x_trace]
68
+ TraceView::XTrace.valid?(xtrace).must_equal true
69
+ end
70
+
71
+ it 'should trace a raw GET request' do
72
+ response = nil
73
+
74
+ TraceView::API.start_trace('rest_client_test') do
75
+ response = RestClient.get 'http://127.0.0.1:8101/?a=1'
76
+ end
77
+
78
+ traces = get_all_traces
79
+ traces.count.must_equal 10
80
+
81
+ # FIXME: We need to switch from making external calls to an internal test
82
+ # stack instead so we can validate cross-app traces.
83
+ # valid_edges?(traces).must_equal true
84
+ validate_outer_layers(traces, 'rest_client_test')
85
+
86
+ traces[1]['Layer'].must_equal 'rest-client'
87
+ traces[1]['Label'].must_equal 'entry'
88
+
89
+ traces[2]['Layer'].must_equal 'net-http'
90
+ traces[2]['Label'].must_equal 'entry'
91
+
92
+ traces[6]['Layer'].must_equal 'net-http'
93
+ traces[6]['Label'].must_equal 'info'
94
+ traces[6]['IsService'].must_equal 1
95
+ traces[6]['RemoteProtocol'].must_equal 'HTTP'
96
+ traces[6]['RemoteHost'].must_equal '127.0.0.1:8101'
97
+ traces[6]['ServiceArg'].must_equal '/?a=1'
98
+ traces[6]['HTTPMethod'].must_equal 'GET'
99
+ traces[6]['HTTPStatus'].must_equal "200"
100
+ traces[6].key?('Backtrace').must_equal TraceView::Config[:nethttp][:collect_backtraces]
101
+
102
+ traces[7]['Layer'].must_equal 'net-http'
103
+ traces[7]['Label'].must_equal 'exit'
104
+
105
+ traces[8]['Layer'].must_equal 'rest-client'
106
+ traces[8]['Label'].must_equal 'exit'
107
+ end
108
+
109
+ it 'should trace a raw POST request' do
110
+ response = nil
111
+
112
+ TraceView::API.start_trace('rest_client_test') do
113
+ response = RestClient.post 'http://127.0.0.1:8101/', :param1 => 'one', :nested => { :param2 => 'two' }
114
+ end
115
+
116
+ traces = get_all_traces
117
+ traces.count.must_equal 10
118
+
119
+ valid_edges?(traces).must_equal true
120
+ validate_outer_layers(traces, 'rest_client_test')
121
+
122
+ traces[1]['Layer'].must_equal 'rest-client'
123
+ traces[1]['Label'].must_equal 'entry'
124
+
125
+ traces[2]['Layer'].must_equal 'net-http'
126
+ traces[2]['Label'].must_equal 'entry'
127
+
128
+ traces[6]['Layer'].must_equal 'net-http'
129
+ traces[6]['Label'].must_equal 'info'
130
+ traces[6]['IsService'].must_equal 1
131
+ traces[6]['RemoteProtocol'].must_equal 'HTTP'
132
+ traces[6]['RemoteHost'].must_equal '127.0.0.1:8101'
133
+ traces[6]['ServiceArg'].must_equal '/'
134
+ traces[6]['HTTPMethod'].must_equal 'POST'
135
+ traces[6]['HTTPStatus'].must_equal "200"
136
+ traces[6].key?('Backtrace').must_equal TraceView::Config[:nethttp][:collect_backtraces]
137
+
138
+ traces[7]['Layer'].must_equal 'net-http'
139
+ traces[7]['Label'].must_equal 'exit'
140
+
141
+ traces[8]['Layer'].must_equal 'rest-client'
142
+ traces[8]['Label'].must_equal 'exit'
143
+ end
144
+
145
+ it 'should trace a ActiveResource style GET request' do
146
+ response = nil
147
+
148
+ TraceView::API.start_trace('rest_client_test') do
149
+ resource = RestClient::Resource.new 'http://127.0.0.1:8101/?a=1'
150
+ response = resource.get
151
+ end
152
+
153
+ traces = get_all_traces
154
+ traces.count.must_equal 10
155
+
156
+ valid_edges?(traces).must_equal true
157
+ validate_outer_layers(traces, 'rest_client_test')
158
+
159
+ traces[1]['Layer'].must_equal 'rest-client'
160
+ traces[1]['Label'].must_equal 'entry'
161
+
162
+ traces[2]['Layer'].must_equal 'net-http'
163
+ traces[2]['Label'].must_equal 'entry'
164
+
165
+ traces[6]['Layer'].must_equal 'net-http'
166
+ traces[6]['Label'].must_equal 'info'
167
+ traces[6]['IsService'].must_equal 1
168
+ traces[6]['RemoteProtocol'].must_equal 'HTTP'
169
+ traces[6]['RemoteHost'].must_equal '127.0.0.1:8101'
170
+ traces[6]['ServiceArg'].must_equal '/?a=1'
171
+ traces[6]['HTTPMethod'].must_equal 'GET'
172
+ traces[6]['HTTPStatus'].must_equal "200"
173
+ traces[6].key?('Backtrace').must_equal TraceView::Config[:nethttp][:collect_backtraces]
174
+
175
+ traces[7]['Layer'].must_equal 'net-http'
176
+ traces[7]['Label'].must_equal 'exit'
177
+
178
+ traces[8]['Layer'].must_equal 'rest-client'
179
+ traces[8]['Label'].must_equal 'exit'
180
+ end
181
+
182
+ it 'should trace requests with redirects' do
183
+ response = nil
184
+
185
+ TraceView::API.start_trace('rest_client_test') do
186
+ resource = RestClient::Resource.new 'http://www.appneta.com/products/traceview?a=1'
187
+ response = resource.get
188
+ end
189
+
190
+ traces = get_all_traces
191
+ traces.count.must_equal 12
192
+
193
+ # FIXME: We need to switch from making external calls to an internal test
194
+ # stack instead so we can validate cross-app traces.
195
+ # valid_edges?(traces).must_equal true
196
+ validate_outer_layers(traces, 'rest_client_test')
197
+
198
+ traces[1]['Layer'].must_equal 'rest-client'
199
+ traces[1]['Label'].must_equal 'entry'
200
+
201
+ traces[2]['Layer'].must_equal 'net-http'
202
+ traces[2]['Label'].must_equal 'entry'
203
+
204
+ traces[3]['Layer'].must_equal 'net-http'
205
+ traces[3]['Label'].must_equal 'info'
206
+ traces[3]['IsService'].must_equal 1
207
+ traces[3]['RemoteProtocol'].must_equal 'HTTP'
208
+ traces[3]['RemoteHost'].must_equal 'www.appneta.com'
209
+ traces[3]['ServiceArg'].must_equal '/products/traceview?a=1'
210
+ traces[3]['HTTPMethod'].must_equal 'GET'
211
+ traces[3]['HTTPStatus'].must_equal "301"
212
+ traces[3].key?('Backtrace').must_equal TraceView::Config[:nethttp][:collect_backtraces]
213
+
214
+ traces[4]['Layer'].must_equal 'net-http'
215
+ traces[4]['Label'].must_equal 'exit'
216
+
217
+ traces[5]['Layer'].must_equal 'rest-client'
218
+ traces[5]['Label'].must_equal 'entry'
219
+
220
+ traces[6]['Layer'].must_equal 'net-http'
221
+ traces[6]['Label'].must_equal 'entry'
222
+
223
+ traces[7]['Layer'].must_equal 'net-http'
224
+ traces[7]['Label'].must_equal 'info'
225
+ traces[7]['IsService'].must_equal 1
226
+ traces[7]['RemoteProtocol'].must_equal 'HTTP'
227
+ traces[7]['RemoteHost'].must_equal 'www.appneta.com'
228
+ traces[7]['ServiceArg'].must_equal '/products/traceview/?a=1'
229
+ traces[7]['HTTPMethod'].must_equal 'GET'
230
+ traces[7]['HTTPStatus'].must_equal "200"
231
+ traces[7].key?('Backtrace').must_equal TraceView::Config[:nethttp][:collect_backtraces]
232
+
233
+ traces[8]['Layer'].must_equal 'net-http'
234
+ traces[8]['Label'].must_equal 'exit'
235
+
236
+ traces[9]['Layer'].must_equal 'rest-client'
237
+ traces[9]['Label'].must_equal 'exit'
238
+
239
+ traces[10]['Layer'].must_equal 'rest-client'
240
+ traces[10]['Label'].must_equal 'exit'
241
+ end
242
+
243
+ it 'should trace and capture raised exceptions' do
244
+ TraceView::API.start_trace('rest_client_test') do
245
+ begin
246
+ RestClient.get 'http://s6KTgaz7636z/resource'
247
+ rescue
248
+ # We want an exception to be raised. Just don't raise
249
+ # it beyond this point.
250
+ end
251
+ end
252
+
253
+ traces = get_all_traces
254
+ traces.count.must_equal 5
255
+
256
+ valid_edges?(traces).must_equal true
257
+ validate_outer_layers(traces, 'rest_client_test')
258
+
259
+ traces[1]['Layer'].must_equal 'rest-client'
260
+ traces[1]['Label'].must_equal 'entry'
261
+
262
+ traces[2]['Layer'].must_equal 'rest-client'
263
+ traces[2]['Label'].must_equal 'error'
264
+ traces[2]['ErrorClass'].must_equal 'SocketError'
265
+ traces[2].key?('ErrorMsg').must_equal true
266
+ traces[2].key?('Backtrace').must_equal true
267
+
268
+ traces[3]['Layer'].must_equal 'rest-client'
269
+ traces[3]['Label'].must_equal 'exit'
270
+ end
271
+
272
+ it 'should obey :collect_backtraces setting when true' do
273
+ TraceView::Config[:rest_client][:collect_backtraces] = true
274
+
275
+ TraceView::API.start_trace('rest_client_test') do
276
+ RestClient.get('http://127.0.0.1:8101/', {:a => 1})
277
+ end
278
+
279
+ traces = get_all_traces
280
+ layer_has_key(traces, 'rest-client', 'Backtrace')
281
+ end
282
+
283
+ it 'should obey :collect_backtraces setting when false' do
284
+ TraceView::Config[:rest_client][:collect_backtraces] = false
285
+
286
+ TraceView::API.start_trace('rest_client_test') do
287
+ RestClient.get('http://127.0.0.1:8101/', {:a => 1})
288
+ end
289
+
290
+ traces = get_all_traces
291
+ layer_doesnt_have_key(traces, 'rest-client', 'Backtrace')
292
+ end
293
+ end
294
+ end