traceview 3.8.0 → 3.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/README.md +3 -3
  4. data/lib/joboe_metal.rb +4 -4
  5. data/lib/oboe_metal.rb +3 -3
  6. data/lib/traceview/api/layerinit.rb +2 -2
  7. data/lib/traceview/api/logging.rb +12 -12
  8. data/lib/traceview/api/profiling.rb +6 -6
  9. data/lib/traceview/api/tracing.rb +1 -1
  10. data/lib/traceview/api/util.rb +1 -1
  11. data/lib/traceview/base.rb +14 -7
  12. data/lib/traceview/config.rb +8 -5
  13. data/lib/traceview/frameworks/padrino/templates.rb +4 -4
  14. data/lib/traceview/frameworks/rails.rb +2 -2
  15. data/lib/traceview/frameworks/rails/inst/action_controller.rb +6 -2
  16. data/lib/traceview/frameworks/rails/inst/action_controller2.rb +4 -2
  17. data/lib/traceview/frameworks/rails/inst/action_controller3.rb +5 -4
  18. data/lib/traceview/frameworks/rails/inst/action_controller4.rb +4 -2
  19. data/lib/traceview/frameworks/rails/inst/action_controller5.rb +22 -11
  20. data/lib/traceview/frameworks/rails/inst/action_controller5_api.rb +23 -12
  21. data/lib/traceview/frameworks/sinatra/templates.rb +4 -4
  22. data/lib/traceview/inst/bunny-client.rb +8 -8
  23. data/lib/traceview/inst/bunny-consumer.rb +1 -1
  24. data/lib/traceview/inst/curb.rb +19 -19
  25. data/lib/traceview/inst/dalli.rb +4 -4
  26. data/lib/traceview/inst/delayed_job.rb +4 -4
  27. data/lib/traceview/inst/em-http-request.rb +6 -6
  28. data/lib/traceview/inst/excon.rb +18 -18
  29. data/lib/traceview/inst/faraday.rb +13 -13
  30. data/lib/traceview/inst/http.rb +12 -12
  31. data/lib/traceview/inst/httpclient.rb +19 -19
  32. data/lib/traceview/inst/memcache.rb +5 -5
  33. data/lib/traceview/inst/memcached.rb +4 -4
  34. data/lib/traceview/inst/mongo.rb +6 -6
  35. data/lib/traceview/inst/moped.rb +28 -28
  36. data/lib/traceview/inst/rack.rb +24 -24
  37. data/lib/traceview/inst/redis.rb +6 -6
  38. data/lib/traceview/inst/resque.rb +6 -6
  39. data/lib/traceview/inst/rest-client.rb +4 -4
  40. data/lib/traceview/inst/sequel.rb +12 -12
  41. data/lib/traceview/inst/sidekiq-client.rb +3 -3
  42. data/lib/traceview/inst/sidekiq-worker.rb +3 -3
  43. data/lib/traceview/inst/twitter-cassandra.rb +17 -17
  44. data/lib/traceview/inst/typhoeus.rb +13 -13
  45. data/lib/traceview/method_profiling.rb +2 -2
  46. data/lib/traceview/ruby.rb +1 -1
  47. data/lib/traceview/util.rb +4 -4
  48. data/lib/traceview/version.rb +1 -1
  49. data/test/frameworks/rails3x_test.rb +105 -0
  50. data/test/frameworks/rails4x_test.rb +97 -0
  51. data/test/frameworks/rails5x_api_test.rb +98 -1
  52. data/test/frameworks/rails5x_test.rb +99 -2
  53. data/test/profiling/legacy_method_profiling_test.rb +1 -1
  54. data/test/support/backcompat_test.rb +2 -2
  55. data/test/support/config_test.rb +1 -1
  56. metadata +2 -2
@@ -29,7 +29,7 @@ module TraceView
29
29
  # args: 0: worker_class, 1: msg, 2: queue, 3: redis_pool
30
30
  report_kvs = collect_kvs(args)
31
31
 
32
- TraceView::API.log_entry('sidekiq-client', report_kvs)
32
+ TraceView::API.log_entry(:'sidekiq-client', report_kvs)
33
33
  args[1]['SourceTrace'] = TraceView::Context.toString if TraceView.tracing?
34
34
 
35
35
  result = yield
