traceview 3.6.0 → 3.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +12 -1
  3. data/CHANGELOG.md +11 -0
  4. data/CONFIG.md +22 -5
  5. data/Rakefile +2 -2
  6. data/gemfiles/delayed_job.gemfile +1 -1
  7. data/gemfiles/frameworks.gemfile +1 -1
  8. data/gemfiles/libraries.gemfile +4 -3
  9. data/gemfiles/rails31.gemfile +2 -0
  10. data/gemfiles/rails32.gemfile +5 -2
  11. data/gemfiles/rails40.gemfile +5 -3
  12. data/gemfiles/rails41.gemfile +6 -4
  13. data/gemfiles/rails42.gemfile +3 -1
  14. data/gemfiles/rails50.gemfile +43 -0
  15. data/lib/rails/generators/traceview/templates/traceview_initializer.rb +56 -32
  16. data/lib/traceview/base.rb +1 -1
  17. data/lib/traceview/frameworks/rails.rb +6 -9
  18. data/lib/traceview/frameworks/rails/inst/action_controller.rb +2 -135
  19. data/lib/traceview/frameworks/rails/inst/action_controller2.rb +59 -0
  20. data/lib/traceview/frameworks/rails/inst/action_controller3.rb +49 -0
  21. data/lib/traceview/frameworks/rails/inst/action_controller4.rb +40 -0
  22. data/lib/traceview/frameworks/rails/inst/action_controller5.rb +39 -0
  23. data/lib/traceview/frameworks/rails/inst/action_view.rb +1 -1
  24. data/lib/traceview/frameworks/rails/inst/active_record.rb +6 -3
  25. data/lib/traceview/frameworks/rails/inst/connection_adapters/postgresql.rb +1 -1
  26. data/lib/traceview/frameworks/rails/inst/connection_adapters/utils.rb +30 -36
  27. data/lib/traceview/frameworks/rails/inst/connection_adapters/utils5x.rb +100 -0
  28. data/lib/traceview/test.rb +39 -0
  29. data/lib/traceview/version.rb +1 -1
  30. data/test/frameworks/rails3x_test.rb +163 -7
  31. data/test/frameworks/rails4x_test.rb +162 -13
  32. data/test/frameworks/rails5x_test.rb +213 -0
  33. data/test/instrumentation/excon_test.rb +3 -0
  34. data/test/instrumentation/sequel_mysql2_test.rb +2 -5
  35. data/test/instrumentation/sequel_mysql_test.rb +2 -5
  36. data/test/instrumentation/sequel_pg_test.rb +2 -5
  37. data/test/minitest_helper.rb +25 -21
  38. data/test/servers/delayed_job.rb +2 -6
  39. data/test/servers/rails3x_8140.rb +16 -6
  40. data/test/servers/rails4x_8140.rb +20 -9
  41. data/test/servers/rails5x_8140.rb +112 -0
  42. metadata +13 -4
  43. data/lib/traceview/frameworks/rails/inst/connection_adapters/oracle.rb +0 -18
@@ -224,7 +224,7 @@ module TraceViewBase
224
224
  Pry.commands.alias_command 'n', 'next'
225
225
  Pry.commands.alias_command 'f', 'finish'
226
226
 
227
- Pry::Commands.command /^$/, 'repeat last command' do
227
+ Pry::Commands.command(/^$/, 'repeat last command') do
228
228
  _pry_.run_command Pry.history.to_a.last
229
229
  end
230
230
  end
@@ -65,14 +65,11 @@ module TraceView
65
65
 
66
66
  def self.load_instrumentation
67
67
  # Load the Rails specific instrumentation
68
- pattern = File.join(File.dirname(__FILE__), 'rails/inst', '*.rb')
69
- Dir.glob(pattern) do |f|
70
- begin
71
- require f
72
- rescue => e
73
- TraceView.logger.error "[traceview/loading] Error loading rails insrumentation file '#{f}' : #{e}"
74
- end
75
- end
68
+ require 'traceview/frameworks/rails/inst/action_controller'
69
+ require 'traceview/frameworks/rails/inst/action_view'
70
+ require 'traceview/frameworks/rails/inst/action_view_2x'
71
+ require 'traceview/frameworks/rails/inst/action_view_30'
72
+ require 'traceview/frameworks/rails/inst/active_record'
76
73
 
77
74
  TraceView.logger.info "TraceView gem #{TraceView::Version::STRING} successfully loaded."
78
75
  end
@@ -105,7 +102,7 @@ if defined?(::Rails)
105
102
 
