Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resque activejob #1233

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions lib/elastic_apm/spies/resque.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
32 changes: 32 additions & 0 deletions spec/elastic_apm/spies/resque_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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