@@ -37,10 +37,10 @@ module TraceView
37
37
  report_kvs = { :JobID => result['jid'] }
38
38
  result
39
39
  rescue => e
40
- TraceView::API.log_exception('sidekiq-client', e, report_kvs)
40
+ TraceView::API.log_exception(:'sidekiq-client', e, report_kvs)
41
41
  raise
42
42
  ensure
43
- TraceView::API.log_exit('sidekiq-client', report_kvs)
43
+ TraceView::API.log_exit(:'sidekiq-client', report_kvs)
44
44
  end
45
45
  end
46
46
  end
@@ -18,10 +18,10 @@ module TraceView
18
18
  report_kvs[:JobName] = worker.class.to_s
19
19
  report_kvs[:MsgID] = msg['jid']
20
20
  report_kvs[:Args] = msg['args'].to_s[0..1024] if TV::Config[:sidekiqworker][:log_args]
21
- report_kvs['Backtrace'] = TV::API.backtrace if TV::Config[:sidekiqworker][:collect_backtraces]
21
+ report_kvs[:Backtrace] = TV::API.backtrace if TV::Config[:sidekiqworker][:collect_backtraces]
22
22
 
23
23
  # Webserver Spec KVs
24
- report_kvs['HTTP-Host'] = Socket.gethostname
24
+ report_kvs[:'HTTP-Host'] = Socket.gethostname
25
25
  report_kvs[:Controller] = "Sidekiq_#{queue}"
26
26
  report_kvs[:Action] = msg['class']
27
27
  report_kvs[:URL] = "/sidekiq/#{queue}/#{msg['class']}"
@@ -49,7 +49,7 @@ module TraceView
49
49
  report_kvs['X-TV-Meta'] = args[1]['SourceTrace']
50
50
  end
51
51
 
52
- result = TraceView::API.start_trace('sidekiq-worker', nil, report_kvs) do
52
+ result = TraceView::API.start_trace(:'sidekiq-worker', nil, report_kvs) do
53
53
  yield
54
54
  end
55
55
 
@@ -48,7 +48,7 @@ module TraceView
48
48
 
49
49
  report_kvs = extract_trace_details(:insert, column_family, key, hash, options)
50
50
 
51
- TraceView::API.trace('cassandra', report_kvs) do
51
+ TraceView::API.trace(:cassandra, report_kvs) do
52
52
  insert_without_traceview(column_family, key, hash, options = {})
53
53
  end
54
54
  end
@@ -59,7 +59,7 @@ module TraceView
59
59
  args = [column_family, key] + columns_and_options
60
60
  report_kvs = extract_trace_details(:remove, column_family, key, columns_and_options)
61
61
 
62
- TraceView::API.trace('cassandra', report_kvs) do
62
+ TraceView::API.trace(:cassandra, report_kvs) do
63
63
  send :remove_without_traceview, *args
64
64
  end
65
65
  end
@@ -70,7 +70,7 @@ module TraceView
70
70
  args = [column_family, key] + columns_and_options
71
71
  report_kvs = extract_trace_details(:count_columns, column_family, key, columns_and_options)
72
72
 
73
- TraceView::API.trace('cassandra', report_kvs) do
73
+ TraceView::API.trace(:cassandra, report_kvs) do
74
74
  send :count_columns_without_traceview, *args
75
75
  end
76
76
  end
@@ -81,7 +81,7 @@ module TraceView
81
81
  if TraceView.tracing? && !TraceView.tracing_layer_op?(:multi_get_columns)
82
82
  report_kvs = extract_trace_details(:get_columns, column_family, key, columns_and_options)
83
83
 
84
- TraceView::API.trace('cassandra', report_kvs) do
84
+ TraceView::API.trace(:cassandra, report_kvs) do
85
85
  send :get_columns_without_traceview, *args
86
86
  end
87
87
  else
@@ -95,7 +95,7 @@ module TraceView
95
95
  args = [column_family, key] + columns_and_options
96
96
  report_kvs = extract_trace_details(:multi_get_columns, column_family, key, columns_and_options)
97
97
 
98
- TraceView::API.trace('cassandra', report_kvs, :multi_get_columns) do
98
+ TraceView::API.trace(:cassandra, report_kvs, :multi_get_columns) do
99
99
  send :multi_get_columns_without_traceview, *args
100
100
  end
