Skip to content
This repository has been archived by the owner on Aug 25, 2020. It is now read-only.

Commit

Permalink
Merge pull request #2 from dblock/disabled
Browse files Browse the repository at this point in the history
Set `DISABLE_NEW_RELIC_GRAPE` at runtime to disable instrumentation.
  • Loading branch information
flyerhzm committed Dec 28, 2012
2 parents fde55c5 + bfdd8b7 commit 4bf928a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Next Release
============

* Changed namespace from `Newrelic` to `NewRelic` to be consistent with the RPM gem - [@dblock](https://github.com/dblock)
* Changed namespace from `Newrelic` to `NewRelic` to be consistent with the RPM gem - [@dblock](https://github.com/dblock).
* Set `DISABLE_NEW_RELIC_GRAPE` to disable instrumentation - [@dblock](https://github.com/dblock).

1.0.0 (12/18/2012)
==================
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ Or install it yourself as:

That's it.

## Disabling Instrumentation

Set `disable_grape` in `newrelic.yml` or `ENV['DISABLE_NEW_RELIC_GRAPE']` to disable instrumentation.

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
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
3. Update `CHANGELOG.md` describing your changes
4. Commit your changes (`git commit -am 'Add some feature'`)
5. Push to the branch (`git push origin my-new-feature`)
6. Create new Pull Request

[0]: https://github.com/intridea/grape
[1]: http://artsy.github.com/blog/2012/11/29/measuring-performance-in-grape-apis-with-new-relic/
8 changes: 4 additions & 4 deletions lib/newrelic-grape/instrument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class Grape < ::Grape::Middleware::Base

def call!(env)
@env = env

@newrelic_request = ::Rack::Request.new(env)
trace_options = {
:category => :rack,
Expand All @@ -25,6 +24,7 @@ def request_path
def request_method
@newrelic_request.request_method
end

end
end
end
Expand All @@ -34,7 +34,7 @@ def request_method
@name = :grape

depends_on do
defined?(::Grape) and not ::NewRelic::Control.instance['disable_grape']
defined?(::Grape) && ! ::NewRelic::Control.instance['disable_grape'] && ! ENV['DISABLE_NEW_RELIC_GRAPE']
end

executes do
Expand All @@ -43,10 +43,10 @@ def request_method

executes do
::Grape::Endpoint.class_eval do
alias_method :origin_build_middleware, :build_middleware
alias_method :grape_build_middleware, :build_middleware

def build_middleware
builder = origin_build_middleware
builder = grape_build_middleware
builder.use ::NewRelic::Agent::Instrumentation::Grape
builder
end
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@

require 'grape'
require 'newrelic_rpm'
require 'newrelic-grape'
require 'newrelic-grape'

0 comments on commit 4bf928a

Please sign in to comment.