Class: Atatus::Spies::SequelSpy Private

Inherits:
Object
  • Object
show all
Defined in:
lib/atatus/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

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'
ACTION =

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.

'query'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.summarizerObject

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.



30
31
32
# File 'lib/atatus/spies/sequel.rb', line 30

def self.summarizer
  @summarizer ||= Sql.summarizer
end

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.



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
# File 'lib/atatus/spies/sequel.rb', line 34

def install
  require 'sequel/database/logging'

  if defined?(::Sequel) && defined?(::Sequel::Database)

    ::Sequel::Database.class_eval do
      alias log_connection_yield_without_apm log_connection_yield

      def log_connection_yield(sql, connection, args = nil, &block)
        unless Atatus.current_transaction
          return log_connection_yield_without_apm(
            sql, connection, args, &block
          )
        end

        subtype = database_type.to_s

        name =
          Atatus::Spies::SequelSpy.summarizer.summarize sql

        context = Atatus::Span::Context.new(
          db: { statement: sql, type: 'sql', user: opts[:user] },
          destination: { name: subtype, resource: subtype, type: TYPE }
        )

        span = Atatus.start_span(
          name,
          TYPE,
          subtype: subtype,
          action: ACTION,
          context: context
        )
        yield.tap do |result|
          if name =~ /^(UPDATE|DELETE)/
            if connection.respond_to?(:changes)
              span.context.db.rows_affected = connection.changes
            elsif result.is_a?(Integer)
              span.context.db.rows_affected = result
            end
          end
        end
      ensure
        Atatus.end_span
      end
    end

  end
end