Skip to content

Commit

Permalink
Rewrite NewRelic extension to use Module.prepend rather than the depr…
Browse files Browse the repository at this point in the history
…ecated alias_method_chain
  • Loading branch information
magni- committed Jul 18, 2019
1 parent e2334d5 commit 9a17d29
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 19 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -15,4 +15,5 @@ group :test do
gem 'rake'
gem 'rspec'
gem 'timecop'
gem 'newrelic_rpm'
end
37 changes: 18 additions & 19 deletions 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
Expand Down
26 changes: 26 additions & 0 deletions 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

0 comments on commit 9a17d29

Please sign in to comment.