Module: Instana::Instrumentation::AbstractMysqlAdapter
- Defined in:
- lib/instana/frameworks/instrumentation/abstract_mysql_adapter.rb
Constant Summary collapse
- IGNORED_PAYLOADS =
%w(SCHEMA EXPLAIN CACHE).freeze
- EXPLAINED_SQLS =
/\A\s*(with|select|update|delete|insert)\b/i
Class Method Summary collapse
-
.included(klass) ⇒ Object
This module supports instrumenting ActiveRecord with the mysql2 adapter.
Instance Method Summary collapse
-
#collect(sql) ⇒ Hash
Collect up this DB connection info for reporting.
- #execute_with_instana(sql, name = nil) ⇒ Object
-
#ignore_payload?(name, sql) ⇒ Boolean
In the spirit of ::ActiveRecord::ExplainSubscriber.ignore_payload? There are only certain calls that we’re interested in tracing.
Class Method Details
.included(klass) ⇒ Object
This module supports instrumenting ActiveRecord with the mysql2 adapter.
9 10 11 12 13 14 15 |
# File 'lib/instana/frameworks/instrumentation/abstract_mysql_adapter.rb', line 9 def self.included(klass) if ActiveRecord::VERSION::STRING >= '3.2' Instana::Util.method_alias(klass, :execute) @@sanitize_regexp = Regexp.new('(\'[\s\S][^\']*\'|\d*\.\d+|\d+|NULL)', Regexp::IGNORECASE) end end |
Instance Method Details
#collect(sql) ⇒ Hash
Collect up this DB connection info for reporting.
22 23 24 25 26 27 28 29 30 |
# File 'lib/instana/frameworks/instrumentation/abstract_mysql_adapter.rb', line 22 def collect(sql) payload = { :activerecord => {} } payload[:activerecord][:sql] = sql.gsub(@@sanitize_regexp, '?') payload[:activerecord][:adapter] = @config[:adapter] payload[:activerecord][:host] = @config[:host] payload[:activerecord][:db] = @config[:database] payload[:activerecord][:username] = @config[:username] payload end |
#execute_with_instana(sql, name = nil) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/instana/frameworks/instrumentation/abstract_mysql_adapter.rb', line 43 def execute_with_instana(sql, name = nil) tracing = ::Instana.tracer.tracing? if !tracing || ignore_payload?(name, sql) return execute_without_instana(sql, name) elsif ::Instana.tracer.current_span[:n] == :activerecord return execute_without_instana(sql, name) end kv_payload = collect(sql) ::Instana.tracer.trace(:activerecord, kv_payload) do execute_without_instana(sql, name) end end |
#ignore_payload?(name, sql) ⇒ Boolean
In the spirit of ::ActiveRecord::ExplainSubscriber.ignore_payload? There are only certain calls that we’re interested in tracing. e.g. No use to instrument framework caches.
39 40 41 |
# File 'lib/instana/frameworks/instrumentation/abstract_mysql_adapter.rb', line 39 def ignore_payload?(name, sql) IGNORED_PAYLOADS.include?(name) || sql !~ EXPLAINED_SQLS end |