Sha256: 4d4ee507f56d76062ed6590539dea305328a04a0a4a8da1ea631d6157d300c1b

Contents?: true

Size: 1.07 KB

Versions: 14

Compression:

Stored size: 1.07 KB

Contents

require "active_support/notifications"
require "active_record/log_subscriber"

module Sapience
  module Extensions
    module ActiveRecord
      class LogSubscriber < ::ActiveRecord::LogSubscriber
        include Sapience::Loggable

        def identity(event)
          event = normalize(event)
          debug(event) if logger && event
        end
        alias_method :sql, :identity

        private

        def normalize(event)
          data = event.payload

          return if "SCHEMA" == data[:name]

          data.merge! runtimes(event)
          data.merge! extract_sql(data)

          data.merge! tags(data)
        end

        def runtimes(event)
          if event.duration
            { duration: event.duration.to_f.round(2) }
          else
            {}
          end
        end

        def extract_sql(data)
          { sql: data[:sql].squeeze(" ") }
        end

        def tags(data)
          tags = Sapience.tags.dup
          tags.push("request")
          tags.push("exception") if data[:exception]
          { tags: tags }
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
sapience-2.4.0 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-2.3.5 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-2.3.4 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-2.3.3 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-2.2.3 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-2.2.1 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-2.2.0 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-2.1.0 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-2.0.5 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-2.0.4 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-2.0.3 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-2.0.2 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-2.0.1 lib/sapience/extensions/active_record/log_subscriber.rb
sapience-2.0.0 lib/sapience/extensions/active_record/log_subscriber.rb