101
101
  end
@@ -106,7 +106,7 @@ module TraceView
106
106
  args = [column_family, key] + columns_and_options
107
107
  report_kvs = extract_trace_details(:get, column_family, key, columns_and_options)
108
108
 
109
- TraceView::API.trace('cassandra', report_kvs, :get) do
109
+ TraceView::API.trace(:cassandra, report_kvs, :get) do
110
110
  send :get_without_traceview, *args
111
111
  end
112
112
  end
@@ -117,7 +117,7 @@ module TraceView
117
117
  if TraceView.tracing? && !TraceView.tracing_layer_op?(:get)
118
118
  report_kvs = extract_trace_details(:multi_get, column_family, key, columns_and_options)
119
119
 
120
- TraceView::API.trace('cassandra', report_kvs) do
120
+ TraceView::API.trace(:cassandra, report_kvs) do
121
121
  send :multi_get_without_traceview, *args
122
122
  end
123
123
  else
@@ -131,7 +131,7 @@ module TraceView
131
131
  args = [column_family, key] + columns_and_options
132
132
  report_kvs = extract_trace_details(:exists?, column_family, key, columns_and_options)
133
133
 
134
- TraceView::API.trace('cassandra', report_kvs) do
134
+ TraceView::API.trace(:cassandra, report_kvs) do
135
135
  send :exists_without_traceview?, *args
136
136
  end
137
137
  end
@@ -140,7 +140,7 @@ module TraceView
140
140
  if TraceView.tracing? && !TraceView.tracing_layer_op?(:get_range_batch)
141
141
  report_kvs = extract_trace_details(:get_range_single, column_family, nil, nil)
142
142
 
143
- TraceView::API.trace('cassandra', report_kvs) do
143
+ TraceView::API.trace(:cassandra, report_kvs) do
144
144
  get_range_single_without_traceview(column_family, options)
145
145
  end
146
146
  else
@@ -153,7 +153,7 @@ module TraceView
153
153
 
154
154
  report_kvs = extract_trace_details(:get_range_batch, column_family, nil, nil)
155
155
 
156
- TraceView::API.trace('cassandra', report_kvs, :get_range_batch) do
156
+ TraceView::API.trace(:cassandra, report_kvs, :get_range_batch) do
157
157
  get_range_batch_without_traceview(column_family, options)
158
158
  end
159
159
  end
@@ -164,7 +164,7 @@ module TraceView
164
164
  args = [column_family, index_clause] + columns_and_options
165
165
  report_kvs = extract_trace_details(:get_indexed_slices, column_family, nil, columns_and_options)
166
166
 
167
- TraceView::API.trace('cassandra', report_kvs) do
167
+ TraceView::API.trace(:cassandra, report_kvs) do
168
168
  send :get_indexed_slices_without_traceview, *args
169
169
  end
170
170
  end
@@ -183,7 +183,7 @@ module TraceView
183
183
  TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" if TraceView::Config[:verbose]
184
184
  end
185
185
 
186
- TraceView::API.trace('cassandra', report_kvs) do
186
+ TraceView::API.trace(:cassandra, report_kvs) do
187
187
  create_index_without_traceview(keyspace, column_family, column_name, validation_class)
188
188
  end
189
189
  end
@@ -199,7 +199,7 @@ module TraceView
199
199
  TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" if TraceView::Config[:verbose]
200
200
  end
201
201
 
202
- TraceView::API.trace('cassandra', report_kvs) do
202
+ TraceView::API.trace(:cassandra, report_kvs) do
203
203
  drop_index_without_traceview(keyspace, column_family, column_name)
204
204
  end
205
205
  end
@@ -214,7 +214,7 @@ module TraceView
214
214
  TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" if TraceView::Config[:verbose]
215
215
  end
216
216
 
217
- TraceView::API.trace('cassandra', report_kvs) do
217
+ TraceView::API.trace(:cassandra, report_kvs) do
218
218
  add_column_family_without_traceview(cf_def)
219
219
  end
220
220
  end
@@ -224,7 +224,7 @@ module TraceView
224
224
 
225
225
  report_kvs = extract_trace_details(:drop_column_family, column_family, nil, nil)
226
226
 
227
- TraceView::API.trace('cassandra', report_kvs) do
227
+ TraceView::API.trace(:cassandra, report_kvs) do
228
228
  drop_column_family_without_traceview(column_family)
