Class: HoneycombRails::Subscribers::ActiveRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/honeycomb-rails/subscribers/active_record.rb

Instance Method Summary collapse

Constructor Details

#initialize(honeybuilder) ⇒ ActiveRecord

Returns a new instance of ActiveRecord.



8
9
10
# File 'lib/honeycomb-rails/subscribers/active_record.rb', line 8

def initialize(honeybuilder)
  @honeybuilder = honeybuilder
end

Instance Method Details

#call(*args) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/honeycomb-rails/subscribers/active_record.rb', line 18

def call(*args)
  event = ActiveSupport::Notifications::Event.new(*args)
  data = event.payload.slice(:name, :connection_id)
  data[:sql] = event.payload[:sql].strip
  event.payload[:binds].each do |b|
    case b
    when Array
      data["bind_#{ b[0].name }".to_sym] = b[1]
    else
      data["bind_#{ b.name }".to_sym] = b.value
    end
  end
  data[:duration] = event.duration

  # NOTE: Backtraces can be very verbose! Keep an eye on the data that gets sent
  #       into Honeycomb and, if needed, experiment with BacktraceCleaner's
  #       filters and silencers to trim down the noise.
  data[:local_stack] = Rails.backtrace_cleaner.clean(caller)

  @honeybuilder.send_now(data)
end

#subscribe!Object



12
13
14
15
16
# File 'lib/honeycomb-rails/subscribers/active_record.rb', line 12

def subscribe!
  ::ActiveSupport::Notifications.subscribe(/sql.active_record/) do |*args|
    call(*args)
  end
end