106
103
  initializer 'traceview.rack' do |app|
107
104
  TraceView.logger.info '[traceview/loading] Instrumenting rack' if TraceView::Config[:verbose]
108
- app.config.middleware.insert 0, 'TraceView::Rack'
105
+ app.config.middleware.insert 0, TraceView::Rack
109
106
  end
110
107
 
111
108
  config.after_initialize do
@@ -69,145 +69,12 @@ module TraceView
69
69
  TraceView::API.log_exit('actionview')
70
70
  end
71
71
  end
72
-
73
- #
74
- # ActionController3
75
- #
76
- # This modules contains the instrumentation code specific
77
- # to Rails v3
78
- #
79
- module ActionController3
80
- include ::TraceView::Inst::RailsBase
81
-
82
- def self.included(base)
83
- base.class_eval do
84
- alias_method_chain :process, :traceview
85
- alias_method_chain :process_action, :traceview
86
- alias_method_chain :render, :traceview
87
- end
88
- end
89
-
90
- def process_with_traceview(*args)
91
- TraceView::API.log_entry('rails')
92
- process_without_traceview(*args)
93
-
94
- rescue Exception => e
95
- TraceView::API.log_exception(nil, e) if log_rails_error?(e)
96
- raise
97
- ensure
98
- TraceView::API.log_exit('rails')
99
- end
100
-
101
- def process_action_with_traceview(*args)
102
- report_kvs = {
103
- :Controller => self.class.name,
104
- :Action => action_name,
105
- }
106
- TraceView::API.log(nil, 'info', report_kvs)
107
-
108
- process_action_without_traceview(*args)
109
- rescue Exception
110
- report_kvs[:Status] = 500
111
- TraceView::API.log(nil, 'info', report_kvs)
112
- raise
113
- end
114
- end
115
-
116
- #
117
- # ActionController4
118
- #
119
- # This modules contains the instrumentation code specific
120
- # to Rails v4
121
- #
122
- module ActionController4
123
- include ::TraceView::Inst::RailsBase
124
-
125
- def self.included(base)
126
- base.class_eval do
127
- alias_method_chain :process_action, :traceview
128
- alias_method_chain :render, :traceview
129
- end
130
- end
131
-
132
- def process_action_with_traceview(method_name, *args)
133
- report_kvs = {
134
- :Controller => self.class.name,
135
- :Action => self.action_name,
136
- }
137
-
138
- TraceView::API.log_entry('rails', report_kvs)
139
- process_action_without_traceview(method_name, *args)
140
-
141
- rescue Exception => e
142
- TraceView::API.log_exception(nil, e) if log_rails_error?(e)
143
- raise
144
- ensure
145
- TraceView::API.log_exit('rails')
146
- end
147
- end
148
72
  end
149
73
  end
150
74
 
151
75
  if defined?(ActionController::Base) && TraceView::Config[:action_controller][:enabled]
152
- if ::Rails::VERSION::MAJOR == 4
153
-
154
- class ActionController::Base
155
- include TraceView::Inst::ActionController4
156
- end
157
-
158
- elsif ::Rails::VERSION::MAJOR == 3
159
-
160
- class ActionController::Base
161
- include TraceView::Inst::ActionController3
162
- end
163
-
164
- elsif ::Rails::VERSION::MAJOR == 2
165
-
166
- ActionController::Base.class_eval do
167
- include ::TraceView::Inst::RailsBase
168
-
169
- alias :perform_action_without_traceview :perform_action
170
- alias :rescue_action_without_traceview :rescue_action
171
- alias :process_without_traceview :process
172
- alias :render_without_traceview :render
173
-
174
- def process(*args)
175
- TraceView::API.log_entry('rails')
176
- process_without_traceview(*args)
177
-
178
- rescue Exception => e
179
- TraceView::API.log_exception(nil, e) if log_rails_error?(e)
180
- raise
181
- ensure
182
- TraceView::API.log_exit('rails')
183
- end
184
-
185
- def perform_action(*arguments)
186
- report_kvs = {
187
- :Controller => @_request.path_parameters['controller'],
188
- :Action => @_request.path_parameters['action']
189
- }
190
- TraceView::API.log(nil, 'info', report_kvs)
191
- perform_action_without_traceview(*arguments)
192
- end
193
-
194
- def rescue_action(exn)
195
- TraceView::API.log_exception(nil, exn) if log_rails_error?(exn)
196
- rescue_action_without_traceview(exn)
197
- end
198
-
199
- def render(options = nil, extra_options = {}, &block)
200
- TraceView::API.log_entry('actionview')
201
- render_without_traceview(options, extra_options, &block)
202
-
203
- rescue Exception => e
204
- TraceView::API.log_exception(nil, e) if log_rails_error?(e)
205
- raise
206
- ensure
207
- TraceView::API.log_exit('actionview')
208
- end
209
- end
210
- end
211
76
  TraceView.logger.info '[traceview/loading] Instrumenting actioncontroler' if TraceView::Config[:verbose]