229
229
  end
230
230
  end
@@ -235,7 +235,7 @@ module TraceView
235
235
  report_kvs = extract_trace_details(:add_keyspace, nil, nil, nil)
236
236
  report_kvs[:Name] = ks_def.name rescue ''
237
237
 
238
- TraceView::API.trace('cassandra', report_kvs) do
238
+ TraceView::API.trace(:cassandra, report_kvs) do
239
239
  add_keyspace_without_traceview(ks_def)
240
240
  end
241
241
  end
@@ -246,7 +246,7 @@ module TraceView
246
246
  report_kvs = extract_trace_details(:drop_keyspace, nil, nil, nil)
247
247
  report_kvs[:Name] = keyspace.to_s rescue ''
248
248
 
249
- TraceView::API.trace('cassandra', report_kvs) do
249
+ TraceView::API.trace(:cassandra, report_kvs) do
250
250
  drop_keyspace_without_traceview(keyspace)
251
251
  end
252
252
  end
@@ -12,7 +12,7 @@ module TraceView
12
12
  def run_with_traceview
13
13
  return run_without_traceview unless TraceView.tracing?
14
14
 
15
- TraceView::API.log_entry('typhoeus')
15
+ TraceView::API.log_entry(:typhoeus)
16
16
 
17
17
  # Prepare X-Trace header handling
18
18
  blacklisted = TraceView::API.blacklisted?(url)
@@ -23,26 +23,26 @@ module TraceView
23
23
  response = run_without_traceview
24
24
 
25
25
  if response.code == 0
26
- TraceView::API.log('typhoeus', 'error', { :ErrorClass => response.return_code,
27
- :ErrorMsg => response.return_message })
26
+ TraceView::API.log(:typhoeus, :error, { :ErrorClass => response.return_code,
27
+ :ErrorMsg => response.return_message })
28
28
  end
29
29
 
30
30
  kvs = {}
31
- kvs['IsService'] = 1
31
+ kvs[:IsService] = 1
32
32
  kvs[:HTTPStatus] = response.code
33
- kvs['Backtrace'] = TraceView::API.backtrace if TraceView::Config[:typhoeus][:collect_backtraces]
33
+ kvs[:Backtrace] = TraceView::API.backtrace if TraceView::Config[:typhoeus][:collect_backtraces]
34
34
 
35
35
  uri = URI(response.effective_url)
36
36
 
37
37
  # Conditionally log query params
38
38
  if TraceView::Config[:typhoeus][:log_args]
39
- kvs['RemoteURL'] = uri.to_s
39
+ kvs[:RemoteURL] = uri.to_s
40
40
  else
41
- kvs['RemoteURL'] = uri.to_s.split('?').first
41
+ kvs[:RemoteURL] = uri.to_s.split('?').first
42
42
  end
43
43
 
44
- kvs['HTTPMethod'] = ::TraceView::Util.upcase(options[:method])
45
- kvs['Blacklisted'] = true if blacklisted
44
+ kvs[:HTTPMethod] = ::TraceView::Util.upcase(options[:method])
45
+ kvs[:Blacklisted] = true if blacklisted
46
46
 
47
47
  # Re-attach net::http edge unless it's blacklisted or if we don't have a
48
48
  # valid X-Trace header
@@ -60,13 +60,13 @@ module TraceView
60
60
  end
61
61
  end
62
62
 
63
- TraceView::API.log('typhoeus', 'info', kvs)
63
+ TraceView::API.log(:typhoeus, :info, kvs)
64
64
  response
65
65
  rescue => e
66
- TraceView::API.log_exception('typhoeus', e)
66
+ TraceView::API.log_exception(:typhoeus, e)
67
67
  raise e
68
68
  ensure
69
- TraceView::API.log_exit('typhoeus')
69
+ TraceView::API.log_exit(:typhoeus)
70
70
  end
71
71
  end
72
72
 
@@ -84,7 +84,7 @@ module TraceView
84
84
  # FIXME: Until we figure out a strategy to deal with libcurl internal
85
85
  # threading and Ethon's use of easy handles, here we just do a simple
86
86
  # trace of the hydra run.
87
- TraceView::API.trace("typhoeus_hydra", kvs) do
87
+ TraceView::API.trace(:typhoeus_hydra, kvs) do
88
88
  run_without_traceview
