Module: AppPerfRpm::Utils

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.log_source_and_backtrace(span, instrument) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/app_perf_rpm/utils.rb', line 29

def self.log_source_and_backtrace(span, instrument)
  config = ::AppPerfRpm.config.instrumentation[instrument] || {}
  if kind = config[:backtrace]
    backtrace = AppPerfRpm::Backtrace.backtrace(kind: kind)
    if backtrace.length > 0
      span.log(event: "backtrace", stack: backtrace)
    end
  end
  if config[:source]
    source = AppPerfRpm::Backtrace.source_extract
    if source.length > 0
      span.log(event: "source", stack: source)
    end
  end
end

Instance Method Details

#connection_configObject



11
12
13
14
15
16
17
# File 'lib/app_perf_rpm/utils.rb', line 11

def connection_config
  @connection_config ||= if ::ActiveRecord::VERSION::MAJOR == 2 || (::ActiveRecord::VERSION::MAJOR == 3 && ::ActiveRecord::VERSION::MINOR < 1)
                           ActiveRecord::Base.connection.instance_variable_get(:@config)
                         else
                           ::ActiveRecord::Base.connection_config
                         end
end

#format_redis(command) ⇒ Object



19
20
21
22
23
# File 'lib/app_perf_rpm/utils.rb', line 19

def format_redis(command)
  command.is_a?(Symbol) ? command.to_s.upcase : command.to_s
rescue StandardError => e
  "?"
end

#format_redis_command(command) ⇒ Object



25
26
27
# File 'lib/app_perf_rpm/utils.rb', line 25

def format_redis_command(command)
  command.map { |x| format_redis(x) }.join(' ')
end

#sanitize_sql(sql, adapter) ⇒ Object



7
8
9
# File 'lib/app_perf_rpm/utils.rb', line 7

def sanitize_sql(sql, adapter)
  sql.gsub(REGEXP, '?')
end