Module: Oboe::Inst::ConnectionAdapters::Utils
- Defined in:
- lib/oboe/frameworks/rails/inst/connection_adapters/utils.rb
Instance Method Summary collapse
- #begin_db_transaction_with_oboe ⇒ Object
- #exec_delete_with_oboe(sql, name = nil, binds = []) ⇒ Object
- #exec_insert_with_oboe(sql, name = nil, binds = [], *args) ⇒ Object
- #exec_query_with_oboe(sql, name = nil, binds = []) ⇒ Object
-
#execute_with_oboe(sql, name = nil) ⇒ Object
def cfg @config end.
- #extract_trace_details(sql, name = nil, binds = []) ⇒ Object
-
#ignore_payload?(name) ⇒ Boolean
We don’t want to trace framework caches.
Instance Method Details
#begin_db_transaction_with_oboe ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/oboe/frameworks/rails/inst/connection_adapters/utils.rb', line 102 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
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/oboe/frameworks/rails/inst/connection_adapters/utils.rb', line 78 def exec_delete_with_oboe(sql, name = nil, binds = []) if Oboe.tracing? && !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
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/oboe/frameworks/rails/inst/connection_adapters/utils.rb', line 90 def exec_insert_with_oboe(sql, name = nil, binds = [], *args) if Oboe.tracing? && !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
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/oboe/frameworks/rails/inst/connection_adapters/utils.rb', line 66 def exec_query_with_oboe(sql, name = nil, binds = []) if Oboe.tracing? && !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
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/oboe/frameworks/rails/inst/connection_adapters/utils.rb', line 54 def execute_with_oboe(sql, name = nil) if Oboe.tracing? && !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 |
# File 'lib/oboe/frameworks/rails/inst/connection_adapters/utils.rb', line 9 def extract_trace_details(sql, name = nil, binds = []) opts = {} begin if Oboe::Config[:sanitize_sql] # Sanitize SQL and don't report binds opts[:Query] = sql.gsub(/\'[\s\S][^\']*\'/, '?') else # Report raw SQL and any binds if they exist opts[:Query] = sql.to_s opts[:QueryArgs] = binds.map { |col, val| type_cast(val, col) } unless binds.empty? 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.key?('database') opts[:RemoteHost] = config['host'] if config.key?('host') opts[:Flavor] = config['adapter'] if config.key?('adapter') rescue StandardError => 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.
44 45 46 47 48 |
# File 'lib/oboe/frameworks/rails/inst/connection_adapters/utils.rb', line 44 def ignore_payload?(name) %w(SCHEMA EXPLAIN CACHE).include?(name.to_s) || (name && name.to_sym == :skip_logging) || name == 'ActiveRecord::SchemaMigration Load' end |