89
89
  end
90
90
  end
@@ -5,7 +5,7 @@ module TraceView
5
5
  report_kvs[:Backtrace] = TraceView::API.backtrace(2) if opts[:backtrace]
6
6
  report_kvs[:Arguments] = args if opts[:arguments]
7
7
 
8
- TraceView::API.log(nil, 'profile_entry', report_kvs)
8
+ TraceView::API.log(nil, :profile_entry, report_kvs)
9
9
 
10
10
  begin
11
11
  rv = self.send(method, *args, &block)
@@ -18,7 +18,7 @@ module TraceView
18
18
  report_kvs.delete(:Backtrace)
19
19
  report_kvs.delete(:Controller)
20
20
  report_kvs.delete(:Action)
21
- TraceView::API.log(nil, 'profile_exit', report_kvs)
21
+ TraceView::API.log(nil, :profile_exit, report_kvs)
22
22
  end
23
23
  end
24
24
  end
@@ -31,6 +31,6 @@ module TraceView
31
31
  end
32
32
  end
33
33
 
34
- if TraceView.loaded and !TraceView.framework?
34
+ if TraceView.loaded && !TraceView.framework?
35
35
  ::TraceView::Ruby.load
36
36
  end
@@ -42,8 +42,8 @@ module TraceView
42
42
  cls.private_method_defined?(without_traceview.to_sym)
43
43
 
44
44
  cls.class_eval do
45
- alias_method without_traceview, "#{method}"
46
- alias_method "#{method}", with_traceview
45
+ alias_method without_traceview, method.to_s
46
+ alias_method method.to_s, with_traceview
47
47
  end
48
48
  end
49
49
  else
@@ -71,8 +71,8 @@ module TraceView
71
71
 
72
72
  # Only alias if we haven't done so already
73
73
  unless cls.singleton_methods.include? without_traceview.to_sym
74
- cls.singleton_class.send(:alias_method, without_traceview, "#{method}")
75
- cls.singleton_class.send(:alias_method, "#{method}", with_traceview)
74
+ cls.singleton_class.send(:alias_method, without_traceview, method.to_s)
75
+ cls.singleton_class.send(:alias_method, method.to_s, with_traceview)
76
76
  end
77
77
  else TraceView.logger.warn "[traceview/loading] Couldn't properly instrument #{name}. Partial traces may occur."
78
78
  end
@@ -8,7 +8,7 @@ module TraceView
8
8
  module Version
9
9
  MAJOR = 3
10
10
  MINOR = 8
11
- PATCH = 0
11
+ PATCH = 1
12
12
  BUILD = nil
13
13
 
14
14
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
@@ -8,9 +8,14 @@ if defined?(::Rails)
8
8
  describe "Rails3x" do
9
9
  before do
10
10
  clear_all_traces
11
+ @collect_backtraces = TraceView::Config[:action_controller][:collect_backtraces]
11
12
  ENV['DBTYPE'] = "postgresql" unless ENV['DBTYPE']
12
13
  end
13
14
 
15
+ after do
16
+ TraceView::Config[:action_controller][:collect_backtraces] = @collect_backtraces
17
+ end
18
+
14
19
  it "should trace a request to a rails stack" do
15
20
 
16
21
  uri = URI.parse('http://127.0.0.1:8140/hello/world')
@@ -294,5 +299,105 @@ if defined?(::Rails)
294
299
  r.header.key?('X-Trace').must_equal true
295
300
  r.header['X-Trace'].must_equal traces[13]['X-Trace']
296
301
  end
