Permalink
Browse files

add class variable in NewRelic::Rake to promise starting newrelic age…

…nt only once
  • Loading branch information...
1 parent 4b0db43 commit d54fffbfa4d90f52a5b08365733c553517634c4e @flyerhzm flyerhzm committed Mar 23, 2013
Showing with 14 additions and 11 deletions.
  1. +10 −2 lib/newrelic-rake.rb
  2. +4 −9 lib/newrelic-rake/instrument.rb
View
@@ -1,8 +1,16 @@
require "newrelic-rake/version"
require "newrelic-rake/instrument"
-module Newrelic
+module NewRelic
module Rake
- # Your code goes here...
+ class <<self
+ def started=(started)
+ @started = started
+ end
+
+ def started?
+ !!@started
+ end
+ end
end
end
@@ -15,17 +15,12 @@
::Rake::Task.class_eval do
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
- alias_method :origin_invoke_with_call_chain, :invoke_with_call_chain
- def invoke_with_call_chain(task_args, invocation_chain)
- # empty invocation chain invoke first and only once
- if invocation_chain.is_a? Rake::InvocationChain::EmptyInvocationChain
- NewRelic::Agent.manual_start(:dispatcher => :rake)
- end
- origin_invoke_with_call_chain(task_args, invocation_chain)
- end
-
alias_method :origin_execute, :execute
def execute(args=nil)
+ unless NewRelic::Rake.started?
+ NewRelic::Agent.manual_start(:dispatcher => :rake)
+ NewRelic::Rake.started = true
+ end
perform_action_with_newrelic_trace(:name => self.name, :category => "OtherTransaction/Rake") do
origin_execute(args)
end

0 comments on commit d54fffb

Please sign in to comment.