Module: TraceView::Inst::ConnectionAdapters::Utils
- Defined in:
- lib/traceview/frameworks/rails/inst/connection_adapters/utils.rb,
lib/traceview/frameworks/rails/inst/connection_adapters/utils5x.rb
Instance Method Summary collapse
- #begin_db_transaction_with_traceview ⇒ Object
- #exec_delete_with_traceview(sql, name = nil, binds = []) ⇒ Object
- #exec_insert_with_traceview(sql, name = nil, binds = [], *args) ⇒ Object
- #exec_query_with_traceview(sql, name = nil, binds = [], prepare: false) ⇒ Object
-
#execute_with_traceview(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_traceview ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'lib/traceview/frameworks/rails/inst/connection_adapters/utils.rb', line 108 def begin_db_transaction_with_traceview if TraceView.tracing? TraceView::API.trace('activerecord', :Query => 'BEGIN') do begin_db_transaction_without_traceview end else begin_db_transaction_without_traceview end end |
#exec_delete_with_traceview(sql, name = nil, binds = []) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/traceview/frameworks/rails/inst/connection_adapters/utils.rb', line 84 def exec_delete_with_traceview(sql, name = nil, binds = []) if TraceView.tracing? && !ignore_payload?(name) opts = extract_trace_details(sql, name, binds) TraceView::API.trace('activerecord', opts || {}) do exec_delete_without_traceview(sql, name, binds) end else exec_delete_without_traceview(sql, name, binds) end end |
#exec_insert_with_traceview(sql, name = nil, binds = [], *args) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/traceview/frameworks/rails/inst/connection_adapters/utils.rb', line 96 def exec_insert_with_traceview(sql, name = nil, binds = [], *args) if TraceView.tracing? && !ignore_payload?(name) opts = extract_trace_details(sql, name, binds) TraceView::API.trace('activerecord', opts || {}) do exec_insert_without_traceview(sql, name, binds, *args) end else exec_insert_without_traceview(sql, name, binds, *args) end end |
#exec_query_with_traceview(sql, name = nil, binds = [], prepare: false) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/traceview/frameworks/rails/inst/connection_adapters/utils.rb', line 72 def exec_query_with_traceview(sql, name = nil, binds = []) if TraceView.tracing? && !ignore_payload?(name) opts = extract_trace_details(sql, name, binds) TraceView::API.trace('activerecord', opts || {}) do exec_query_without_traceview(sql, name, binds) end else exec_query_without_traceview(sql, name, binds) end end |
#execute_with_traceview(sql, name = nil) ⇒ Object
def cfg
@config
end
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/traceview/frameworks/rails/inst/connection_adapters/utils.rb', line 60 def execute_with_traceview(sql, name = nil) if TraceView.tracing? && !ignore_payload?(name) opts = extract_trace_details(sql, name) TraceView::API.trace('activerecord', opts || {}) do execute_without_traceview(sql, name) end else execute_without_traceview(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 |
# File 'lib/traceview/frameworks/rails/inst/connection_adapters/utils.rb', line 9 def extract_trace_details(sql, name = nil, binds = []) opts = {} if TraceView::Config[:sanitize_sql] # Sanitize SQL and don't report binds opts[:Query] = TraceView::Util.sanitize_sql(sql) else # Report raw SQL and any binds if they exist opts[:Query] = sql.to_s opts[:QueryArgs] = binds.map { |col, val| [col.name, val.to_s] } unless binds.empty? end opts[:Name] = name.to_s if name opts[:Backtrace] = TraceView::API.backtrace if TraceView::Config[:active_record][:collect_backtraces] if ::Rails::VERSION::MAJOR == 2 config = ::Rails.configuration.database_configuration[::Rails.env] else config = ActiveRecord::Base.connection.instance_variable_get(:@config) end if config opts[:Database] = config['database'] if config.key?('database') opts[:RemoteHost] = config['host'] if config.key?('host') adapter_name = config[:adapter] case adapter_name when /mysql/i opts[:Flavor] = 'mysql' when /postgres/i opts[:Flavor] = 'postgresql' end end rescue StandardError => e TraceView.logger.debug "Exception raised capturing ActiveRecord KVs: #{e.inspect}" TraceView.logger.debug e.backtrace.join('\n') ensure return opts end |
#ignore_payload?(name) ⇒ Boolean
We don’t want to trace framework caches. Only instrument SQL that directly hits the database.
50 51 52 53 54 |
# File 'lib/traceview/frameworks/rails/inst/connection_adapters/utils.rb', line 50 def ignore_payload?(name) %w(SCHEMA EXPLAIN CACHE).include?(name.to_s) || (name && name.to_sym == :skip_logging) || name == 'ActiveRecord::SchemaMigration Load' end |