Module: ILove::Tracing::Sql

Defined in:
lib/ilove/tracing/sql.rb

Class Method Summary collapse

Class Method Details

.setup(_cfg) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ilove/tracing/sql.rb', line 4

def self.setup(_cfg)
  raise 'Cannot trace sql without ActiveSupport' unless defined?(::ActiveSupport)

  ActiveSupport::Notifications.subscribe('sql.active_record') do |_name, start, finish, _id, payload|
    span = OpenTracing.start_span 'sql.active_record',
                                  start_time: start,
                                  child_of: OpenTracing.active_span,
                                  tags: {
                                    'sql.statement' => payload[:sql],
                                    'sql.statement_name' => payload[:statement_name],
                                    'sql.name' => payload[:name]
                                  }

    span.finish end_time: finish
  end
end