module DatabaseHelper
get_profiler
- It will return the database driver of the Object
.
Public Instance Methods
check_prepared_stmt_by_placeholder(placeholder, statement, payload)
click to toggle source
Check the prepared statement by placeholder if its valid placeholder - contains the prepared statement pattern.
Placeholder for mysql, sqlite, jdbc oracle, db2 is ?, example "SELECT * FROM posts WHERE author = ? and id = ?" Placeholder for postgres is $1, $2,...$n, example "SELECT * FROM posts WHERE author = $1 and id = $2"
statement - contains the db properties such as SQL, PROVIDER, etc.
So if there's payload value we append PREFIX_SQL_PARAMETERS to the existing object properties.
payload - contains the payload which is the payload value/data of the placeholder.
Example payload: {:sql=>"SELECT * FROM posts WHERE author = ? and id = ?", :db_adapter=>"mysql2::client", :binds=>["J.K. Rowling", 1]}
# File lib/stackify_apm/helper/database_helper.rb, line 37 def check_prepared_stmt_by_placeholder(placeholder, statement, payload) sqlParam = [] unless payload[:binds].nil? payload[:binds].each_with_index do |record, idx| if record && defined?(record.value) StackifyRubyAPM::Util.pushToAryIndex(sqlParam, idx, record.value[0..999]) elsif ((record && record.instance_of?(Array)) && defined?(record[1])) StackifyRubyAPM::Util.pushToAryIndex(sqlParam, idx, record[1][0..999]) else StackifyRubyAPM::Util.pushToAryIndex(sqlParam, idx, record[0..999]) end end statement[:PREFIX_SQL_PARAMETERS] = sqlParam[0..99].to_json if sqlParam.count > 0 statement[:PREFIX_SQL_PARAMETER_COUNT] = sqlParam.length.to_s if sqlParam.count > 0 true else false end end
get_common_db_properties()
click to toggle source
Common DB span properties shared to sequel, activerecord, etc.
# File lib/stackify_apm/helper/database_helper.rb, line 58 def get_common_db_properties { CATEGORY: 'Database', SUBCATEGORY: 'Execute', COMPONENT_CATEGORY: 'DB Query', COMPONENT_DETAIL: 'Execute SQL Query', PROVIDER: 'generic' } end
get_profiler(driver)
click to toggle source
return back valid PROVIDER based on driver name passed in rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity
# File lib/stackify_apm/helper/database_helper.rb, line 9 def get_profiler(driver) if driver.to_s.empty? 'generic' elsif driver.include? 'mysql' 'mysql' elsif driver.include? 'postgres' 'postgresql' elsif driver.include? 'oci8' 'oracle' elsif driver.include? 'db2' 'db2' elsif driver.include? 'sqlite' 'sqlite' else 'generic' end end