class ActiveRecord::OpenTracing::Processor

Constants

COMPONENT_NAME
DB_TYPE
DEFAULT_OPERATION_NAME
SPAN_KIND

Public Class Methods

new(tracer) click to toggle source
# File lib/active_record/opentracing/processor.rb, line 11
def initialize(tracer)
  @tracer = tracer
end

Public Instance Methods

call(_event_name, start, finish, _id, payload) click to toggle source
# File lib/active_record/opentracing/processor.rb, line 15
def call(_event_name, start, finish, _id, payload)
  span = @tracer.start_span(
    payload[:name] || DEFAULT_OPERATION_NAME,
    start_time: start,
    tags: {
      'component' => COMPONENT_NAME,
      'span.kind' => SPAN_KIND,
      'db.instance' => db_instance,
      'db.cached' => payload.fetch(:cached, false),
      'db.statement' => payload.fetch(:sql).squish,
      'db.type' => DB_TYPE,
      'peer.address' => db_address
    }
  )

  if (exception = payload[:exception_object])
    span.set_tag('error', true)
    span.log_kv(
      event: 'error',
      'error.kind': exception.class.to_s,
      'error.object': exception,
      message: exception.message,
      stack: exception.backtrace.join("\n")
    )
  end

  span.finish(end_time: finish)
end

Private Instance Methods

db_address() click to toggle source
# File lib/active_record/opentracing/processor.rb, line 50
def db_address
  @db_address ||= begin
    connection_config = db_config
    username = connection_config[:username]
    host = connection_config[:host]
    database = connection_config.fetch(:database)
    vendor = connection_config.fetch(:adapter)

    str = String.new('')
    str << "#{vendor}://"
    str << username if username
    str << "@#{host}" if host
    str << "/#{database}"
    str
  end
end
db_config() click to toggle source
# File lib/active_record/opentracing/processor.rb, line 67
def db_config
  @db_config ||= ActiveRecord::Base.connection_db_config.configuration_hash
end
db_instance() click to toggle source
# File lib/active_record/opentracing/processor.rb, line 46
def db_instance
  @db_instance ||= db_config.fetch(:database)
end