Module: AppPerfRpm::Instruments::ActiveRecordImport

Includes:
Utils
Defined in:
lib/app_perf_rpm/instruments/activerecord_import.rb

Instance Method Summary collapse

Methods included from Utils

#connection_config, #format_redis, #format_redis_command, log_source_and_backtrace, #sanitize_sql

Instance Method Details

#insert_many_with_trace(sql, values, *args) ⇒ Object



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
# File 'lib/app_perf_rpm/instruments/activerecord_import.rb', line 8

def insert_many_with_trace( sql, values, *args )
  if ::AppPerfRpm::Tracer.tracing?
    sql_copy = sql.dup
    base_sql, post_sql = if sql_copy.dup.is_a?( String )
      [sql_copy, '']
    elsif sql.is_a?( Array )
      [sql_copy.shift, sql_copy.join( ' ' )]
    end

    adapter = connection_config.fetch(:adapter)
    sanitized_sql = sanitize_sql(base_sql + values.join( ',' ) + post_sql, adapter)

    span = AppPerfRpm.tracer.start_span(self.class.name || 'sql.query', tags: {
      "component" => "ActiveRecordImport",
      "span.kind" => "client",
      "db.statement" => sanitized_sql,
      "db.user" => connection_config.fetch(:username, 'unknown'),
      "db.instance" => connection_config.fetch(:database),
      "db.vendor" => adapter,
      "db.type" => "sql"
    })
    AppPerfRpm::Utils.log_source_and_backtrace(span, :active_record_import)
  end

  insert_many_without_trace(sql, values, *args)
rescue Exception => e
  if span
    span.set_tag('error', true)
    span.log_error(e)
  end
  raise
ensure
  span.finish if span
end