diff --git a/Gemfile b/Gemfile index a96d353..31730e3 100644 --- a/Gemfile +++ b/Gemfile @@ -15,4 +15,5 @@ group :test do gem 'rake' gem 'rspec' gem 'timecop' + gem 'newrelic_rpm' end diff --git a/lib/queue_classic_plus/new_relic.rb b/lib/queue_classic_plus/new_relic.rb index 2bd6c45..905d924 100644 --- a/lib/queue_classic_plus/new_relic.rb +++ b/lib/queue_classic_plus/new_relic.rb @@ -1,30 +1,29 @@ require 'new_relic/agent/method_tracer' -QueueClassicPlus::Base.class_eval do - class << self - include NewRelic::Agent::Instrumentation::ControllerInstrumentation +module QueueClassicNewRelic + include NewRelic::Agent::Instrumentation::ControllerInstrumentation - def new_relic_key - "Custom/QueueClassicPlus/#{librato_key}" - end + def new_relic_key + "Custom/QueueClassicPlus/#{librato_key}" + end - def _perform_with_new_relic(*args) - opts = { - name: 'perform', - class_name: self.name, - category: 'OtherTransaction/QueueClassicPlus', - } + def _perform(*args) + opts = { + name: 'perform', + class_name: self.name, + category: 'OtherTransaction/QueueClassicPlus', + } - perform_action_with_newrelic_trace(opts) do - if NewRelic::Agent.config[:'queue_classic_plus.capture_params'] - NewRelic::Agent.add_custom_parameters(job_arguments: args) - end - _perform_without_new_relic *args + perform_action_with_newrelic_trace(opts) do + if NewRelic::Agent.config[:'queue_classic_plus.capture_params'] + NewRelic::Agent.add_custom_parameters(job_arguments: args) end - end - alias_method_chain :_perform, :new_relic + super + end end + + QueueClassicPlus::Base.singleton_class.send(:prepend, QueueClassicNewRelic) end QueueClassicPlus::CustomWorker.class_eval do diff --git a/spec/new_relic_spec.rb b/spec/new_relic_spec.rb new file mode 100644 index 0000000..6dfa87c --- /dev/null +++ b/spec/new_relic_spec.rb @@ -0,0 +1,26 @@ +describe 'requiring queue_classic_plus/new_relic' do + subject do + Class.new(QueueClassicPlus::Base) do + @queue = :test + + def self.perform + end + + def self.name + 'Funky::Name' + end + end + end + + it 'adds NewRelic profiling support' do + expect(subject).to receive(:perform_action_with_newrelic_trace).once.with({ + name: 'perform', + class_name: 'Funky::Name', + category: 'OtherTransaction/QueueClassicPlus', + }) + + subject._perform + require 'queue_classic_plus/new_relic' + subject._perform + end +end