traceview 3.0.0-java

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 (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,58 @@
1
+ # Copyright (c) 2013 AppNeta, Inc.
2
+ # All rights reserved.
3
+
4
+ module TraceView
5
+ module PadrinoInst
6
+ module Rendering
7
+ def self.included(klass)
8
+ ::TraceView::Util.method_alias(klass, :render, ::Padrino::Rendering)
9
+ end
10
+
11
+ def render_with_traceview(engine, data = nil, options = {}, locals = {}, &block)
12
+ if TraceView.tracing?
13
+ report_kvs = {}
14
+
15
+ if data
16
+ report_kvs[:engine] = engine
17
+ report_kvs[:template] = data
18
+ else
19
+ report_kvs[:template] = engine
20
+ end
21
+
22
+ if TraceView.tracing_layer_op?('render')
23
+ # For recursive calls to :render (for sub-partials and layouts),
24
+ # use method profiling.
25
+ begin
26
+ report_kvs[:FunctionName] = :render
27
+ report_kvs[:Class] = :Rendering
28
+ report_kvs[:Module] = 'Padrino'
29
+ report_kvs[:File] = __FILE__
30
+ report_kvs[:LineNumber] = __LINE__
31
+ rescue StandardError => e
32
+ ::TraceView.logger.debug e.message
33
+ ::TraceView.logger.debug e.backtrace.join(', ')
34
+ end
35
+
36
+ TraceView::API.profile(report_kvs[:template], report_kvs, false) do
37
+ render_without_traceview(engine, data, options, locals, &block)
38
+ end
39
+ else
40
+ # Fall back to the raw tracing API so we can pass KVs
41
+ # back on exit (a limitation of the TraceView::API.trace
42
+ # block method) This removes the need for an info
43
+ # event to send additonal KVs
44
+ ::TraceView::API.log_entry('render', {}, 'render')
45
+
46
+ begin
47
+ render_without_traceview(engine, data, options, locals, &block)
48
+ ensure
49
+ ::TraceView::API.log_exit('render', report_kvs)
50
+ end
51
+ end
52
+ else
53
+ render_without_traceview(engine, data, options, locals, &block)
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,64 @@
1
+ # Copyright (c) 2014 AppNeta, Inc.
2
+ # All rights reserved.
3
+
4
+ module TraceView
5
+ module PadrinoInst
6
+ module Routing
7
+ def self.included(klass)
8
+ ::TraceView::Util.method_alias(klass, :dispatch!, ::Padrino::Routing)
9
+ end
10
+
11
+ def dispatch_with_traceview
12
+ if TraceView.tracing?
13
+ report_kvs = {}
14
+
15
+ # Fall back to the raw tracing API so we can pass KVs
16
+ # back on exit (a limitation of the TraceView::API.trace
17
+ # block method) This removes the need for an info
18
+ # event to send additonal KVs
19
+ ::TraceView::API.log_entry('padrino', {})
20
+
21
+ begin
22
+ r = dispatch_without_traceview
23
+
24
+ # Report Controller/Action as best possible
25
+ if request.controller and not request.controller.empty?
26
+ report_kvs[:Controller] = request.controller
27
+ else
28
+ report_kvs[:Controller] = self.class
29
+ end
30
+
31
+ report_kvs[:Action] = request.action
32
+ r
33
+ ensure
34
+ ::TraceView::API.log_exit('padrino', report_kvs)
35
+ end
36
+ else
37
+ dispatch_without_traceview
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ if defined?(::Padrino)
45
+ # This instrumentation is a superset of the Sinatra instrumentation similar
46
+ # to how Padrino is a superset of Sinatra itself.
47
+ ::TraceView.logger.info "[traceview/loading] Instrumenting Padrino" if TraceView::Config[:verbose]
48
+
49
+ require 'traceview/frameworks/padrino/templates'
50
+
51
+ Padrino.after_load do
52
+ ::TraceView.logger = ::Padrino.logger if ::Padrino.respond_to?(:logger)
53
+ ::TraceView::Loading.load_access_key
54
+ ::TraceView::Inst.load_instrumentation
55
+
56
+ ::TraceView::Util.send_include(::Padrino::Routing::InstanceMethods, ::TraceView::PadrinoInst::Routing)
57
+ if defined?(::Padrino::Rendering)
58
+ ::TraceView::Util.send_include(::Padrino::Rendering::InstanceMethods, ::TraceView::PadrinoInst::Rendering)
59
+ end
60
+
61
+ # Report __Init after fork when in Heroku
62
+ TraceView::API.report_init unless TraceView.heroku?
63
+ end
64
+ end
@@ -0,0 +1,5 @@
1
+ <script type="text/javascript">(function(){var d=this._tly={q:[],mark:function(a,b){d.q.push(["mark",a,b||(new Date).getTime()])},measure:function(a,b,c){d.q.push(["measure",a,b,c||(new Date).getTime()])},done:function(a){d.q.push(["done",a])},cid:"<%= TraceView::Config[:rum_id] %>",xt:"<%= TraceView::Context.toString %>"};d.mark("firstbyte");var f;f=function(){};var g=0;function h(a){return function(b){b[a]||(b[a]=!0,d.measure(["_ajax",b.a,a]))}}var i=h("recv"),j=h("send");
2
+ function l(){var a=this&&this._tl,b=a.b;4===this.readyState&&i(a);f();for(a=0;a<b.length;a++)b[a].apply(this,arguments)}var m=this.XMLHttpRequest,n=m&&m.prototype;
3
+ if(n){var o=n.open;n.open=function(a,b,c,e,u){f();this._tl||(this._tl={a:g++,async:c,b:[]},d.measure(["_ajax",this._tl.a,"init",a,b]));return e?o.call(this,a,b,c,e,u):o.call(this,a,b,c)};var p=n.send;n.send=function(a){function b(){try{var a;a:{var b=l;try{if(c.addEventListener){c.addEventListener("readystatechange",b);a=!0;break a}}catch(w){}a=!1}if(!a){var k=c.onreadystatechange;if(k){if(!k.apply)return;f();e.b.push(k)}f();c.onreadystatechange=l}}catch(x){}}var c=this,e=c&&c._tl;f();b();j(e);a=
4
+ p.call(c,a);!e.async||4===c.readyState?i(e):setTimeout(function(){try{4===c.readyState?i(e):c.onreadystatechange!==l&&b()}catch(a){}},0);return a}}this.onerror=function(a,b,c){d.measure(["_jserror ",a,"|",b,"|",c].join(""))};var q=this.attachEvent,r=this.addEventListener;var s=function(){d.measure("winload");d.done()};q?q("onload",s):r&&r("load",s,!1);var t=document.createElement("script");t.type="text/javascript";t.async=!0;t.src=("http:"===document.location.protocol?"http:":"https:")+"//d2gfdmu30u15x7.cloudfront.net/1/tly.js";
5
+ var v=document.getElementsByTagName("script")[0];v.parentNode.insertBefore(t,v);}());</script>
@@ -0,0 +1 @@
1
+ <script type="text/javascript">this._tly&&this._tly.measure("domload");</script>
@@ -0,0 +1,3 @@
1
+ <script type="text/javascript">(function(){var b=this._tly={q:[],mark:function(a,c){b.q.push(["mark",a,c||(new Date).getTime()])},measure:function(a,c,e){b.q.push(["measure",a,c,e||(new Date).getTime()])},done:function(a){b.q.push(["done",a])},cid:"<%= TraceView::Config[:rum_id] %>",xt:"<%= TraceView::Context.toString %>"};b.mark("firstbyte");this.onerror=function(a,c,e){b.measure(["_jserror ",a,"|",c,"|",e].join(""))};var d=this.attachEvent,f=this.addEventListener;var g=function(){b.measure("winload");b.done()};d?d("onload",g):f&&f("load",g,!1);var h=document.createElement("script");
2
+ h.type="text/javascript";h.async=!0;h.src=("http:"===document.location.protocol?"http:":"https:")+"//d2gfdmu30u15x7.cloudfront.net/1/tly.js";var i=document.getElementsByTagName("script")[0];i.parentNode.insertBefore(h,i);}());</script>
3
+
@@ -0,0 +1,216 @@
1
+ # Copyright (c) 2013 AppNeta, Inc.
2
+ # All rights reserved.
3
+
4
+ module TraceView
5
+ module Inst
6
+ #
7
+ # RailsBase
8
+ #
9
+ # This module contains the instrumentation code common to
10
+ # many Rails versions.
11
+ #
12
+ module RailsBase
13
+ #
14
+ # has_handler?
15
+ #
16
+ # Determins if <tt>exception</tt> has a registered
17
+ # handler via <tt>rescue_from</tt>
18
+ #
19
+ def has_handler?(exception)
20
+ # Don't log exceptions if they have a rescue handler set
21
+ has_handler = false
22
+ rescue_handlers.detect { | klass_name, handler |
23
+ # Rescue handlers can be specified as strings or constant names
24
+ klass = self.class.const_get(klass_name) rescue nil
25
+ klass ||= klass_name.constantize rescue nil
26
+ has_handler = exception.is_a?(klass) if klass
27
+ }
28
+ has_handler
29
+ rescue => e
30
+ TraceView.logger.debug "[traceview/debug] Error searching Rails handlers: #{e.message}"
31
+ return false
32
+ end
33
+
34
+ #
35
+ # log_rails_error?
36
+ #
37
+ # Determins whether we should log a raised exception to the
38
+ # TraceView dashboard. This is determined by whether the exception
39
+ # has a rescue handler setup and the value of
40
+ # TraceView::Config[:report_rescued_errors]
41
+ #
42
+ def log_rails_error?(exception)
43
+ # As it's perculating up through the layers... make sure that
44
+ # we only report it once.
45
+ return false if exception.instance_variable_get(:@traceview_logged)
46
+
47
+ has_handler = has_handler?(exception)
48
+
49
+ if !has_handler || (has_handler && TraceView::Config[:report_rescued_errors])
50
+ return true
51
+ end
52
+ false
53
+ end
54
+
55
+ #
56
+ # render_with_traceview
57
+ #
58
+ # Our render wrapper that just times and conditionally
59
+ # reports raised exceptions
60
+ #
61
+ def render_with_traceview(*args, &blk)
62
+ TraceView::API.log_entry('actionview')
63
+ render_without_traceview(*args, &blk)
64
+
65
+ rescue Exception => e
66
+ TraceView::API.log_exception(nil, e) if log_rails_error?(e)
67
+ raise
68
+ ensure
69
+ TraceView::API.log_exit('actionview')
70
+ end
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 => self.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
+ return process_action_without_traceview(method_name, *args) if TraceView::Config[:action_blacklist].present? &&
134
+ TraceView::Config[:action_blacklist][[self.controller_name, self.action_name].join('#')]
135
+
136
+ report_kvs = {
137
+ :Controller => self.class.name,
138
+ :Action => self.action_name,
139
+ }
140
+
141
+ TraceView::API.log_entry('rails')
142
+ process_action_without_traceview(method_name, *args)
143
+
144
+ rescue Exception => e
145
+ TraceView::API.log_exception(nil, e) if log_rails_error?(e)
146
+ raise
147
+ ensure
148
+ TraceView::API.log_exit('rails')
149
+ end
150
+ end
151
+ end
152
+ end
153
+
154
+ if defined?(ActionController::Base) && TraceView::Config[:action_controller][:enabled]
155
+ if ::Rails::VERSION::MAJOR == 4
156
+
157
+ class ActionController::Base
158
+ include TraceView::Inst::ActionController4
159
+ end
160
+
161
+ elsif ::Rails::VERSION::MAJOR == 3
162
+
163
+ class ActionController::Base
164
+ include TraceView::Inst::ActionController3
165
+ end
166
+
167
+ elsif ::Rails::VERSION::MAJOR == 2
168
+
169
+ ActionController::Base.class_eval do
170
+ include ::TraceView::Inst::RailsBase
171
+
172
+ alias :perform_action_without_traceview :perform_action
173
+ alias :rescue_action_without_traceview :rescue_action
174
+ alias :process_without_traceview :process
175
+ alias :render_without_traceview :render
176
+
177
+ def process(*args)
178
+ TraceView::API.log_entry('rails')
179
+ process_without_traceview(*args)
180
+
181
+ rescue Exception => e
182
+ TraceView::API.log_exception(nil, e) if log_rails_error?(e)
183
+ raise
184
+ ensure
185
+ TraceView::API.log_exit('rails')
186
+ end
187
+
188
+ def perform_action(*arguments)
189
+ report_kvs = {
190
+ :Controller => @_request.path_parameters['controller'],
191
+ :Action => @_request.path_parameters['action']
192
+ }
193
+ TraceView::API.log(nil, 'info', report_kvs)
194
+ perform_action_without_traceview(*arguments)
195
+ end
196
+
197
+ def rescue_action(exn)
198
+ TraceView::API.log_exception(nil, exn) if log_rails_error?(exn)
199
+ rescue_action_without_traceview(exn)
200
+ end
201
+
202
+ def render(options = nil, extra_options = {}, &block)
203
+ TraceView::API.log_entry('actionview')
204
+ render_without_traceview(options, extra_options, &block)
205
+
206
+ rescue Exception => e
207
+ TraceView::API.log_exception(nil, e) if log_rails_error?(e)
208
+ raise
209
+ ensure
210
+ TraceView::API.log_exit('actionview')
211
+ end
212
+ end
213
+ end
214
+ TraceView.logger.info '[traceview/loading] Instrumenting actioncontroler' if TraceView::Config[:verbose]
215
+ end
216
+ # vim:set expandtab:tabstop=2
@@ -0,0 +1,56 @@
1
+ # Copyright (c) 2013 AppNeta, Inc.
2
+ # All rights reserved.
3
+
4
+ if defined?(ActionView::Base) && TraceView::Config[:action_view][:enabled]
5
+
6
+ ##
7
+ # ActionView Instrumentation is version dependent. ActionView 2.x is separate
8
+ # and ActionView 3.0 is a special case.
9
+ # Everything else goes here. (ActionView 3.1 - 4.0 as of this writing)
10
+ #
11
+ if (Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR > 0) || Rails::VERSION::MAJOR == 4
12
+
13
+ TraceView.logger.info '[traceview/loading] Instrumenting actionview' if TraceView::Config[:verbose]
14
+
15
+ ActionView::PartialRenderer.class_eval do
16
+ alias :render_partial_without_traceview :render_partial
17
+ def render_partial
18
+ entry_kvs = {}
19
+ begin
20
+ name = TraceView::Util.prettify(@options[:partial]) if @options.is_a?(Hash)
21
+ entry_kvs[:FunctionName] = :render_partial
22
+ entry_kvs[:Class] = :PartialRenderer
23
+ entry_kvs[:Module] = :ActionView
24
+ entry_kvs[:File] = __FILE__
25
+ entry_kvs[:LineNumber] = __LINE__
26
+ rescue
27
+ end
28
+
29
+ TraceView::API.profile(name, entry_kvs, TraceView::Config[:action_view][:collect_backtraces]) do
30
+ render_partial_without_traceview
31
+ end
32
+ end
33
+
34
+ alias :render_collection_without_traceview :render_collection
35
+ def render_collection
36
+ entry_kvs = {}
37
+ begin
38
+ name = TraceView::Util.prettify(@path)
39
+ entry_kvs[:FunctionName] = :render_collection
40
+ entry_kvs[:Class] = :PartialRenderer
41
+ entry_kvs[:Module] = :ActionView
42
+ entry_kvs[:File] = __FILE__
43
+ entry_kvs[:LineNumber] = __LINE__
44
+ rescue
45
+ end
46
+
47
+ TraceView::API.profile(name, entry_kvs, TraceView::Config[:action_view][:collect_backtraces]) do
48
+ render_collection_without_traceview
49
+ end
50
+ end
51
+
52
+ end
53
+ end
54
+ end
55
+
56
+ # vim:set expandtab:tabstop=2
@@ -0,0 +1,54 @@
1
+ # Copyright (c) 2013 AppNeta, Inc.
2
+ # All rights reserved.
3
+
4
+ if defined?(ActionView::Base) && TraceView::Config[:action_view][:enabled]
5
+
6
+ if Rails::VERSION::MAJOR == 2
7
+
8
+ TraceView.logger.info '[traceview/loading] Instrumenting actionview' if TraceView::Config[:verbose]
9
+
10
+ ActionView::Partials.module_eval do
11
+ alias :render_partial_without_traceview :render_partial
12
+ def render_partial(options = {})
13
+ if options.key?(:partial) && options[:partial].is_a?(String)
14
+ entry_kvs = {}
15
+ begin
16
+ name = TraceView::Util.prettify(options[:partial]) if options.is_a?(Hash)
17
+ entry_kvs[:FunctionName] = :render_partial
18
+ entry_kvs[:Class] = :Partials
19
+ entry_kvs[:Module] = :ActionView
20
+ entry_kvs[:File] = __FILE__
21
+ entry_kvs[:LineNumber] = __LINE__
22
+ rescue
23
+ end
24
+
25
+ TraceView::API.profile(name, entry_kvs, TraceView::Config[:action_view][:collect_backtraces]) do
26
+ render_partial_without_traceview(options)
27
+ end
28
+ else
29
+ render_partial_without_traceview(options)
30
+ end
31
+ end
32
+
33
+ alias :render_partial_collection_without_traceview :render_partial_collection
34
+ def render_partial_collection(options = {})
35
+ entry_kvs = {}
36
+ begin
37
+ name = 'partial_collection'
38
+ entry_kvs[:FunctionName] = :render_partial_collection
39
+ entry_kvs[:Class] = :Partials
40
+ entry_kvs[:Module] = :ActionView
41
+ entry_kvs[:File] = __FILE__
42
+ entry_kvs[:LineNumber] = __LINE__
43
+ rescue
44
+ end
45
+
46
+ TraceView::API.profile(name, entry_kvs, TraceView::Config[:action_view][:collect_backtraces]) do
47
+ render_partial_collection_without_traceview(options)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ # vim:set expandtab:tabstop=2
@@ -0,0 +1,48 @@
1
+ # Copyright (c) 2013 AppNeta, Inc.
2
+ # All rights reserved.
3
+
4
+ if defined?(ActionView::Base) && TraceView::Config[:action_view][:enabled]
5
+
6
+ if Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR == 0
7
+
8
+ ActionView::Partials::PartialRenderer.class_eval do
9
+ alias :render_partial_without_traceview :render_partial
10
+ def render_partial(object = @object)
11
+ entry_kvs = {}
12
+ begin
13
+ name = TraceView::Util.prettify(@options[:partial]) if @options.is_a?(Hash)
14
+ entry_kvs[:FunctionName] = :render_partial
15
+ entry_kvs[:Class] = :PartialRenderer
16
+ entry_kvs[:Module] = 'ActionView::Partials'
17
+ entry_kvs[:File] = __FILE__
18
+ entry_kvs[:LineNumber] = __LINE__
19
+ rescue
20
+ end
21
+
22
+ TraceView::API.profile(name, entry_kvs, TraceView::Config[:action_view][:collect_backtraces]) do
23
+ render_partial_without_traceview(object)
24
+ end
25
+ end
26
+
27
+ alias :render_collection_without_traceview :render_collection
28
+ def render_collection
29
+ entry_kvs = {}
30
+ begin
31
+ name = TraceView::Util.prettify(@path)
32
+ entry_kvs[:FunctionName] = :render_collection
33
+ entry_kvs[:Class] = :PartialRenderer
34
+ entry_kvs[:Module] = 'ActionView::Partials'
35
+ entry_kvs[:File] = __FILE__
36
+ entry_kvs[:LineNumber] = __LINE__
37
+ rescue
38
+ end
39
+
40
+ TraceView::API.profile(name, entry_kvs, TraceView::Config[:action_view][:collect_backtraces]) do
41
+ render_collection_without_traceview
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ # vim:set expandtab:tabstop=2
@@ -0,0 +1,24 @@
1
+ # Copyright (c) 2013 AppNeta, Inc.
2
+ # All rights reserved.
3
+
4
+ require 'traceview/frameworks/rails/inst/connection_adapters/utils'
5
+ require 'traceview/frameworks/rails/inst/connection_adapters/mysql'
6
+ require 'traceview/frameworks/rails/inst/connection_adapters/mysql2'
7
+ require 'traceview/frameworks/rails/inst/connection_adapters/postgresql'
8
+ require 'traceview/frameworks/rails/inst/connection_adapters/oracle'
9
+
10
+ if TraceView::Config[:active_record][:enabled] && !defined?(JRUBY_VERSION)
11
+ begin
12
+ adapter = ActiveRecord::Base.connection.adapter_name.downcase
13
+
14
+ TraceView::Inst::ConnectionAdapters::FlavorInitializers.mysql if adapter == 'mysql'
15
+ TraceView::Inst::ConnectionAdapters::FlavorInitializers.mysql2 if adapter == 'mysql2'
16
+ TraceView::Inst::ConnectionAdapters::FlavorInitializers.postgresql if adapter == 'postgresql'
17
+ TraceView::Inst::ConnectionAdapters::FlavorInitializers.oracle if adapter == 'oracleenhanced'
18
+
19
+ rescue StandardError => e
20
+ TraceView.logger.error "[traceview/error] TraceView/ActiveRecord error: #{e.inspect}"
21
+ TraceView.logger.debug e.backtrace.join("\n")
22
+ end
23
+ end
24
+ # vim:set expandtab:tabstop=2
@@ -0,0 +1,43 @@
1
+ # Copyright (c) 2013 AppNeta, Inc.
2
+ # All rights reserved.
3
+
4
+ module TraceView
5
+ module Inst
6
+ module ConnectionAdapters
7
+ module FlavorInitializers
8
+ def self.mysql
9
+ TraceView.logger.info '[traceview/loading] Instrumenting activerecord mysqladapter' if TraceView::Config[:verbose]
10
+
11
+ # ActiveRecord 3.2 and higher
12
+ if (::ActiveRecord::VERSION::MAJOR == 3 && ::ActiveRecord::VERSION::MINOR >= 2) ||
13
+ ::ActiveRecord::VERSION::MAJOR == 4
14
+
15
+ # AbstractMysqlAdapter
16
+ TraceView::Util.send_include(::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter,
17
+ ::TraceView::Inst::ConnectionAdapters::Utils)
18
+ TraceView::Util.method_alias(::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter, :execute)
19
+
20
+ # MysqlAdapter
21
+ TraceView::Util.send_include(::ActiveRecord::ConnectionAdapters::MysqlAdapter,
22
+ ::TraceView::Inst::ConnectionAdapters::Utils)
23
+ TraceView::Util.method_alias(::ActiveRecord::ConnectionAdapters::MysqlAdapter, :exec_query)
24
+
25
+ else
26
+ # ActiveRecord 3.1 and below
27
+
28
+ # MysqlAdapter
29
+ TraceView::Util.send_include(::ActiveRecord::ConnectionAdapters::MysqlAdapter,
30
+ ::TraceView::Inst::ConnectionAdapters::Utils)
31
+
32
+ TraceView::Util.method_alias(::ActiveRecord::ConnectionAdapters::MysqlAdapter, :execute)
33
+
34
+ if ::ActiveRecord::VERSION::MAJOR == 3 && ::ActiveRecord::VERSION::MINOR == 1
35
+ TraceView::Util.method_alias(::ActiveRecord::ConnectionAdapters::MysqlAdapter, :begin_db_transaction)
36
+ TraceView::Util.method_alias(::ActiveRecord::ConnectionAdapters::MysqlAdapter, :exec_delete)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,28 @@
1
+ # Copyright (c) 2013 AppNeta, Inc.
2
+ # All rights reserved.
3
+
4
+ module TraceView
5
+ module Inst
6
+ module ConnectionAdapters
7
+ module FlavorInitializers
8
+ def self.mysql2
9
+ TraceView.logger.info '[traceview/loading] Instrumenting activerecord mysql2adapter' if TraceView::Config[:verbose]
10
+
11
+ TraceView::Util.send_include(::ActiveRecord::ConnectionAdapters::Mysql2Adapter,
12
+ ::TraceView::Inst::ConnectionAdapters::Utils)
13
+
14
+ if (::ActiveRecord::VERSION::MAJOR == 3 && ::ActiveRecord::VERSION::MINOR == 0) ||
15
+ ::ActiveRecord::VERSION::MAJOR == 2
16
+ # ActiveRecord 3.0 and prior
17
+ TraceView::Util.method_alias(::ActiveRecord::ConnectionAdapters::Mysql2Adapter, :execute)
18
+ else
19
+ # ActiveRecord 3.1 and above
20
+ TraceView::Util.method_alias(::ActiveRecord::ConnectionAdapters::Mysql2Adapter, :exec_insert)
21
+ TraceView::Util.method_alias(::ActiveRecord::ConnectionAdapters::Mysql2Adapter, :exec_query)
22
+ TraceView::Util.method_alias(::ActiveRecord::ConnectionAdapters::Mysql2Adapter, :exec_delete)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,18 @@
1
+ # Copyright (c) 2013 AppNeta, Inc.
2
+ # All rights reserved.
3
+
4
+ module TraceView
5
+ module Inst
6
+ module ConnectionAdapters
7
+ module FlavorInitializers
8
+ def self.oracle
9
+ TraceView.logger.info '[traceview/loading] Instrumenting activerecord oracleenhancedadapter' if TraceView::Config[:verbose]
10
+ ::ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.module_eval do
11
+ include TraceView::Inst::ConnectionAdapters
12
+ end if defined?(::ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,30 @@
1
+ # Copyright (c) 2013 AppNeta, Inc.
2
+ # All rights reserved.
3
+
4
+ module TraceView
5
+ module Inst
6
+ module ConnectionAdapters
7
+ module FlavorInitializers
8
+ def self.postgresql
9
+
10
+ TraceView.logger.info '[traceview/loading] Instrumenting activerecord postgresqladapter' if TraceView::Config[:verbose]
11
+
12
+ TraceView::Util.send_include(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter,
13
+ ::TraceView::Inst::ConnectionAdapters::Utils)
14
+
15
+ if (::ActiveRecord::VERSION::MAJOR == 3 && ::ActiveRecord::VERSION::MINOR > 0) ||
16
+ ::ActiveRecord::VERSION::MAJOR == 4
17
+
18
+ # ActiveRecord 3.1 and up
19
+ TraceView::Util.method_alias(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter, :exec_query)
20
+ TraceView::Util.method_alias(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter, :exec_delete)
21
+
22
+ else
23
+ # ActiveRecord 3.0 and prior
24
+ TraceView::Util.method_alias(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter, :execute)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end