Class: StackifyRubyAPM::Spies::PostgresqlAdapterSpy Private

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



12
13
14
15
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/stackify_apm/spies/sinatra_activerecord/postgresql_adapter.rb', line 12

def install
  ActiveRecord::ConnectionAdapters::PostgreSQL::DatabaseStatements.class_eval do
    alias_method 'exec_query_without_apm', 'exec_query'
    alias_method 'exec_delete_without_apm', 'exec_delete'
    alias_method 'exec_update_without_apm', 'exec_update'

    def exec_update(sql, name = nil, binds = [])
      result = nil

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

      ctx = Span::Context.new(
        CATEGORY: 'Database',
        SUBCATEGORY: 'Execute',
        COMPONENT_CATEGORY: 'DB Query',
        COMPONENT_DETAIL: 'Execute SQL Query',
        SQL: sql,
        PROVIDER: 'postgresql'
      )

      result = exec_update_without_apm(sql, name, binds)

      StackifyRubyAPM.span name, TYPE, context: ctx do
        return result
      end
    end

    def exec_delete(sql, name = nil, binds = [])
      result = nil

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

      ctx = Span::Context.new(
        CATEGORY: 'Database',
        SUBCATEGORY: 'Execute',
        COMPONENT_CATEGORY: 'DB Query',
        COMPONENT_DETAIL: 'Execute SQL Query',
        SQL: sql,
        PROVIDER: 'postgresql'
      )

      result = exec_delete_without_apm(sql, name, binds)

      StackifyRubyAPM.span name, TYPE, context: ctx do
        return result
      end
    end

    # 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

      ctx = Span::Context.new(
        CATEGORY: 'Database',
        SUBCATEGORY: 'Execute',
        COMPONENT_CATEGORY: 'DB Query',
        COMPONENT_DETAIL: 'Execute SQL Query',
        SQL: sql,
        PROVIDER: 'postgresql'
      )

      result = exec_query_without_apm(sql, name, binds)

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