77
+ require "traceview/frameworks/rails/inst/action_controller#{Rails::VERSION::MAJOR}"
78
+ ::TraceView::Util.send_include(::ActionController::Base, TraceView::Inst::ActionController)
212
79
  end
213
80
  # vim:set expandtab:tabstop=2
@@ -0,0 +1,59 @@
1
+ # Copyright (c) 2016 AppNeta, Inc.
2
+ # All rights reserved.
3
+
4
+ module TraceView
5
+ module Inst
6
+ #
7
+ # ActionController
8
+ #
9
+ # This modules contains the instrumentation code specific
10
+ # to Rails v2
11
+ #
12
+ module ActionController
13
+ include ::TraceView::Inst::RailsBase
14
+
15
+ def self.included(klass)
16
+ ::TraceView::Util.method_alias(klass, :perform_action)
17
+ ::TraceView::Util.method_alias(klass, :rescue_action)
18
+ ::TraceView::Util.method_alias(klass, :process)
19
+ ::TraceView::Util.method_alias(klass, :render)
20
+ end
21
+
22
+ def process_with_traceview(*args)
23
+ TraceView::API.log_entry('rails')
24
+ process_without_traceview(*args)
25
+
26
+ rescue Exception => e
27
+ TraceView::API.log_exception(nil, e) if log_rails_error?(e)
28
+ raise
29
+ ensure
30
+ TraceView::API.log_exit('rails')
31
+ end
32
+
33
+ def perform_action_with_traceview(*arguments)
34
+ report_kvs = {
35
+ :Controller => @_request.path_parameters['controller'],
36
+ :Action => @_request.path_parameters['action']
37
+ }
38
+ TraceView::API.log(nil, 'info', report_kvs)
39
+ perform_action_without_traceview(*arguments)
40
+ end
41
+
42
+ def rescue_action_with_traceview(exn)
43
+ TraceView::API.log_exception(nil, exn) if log_rails_error?(exn)
44
+ rescue_action_without_traceview(exn)
45
+ end
46
+
47
+ def render_with_traceview(options = nil, extra_options = {}, &block)
48
+ TraceView::API.log_entry('actionview')
49
+ render_without_traceview(options, extra_options, &block)
50
+
51
+ rescue Exception => e
52
+ TraceView::API.log_exception(nil, e) if log_rails_error?(e)
53
+ raise
54
+ ensure
55
+ TraceView::API.log_exit('actionview')
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,49 @@
1
+ # Copyright (c) 2016 AppNeta, Inc.
2
+ # All rights reserved.
3
+
4
+ module TraceView
5
+ module Inst
6
+ #
7
+ # ActionController
8
+ #
9
+ # This modules contains the instrumentation code specific
10
+ # to Rails v3
11
+ #
12
+ module ActionController
13
+ include ::TraceView::Inst::RailsBase
14
+
15
+ def self.included(base)
16
+ base.class_eval do
17
+ alias_method_chain :process, :traceview
18
+ alias_method_chain :process_action, :traceview
19
+ alias_method_chain :render, :traceview
20
+ end
21
+ end
22
+
23
+ def process_with_traceview(*args)
24
+ TraceView::API.log_entry('rails')
25
+ process_without_traceview(*args)
26
+
27
+ rescue Exception => e
28
+ TraceView::API.log_exception(nil, e) if log_rails_error?(e)
29
+ raise
30
+ ensure
31
+ TraceView::API.log_exit('rails')
32
+ end
33
+
34
+ def process_action_with_traceview(*args)
35
+ report_kvs = {
36
+ :Controller => self.class.name,
37
+ :Action => action_name,
38
+ }
39
+ TraceView::API.log(nil, 'info', report_kvs)
40
+
41
+ process_action_without_traceview(*args)
42
+ rescue Exception
43
+ report_kvs[:Status] = 500
44
+ TraceView::API.log(nil, 'info', report_kvs)
45
+ raise
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,40 @@
1
+ # Copyright (c) 2013 AppNeta, Inc.
2
+ # All rights reserved.
3
+
4
+ module TraceView
5
+ module Inst
6
+ #
7
+ # ActionController
8
+ #
9
+ # This modules contains the instrumentation code specific
10
+ # to Rails v4
11
+ #
12
+ module ActionController
13
+ include ::TraceView::Inst::RailsBase
14
+
15
+ def self.included(base)
16
+ base.class_eval do
17
+ alias_method_chain :process_action, :traceview
18
+ alias_method_chain :render, :traceview
19
+ end
20
+ end
21
+
22
+ def process_action_with_traceview(method_name, *args)
23
+ report_kvs = {
24
+ :Controller => self.class.name,
25
+ :Action => self.action_name,
26
+ }
27
+
28
+ TraceView::API.log_entry('rails', report_kvs)
29
+ process_action_without_traceview(method_name, *args)
30
+
31
+ rescue Exception => e
32
+ TraceView::API.log_exception(nil, e) if log_rails_error?(e)
33
+ raise
34
+ ensure
35
+ TraceView::API.log_exit('rails')
36
+ end
37
+ end
38
+ end
39
+ end
40
+
@@ -0,0 +1,39 @@
1
+ # Copyright (c) 2016 AppNeta, Inc.
2
+ # All rights reserved.
3
+
4
+ module TraceView
5
+ module Inst
6
+ #
7
+ # ActionController
8
+ #
9
+ # This modules contains the instrumentation code specific
10
+ # to Rails v5
11
+ #
12
+ module ActionController
13
+ include ::TraceView::Inst::RailsBase
14
+
15
+ def self.included(base)
16
+ base.class_eval do
17
+ alias_method_chain :process_action, :traceview
18
+ alias_method_chain :render, :traceview
19
+ end
20
+ end
21
+
22
+ def process_action_with_traceview(method_name, *args)
23
+ report_kvs = {
24
+ :Controller => self.class.name,
25
+ :Action => self.action_name,
26
+ }
27
+
28
+ TraceView::API.log_entry('rails', report_kvs)
29
+ process_action_without_traceview(method_name, *args)
30
+
31
+ rescue Exception => e
32
+ TraceView::API.log_exception(nil, e) if log_rails_error?(e)
33
+ raise
34
+ ensure
35
+ TraceView::API.log_exit('rails')
36
+ end
37
+ end
38
+ end
39
+ end
@@ -8,7 +8,7 @@ if defined?(ActionView::Base) && TraceView::Config[:action_view][:enabled]
8
8
  # and ActionView 3.0 is a special case.
