oboe 1.3.9.1 → 1.4.0.2

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.
@@ -77,41 +77,6 @@ end
77
77
  module Oboe
78
78
  include Oboe_metal
79
79
 
80
- # TODO: Ensure that the :tracing_mode is set to "always", "through", or "never"
81
- Config = {
82
- :tracing_mode => "through",
83
- :reporter_host => "127.0.0.1",
84
- :sample_rate => 1000000
85
- }
86
-
87
- def self.passthrough?
88
- ["always", "through"].include?(Oboe::Config[:tracing_mode])
89
- end
90
-
91
- def self.always?
92
- Oboe::Config[:tracing_mode] == "always"
93
- end
94
-
95
- def self.through?
96
- Oboe::Config[:tracing_mode] == "through"
97
- end
98
-
99
- def self.never?
100
- Oboe::Config[:tracing_mode] == "never"
101
- end
102
-
103
- def self.now?
104
- Oboe::Context.isValid and not Oboe.never?
105
- end
106
-
107
- def self.start?
108
- not Oboe::Context.isValid and Oboe.always?
109
- end
110
-
111
- def self.continue?
112
- Oboe::Context.isValid and not Oboe.never?
113
- end
114
-
115
80
  def self.log(layer, label, options = {})
116
81
  Context.log(layer, label, options = options)
117
82
  end
@@ -60,15 +60,15 @@ module Oboe
60
60
  #
61
61
  # Returns nothing.
62
62
  def log_start(layer, xtrace, opts={})
63
- return if Oboe::Config.never?
63
+ return if Oboe.never?
64
64
 
65
65
  if xtrace
66
66
  Oboe::Context.fromString(xtrace)
67
67
  end
68
68
 
69
- if Oboe::Config.tracing?
69
+ if Oboe.tracing?
70
70
  log_entry(layer, opts)
71
- elsif Oboe::Config.always? or Oboe::Config.sample?
71
+ elsif Oboe.always? or Oboe.sample?
72
72
  log_event(layer, 'entry', Oboe::Context.startTrace, opts)
73
73
  end
74
74
  end
@@ -4,7 +4,7 @@
4
4
  module Oboe
5
5
  module API
6
6
  module Memcache
7
- MEMCACHE_OPS = %w{add append cas decr decrement delete fetch get get_multi incr increment prepend replace set}
7
+ MEMCACHE_OPS = %w{add append cas decr decrement delete fetch get incr increment prepend replace set}
8
8
 
9
9
  def memcache_hit?(result)
10
10
  result.nil? ? 0 : 1
@@ -118,7 +118,7 @@ module Oboe
118
118
  log_start(layer, xtrace, opts)
119
119
  exit_evt = Oboe::Context.createEvent
120
120
  begin
121
- target['X-Trace'] = Oboe::Event.metadataString(exit_evt) if Oboe::Config.tracing?
121
+ target['X-Trace'] = Oboe::Event.metadataString(exit_evt) if Oboe.tracing?
122
122
  yield
123
123
  rescue Exception => e
124
124
  log_exception(layer, e)
@@ -2,38 +2,113 @@
2
2
  # All rights reserved.
3
3
 
4
4
  module Oboe
5
- # The following is done for compatability with older versions of oboe and
6
- # oboe_fu (0.2.x)
7
- if not defined?(Oboe::Config)
8
- Config = {
9
- :tracing_mode => "through",
10
- :reporter_host => "127.0.0.1",
11
- :sample_rate => 3e5
12
- }
13
- end
14
-
15
- class << Config
16
- def always?
17
- self[:tracing_mode].to_s == "always"
18
- end
19
5
 
20
- def never?
21
- self[:tracing_mode].to_s == "never"
22
- end
6
+ def self.always?
7
+ Oboe::Config[:tracing_mode].to_s == "always"
8
+ end
23
9
 
24
- def tracing?
25
- Oboe::Context.isValid and not never?
26
- end
10
+ def self.continue?
11
+ Oboe::Context.isValid and not Oboe.never?
12
+ end
27
13
 
