# 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