Module: XRay::Rails::ActiveRecord

Defined in:
lib/aws-xray-sdk/facets/rails/active_record.rb

Overview

Recording Rails database transactions as subsegments.

Constant Summary collapse

IGNORE_OPS =
['SCHEMA', 'ActiveRecord::SchemaMigration Load',
'ActiveRecord::InternalMetadata Load'].freeze
DB_TYPE_MAPPING =
{
  mysql2: 'MySQL',
  postgresql: 'PostgreSQL'
}.freeze

Class Method Summary collapse

Class Method Details

.record(transaction) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/aws-xray-sdk/facets/rails/active_record.rb', line 15

def record(transaction)
  payload = transaction.payload
  pool, conn = get_pool_n_conn(payload[:connection_id])

  return if IGNORE_OPS.include?(payload[:name]) || pool.nil? || conn.nil?
  db_config = pool.spec.config
  name, sql = build_name_sql_meta config: db_config, conn: conn
  subsegment = XRay.recorder.begin_subsegment name, namespace: 'remote'
  subsegment.start_time = transaction.time.to_f
  subsegment.sql = sql
  XRay.recorder.end_subsegment end_time: transaction.end.to_f
end