28
- def start?
29
- not Oboe::Context.isValid and always?
14
+ def self.log(layer, label, options = {})
15
+ Context.log(layer, label, options = options)
16
+ end
17
+
18
+ def self.never?
19
+ Oboe::Config[:tracing_mode].to_s == "never"
20
+ end
21
+
22
+ def self.now?
23
+ Oboe::Context.isValid and not Oboe.never?
24
+ end
25
+
26
+ def self.passthrough?
27
+ ["always", "through"].include?(Oboe::Config[:tracing_mode])
28
+ end
29
+
30
+ def self.sample?
31
+ # Note that this the only point in the code that currently does and
32
+ # should ever read the sample rate. When autopilot is released, modify
33
+ # the line below and that line only.
34
+ Oboe::Config[:sample_rate].to_i < rand(1e6)
35
+ end
36
+
37
+ def self.start?
38
+ not Oboe::Context.isValid and Oboe.always?
39
+ end
40
+
41
+ def self.through?
42
+ Oboe::Config[:tracing_mode] == "through"
43
+ end
44
+
45
+ def self.tracing?
46
+ Oboe::Context.isValid and not Oboe.never?
47
+ end
48
+
49
+ ############################
50
+ # Oboe Configuration Module
51
+ ############################
52
+ module Config
53
+ @@config = {}
54
+
55
+ @@instrumentation = [ :cassandra, :dalli, :nethttp, :memcached, :memcache, :mongo,
56
+ :moped, :rack, :resque, :action_controller, :action_view,
57
+ :active_record ]
58
+
59
+ def self.show
60
+ @@config
30
61
  end
31
62
 
32
- def sample?
33
- # Note that this the only point in the code that currently does and
34
- # should ever read the sample rate. When autopilot is released, modify
35
- # the line below and that line only.
36
- self[:sample_rate].to_i < rand(1e6)
63
+ def self.initialize(data={})
64
+ # Setup default instrumentation values
65
+ @@instrumentation.each do |k|
66
+ @@config[k] = {}
67
+ @@config[k][:enabled] = true
68
+ @@config[k][:log_args] = true
69
+ end
70
+
71
+ # Special instrument specific flags
72
+ #
73
+ # :link_workers - associates enqueue operations with the jobs they queue by piggybacking
74
+ # an additional argument that is stripped prior to job proecessing
75
+ # !!Note: Make sure both the queue side and the Resque workers are instrumented
76
+ # or jobs will fail
77
+ # (Default: false)
78
+ @@config[:resque][:link_workers] = false
79
+
80
+ update!(data)
81
+ end
82
+
83
+ def self.update!(data)
84
+ data.each do |key, value|
85
+ self[key] = value
86
+ end
87
+ end
88
+
89
+ def self.[](key)
90
+ @@config[key.to_sym]
91
+ end
92
+
93
+ def self.[]=(key, value)
94
+ @@config[key.to_sym] = value
95
+ end
96
+
97
+ def self.method_missing(sym, *args)
98
+ if sym.to_s =~ /(.+)=$/
99
+ self[$1] = args.first
100
+ else
101
+ self[sym]
102
+ end
37
103
  end
38
104
  end
39
105
  end
106
+
107
+ config = {
108
+ :tracing_mode => "through",
109
+ :reporter_host => "127.0.0.1",
110
+ :sample_rate => 1000000,
111
+ :verbose => false }
112
+
113
+ Oboe::Config.initialize(config)
114
+
@@ -5,8 +5,8 @@ module Oboe
5
5
 
6
6
  def oboe_rum_header
7
7
  begin
8
- return unless Oboe::Config.has_key?(:rum_id)
9
- if Oboe::Config.tracing?
8
+ return unless Oboe::Config.rum_id
9
+ if Oboe.tracing?
10
10
  if request.xhr?
11
11
  header_tmpl = File.read(File.dirname(__FILE__) + '/rails/helpers/rum/rum_ajax_header.js.erb')
12
12
  else
