Permalink
Browse files

Only enable/disable at load time.

  • Loading branch information...
1 parent cd3175d commit 74e00074019d205627e4009da86f5ede1c05cb2e @dblock dblock committed Dec 28, 2012
Showing with 9 additions and 57 deletions.
  1. +8 −18 lib/newrelic-grape/instrument.rb
  2. +0 −38 spec/newrelic-grape/instrumenter_spec.rb
  3. +1 −1 spec/spec_helper.rb
@@ -6,17 +6,13 @@ class Grape < ::Grape::Middleware::Base
def call!(env)
@env = env
- unless NewRelic::Agent::Instrumentation::Grape.disabled?
- @newrelic_request = ::Rack::Request.new(env)
- trace_options = {
- :category => :rack,
- :path => "#{request_method} #{request_path}",
- :request => @newrelic_request
- }
- perform_action_with_newrelic_trace(trace_options) do
- @app_response = @app.call(@env)
- end
- else
+ @newrelic_request = ::Rack::Request.new(env)
+ trace_options = {
+ :category => :rack,
+ :path => "#{request_method} #{request_path}",
+ :request => @newrelic_request
+ }
+ perform_action_with_newrelic_trace(trace_options) do
@app_response = @app.call(@env)
end
end
@@ -29,12 +25,6 @@ def request_method
@newrelic_request.request_method
end
- class << self
- def disabled?
- ::NewRelic::Control.instance['disable_grape'] || ENV['DISABLE_NEW_RELIC_GRAPE']
- end
- end
-
end
end
end
@@ -44,7 +34,7 @@ def disabled?
@name = :grape
depends_on do
- defined?(::Grape) && ! NewRelic::Agent::Instrumentation::Grape.disabled?
+ defined?(::Grape) && ! ::NewRelic::Control.instance['disable_grape'] && ! ENV['DISABLE_NEW_RELIC_GRAPE']
end
executes do
@@ -21,44 +21,6 @@ def app
last_response.body.should == "Hello World"
end
- it "not disabled?" do
- NewRelic::Agent::Instrumentation::Grape.should_not be_disabled
- end
-
- context "disable_grape" do
- before do
- ::NewRelic::Control.stub(:instance).and_return({ 'disable_grape' => true })
- end
- it "disabled?" do
- NewRelic::Agent::Instrumentation::Grape.should be_disabled
- end
- it "turns off instrumentation" do
- NewRelic::Agent::Instrumentation::Grape.any_instance.should_not_receive(:perform_action_with_newrelic_trace).and_yield
- get "/hello"
- last_response.status.should == 200
- last_response.body.should == "Hello World"
- end
- end
-
- context "DISABLE_NEW_RELIC_GRAPE" do
- before do
- @disable_new_relic_grape = ENV['DISABLE_NEW_RELIC_GRAPE']
- ENV['DISABLE_NEW_RELIC_GRAPE'] = '1'
- end
- it "disabled?" do
- NewRelic::Agent::Instrumentation::Grape.should be_disabled
- end
- it "turns off instrumentation" do
- NewRelic::Agent::Instrumentation::Grape.any_instance.should_not_receive(:perform_action_with_newrelic_trace).and_yield
- get "/hello"
- last_response.status.should == 200
- last_response.body.should == "Hello World"
- end
- after do
- ENV['DISABLE_NEW_RELIC_GRAPE'] = @disable_new_relic_grape
- end
- end
-
end
View
@@ -12,4 +12,4 @@
require 'grape'
require 'newrelic_rpm'
-require 'newrelic-grape'
+require 'newrelic-grape'

0 comments on commit 74e0007

Please sign in to comment.