Module: TraceView::Inst::Sequel

Defined in:
lib/traceview/inst/sequel.rb

Instance Method Summary collapse

Instance Method Details

#extract_trace_details(sql, opts) ⇒ Object



7
8
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
# File 'lib/traceview/inst/sequel.rb', line 7

def extract_trace_details(sql, opts)
  kvs = {}

  if TraceView::Config[:sanitize_sql]
    # Sanitize SQL and don't report binds
    if sql.is_a?(Symbol)
      kvs[:Query] = sql
    else
      kvs[:Query] = sql.gsub(/('[\s\S][^\']*\'|\d*\.\d*)/, '?')
    end
  else
    # Report raw SQL and any binds if they exist
    kvs[:Query] = sql.to_s
    kvs[:QueryArgs] = opts[:arguments] if opts.is_a?(Hash) and opts.key?(:arguments)
  end
  kvs[:IsPreparedStatement] = true if sql.is_a?(Symbol)

  kvs[:Backtrace] = TraceView::API.backtrace if TraceView::Config[:sequel][:collect_backtraces]

  if ::Sequel::VERSION < '3.41.0' && !(self.class.to_s =~ /Dataset$/)
    db_opts = @opts
  elsif @pool
    db_opts = @pool.db.opts
  else
    db_opts = @db.opts
  end

  kvs[:Database]   = db_opts[:database]
  kvs[:RemoteHost] = db_opts[:host]
  kvs[:RemotePort] = db_opts[:port] if db_opts.key?(:port)
  kvs[:Flavor]     = db_opts[:adapter]
rescue => e
  TraceView.logger.debug "[traceview/debug Error capturing Sequel KVs: #{e.message}" if TraceView::Config[:verbose]
ensure
  return kvs
end