302
+
303
+ it "should collect backtraces when true" do
304
+
305
+ TraceView::Config[:action_controller][:collect_backtraces] = true
306
+
307
+ uri = URI.parse('http://127.0.0.1:8140/hello/world')
308
+ r = Net::HTTP.get_response(uri)
309
+
310
+ traces = get_all_traces
311
+
312
+ traces.count.must_equal 8
313
+ unless defined?(JRUBY_VERSION)
314
+ # We don't test this under JRuby because the Java instrumentation
315
+ # for the DB drivers doesn't use our test reporter hence we won't
316
+ # see all trace events. :-( To be improved.
317
+ valid_edges?(traces).must_equal true
318
+ end
319
+ validate_outer_layers(traces, 'rack')
320
+
321
+ traces[0]['Layer'].must_equal "rack"
322
+ traces[0]['Label'].must_equal "entry"
323
+ traces[0]['URL'].must_equal "/hello/world"
324
+
325
+ traces[1]['Layer'].must_equal "rack"
326
+ traces[1]['Label'].must_equal "info"
327
+
328
+ traces[2]['Layer'].must_equal "rails"
329
+ traces[2]['Label'].must_equal "entry"
330
+
331
+ traces[3]['Label'].must_equal "info"
332
+ traces[3]['Controller'].must_equal "HelloController"
333
+ traces[3]['Action'].must_equal "world"
334
+ traces[3].key?('Backtrace').must_equal true
335
+
336
+ traces[4]['Layer'].must_equal "actionview"
337
+ traces[4]['Label'].must_equal "entry"
338
+
339
+ traces[5]['Layer'].must_equal "actionview"
340
+ traces[5]['Label'].must_equal "exit"
341
+
342
+ traces[6]['Layer'].must_equal "rails"
343
+ traces[6]['Label'].must_equal "exit"
344
+
345
+ traces[7]['Layer'].must_equal "rack"
346
+ traces[7]['Label'].must_equal "exit"
347
+
348
+ # Validate the existence of the response header
349
+ r.header.key?('X-Trace').must_equal true
350
+ r.header['X-Trace'].must_equal traces[7]['X-Trace']
351
+ end
352
+
353
+ it "should NOT collect backtraces when false" do
354
+
355
+ TraceView::Config[:action_controller][:collect_backtraces] = false
356
+
357
+ uri = URI.parse('http://127.0.0.1:8140/hello/world')
358
+ r = Net::HTTP.get_response(uri)
359
+
360
+ traces = get_all_traces
361
+
362
+ traces.count.must_equal 8
363
+ unless defined?(JRUBY_VERSION)
364
+ # We don't test this under JRuby because the Java instrumentation
365
+ # for the DB drivers doesn't use our test reporter hence we won't
366
+ # see all trace events. :-( To be improved.
367
+ valid_edges?(traces).must_equal true
368
+ end
369
+ validate_outer_layers(traces, 'rack')
370
+
371
+ traces[0]['Layer'].must_equal "rack"
372
+ traces[0]['Label'].must_equal "entry"
373
+ traces[0]['URL'].must_equal "/hello/world"
374
+
375
+ traces[1]['Layer'].must_equal "rack"
376
+ traces[1]['Label'].must_equal "info"
377
+
378
+ traces[2]['Layer'].must_equal "rails"
379
+ traces[2]['Label'].must_equal "entry"
380
+
381
+ traces[3]['Label'].must_equal "info"
382
+ traces[3]['Controller'].must_equal "HelloController"
383
+ traces[3]['Action'].must_equal "world"
384
+ traces[3].key?('Backtrace').must_equal false
385
+
386
+ traces[4]['Layer'].must_equal "actionview"
387
+ traces[4]['Label'].must_equal "entry"
388
+
389
+ traces[5]['Layer'].must_equal "actionview"
390
+ traces[5]['Label'].must_equal "exit"
391
+
392
+ traces[6]['Layer'].must_equal "rails"
393
+ traces[6]['Label'].must_equal "exit"
394
+
395
+ traces[7]['Layer'].must_equal "rack"
396
+ traces[7]['Label'].must_equal "exit"
397
+
398
+ # Validate the existence of the response header
399
+ r.header.key?('X-Trace').must_equal true
400
+ r.header['X-Trace'].must_equal traces[7]['X-Trace']
401
+ end
297
402
  end
298
403
  end
@@ -8,9 +8,14 @@ if defined?(::Rails)
8
8
  describe "Rails4x" do
9
9
  before do
10
10
  clear_all_traces
11
+ @collect_backtraces = TraceView::Config[:action_controller][:collect_backtraces]
11
12
  ENV['DBTYPE'] = "postgresql" unless ENV['DBTYPE']
12
13
  end
13
14
 
15
+ after do
16
+ TraceView::Config[:action_controller][:collect_backtraces] = @collect_backtraces
17
+ end
18
+
14
19
  it "should trace a request to a rails stack" do
15
20
 
16
21
  uri = URI.parse('http://127.0.0.1:8140/hello/world')