9
9
  # Everything else goes here. (ActionView 3.1 - 4.0 as of this writing)
10
10
  #
11
- if (Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR > 0) || Rails::VERSION::MAJOR == 4
11
+ if (Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR > 0) || Rails::VERSION::MAJOR >= 4
12
12
 
13
13
  TraceView.logger.info '[traceview/loading] Instrumenting actionview' if TraceView::Config[:verbose]
14
14
 
@@ -1,20 +1,23 @@
1
1
  # Copyright (c) 2013 AppNeta, Inc.
2
2
  # All rights reserved.
3
3
 
4
- require 'traceview/frameworks/rails/inst/connection_adapters/utils'
5
4
  require 'traceview/frameworks/rails/inst/connection_adapters/mysql'
6
5
  require 'traceview/frameworks/rails/inst/connection_adapters/mysql2'
7
6
  require 'traceview/frameworks/rails/inst/connection_adapters/postgresql'
8
- require 'traceview/frameworks/rails/inst/connection_adapters/oracle'
9
7
 
10
8
  if TraceView::Config[:active_record][:enabled] && !defined?(JRUBY_VERSION)
11
9
  begin
12
10
  adapter = ActiveRecord::Base.connection.adapter_name.downcase
13
11
 
12
+ if Rails::VERSION::MAJOR < 5
13
+ require 'traceview/frameworks/rails/inst/connection_adapters/utils'
14
+ else
15
+ require 'traceview/frameworks/rails/inst/connection_adapters/utils5x'
16
+ end
17
+
14
18
  TraceView::Inst::ConnectionAdapters::FlavorInitializers.mysql if adapter == 'mysql'
15
19
  TraceView::Inst::ConnectionAdapters::FlavorInitializers.mysql2 if adapter == 'mysql2'
16
20
  TraceView::Inst::ConnectionAdapters::FlavorInitializers.postgresql if adapter == 'postgresql'
17
- TraceView::Inst::ConnectionAdapters::FlavorInitializers.oracle if adapter == 'oracleenhanced'
18
21
 
19
22
  rescue StandardError => e
