Module: Oboe::Inst::ConnectionAdapters::Utils

Defined in:
lib/oboe/frameworks/rails/inst/connection_adapters/utils.rb

Instance Method Summary collapse

Instance Method Details

#begin_db_transaction_with_oboeObject



110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/oboe/frameworks/rails/inst/connection_adapters/utils.rb', line 110

def begin_db_transaction_with_oboe()
  if Oboe.tracing?
    opts = {}

    opts[:Query] = "BEGIN"
    Oboe::API.trace('activerecord', opts || {}) do
      begin_db_transaction_without_oboe()
    end
  else
    begin_db_transaction_without_oboe()
  end
end

#exec_delete_with_oboe(sql, name = nil, binds = []) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/oboe/frameworks/rails/inst/connection_adapters/utils.rb', line 86

def exec_delete_with_oboe(sql, name = nil, binds = [])
  if Oboe.tracing? and !ignore_payload?(name)

    opts = extract_trace_details(sql, name, binds)
    Oboe::API.trace('activerecord', opts || {}) do
      exec_delete_without_oboe(sql, name, binds)
    end
  else
    exec_delete_without_oboe(sql, name, binds)
  end
end

#exec_insert_with_oboe(sql, name = nil, binds = [], *args) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/oboe/frameworks/rails/inst/connection_adapters/utils.rb', line 98

def exec_insert_with_oboe(sql, name = nil, binds = [], *args)
  if Oboe.tracing? and !ignore_payload?(name)

    opts = extract_trace_details(sql, name, binds)
    Oboe::API.trace('activerecord', opts || {}) do
      exec_insert_without_oboe(sql, name, binds, *args)
    end
  else
    exec_insert_without_oboe(sql, name, binds, *args)
  end
end

#exec_query_with_oboe(sql, name = nil, binds = []) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/oboe/frameworks/rails/inst/connection_adapters/utils.rb', line 74

def exec_query_with_oboe(sql, name = nil, binds = [])
  if Oboe.tracing? and !ignore_payload?(name)

    opts = extract_trace_details(sql, name, binds)
    Oboe::API.trace('activerecord', opts || {}) do
      exec_query_without_oboe(sql, name, binds)
    end
  else
    exec_query_without_oboe(sql, name, binds)
  end
end

#execute_with_oboe(sql, name = nil) ⇒ Object

def cfg

@config

end



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/oboe/frameworks/rails/inst/connection_adapters/utils.rb', line 62

def execute_with_oboe(sql, name = nil)
  if Oboe.tracing? and !ignore_payload?(name)

    opts = extract_trace_details(sql, name)
    Oboe::API.trace('activerecord', opts || {}) do
      execute_without_oboe(sql, name)
    end
  else
    execute_without_oboe(sql, name)
  end
end

#extract_trace_details(sql, name = nil, binds = []) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/oboe/frameworks/rails/inst/connection_adapters/utils.rb', line 9

def extract_trace_details(sql, name = nil, binds = [])
  opts = {}

  begin
    if binds.empty? 
      # Raw SQL.  Sanitize if requested
      if Oboe::Config[:sanitize_sql]
        opts[:Query] = sql.gsub(/\'[\s\S][^\']*\'/, '?')
      else
        opts[:Query] = sql.to_s
      end
    else
      # We have bind parameters.  Only report if :sanitize_sql isn't true
      unless Oboe::Config[:sanitize_sql]
        opts[:Query] = sql.to_s
        opts[:QueryArgs] = binds.map { |col, val| type_cast(val, col) }
      else
        opts[:Query] = sql.gsub(/\'[\s\S][^\']*\'/, '?')
      end
    end

    opts[:Name] = name.to_s if name
    opts[:Backtrace] = Oboe::API.backtrace if Oboe::Config[:active_record][:collect_backtraces]

    if ::Rails::VERSION::MAJOR == 2
      config = ::Rails.configuration.database_configuration[::Rails.env]
    else
      config = ::Rails.application.config.database_configuration[::Rails.env]
    end  

    opts[:Database]   = config["database"] if config.has_key?("database")
    opts[:RemoteHost] = config["host"]     if config.has_key?("host")
    opts[:Flavor]     = config["adapter"]  if config.has_key?("adapter")
  rescue Exception => e
    Oboe.logger.debug "Exception raised capturing ActiveRecord KVs: #{e.inspect}"
    Oboe.logger.debug e.backtrace.join("\n")
  end

  return opts || {}
end

#ignore_payload?(name) ⇒ Boolean

We don’t want to trace framework caches. Only instrument SQL that directly hits the database.

Returns:

  • (Boolean)


52
53
54
55
56
# File 'lib/oboe/frameworks/rails/inst/connection_adapters/utils.rb', line 52

def ignore_payload?(name)
  %w(SCHEMA EXPLAIN CACHE).include? name.to_s or 
    (name and name.to_sym == :skip_logging) or
      name == "ActiveRecord::SchemaMigration Load"
end