Module: Instana::Instrumentation::ActiveRecord

Defined in:
lib/instana/instrumentation/active_record.rb

Constant Summary collapse

IGNORED_NAMES =
%w[SCHEMA EXPLAIN CACHE].freeze
IGNORED_SQL =
%w[BEGIN COMMIT SET].freeze
SANITIZE_REGEXP =
/('[\s\S][^']*'|\d*\.\d+|\d+|NULL)/i

Instance Method Summary collapse

Instance Method Details

#log(sql, name = 'SQL', binds = [], *args, **kwargs, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/instana/instrumentation/active_record.rb', line 11

def log(sql, name = 'SQL', binds = [], *args, **kwargs, &block)
  call_payload = {
    activerecord: {
      adapter: @config[:adapter],
      host: @config[:host],
      username: @config[:username],
      db: @config[:database],
      sql: maybe_sanitize(sql)
    }
  }

  if binds.all? { |b| b.respond_to?(:value_before_type_cast) } && !::Instana.config[:sanitize_sql]
    mapped = binds.map(&:value_before_type_cast)
    call_payload[:activerecord][:binds] = mapped
  end

  maybe_trace(call_payload, name) { super(sql, name, binds, *args, **kwargs, &block) }
end