Permalink
Browse files

wrap Rake::Task#invoke with newrelic instrument

  • Loading branch information...
1 parent a6d2771 commit ffaf5b0c9143fa05857658d40c3e03cb72b16c78 @flyerhzm flyerhzm committed Oct 11, 2012
Showing with 34 additions and 4 deletions.
  1. +3 −2 README.md
  2. +1 −0 lib/newrelic-rake.rb
  3. +28 −0 lib/newrelic-rake/instrument.rb
  4. +2 −2 newrelic-rake.gemspec
View
@@ -1,6 +1,6 @@
# Newrelic::Rake
-TODO: Write a gem description
+NewRelic instrument for rake task.
## Installation
@@ -18,7 +18,7 @@ Or install it yourself as:
## Usage
-TODO: Write usage instructions here
+nothing special to set.
## Contributing
@@ -27,3 +27,4 @@ TODO: Write usage instructions here
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
+
@@ -1,4 +1,5 @@
require "newrelic-rake/version"
+require "newrelic-rake/instrument"
module Newrelic
module Rake
@@ -0,0 +1,28 @@
+DependencyDetection.defer do
+ @name = :rake
+
+ depends_on do
+ defined?(::Rake) and not ::NewRelic::Control.instance['disable_rake']
+ end
+
+ executes do
+ NewRelic::Agent.logger.debug 'Installing Rake instrumentation'
+ end
+
+ executes do
+ ::Rake::Task.class_eval do
+ include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
+
+ alias_method :origin_invoke, :invoke
+ def invoke(*args)
+ NewRelic::Agent.manual_start
+ perform_action_with_newrelic_trace(:name => self.name) do
+ origin_invoke(*args)
+ end
+ ensure
+ NewRelic::Agent.shutdown
+ end
+ end
+ end
+end
+
@@ -8,8 +8,8 @@ Gem::Specification.new do |gem|
gem.version = Newrelic::Rake::VERSION
gem.authors = ["Richard Huang"]
gem.email = ["flyerhzm@gmail.com"]
- gem.description = %q{TODO: Write a gem description}
- gem.summary = %q{TODO: Write a gem summary}
+ gem.description = %q{newrelic instrument for rake task}
+ gem.summary = %q{newrelic instrument for rake task.}
gem.homepage = ""
gem.files = `git ls-files`.split($/)

0 comments on commit ffaf5b0

Please sign in to comment.