Sha256: 65c99ac47a3a7ab87f7ddd78b495c9b6d17d703b3b89fb06722a42d0917fa2de

Contents?: true

Size: 1.44 KB

Versions: 12

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module PlainApm
  module Hooks
    class ActionView < ActiveSupportSubscriber
      NOTIFICATION_PATTERN = /\A[^!]\w+\.action_view\Z/.freeze

      private

      def notification_pattern
        NOTIFICATION_PATTERN
      end

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

        case name
        when "render_collection"
          base.merge({
            "identifier" => identifier(payload[:identifier]),
            "layout" => payload[:layout],
            "count" => payload[:count],
            "cache_hits" => payload[:cache_hits]
          })
        when "render_layout"
          base.merge({
            "identifier" => identifier(payload[:identifier])
          })
        when "render_template"
          base.merge({
            "identifier" => identifier(payload[:identifier]),
            "layout" => payload[:layout]
          })
        when "render_partial"
          base.merge({
            "identifier" => identifier(payload[:identifier]),
            "layout" => payload[:layout],
            "cache_hit" => payload[:cache_hit]
          })
        end
      end

      # strip rails root
      def identifier(id)
        return id unless defined?(Rails) && Rails.respond_to?(:root)

        root = Rails.root.to_s

        id.start_with?(root) ? id[root.size + 1..-1] : id # standard:disable Style/SlicingWithRange
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
plain_apm-0.9.2 lib/plain_apm/hooks/action_view.rb
plain_apm-0.9.1 lib/plain_apm/hooks/action_view.rb
plain_apm-0.9.0 lib/plain_apm/hooks/action_view.rb
plain_apm-0.8.8 lib/plain_apm/hooks/action_view.rb
plain_apm-0.8.7 lib/plain_apm/hooks/action_view.rb
plain_apm-0.8.6 lib/plain_apm/hooks/action_view.rb
plain_apm-0.8.5 lib/plain_apm/hooks/action_view.rb
plain_apm-0.8.4 lib/plain_apm/hooks/action_view.rb
plain_apm-0.8.3 lib/plain_apm/hooks/action_view.rb
plain_apm-0.8.2 lib/plain_apm/hooks/action_view.rb
plain_apm-0.8.1 lib/plain_apm/hooks/action_view.rb
plain_apm-0.8.0 lib/plain_apm/hooks/action_view.rb