@@ -22,8 +22,8 @@ module Oboe
22
22
 
23
23
  def oboe_rum_footer
24
24
  begin
25
- return unless Oboe::Config.has_key?(:rum_id)
26
- if Oboe::Config.tracing?
25
+ return unless Oboe::Config.rum_id
26
+ if Oboe.tracing?
27
27
  # Even though the footer template is named xxxx.erb, there are no ERB tags in it so we'll
28
28
  # skip that step for now
29
29
  footer_tmpl = File.read(File.dirname(__FILE__) + '/rails/helpers/rum/rum_footer.js.erb')
@@ -53,7 +53,6 @@ module Oboe
53
53
  require tr_initializer if File.exists?(tr_initializer)
54
54
  end
55
55
 
56
-
57
56
  def self.load_instrumentation
58
57
  # Load the Rails specific instrumentation
59
58
  pattern = File.join(File.dirname(__FILE__), 'rails/inst', '*.rb')
@@ -101,7 +100,7 @@ if defined?(::Rails)
101
100
  end
102
101
 
103
102
  initializer 'oboe.rack' do |app|
104
- puts "[oboe/loading] Instrumenting rack" if true or Oboe::Config[:verbose]
103
+ puts "[oboe/loading] Instrumenting rack" if Oboe::Config[:verbose]
105
104
  app.config.middleware.insert 0, "Oboe::Rack"
106
105
  end
107
106
 
@@ -115,14 +114,15 @@ if defined?(::Rails)
115
114
  else
116
115
  Oboe::Rails.load_initializer
117
116
  Oboe::Loading.load_access_key
118
-
119
- puts "[oboe/loading] Instrumenting rack" if true or Oboe::Config[:verbose]
120
- Rails.configuration.middleware.insert 0, "Oboe::Rack"
121
-
122
- Oboe::Inst.load_instrumentation
123
- Oboe::Rails.load_instrumentation
124
- Oboe::Rails.include_helpers
125
117
 
118
+ Rails.configuration.after_initialize do
119
+ puts "[oboe/loading] Instrumenting rack" if Oboe::Config[:verbose]
120
+ Rails.configuration.middleware.insert 0, "Oboe::Rack"
121
+
122
+ Oboe::Inst.load_instrumentation
123
+ Oboe::Rails.load_instrumentation
124
+ Oboe::Rails.include_helpers
125
+ end
126
126
  end
127
127
  end
128
128
 
@@ -4,14 +4,21 @@
4
4
  module Oboe
5
5
  module Inst
6
6
  module Rails3ActionController
7
- def process(*args)
8
-
7
+ def self.included(base)
8
+ base.class_eval do
9
+ alias_method_chain :render, :oboe
10
+ alias_method_chain :process, :oboe
11
+ alias_method_chain :process_action, :oboe
12
+ end
13
+ end
14
+
15
+ def process_with_oboe(*args)
9
16
  Oboe::API.trace('rails', {}) do
10
- super
17
+ process_without_oboe *args
11
18
  end
12
19
  end
13
20
 
14
- def process_action(*args)
21
+ def process_action_with_oboe(*args)
15
22
  report_kvs = {
16
23
  'HTTP-Host' => @_request.headers['HTTP_HOST'],
17
24
  :URL => @_request.headers['REQUEST_URI'],
@@ -19,27 +26,28 @@ module Oboe
19
26
  :Controller => self.class.name,
20
27
  :Action => self.action_name,
21
28
  }
22
- super
29
+ result = process_action_without_oboe *args
23
30
 
24
31
  report_kvs[:Status] = @_response.status
25
32
  Oboe::API.log('rails', 'info', report_kvs)
26
-
33
+
34
+ result
27
35
  rescue Exception => exception
28
36
  report_kvs[:Status] = 500
29
37
  Oboe::API.log('rails', 'info', report_kvs)
30
38
  raise
31
39
  end
32
40
 
33
- def render(*args)
41
+ def render_with_oboe(*args)
34
42
  Oboe::API.trace('actionview', {}) do
