oboe 1.3.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.
@@ -0,0 +1,86 @@
1
+ # Copyright (c) 2012 by Tracelytics, Inc.
2
+ # All rights reserved.
3
+
4
+ module Oboe
5
+ module Inst
6
+ module Rails3ActionController
7
+ def process(*args)
8
+
9
+ header = request.headers['X-Trace']
10
+ Oboe::API.start_trace_with_target('rails', header, response.headers) do
11
+ super
12
+ end
13
+ end
14
+
15
+ def process_action(*args)
16
+ opts = {
17
+ 'HTTP-Host' => @_request.headers['HTTP_HOST'],
18
+ :URL => @_request.headers['REQUEST_URI'],
19
+ :Method => @_request.headers['REQUEST_METHOD'],
20
+ :Controller => self.class.name,
21
+ :Action => self.action_name,
22
+ }
23
+ super
24
+
25
+ opts[:Status] = @_response.status
26
+ Oboe::API.log('rails', 'info', opts)
27
+
28
+ rescue Exception => exception
29
+ opts[:Status] = 500
30
+ Oboe::API.log('rails', 'info', opts)
31
+ end
32
+
33
+ def render(*args)
34
+ Oboe::API.trace('render', {}) do
35
+ super
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ if defined?(ActionController::Base)
43
+ if ::Rails::VERSION::MAJOR == 3
44
+ Oboe::API.report_init('rails')
45
+
46
+ class ActionController::Base
47
+ include Oboe::Inst::Rails3ActionController
48
+ end
49
+ elsif ::Rails::VERSION::MAJOR == 2
50
+ Oboe::API.report_init('rails')
51
+
52
+ ActionController::Base.class_eval do
53
+ alias :perform_action_without_oboe :perform_action
54
+ alias :rescue_action_without_oboe :rescue_action
55
+ alias :process_without_oboe :process
56
+
57
+ def process(*args)
58
+ header = args[0].headers['X-Trace']
59
+ Oboe::API.start_trace_with_target('rails', header, args[1].headers) do
60
+ process_without_oboe(*args)
61
+ end
62
+ end
63
+
64
+ def perform_action(*arguments)
65
+ opts = {
66
+ 'HTTP-Host' => @_request.headers['HTTP_HOST'],
67
+ :URL => @_request.headers['REQUEST_URI'],
68
+ :Method => @_request.headers['REQUEST_METHOD'],
69
+ :Status => @_response.status,
70
+ 'Controller' => @_request.path_parameters['controller'],
71
+ 'Action' => @_request.path_parameters['action']
72
+ }
73
+
74
+ Oboe::API.log('rails', 'info', opts)
75
+ perform_action_without_oboe(*arguments)
76
+ end
77
+
78
+ def rescue_action(exn)
79
+ Oboe::API.log_exception('rails', exn)
80
+ rescue_action_without_oboe(exn)
81
+ end
82
+ end
83
+ end
84
+ puts "[oboe/loading] Instrumenting ActionControler" if Oboe::Config[:verbose]
85
+ end
86
+ # vim:set expandtab:tabstop=2
@@ -0,0 +1,291 @@
1
+ # Copyright (c) 2012 by Tracelytics, Inc.
2
+ # All rights reserved.
3
+
4
+ module Oboe
5
+ module Inst
6
+ module ConnectionAdapters
7
+ module Utils
8
+ def extract_trace_details(sql, name = nil)
9
+ opts = {}
10
+
11
+ opts[:Query] = sql.to_s
12
+ opts[:Name] = name.to_s if name
13
+
14
+ if defined?(ActiveRecord::Base.connection.cfg)
15
+ opts[:Database] = ActiveRecord::Base.connection.cfg[:database]
16
+ if ActiveRecord::Base.connection.cfg.has_key?(:host)
17
+ opts[:RemoteHost] = ActiveRecord::Base.connection.cfg[:host]
18
+ end
19
+ end
20
+
21
+ if defined?(ActiveRecord::Base.connection.adapter_name)
22
+ opts[:Flavor] = ActiveRecord::Base.connection.adapter_name
23
+ end
24
+
25
+ return opts || {}
26
+ end
27
+
28
+ # We don't want to trace framework caches. Only instrument SQL that
29
+ # directly hits the database.
30
+ def ignore_payload?(name)
31
+ %w(SCHEMA EXPLAIN CACHE).include? name.to_s or (name and name.to_sym == :skip_logging)
32
+ end
33
+
34
+ def cfg
35
+ @config
36
+ end
37
+
38
+ def execute_with_oboe(sql, name = nil)
39
+ if Oboe::Config.tracing? and !ignore_payload?(name)
40
+
41
+ opts = extract_trace_details(sql, name)
42
+ Oboe::API.trace('ActiveRecord', opts || {}) do
43
+ execute_without_oboe(sql, name)
44
+ end
45
+ else
46
+ execute_without_oboe(sql, name)
47
+ end
48
+ end
49
+
50
+ def exec_query_with_oboe(sql, name = nil, binds = [])
51
+ if Oboe::Config.tracing? and !ignore_payload?(name)
52
+
53
+ opts = extract_trace_details(sql, name)
54
+ Oboe::API.trace('ActiveRecord', opts || {}) do
55
+ exec_query_without_oboe(sql, name, binds)
56
+ end
57
+ else
58
+ exec_query_without_oboe(sql, name, binds)
59
+ end
60
+ end
61
+
62
+ def exec_delete_with_oboe(sql, name = nil, binds = [])
63
+ if Oboe::Config.tracing? and !ignore_payload?(name)
64
+
65
+ opts = extract_trace_details(sql, name)
66
+ Oboe::API.trace('ActiveRecord', opts || {}) do
67
+ exec_delete_without_oboe(sql, name, binds)
68
+ end
69
+ else
70
+ exec_delete_without_oboe(sql, name, binds)
71
+ end
72
+ end
73
+
74
+ def exec_insert_with_oboe(sql, name = nil, binds = [])
75
+ if Oboe::Config.tracing? and !ignore_payload?(name)
76
+
77
+ opts = extract_trace_details(sql, name)
78
+ Oboe::API.trace('ActiveRecord', opts || {}) do
79
+ exec_insert_without_oboe(sql, name, binds)
80
+ end
81
+ else
82
+ exec_insert_without_oboe(sql, name, binds)
83
+ end
84
+ end
85
+
86
+ def begin_db_transaction_with_oboe()
87
+ if Oboe::Config.tracing?
88
+ opts = {}
89
+
90
+ opts[:Query] = "BEGIN"
91
+ Oboe::API.trace('ActiveRecord', opts || {}) do
92
+ begin_db_transaction_without_oboe()
93
+ end
94
+ else
95
+ begin_db_transaction_without_oboe()
96
+ end
97
+ end
98
+ end # Utils
99
+
100
+ module PostgreSQLAdapter
101
+ include Oboe::Inst::ConnectionAdapters::Utils
102
+
103
+ def self.included(cls)
104
+ cls.class_eval do
105
+ if ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::method_defined? :exec_query
106
+ alias exec_query_without_oboe exec_query
107
+ alias exec_query exec_query_with_oboe
108
+ else puts "[oboe/loading] Couldn't properly instrument ActiveRecord layer. Partial traces may occur."
109
+ end
110
+
111
+ if ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::method_defined? :exec_delete
112
+ alias exec_delete_without_oboe exec_delete
113
+ alias exec_delete exec_delete_with_oboe
114
+ else puts "[oboe/loading] Couldn't properly instrument ActiveRecord layer. Partial traces may occur."
115
+ end
116
+ end
117
+ end
118
+ end # PostgreSQLAdapter
119
+
120
+ module LegacyPostgreSQLAdapter
121
+ include Oboe::Inst::ConnectionAdapters::Utils
122
+
123
+ def self.included(cls)
124
+ cls.class_eval do
125
+ if ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::method_defined? :execute
126
+ alias execute_without_oboe execute
127
+ alias execute execute_with_oboe
128
+ else puts "[oboe/loading] Couldn't properly instrument ActiveRecord layer. Partial traces may occur."
129
+ end
130
+ end
131
+ end
132
+ end # LegacyPostgreSQLAdapter
133
+
134
+ module AbstractMysqlAdapter
135
+ include Oboe::Inst::ConnectionAdapters::Utils
136
+
137
+ def self.included(cls)
138
+ cls.class_eval do
139
+ if ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::method_defined? :execute
140
+ alias execute_without_oboe execute
141
+ alias execute execute_with_oboe
142
+ else puts "[oboe/loading] Couldn't properly instrument ActiveRecord layer. Partial traces may occur."
143
+ end
144
+ end
145
+ end
146
+ end # AbstractMysqlAdapter
147
+
148
+ module MysqlAdapter
149
+ include Oboe::Inst::ConnectionAdapters::Utils
150
+
151
+ def self.included(cls)
152
+ cls.class_eval do
153
+ if ActiveRecord::ConnectionAdapters::MysqlAdapter::method_defined? :exec_query
154
+ alias exec_query_without_oboe exec_query
155
+ alias exec_query exec_query_with_oboe
156
+ else puts "[oboe/loading] Couldn't properly instrument ActiveRecord layer. Partial traces may occur."
157
+ end
158
+ end
159
+ end
160
+ end # MysqlAdapter
161
+
162
+ module LegacyMysqlAdapter
163
+ include Oboe::Inst::ConnectionAdapters::Utils
164
+
165
+ def self.included(cls)
166
+ cls.class_eval do
167
+ if ActiveRecord::ConnectionAdapters::MysqlAdapter::method_defined? :execute
168
+ alias execute_without_oboe execute
169
+ alias execute execute_with_oboe
170
+ else puts "[oboe/loading] Couldn't properly instrument ActiveRecord layer. Partial traces may occur."
171
+ end
172
+
173
+ if ::Rails::VERSION::MAJOR == 3 and ::Rails::VERSION::MINOR == 1
174
+ if ActiveRecord::ConnectionAdapters::MysqlAdapter::method_defined? :begin_db_transaction
175
+ alias begin_db_transaction_without_oboe begin_db_transaction
176
+ alias begin_db_transaction begin_db_transaction_with_oboe
177
+ else puts "[oboe/loading] Couldn't properly instrument ActiveRecord layer. Partial traces may occur."
178
+ end
179
+ end
180
+
181
+ if ::Rails::VERSION::MAJOR == 3 and ::Rails::VERSION::MINOR > 0
182
+ if ActiveRecord::ConnectionAdapters::MysqlAdapter::method_defined? :exec_query
183
+ alias exec_query_without_oboe exec_query
184
+ alias exec_query exec_query_with_oboe
185
+ else puts "[oboe/loading] Couldn't properly instrument ActiveRecord layer. Partial traces may occur."
186
+ end
187
+
188
+ if ActiveRecord::ConnectionAdapters::MysqlAdapter::method_defined? :exec_delete
189
+ alias exec_delete_without_oboe exec_delete
190
+ alias exec_delete exec_delete_with_oboe
191
+ else puts "[oboe/loading] Couldn't properly instrument ActiveRecord layer. Partial traces may occur."
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end # LegacyMysqlAdapter
197
+
198
+ module Mysql2Adapter
199
+ include Oboe::Inst::ConnectionAdapters::Utils
200
+
201
+ def self.included(cls)
202
+ cls.class_eval do
203
+ if ::Rails::VERSION::MAJOR == 2 or (::Rails::VERSION::MAJOR == 3 and ::Rails::VERSION::MINOR == 0)
204
+ if ActiveRecord::ConnectionAdapters::Mysql2Adapter::method_defined? :execute
205
+ alias execute_without_oboe execute
206
+ alias execute execute_with_oboe
207
+ else puts "[oboe/loading] Couldn't properly instrument ActiveRecord layer. Partial traces may occur."
208
+ end
209
+ else
210
+ if ActiveRecord::ConnectionAdapters::Mysql2Adapter::method_defined? :exec_insert
211
+ alias exec_insert_without_oboe exec_insert
212
+ alias exec_insert exec_insert_with_oboe
213
+ else puts "[oboe/loading] Couldn't properly instrument ActiveRecord layer. Partial traces may occur."
214
+ end
215
+
216
+ # In Rails 3.1, exec_query was defined as a private method
217
+ if ActiveRecord::ConnectionAdapters::Mysql2Adapter::method_defined? :exec_query or
218
+ ActiveRecord::ConnectionAdapters::Mysql2Adapter::private_method_defined? :exec_query
219
+ alias exec_query_without_oboe exec_query
220
+ alias exec_query exec_query_with_oboe
221
+ else puts "[oboe/loading] Couldn't properly instrument ActiveRecord layer. Partial traces may occur."
222
+ end
223
+
224
+ if ActiveRecord::ConnectionAdapters::Mysql2Adapter::method_defined? :exec_delete
225
+ alias exec_delete_without_oboe exec_delete
226
+ alias exec_delete exec_delete_with_oboe
227
+ else puts "[oboe/loading] Couldn't properly instrument ActiveRecord layer. Partial traces may occur."
228
+ end
229
+ end
230
+ end
231
+ end
232
+ end # Mysql2Adapter
233
+
234
+ module FlavorInitializers
235
+ def self.mysql
236
+ if ActiveRecord::Base::connection.adapter_name.downcase.to_sym == :mysql
237
+ puts "[oboe/loading] Instrumenting ActiveRecord MysqlAdapter" if Oboe::Config[:verbose]
238
+ if ::Rails::VERSION::MAJOR == 3 and ::Rails::VERSION::MINOR > 1
239
+ ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.module_eval do
240
+ include Oboe::Inst::ConnectionAdapters::AbstractMysqlAdapter
241
+ end
242
+ ActiveRecord::ConnectionAdapters::MysqlAdapter.module_eval do
243
+ include Oboe::Inst::ConnectionAdapters::MysqlAdapter
244
+ end
245
+ else
246
+ ActiveRecord::ConnectionAdapters::MysqlAdapter.module_eval do
247
+ include Oboe::Inst::ConnectionAdapters::LegacyMysqlAdapter
248
+ end
249
+ end
250
+ end
251
+ end
252
+
253
+ def self.mysql2
254
+ if ActiveRecord::Base::connection.adapter_name.downcase.to_sym == :mysql2
255
+ puts "[oboe/loading] Instrumenting ActiveRecord Mysql2Adapter" if Oboe::Config[:verbose]
256
+ ActiveRecord::ConnectionAdapters::Mysql2Adapter.module_eval do
257
+ include Oboe::Inst::ConnectionAdapters::Mysql2Adapter
258
+ end
259
+ end
260
+ end
261
+
262
+ def self.postgresql
263
+ if ActiveRecord::Base::connection.adapter_name.downcase.to_sym == :postgresql
264
+ puts "[oboe/loading] Instrumenting ActiveRecord PostgreSQLAdapter" if Oboe::Config[:verbose]
265
+ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.module_eval do
266
+ if ::Rails::VERSION::MAJOR == 3 and ::Rails::VERSION::MINOR > 0
267
+ include Oboe::Inst::ConnectionAdapters::PostgreSQLAdapter
268
+ else
269
+ include Oboe::Inst::ConnectionAdapters::LegacyPostgreSQLAdapter
270
+ end
271
+ end
272
+ end
273
+ end
274
+
275
+ def self.oracle
276
+ if ActiveRecord::Base::connection.adapter_name.downcase.to_sym == :oracleenhanced
277
+ puts "[oboe/loading] Instrumenting ActiveRecord OracleEnhancedAdapter" if Oboe::Config[:verbose]
278
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.module_eval do
279
+ include Oboe::Inst::ConnectionAdapters
280
+ end
281
+ end
282
+ end
283
+ end
284
+ end
285
+ end
286
+ end
287
+
288
+ Oboe::Inst::ConnectionAdapters::FlavorInitializers.mysql
289
+ Oboe::Inst::ConnectionAdapters::FlavorInitializers.mysql2
290
+ Oboe::Inst::ConnectionAdapters::FlavorInitializers.postgresql
291
+ Oboe::Inst::ConnectionAdapters::FlavorInitializers.oracle
@@ -0,0 +1,45 @@
1
+ # Copyright (c) 2012 by Tracelytics, Inc.
2
+ # All rights reserved.
3
+
4
+ module Oboe
5
+ module Inst
6
+ module Dalli
7
+ include Oboe::API::Memcache
8
+
9
+ def self.included(cls)
10
+ cls.class_eval do
11
+ puts "[oboe/loading] Instrumenting Memcache (Dalli)" if Oboe::Config[:verbose]
12
+ if ::Dalli::Client.private_method_defined? :perform
13
+ alias perform_without_oboe perform
14
+ alias perform perform_with_oboe
15
+ else puts "[oboe/loading] Couldn't properly instrument Memcache (Dalli). Partial traces may occur."
16
+ end
17
+ end
18
+ end
19
+
20
+ def perform_with_oboe(op, key, *args)
21
+ if Oboe::Config.tracing?
22
+ opts = {}
23
+ opts[:KVOp] = op
24
+ opts[:KVKey] = key
25
+
26
+ Oboe::API.trace('memcache', opts || {}) do
27
+ result = perform_without_oboe(op, key, *args)
28
+ if op == :get and key.class == String
29
+ Oboe::API.log('memcache', 'info', { :KVHit => memcache_hit?(result) })
30
+ end
31
+ result
32
+ end
33
+ else
34
+ perform_without_oboe(op, key, *args)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ if defined?(Dalli)
42
+ Dalli::Client.module_eval do
43
+ include Oboe::Inst::Dalli
44
+ end
45
+ end
@@ -0,0 +1,40 @@
1
+ # Copyright (c) 2012 by Tracelytics, Inc.
2
+ # All rights reserved.
3
+
4
+ require 'net/http'
5
+
6
+ Net::HTTP.class_eval do
7
+ def request_with_oboe(*args, &block)
8
+ unless started?
9
+ return request_without_oboe(*args, &block)
10
+ end
11
+
12
+ Oboe::API.trace('net-http') do
13
+ opts = {}
14
+ if args.length and args[0]
15
+ req = args[0]
16
+ req['X-Trace'] = Oboe::Context.toString()
17
+
18
+ opts['IsService'] = 1
19
+ opts['RemoteProtocol'] = use_ssl? ? 'HTTPS' : 'HTTP'
20
+ opts['RemoteHost'] = addr_port
21
+ opts['ServiceArg'] = req.path
22
+ opts['Method'] = req.method
23
+ end
24
+
25
+ Oboe::API.log('net-http', 'info', opts)
26
+ resp = request_without_oboe(*args, &block)
27
+
28
+ xtrace = resp.get_fields('X-Trace')
29
+ if xtrace and xtrace.size and Oboe::Config.tracing?
30
+ Oboe::Context.fromString(xtrace[0])
31
+ end
32
+ next resp
33
+ end
34
+ end
35
+
36
+ alias request_without_oboe request
37
+ alias request request_with_oboe
38
+
39
+ puts "[oboe/loading] Instrumenting net/http" if Oboe::Config[:verbose]
40
+ end