Class: ApiNewRelicInstrumenter

Inherits:
Grape::Middleware::Base
  • Object
show all
Includes:
NewRelic::Agent::Instrumentation::ControllerInstrumentation
Defined in:
lib/trogdir_api/newrelic.rb

Overview

Instance Method Summary collapse

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)
  trace_options = {
    :category => :rack,
    :path => "#{route_path}\##{route_method}",
    :request => Rack::Request.new(env)
  }

  perform_action_with_newrelic_trace(trace_options) do
    result = yield
    MetricFrame.abort_transaction! if result.first == 404 # ignore cascaded calls
    result
  end
end

#envObject



28
29
30
# File 'lib/trogdir_api/newrelic.rb', line 28

def env
  @env
end

#routeObject



32
33
34
# File 'lib/trogdir_api/newrelic.rb', line 32

def route
  env['api.endpoint'].routes.first
end

#route_methodObject



36
37
38
# File 'lib/trogdir_api/newrelic.rb', line 36

def route_method
  route.route_method.downcase
end

#route_pathObject



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