Sha256: 427979df893d1d0efad2a6f6d2982a183b12956797353c3e28d0c74229af8f42

Contents?: true

Size: 1.71 KB

Versions: 14

Compression:

Stored size: 1.71 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, source = *event.name.split(".")
        payload = event.payload

        base = {
          "source" => source,
          "name" => name,
          "backtrace" => filtered_backtrace,
          "started_at" => event.time,
          "finished_at" => event.end,
          "allocations" => event.allocations,
          "thread_allocations" => event.thread_allocations
        }

        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.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

14 entries across 14 versions & 1 rubygems

Version Path
plain_apm-0.6.6 lib/plain_apm/hooks/action_view.rb
plain_apm-0.6.5 lib/plain_apm/hooks/action_view.rb
plain_apm-0.6.4 lib/plain_apm/hooks/action_view.rb
plain_apm-0.6.3 lib/plain_apm/hooks/action_view.rb
plain_apm-0.6.2 lib/plain_apm/hooks/action_view.rb
plain_apm-0.6.1 lib/plain_apm/hooks/action_view.rb
plain_apm-0.5.7 lib/plain_apm/hooks/action_view.rb
plain_apm-0.5.6 lib/plain_apm/hooks/action_view.rb
plain_apm-0.5.5 lib/plain_apm/hooks/action_view.rb
plain_apm-0.5.4 lib/plain_apm/hooks/action_view.rb
plain_apm-0.5.3 lib/plain_apm/hooks/action_view.rb
plain_apm-0.5.2 lib/plain_apm/hooks/action_view.rb
plain_apm-0.5.1 lib/plain_apm/hooks/action_view.rb
plain_apm-0.5.0 lib/plain_apm/hooks/action_view.rb