BigW Consortium Gitlab

active_record.rb 537 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10
module Gitlab
  module Metrics
    module Subscribers
      # Class for tracking the total query duration of a transaction.
      class ActiveRecord < ActiveSupport::Subscriber
        attach_to :active_record

        def sql(event)
          return unless current_transaction

11
          current_transaction.increment(:sql_duration, event.duration)
12
          current_transaction.increment(:sql_count, 1)
13 14 15 16 17 18 19 20 21 22 23
        end

        private

        def current_transaction
          Transaction.current
        end
      end
    end
  end
end