This repository has been archived by the owner on Apr 1, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update resque instrumentation to use a plugin for most of the work
- Loading branch information
1 parent
f75ee3b
commit 8990ce6
Showing
2 changed files
with
27 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,32 @@ | ||
|
||
module RPMContrib | ||
SUPPORTS_FORK = | ||
begin | ||
# jruby has a Kernel.fork method, but it raises NotImplementedError by default | ||
if Kernel.respond_to?(:fork) | ||
Kernel.fork { exit! } | ||
true | ||
else | ||
false | ||
module Resque | ||
module Plugins | ||
module NewRelicInstrumentation | ||
include NewRelic::Agent::Instrumentation::ControllerInstrumentation | ||
|
||
def around_perform_with_monitoring(*args) | ||
perform_action_with_newrelic_trace(:name => 'perform', :class_name => class_name, :category => 'OtherTransaction/ResqueJob') do | ||
yield(*args) | ||
end | ||
end | ||
rescue NotImplementedError | ||
false | ||
end | ||
end | ||
end | ||
|
||
module RPMContrib | ||
module Instrumentation | ||
# == Resque Instrumentation | ||
# | ||
# Installs a hook to ensure the agent starts manually when the worker | ||
# starts and also adds the tracer to the process method which executes | ||
# in the forked task. | ||
module Resque | ||
def self.flush_metric_data | ||
return if !NewRelic::Agent.agent.started? || NewRelic::Agent.agent.instance_variable_get(:@worker_loop).nil? | ||
NewRelic::Agent.agent.instance_variable_get(:@worker_loop).run_task | ||
::Resque.before_first_fork do | ||
NewRelic::Agent.manual_start(:dispatcher => :resque) | ||
end | ||
|
||
::Resque::Job.class_eval do | ||
include NewRelic::Agent::Instrumentation::ControllerInstrumentation | ||
|
||
old_perform_method = instance_method(:perform) | ||
|
||
define_method(:perform) do | ||
class_name = (payload_class ||self.class).name | ||
NewRelic::Agent.reset_stats if NewRelic::Agent.respond_to? :reset_stats | ||
perform_action_with_newrelic_trace(:name => 'perform', :class_name => class_name, | ||
:category => 'OtherTransaction/ResqueJob') do | ||
old_perform_method.bind(self).call | ||
end | ||
|
||
if ::RPMContrib::SUPPORTS_FORK | ||
NewRelic::Agent.shutdown unless defined?(::Resque.before_child_exit) | ||
else | ||
::RPMContrib::Instrumentation::ResqueInstrumentation.flush_metric_data unless defined?(::Resque.before_child_exit) | ||
end | ||
|
||
end | ||
::Resque.after_fork do | ||
NewRelic::Agent.after_fork(:force_reconnect => false) | ||
end | ||
|
||
if defined?(::Resque.before_child_exit) | ||
::Resque.before_child_exit do |worker| | ||
if ::RPMContrib::SUPPORTS_FORK | ||
NewRelic::Agent.shutdown | ||
else | ||
::RPMContrib::Instrumentation::ResqueInstrumentation.flush_metric_data | ||
end | ||
end | ||
::Resque::Job.class_eval do | ||
include Resque::Plugins::NewRelicInstrumentation | ||
end | ||
end | ||
end | ||
end if defined?(::Resque::Job) and not NewRelic::Control.instance['disable_resque'] | ||
end if defined?(::Resque) and not NewRelic::Control.instance['disable_resque'] | ||
|