Class: ApiNewRelicInstrumenter
- Inherits:
-
Grape::Middleware::Base
- Object
- Grape::Middleware::Base
- ApiNewRelicInstrumenter
- Includes:
- NewRelic::Agent::Instrumentation::ControllerInstrumentation
- Defined in:
- lib/trogdir_api/newrelic.rb
Overview
Taken from gist.github.com/dblock/4170469
Instance Method Summary collapse
- #call(env) ⇒ Object
- #call_with_newrelic(&block) ⇒ Object
- #env ⇒ Object
- #route ⇒ Object
- #route_method ⇒ Object
- #route_path ⇒ Object
Instance Method Details
#call(env) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/trogdir_api/newrelic.rb', line 21 def call(env) @env = env call_with_newrelic do super end end |
#call_with_newrelic(&block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/trogdir_api/newrelic.rb', line 7 def call_with_newrelic(&block) = { :category => :rack, :path => "#{route_path}\##{route_method}", :request => Rack::Request.new(env) } perform_action_with_newrelic_trace() do result = yield MetricFrame.abort_transaction! if result.first == 404 # ignore cascaded calls result end end |
#env ⇒ Object
28 29 30 |
# File 'lib/trogdir_api/newrelic.rb', line 28 def env @env end |
#route ⇒ Object
32 33 34 |
# File 'lib/trogdir_api/newrelic.rb', line 32 def route env['api.endpoint'].routes.first end |
#route_method ⇒ Object
36 37 38 |
# File 'lib/trogdir_api/newrelic.rb', line 36 def route_method route.route_method.downcase end |
#route_path ⇒ Object
40 41 42 43 |
# File 'lib/trogdir_api/newrelic.rb', line 40 def route_path path = route.route_path.gsub(/^.+:version\/|^\/|:|\(.+\)/, '').tr('/', '-') "api.#{route.route_version}.#{path}" end |