From 7608aa08b539c16f17d013f5db14e9a87420f470 Mon Sep 17 00:00:00 2001 From: Alex Yakubenko Date: Thu, 10 Feb 2022 18:24:43 +0300 Subject: [PATCH 1/3] Recognize Resque jobs wrapped in ActiveJob --- lib/elastic_apm/spies/resque.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/elastic_apm/spies/resque.rb b/lib/elastic_apm/spies/resque.rb index 8f3dd392a..36aca677b 100644 --- a/lib/elastic_apm/spies/resque.rb +++ b/lib/elastic_apm/spies/resque.rb @@ -28,6 +28,7 @@ class ResqueSpy module Ext def perform name = @payload && @payload['class']&.to_s + name = @payload['args'].first['job_class'] if name == 'ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper' transaction = ElasticAPM.start_transaction(name, TYPE) super transaction&.done 'success' From 67d90058677b7da93d690aeb9fb29c710486eae6 Mon Sep 17 00:00:00 2001 From: Alex Yakubenko Date: Thu, 10 Feb 2022 18:40:06 +0300 Subject: [PATCH 2/3] Add Test --- spec/elastic_apm/spies/resque_spec.rb | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/spec/elastic_apm/spies/resque_spec.rb b/spec/elastic_apm/spies/resque_spec.rb index 6214e02fa..8bf7c09b2 100644 --- a/spec/elastic_apm/spies/resque_spec.rb +++ b/spec/elastic_apm/spies/resque_spec.rb @@ -20,6 +20,11 @@ require 'spec_helper' require 'resque' +begin + require 'active_job' +rescue LoadError +end + module ElasticAPM RSpec.describe 'Spy: Resque', :intercept do class TestJob @@ -75,5 +80,32 @@ def self.perform expect(error.exception.type).to eq 'ZeroDivisionError' end end + + context 'ActiveJob', if: defined?(ActiveJob) do + before :all do + class ::ActiveJobbyJob < ActiveJob::Base + self.queue_adapter = :resque + self.logger = nil # stay quiet + + def perform + 'ok' + end + end + end + + after :all do + Object.send(:remove_const, :ActiveJobbyJob) + end + + it 'knows the name of ActiveJob jobs', if: defined?(ActiveJob) do + with_agent do + ActiveJobbyJob.perform_later + end + + transaction, = @intercepted.transactions + expect(transaction).to_not be_nil + expect(transaction.name).to eq 'ActiveJobbyJob' + end + end end end From 9f9116fa6afbd3d9ed42aa20a69c5fb1e9f2b306 Mon Sep 17 00:00:00 2001 From: Alex Yakubenko Date: Thu, 10 Feb 2022 18:54:51 +0300 Subject: [PATCH 3/3] Update CHANGELOG.asciidoc --- CHANGELOG.asciidoc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 70f71fa57..6e4b81f5f 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -19,6 +19,10 @@ endif::[] ===== Added - Feature {pull}2526[#2526] +[float] +===== Fixed +- Fix Resque class names when used through ActiveJob {pull}1233[#1233] + [float] ===== Changed - Change {pull}2526[#2526]