# frozen_string_literal: true module PlainApm module Hooks class ActiveJob < ActiveSupportSubscriber NOTIFICATION_PATTERN = /\A[^!]\w+\.active_job\Z/.freeze private def notification_pattern NOTIFICATION_PATTERN end def payload(event) name, source = *event.name.split(".") payload = event.payload job = payload[:job] base = { "source" => source, "name" => name, "backtrace" => filtered_backtrace, "started_at" => event.time, "finished_at" => event.end, "allocations" => event.allocations, "queue_name" => job.queue_name, "job_id" => job.job_id, "job_class" => job.class.name, "job_arguments" => job.arguments, "executions" => job.executions, "scheduled_at" => job.scheduled_at, "adapter" => payload[:adapter].class.name, "aborted" => payload[:aborted] } case name when "enqueue", "enqueue_at", "perform" base when "enqueue_retry" base.merge({ "error" => payload[:error], "wait" => payload[:wait] }) when "retry_stopped", "discard" base.merge({ "error" => payload[:error] }) when "perform_start" nil end end end end end