Sha256: 602727230153b33c99831a24fdabe719fdfac6a230fff0e8e93eaed0f7c823b5

Contents?: true

Size: 931 Bytes

Versions: 5

Compression:

Stored size: 931 Bytes

Contents

# frozen_string_literal: true

require_relative "active_support_subscriber"

module PlainApm
  module Hooks
    class ActiveRecord < ActiveSupportSubscriber
      NOTIFICATION_PATTERN = /\A[^!]\w+\.active_record\Z/.freeze
      IGNORED_SQL_NAMES = %w[SCHEMA CACHE].freeze

      private

      def notification_pattern
        NOTIFICATION_PATTERN
      end

      def payload(event)
        name, base = attributes_from_notification(event)
        payload = event.payload

        return if IGNORED_SQL_NAMES.include?(payload[:name])

        case name
        when "sql"
          base.tap do |o|
            o[:sql] = payload[:sql]
            o[:sql_name] = payload[:name]
          end
        when "instantiation"
          base.tap do |o|
            o[:class_name] = payload[:class_name]
            o[:record_count] = payload[:record_count]
          end
        else
          nil
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
plain_apm-0.9.7 lib/plain_apm/hooks/active_record.rb
plain_apm-0.9.6 lib/plain_apm/hooks/active_record.rb
plain_apm-0.9.5 lib/plain_apm/hooks/active_record.rb
plain_apm-0.9.4 lib/plain_apm/hooks/active_record.rb
plain_apm-0.9.3 lib/plain_apm/hooks/active_record.rb