Class: StackifyRubyAPM::Spies::SqliteAdapterSpy Private

Inherits:
Object
  • Object
show all
Defined in:
lib/stackify_apm/spies/sinatra_activerecord/sqlite_adapter.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

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.sinatra_active_record.sql'.freeze

Instance Method Summary collapse

Instance Method Details

#installObject

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.



16
17
18
19
20
21
22
23
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
# File 'lib/stackify_apm/spies/sinatra_activerecord/sqlite_adapter.rb', line 16

def install
  ActiveRecord::ConnectionAdapters::SQLite3Adapter.class_eval do
    alias_method 'exec_query_without_apm', 'exec_query'

    # rubocop:disable Lint/UnusedMethodArgument
    def exec_query(sql, name = 'SQL', binds = [], prepare: false)
      result = nil

      unless StackifyRubyAPM.current_transaction
        exec_query_without_apm(sql, name, binds)
      end

      payload = {sql: sql, binds: binds}
      statement = query_variables(payload)
      check_prepared_stmt(statement, payload)

      ctx = Span::Context.new(statement)
      result = exec_query_without_apm(sql, name, binds)

      StackifyRubyAPM.span name, TYPE, context: ctx do
        return result
      end
    end
    # rubocop:enable Lint/UnusedMethodArgument

    def query_variables(payload)
      props = get_common_db_properties
      props[:SQL] = payload[:sql]
      props
    end

    def check_prepared_stmt(statement, payload)
      if StackifyRubyAPM.agent.config.prefix_enabled
        check_prepared_stmt_by_placeholder(payload[:sql].include?('?'), statement, payload)
      end
    end
  end
end