Class: StackifyRubyAPM::Spies::SequelSpy Private
- Inherits:
-
Object
- Object
- StackifyRubyAPM::Spies::SequelSpy
- Defined in:
- lib/stackify_apm/spies/sequel.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- DEFAULT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'SQL'.freeze
- TYPE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'db.sequel.sql'.freeze
- TABLE_REGEX =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%{["'`]?([A-Za-z0-9]+)}.freeze
- REGEXES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ /^BEGIN/i => 'BEGIN', /^COMMIT/i => 'COMMIT', /^SELECT .* FROM #{TABLE_REGEX}/i => 'SELECT FROM ', /^INSERT INTO #{TABLE_REGEX}/i => 'INSERT INTO ', /^UPDATE #{TABLE_REGEX}/i => 'UPDATE ', /^DELETE FROM #{TABLE_REGEX}/i => 'DELETE FROM ' }.freeze
- FORMAT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'%s%s'.freeze
Instance Method Summary collapse
- #install ⇒ Object private
Instance Method Details
#install ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/stackify_apm/spies/sequel.rb', line 24 def install require 'sequel/database/logging' ::Sequel::Database.class_eval do alias_method 'log_connection_yield_without_apm', 'log_connection_yield' def log_connection_yield(sql, *args, &block) return log_connection_yield_without_apm(sql, *args, &block) unless StackifyRubyAPM.current_transaction name = summarize sql db_adapter = '' db_adapter = args[0].class.to_s.gsub('::Database', '').downcase if args[0] context = Span::Context.new( CATEGORY: 'Database', SUBCATEGORY: 'Execute', COMPONENT_CATEGORY: 'DB Query', COMPONENT_DETAIL: 'Execute SQL Query', SQL: sql, PROVIDER: get_profiler(db_adapter) ) StackifyRubyAPM.span(name, TYPE, context: context, &block) end # rubocop:disable Lint/UselessAssignment def summarize(sql) current_sql ||= REGEXES.find do |regex, sig| if (match = sql.match(regex)) break format(FORMAT, sig, match[1] && match[1].gsub(/["']/, '')) end end || DEFAULT end require 'stackify_apm/helper/database_helper' end # rubocop:enable Lint/UselessAssignment end |