20
23
  TraceView.logger.error "[traceview/error] TraceView/ActiveRecord error: #{e.inspect}"
@@ -13,7 +13,7 @@ module TraceView
13
13
  ::TraceView::Inst::ConnectionAdapters::Utils)
14
14
 
15
15
  if (::ActiveRecord::VERSION::MAJOR == 3 && ::ActiveRecord::VERSION::MINOR > 0) ||
16
- ::ActiveRecord::VERSION::MAJOR == 4
16
+ ::ActiveRecord::VERSION::MAJOR >= 4
17
17
 
18
18
  # ActiveRecord 3.1 and up
19
19
  TraceView::Util.method_alias(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter, :exec_query)
@@ -8,44 +8,41 @@ module TraceView
8
8
 
9
9
  def extract_trace_details(sql, name = nil, binds = [])
10
10
  opts = {}
11
+ if TraceView::Config[:sanitize_sql]
12
+ # Sanitize SQL and don't report binds
13
+ opts[:Query] = TraceView::Util.sanitize_sql(sql)
14
+ else
15
+ # Report raw SQL and any binds if they exist
16
+ opts[:Query] = sql.to_s
17
+ opts[:QueryArgs] = binds.map { |col, val| [col.name, val.to_s] } unless binds.empty?
18
+ end
11
19
 
12
- begin
13
- if TraceView::Config[:sanitize_sql]
14
- # Sanitize SQL and don't report binds
15
- opts[:Query] = TraceView::Util.sanitize_sql(sql)
16
- else
17
- # Report raw SQL and any binds if they exist
18
- opts[:Query] = sql.to_s
19
- opts[:QueryArgs] = binds.map { |col, val| type_cast(val, col) } unless binds.empty?
20
- end
20
+ opts[:Name] = name.to_s if name
21
+ opts[:Backtrace] = TraceView::API.backtrace if TraceView::Config[:active_record][:collect_backtraces]
21
22
 
22
- opts[:Name] = name.to_s if name
23
- opts[:Backtrace] = TraceView::API.backtrace if TraceView::Config[:active_record][:collect_backtraces]
23
+ if ::Rails::VERSION::MAJOR == 2
24
+ config = ::Rails.configuration.database_configuration[::Rails.env]
25
+ else
26
+ config = ActiveRecord::Base.connection.instance_variable_get(:@config)
27
+ end
24
28
 
25
- if ::Rails::VERSION::MAJOR == 2
26
- config = ::Rails.configuration.database_configuration[::Rails.env]
27
- else
28
- config = ActiveRecord::Base.connection.instance_variable_get(:@config)
29
- end
29
+ if config
30
+ opts[:Database] = config['database'] if config.key?('database')
31
+ opts[:RemoteHost] = config['host'] if config.key?('host')
32
+ adapter_name = config[:adapter]
30
33
 
31
- if config
32
- opts[:Database] = config['database'] if config.key?('database')
33
- opts[:RemoteHost] = config['host'] if config.key?('host')
34
- adapter_name = config[:adapter]
35
-
36
- case adapter_name
37
- when /mysql/i
38
- opts[:Flavor] = 'mysql'
39
- when /postgres/i
40
- opts[:Flavor] = 'postgresql'
41
- end
34
+ case adapter_name
35
+ when /mysql/i
36
+ opts[:Flavor] = 'mysql'
37
+ when /postgres/i
38
+ opts[:Flavor] = 'postgresql'
42
39
  end
43
- rescue StandardError => e
44
- TraceView.logger.debug "Exception raised capturing ActiveRecord KVs: #{e.inspect}"
45
- TraceView.logger.debug e.backtrace.join('\n')
46
40
  end
47
-
48
- return opts || {}
41
+ rescue StandardError => e
42
+ TraceView.logger.debug "Exception raised capturing ActiveRecord KVs: #{e.inspect}"
43
+ TraceView.logger.debug e.backtrace.join('\n')
44
+ ensure
45
+ return opts
49
46
  end
50
47
 
51
48
  # We don't want to trace framework caches. Only instrument SQL that
@@ -110,10 +107,7 @@ module TraceView
110
107
 
111
108
  def begin_db_transaction_with_traceview
112
109
  if TraceView.tracing?
113
- opts = {}
114
-
115
- opts[:Query] = 'BEGIN'
116
- TraceView::API.trace('activerecord', opts || {}) do
110
+ TraceView::API.trace('activerecord', { :Query => 'BEGIN' }) do
117
111
  begin_db_transaction_without_traceview
118
112
  end
119
113
  else