@@ -286,5 +291,97 @@ if defined?(::Rails)
286
291
  # Validate the existence of the response header
287
292
  r['X-Trace'].must_equal traces[4]['X-Trace']
288
293
  end
294
+
295
+ it "should collect backtraces when true" do
296
+ TraceView::Config[:action_controller][:collect_backtraces] = true
297
+
298
+ uri = URI.parse('http://127.0.0.1:8140/hello/world')
299
+ r = Net::HTTP.get_response(uri)
300
+
301
+ traces = get_all_traces
302
+
303
+ traces.count.must_equal 7
304
+ unless defined?(JRUBY_VERSION)
305
+ # We don't test this under JRuby because the Java instrumentation
306
+ # for the DB drivers doesn't use our test reporter hence we won't
307
+ # see all trace events. :-( To be improved.
308
+ valid_edges?(traces).must_equal true
309
+ end
310
+ validate_outer_layers(traces, 'rack')
311
+
312
+ traces[0]['Layer'].must_equal "rack"
313
+ traces[0]['Label'].must_equal "entry"
314
+ traces[0]['URL'].must_equal "/hello/world"
315
+
316
+ traces[1]['Layer'].must_equal "rack"
317
+ traces[1]['Label'].must_equal "info"
318
+
319
+ traces[2]['Layer'].must_equal "rails"
320
+ traces[2]['Label'].must_equal "entry"
321
+ traces[2]['Controller'].must_equal "HelloController"
322
+ traces[2]['Action'].must_equal "world"
323
+ traces[2].key?('Backtrace').must_equal true
324
+
325
+ traces[3]['Layer'].must_equal "actionview"
326
+ traces[3]['Label'].must_equal "entry"
327
+
328
+ traces[4]['Layer'].must_equal "actionview"
329
+ traces[4]['Label'].must_equal "exit"
330
+
331
+ traces[5]['Layer'].must_equal "rails"
332
+ traces[5]['Label'].must_equal "exit"
333
+
334
+ traces[6]['Layer'].must_equal "rack"
335
+ traces[6]['Label'].must_equal "exit"
336
+
337
+ # Validate the existence of the response header
338
+ r['X-Trace'].must_equal traces[6]['X-Trace']
339
+ end
340
+
341
+ it "should NOT collect backtraces when false" do
342
+ TraceView::Config[:action_controller][:collect_backtraces] = false
343
+
344
+ uri = URI.parse('http://127.0.0.1:8140/hello/world')
345
+ r = Net::HTTP.get_response(uri)
346
+
347
+ traces = get_all_traces
348
+
349
+ traces.count.must_equal 7
350
+ unless defined?(JRUBY_VERSION)
351
+ # We don't test this under JRuby because the Java instrumentation
352
+ # for the DB drivers doesn't use our test reporter hence we won't
353
+ # see all trace events. :-( To be improved.
354
+ valid_edges?(traces).must_equal true
355
+ end
356
+ validate_outer_layers(traces, 'rack')
357
+
358
+ traces[0]['Layer'].must_equal "rack"
359
+ traces[0]['Label'].must_equal "entry"
360
+ traces[0]['URL'].must_equal "/hello/world"
361
+
362
+ traces[1]['Layer'].must_equal "rack"
363
+ traces[1]['Label'].must_equal "info"
364
+
365
+ traces[2]['Layer'].must_equal "rails"
366
+ traces[2]['Label'].must_equal "entry"
367
+ traces[2]['Controller'].must_equal "HelloController"
368
+ traces[2]['Action'].must_equal "world"
369
+ traces[2].key?('Backtrace').must_equal false
370
+
371
+ traces[3]['Layer'].must_equal "actionview"
372
+ traces[3]['Label'].must_equal "entry"
373
+
374
+ traces[4]['Layer'].must_equal "actionview"
375
+ traces[4]['Label'].must_equal "exit"
376
+
377
+ traces[5]['Layer'].must_equal "rails"
378
+ traces[5]['Label'].must_equal "exit"
379
+
380
+ traces[6]['Layer'].must_equal "rack"
381
+ traces[6]['Label'].must_equal "exit"
382
+
383
+ # Validate the existence of the response header
384
+ r['X-Trace'].must_equal traces[6]['X-Trace']
385
+ end
289
386
  end
290
387
  end