35
- super
43
+ render_without_oboe *args
36
44
  end
37
45
  end
38
46
  end
39
47
  end
40
48
  end
41
49
 
42
- if defined?(ActionController::Base)
50
+ if defined?(ActionController::Base) and Oboe::Config[:action_controller][:enabled]
43
51
  if ::Rails::VERSION::MAJOR == 3
44
52
  Oboe::API.report_init('rails')
45
53
 
@@ -92,3 +100,4 @@ if defined?(ActionController::Base)
92
100
  end
93
101
  puts "[oboe/loading] Instrumenting actioncontroler" if Oboe::Config[:verbose]
94
102
  end
103
+ # vim:set expandtab:tabstop=2
@@ -1,9 +1,10 @@
1
1
  # Copyright (c) 2012 by Tracelytics, Inc.
2
2
  # All rights reserved.
3
3
 
4
- if defined?(ActionView::Base)
4
+ if defined?(ActionView::Base) and Oboe::Config[:action_view][:enabled]
5
+
5
6
  if Rails::VERSION::MAJOR == 3
6
- puts "[oboe/loading] Instrumenting actionview"
7
+ puts "[oboe/loading] Instrumenting actionview" if Oboe::Config[:verbose]
7
8
 
8
9
  if Rails::VERSION::MINOR == 0
9
10
  ActionView::Partials::PartialRenderer.class_eval do
@@ -123,7 +124,7 @@ if defined?(ActionView::Base)
123
124
  end
124
125
  end
125
126
  elsif Rails::VERSION::MAJOR == 2
126
- puts "[oboe/loading] Instrumenting ActionView"
127
+ puts "[oboe/loading] Instrumenting actionview" if Oboe::Config[:verbose]
127
128
 
128
129
  ActionView::Partials.module_eval do
129
130
  alias :render_partial_without_oboe :render_partial
@@ -8,19 +8,21 @@ module Oboe
8
8
  def extract_trace_details(sql, name = nil)
9
9
  opts = {}
10
10
 
11
- opts[:Query] = sql.to_s
12
- opts[:Name] = name.to_s if name
13
- opts[:Backtrace] = Oboe::API.backtrace
11
+ begin
12
+ opts[:Query] = sql.to_s
13
+ opts[:Name] = name.to_s if name
14
+ opts[:Backtrace] = Oboe::API.backtrace
14
15
 
15
- if defined?(ActiveRecord::Base.connection.cfg)
16
- opts[:Database] = ActiveRecord::Base.connection.cfg[:database]
17
- if ActiveRecord::Base.connection.cfg.has_key?(:host)
18
- opts[:RemoteHost] = ActiveRecord::Base.connection.cfg[:host]
19
- end
20
- end
16
+ if ::Rails::VERSION::MAJOR == 2
17
+ config = ::Rails.configuration.database_configuration[::Rails.env]
18
+ else
19
+ config = ::Rails.application.config.database_configuration[::Rails.env]
20
+ end
21
21
 
22
- if defined?(ActiveRecord::Base.connection.adapter_name)
23
- opts[:Flavor] = ActiveRecord::Base.connection.adapter_name
22
+ opts[:Database] = config["database"] if config.has_key?("database")
23
+ opts[:RemoteHost] = config["host"] if config.has_key?("host")
24
+ opts[:Flavor] = config["adapter"] if config.has_key?("adapter")
25
+ rescue Exception => e
24
26
  end
25
27
 
26
28
  return opts || {}
@@ -37,7 +39,7 @@ module Oboe
37
39
  end
38
40
 
39
41
  def execute_with_oboe(sql, name = nil)
40
- if Oboe::Config.tracing? and !ignore_payload?(name)
42
+ if Oboe.tracing? and !ignore_payload?(name)
41
43
 
42
44
  opts = extract_trace_details(sql, name)
43
45
  Oboe::API.trace('activerecord', opts || {}) do
@@ -49,7 +51,7 @@ module Oboe
49
51
  end
50
52
 
