lib/one_apm/agent/database.rb in oneapm_rpm-1.3.6 vs lib/one_apm/agent/database.rb in oneapm_rpm-1.3.7.rc1
- old
+ new
@@ -4,11 +4,11 @@
require 'one_apm/agent/database/obfuscation_helpers'
require 'one_apm/agent/database/obfuscator'
require 'one_apm/agent/database/postgres_explain_obfuscator'
module OneApm
- MYSQL_EXPLAIN_COLUMNS = [
+ OA_MYSQL_EXPLAIN_COLUMNS = [
"Id",
"Select Type",
"Table",
"Type",
"Possible Keys",
@@ -19,21 +19,21 @@
"Extra"
].freeze
module Agent
module Database
- MAX_QUERY_LENGTH = 16384
+ OA_MAX_QUERY_LENGTH = 16384
extend self
def capture_query(query)
Helper.correctly_encoded(truncate_query(query))
end
def truncate_query(query)
- if query.length > (MAX_QUERY_LENGTH - 4)
- query[0..MAX_QUERY_LENGTH - 4] + '...'
+ if query.length > (OA_MAX_QUERY_LENGTH - 4)
+ query[0..OA_MAX_QUERY_LENGTH - 4] + '...'
else
query
end
end
@@ -58,14 +58,14 @@
else
:obfuscated
end
end
- RECORD_FOR = [:raw, :obfuscated].freeze
+ OA_RECORD_FOR = [:raw, :obfuscated].freeze
def should_record_sql?(config_section=:transaction_tracer)
- RECORD_FOR.include?(record_sql_method(config_section))
+ OA_RECORD_FOR.include?(record_sql_method(config_section))
end
def should_collect_explain_plans?(config_section=:transaction_tracer)
should_record_sql?(config_section) &&
OneApm::Manager.config["#{config_section}.explain_enabled".to_sym]
@@ -92,11 +92,11 @@
statement = sql.split(";\n")[0] # only explain the first
explain_plan = explain_statement(statement, connection_config, &explainer)
return explain_plan || []
end
- SUPPORTED_ADAPTERS_FOR_EXPLAIN = %w[postgres postgresql mysql2 mysql sqlite].freeze
+ OA_SUPPORTED_ADAPTERS_FOR_EXPLAIN = %w[postgres postgresql mysql2 mysql sqlite].freeze
def explain_statement(statement, config, &explainer)
return unless is_select?(statement)
if statement[-3,3] == '...'
@@ -108,11 +108,11 @@
OneApm::Manager.logger.debug('Unable to collect explain plan for parameterized query.')
return
end
adapter = adapter_from_config(config)
- if !SUPPORTED_ADAPTERS_FOR_EXPLAIN.include?(adapter)
+ if !OA_SUPPORTED_ADAPTERS_FOR_EXPLAIN.include?(adapter)
OneApm::Manager.logger.debug("Not collecting explain plan because an unknown connection adapter ('#{adapter}') was used.")
return
end
handle_exception_in_explain do
@@ -134,27 +134,27 @@
when 'sqlite'
process_explain_results_sqlite(results)
end
end
- QUERY_PLAN = 'QUERY PLAN'.freeze
+ OA_QUERY_PLAN = 'QUERY PLAN'.freeze
def process_explain_results_postgres(results)
if results.is_a?(String)
query_plan_string = results
else
lines = []
- results.each { |row| lines << row[QUERY_PLAN] }
+ results.each { |row| lines << row[OA_QUERY_PLAN] }
query_plan_string = lines.join("\n")
end
unless record_sql_method == :raw
query_plan_string = OneApm::Agent::Database::PostgresExplainObfuscator.obfuscate(query_plan_string)
end
values = query_plan_string.split("\n").map { |line| [line] }
- [[QUERY_PLAN], values]
+ [[OA_QUERY_PLAN], values]
end
def string_explain_plan_results(results)
[nil, [results]]
end
@@ -183,15 +183,15 @@
values = []
results.each { |row| values << row }
[headers, values]
end
- SQLITE_EXPLAIN_COLUMNS = %w[addr opcode p1 p2 p3 p4 p5 comment]
+ OA_SQLITE_EXPLAIN_COLUMNS = %w[addr opcode p1 p2 p3 p4 p5 comment]
def process_explain_results_sqlite(results)
return string_explain_plan_results(results) if results.is_a?(String)
- headers = SQLITE_EXPLAIN_COLUMNS
+ headers = OA_SQLITE_EXPLAIN_COLUMNS
values = []
results.each do |row|
values << headers.map { |h| row[h] }
end
[headers, values]
@@ -208,11 +208,11 @@
# double exception. throw up your hands
nil
end
end
- KNOWN_OPERATIONS = [
+ OA_KNOWN_OPERATIONS = [
'alter',
'select',
'update',
'delete',
'insert',
@@ -222,16 +222,16 @@
'exec',
'execute',
'call'
]
- SQL_COMMENT_REGEX = Regexp.new('/\*.*?\*/', Regexp::MULTILINE).freeze
+ OA_SQL_COMMENT_REGEX = Regexp.new('/\*.*?\*/', Regexp::MULTILINE).freeze
def parse_operation_from_query(sql)
- sql = sql.gsub(SQL_COMMENT_REGEX, '')
+ sql = sql.gsub(OA_SQL_COMMENT_REGEX, '')
if sql =~ /(\w+)/
op = $1.downcase
- return op if KNOWN_OPERATIONS.include?(op)
+ return op if OA_KNOWN_OPERATIONS.include?(op)
end
end
def is_select?(statement)
parse_operation_from_query(statement) == 'select'