Sha256: 3f2cd5da29900b223b8d6d44dfb77348ea07014c42f90fd1e7763c270d00d85c

Contents?: true

Size: 1.26 KB

Versions: 18

Compression:

Stored size: 1.26 KB

Contents

require 'active_support/notifications'

# TODO This needs to be fixed upstream in active_support/notifications/instrumenter.rb
#
# We need to monkeypatch this for now, because the original implementation hardcodes the
# duration to the time elapsed between start and end of the event. The current upstream
# implementation is included here for reference:
#
#   def duration
#     @duration ||= 1000.0 * (@end - @time)
#   end
#
# It should be safe to assume that explicitly provided duration information should be at
# least as precise as the current generic solution, if not more (as in our specific case).
#
module ActiveSupport
  module Notifications
    class Event
      def duration
        payload[:duration] ? (payload[:duration] / 1000.0) : 1000.0 * (self.end - self.time)
      end
    end
  end
end

module LogListener
  def log(message)
    ActiveSupport::Notifications.instrument('sql.data_mapper',
      :name          => 'SQL',
      :sql           => message.query, # TODO think about changing the key to :query
      :start         => message.start,
      :duration      => message.duration,
      :connection_id => self.object_id
    )
    super
  rescue Exception => e
    ::DataMapper.logger.error "[datamapper] #{e.class.name}: #{e.message}: #{message.inspect}}"
  end
end

Version data entries

18 entries across 18 versions & 3 rubygems

Version Path
ardm-rails-1.3.1 lib/dm-rails/railties/log_listener.rb
ardm-rails-1.3.0 lib/dm-rails/railties/log_listener.rb
ardm-rails-1.2.1 lib/dm-rails/railties/log_listener.rb
tpitale-dm-rails-1.3.0 lib/dm-rails/railties/log_listener.rb
tpitale-dm-rails-1.2.2 lib/dm-rails/railties/log_listener.rb
dm-rails-1.2.1 lib/dm-rails/railties/log_listener.rb
tpitale-dm-rails-1.2.1 lib/dm-rails/railties/log_listener.rb
dm-rails-1.2.0 lib/dm-rails/railties/log_listener.rb
dm-rails-1.2.0.rc2 lib/dm-rails/railties/log_listener.rb
dm-rails-1.2.0.rc1 lib/dm-rails/railties/log_listener.rb
dm-rails-1.1.0 lib/dm-rails/railties/log_listener.rb
dm-rails-1.1.0.rc3 lib/dm-rails/railties/log_listener.rb
dm-rails-1.1.0.rc2 lib/dm-rails/railties/log_listener.rb
dm-rails-1.1.0.rc1 lib/dm-rails/railties/log_listener.rb
dm-rails-1.0.4 lib/dm-rails/railties/log_listener.rb
dm-rails-1.0.3 lib/dm-rails/railties/log_listener.rb
dm-rails-1.0.2 lib/dm-rails/railties/log_listener.rb
dm-rails-1.0.1 lib/dm-rails/railties/log_listener.rb