51
53
  def exec_query_with_oboe(sql, name = nil, binds = [])
52
- if Oboe::Config.tracing? and !ignore_payload?(name)
54
+ if Oboe.tracing? and !ignore_payload?(name)
53
55
 
54
56
  opts = extract_trace_details(sql, name)
55
57
  Oboe::API.trace('activerecord', opts || {}) do
@@ -61,7 +63,7 @@ module Oboe
61
63
  end
62
64
 
63
65
  def exec_delete_with_oboe(sql, name = nil, binds = [])
64
- if Oboe::Config.tracing? and !ignore_payload?(name)
66
+ if Oboe.tracing? and !ignore_payload?(name)
65
67
 
66
68
  opts = extract_trace_details(sql, name)
67
69
  Oboe::API.trace('activerecord', opts || {}) do
@@ -73,7 +75,7 @@ module Oboe
73
75
  end
74
76
 
75
77
  def exec_insert_with_oboe(sql, name = nil, binds = [])
76
- if Oboe::Config.tracing? and !ignore_payload?(name)
78
+ if Oboe.tracing? and !ignore_payload?(name)
77
79
 
78
80
  opts = extract_trace_details(sql, name)
79
81
  Oboe::API.trace('activerecord', opts || {}) do
@@ -85,7 +87,7 @@ module Oboe
85
87
  end
86
88
 
87
89
  def begin_db_transaction_with_oboe()
88
- if Oboe::Config.tracing?
90
+ if Oboe.tracing?
89
91
  opts = {}
90
92
 
91
93
  opts[:Query] = "BEGIN"
@@ -234,60 +236,62 @@ module Oboe
234
236
 
235
237
  module FlavorInitializers
236
238
  def self.mysql
237
- if ActiveRecord::Base::connection.adapter_name.downcase.to_sym == :mysql
238
- puts "[oboe/loading] Instrumenting activerecord mysqladapter" if Oboe::Config[:verbose]
239
- if ::Rails::VERSION::MAJOR == 3 and ::Rails::VERSION::MINOR > 1
240
- ::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.module_eval do
241
- include Oboe::Inst::ConnectionAdapters::AbstractMysqlAdapter
242
- end if defined?(::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter)
239
+ puts "[oboe/loading] Instrumenting activerecord mysqladapter" if Oboe::Config[:verbose]
240
+ if ::Rails::VERSION::MAJOR == 3 and ::Rails::VERSION::MINOR > 1
241
+ ::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.module_eval do
242
+ include Oboe::Inst::ConnectionAdapters::AbstractMysqlAdapter
243
+ end if defined?(::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter)
243
244
 
244
- ::ActiveRecord::ConnectionAdapters::MysqlAdapter.module_eval do
245
- include Oboe::Inst::ConnectionAdapters::MysqlAdapter
246
- end if defined?(::ActiveRecord::ConnectionAdapters::MysqlAdapter)
247
- else
248
- ::ActiveRecord::ConnectionAdapters::MysqlAdapter.module_eval do
249
- include Oboe::Inst::ConnectionAdapters::LegacyMysqlAdapter
250
- end if defined?(::ActiveRecord::ConnectionAdapters::MysqlAdapter)
251
- end
245
+ ::ActiveRecord::ConnectionAdapters::MysqlAdapter.module_eval do
246
+ include Oboe::Inst::ConnectionAdapters::MysqlAdapter
247
+ end if defined?(::ActiveRecord::ConnectionAdapters::MysqlAdapter)
248
+ else
249
+ ::ActiveRecord::ConnectionAdapters::MysqlAdapter.module_eval do
250
+ include Oboe::Inst::ConnectionAdapters::LegacyMysqlAdapter
251
+ end if defined?(::ActiveRecord::ConnectionAdapters::MysqlAdapter)
252
252
  end
253
253
  end
254
254
 
255
255
  def self.mysql2
