Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Set `DISABLE_NEW_RELIC_GRAPE` at runtime to disable instrumentation. #2

Merged
merged 6 commits into from

2 participants

@dblock

We have many environments in which the newrelic configuration is entirely driven by environment (this is how you do things on Heroku). So we want to be able to disable instrumentation via ENV as well.

  • Added ENV['DISABLE_NEW_RELIC_GRAPE'] which acts the same way as disable_grape in newrelic.yml.
  • Change the implementation to check both at load time as it runtime. The runtime one lets you make the change without restarting the service through newrelic.yml (if your runtime supports it). This also enables tests since we don't reload everything between tests.

I would actually possibly be for removing the disabled? check from loading. Otherwise you cannot re-enable the instrumentation cause it wasn't loaded. Since I'm 50/50 you can sway one or the other direction :)

@flyerhzm
Owner

I'm curious when will you disable newrelic at runtime? It doesn't affect the application even when newrelic servers down.

@dblock

I can't come up with a useful example when I want to be able to disable the configuration at runtime. So maybe it's not a useful feature.

Any ideas how to reload the entire dependency-driven NewRelic configuration in a test so we can actually test enabling/disabling?

@dblock

I already spent a while trying to figure out how to test this, so I give up :) This change is still a good one I think - it lets you disable instrumentation with an ENV variable. No tests :(

@flyerhzm flyerhzm merged commit 4bf928a into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
3  CHANGELOG.md
@@ -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)
==================
View
11 README.md
@@ -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/
View
8 lib/newrelic-grape/instrument.rb
@@ -6,7 +6,6 @@ class Grape < ::Grape::Middleware::Base
def call!(env)
@env = env
-
@newrelic_request = ::Rack::Request.new(env)
trace_options = {
:category => :rack,
@@ -25,6 +24,7 @@ def request_path
def request_method
@newrelic_request.request_method
end
+
end
end
end
@@ -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
@@ -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
View
2  spec/spec_helper.rb
@@ -12,4 +12,4 @@
require 'grape'
require 'newrelic_rpm'
-require 'newrelic-grape'
+require 'newrelic-grape'
Something went wrong with that request. Please try again.