256
- if ActiveRecord::Base::connection.adapter_name.downcase.to_sym == :mysql2
257
- puts "[oboe/loading] Instrumenting activerecord mysql2adapter" if Oboe::Config[:verbose]
258
- ::ActiveRecord::ConnectionAdapters::Mysql2Adapter.module_eval do
259
- include Oboe::Inst::ConnectionAdapters::Mysql2Adapter
260
- end if defined?(::ActiveRecord::ConnectionAdapters::Mysql2Adapter)
261
- end
256
+ puts "[oboe/loading] Instrumenting activerecord mysql2adapter" if Oboe::Config[:verbose]
257
+ ::ActiveRecord::ConnectionAdapters::Mysql2Adapter.module_eval do
258
+ include Oboe::Inst::ConnectionAdapters::Mysql2Adapter
259
+ end if defined?(::ActiveRecord::ConnectionAdapters::Mysql2Adapter)
262
260
  end
263
261
 
264
262
  def self.postgresql
265
- if ActiveRecord::Base::connection.adapter_name.downcase.to_sym == :postgresql
266
- puts "[oboe/loading] Instrumenting activerecord postgresqladapter" if Oboe::Config[:verbose]
267
- ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.module_eval do
268
- if ::Rails::VERSION::MAJOR == 3 and ::Rails::VERSION::MINOR > 0
269
- include Oboe::Inst::ConnectionAdapters::PostgreSQLAdapter
270
- else
271
- include Oboe::Inst::ConnectionAdapters::LegacyPostgreSQLAdapter
272
- end
273
- end if defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
274
- end
263
+ puts "[oboe/loading] Instrumenting activerecord postgresqladapter" if Oboe::Config[:verbose]
264
+ ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.module_eval do
265
+ if ::Rails::VERSION::MAJOR == 3 and ::Rails::VERSION::MINOR > 0
266
+ include Oboe::Inst::ConnectionAdapters::PostgreSQLAdapter
267
+ else
268
+ include Oboe::Inst::ConnectionAdapters::LegacyPostgreSQLAdapter
269
+ end
270
+ end if defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
275
271
  end
276
272
 
277
273
  def self.oracle
278
- if ActiveRecord::Base::connection.adapter_name.downcase.to_sym == :oracleenhanced
279
- puts "[oboe/loading] Instrumenting activerecord oracleenhancedadapter" if Oboe::Config[:verbose]
280
- ::ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.module_eval do
281
- include Oboe::Inst::ConnectionAdapters
282
- end if defined?(::ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter)
283
- end
274
+ puts "[oboe/loading] Instrumenting activerecord oracleenhancedadapter" if Oboe::Config[:verbose]
275
+ ::ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.module_eval do
276
+ include Oboe::Inst::ConnectionAdapters
277
+ end if defined?(::ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter)
284
278
  end
285
279
  end
286
280
  end
287
281
  end
288
282
  end
289
283
 
290
- Oboe::Inst::ConnectionAdapters::FlavorInitializers.mysql
291
- Oboe::Inst::ConnectionAdapters::FlavorInitializers.mysql2
292
- Oboe::Inst::ConnectionAdapters::FlavorInitializers.postgresql
293
- Oboe::Inst::ConnectionAdapters::FlavorInitializers.oracle
284
+ if Oboe::Config[:active_record][:enabled]
285
+ begin
286
+ adapter = ActiveRecord::Base::connection.adapter_name.downcase
287
+
288
+ Oboe::Inst::ConnectionAdapters::FlavorInitializers.mysql if adapter == "mysql"
289
+ Oboe::Inst::ConnectionAdapters::FlavorInitializers.mysql2 if adapter == "mysql2"
290
+ Oboe::Inst::ConnectionAdapters::FlavorInitializers.postgresql if adapter == "postgresql"
291
+ Oboe::Inst::ConnectionAdapters::FlavorInitializers.oracle if adapter == "oracleenhanced"
292
+
293
+ rescue Exception => e
294
+ puts "[oboe/error] Oboe/ActiveRecord error: #{e.message}" if Oboe::Config[:verbose]
295
+ end
296
+ end
297
+ # vim:set expandtab:tabstop=2