Class: Rester::Service::Middleware::NewRelic

Inherits:
Base
  • Object
show all
Includes:
NewRelic::Agent::Instrumentation::ControllerInstrumentation
Defined in:
lib/rester/service/middleware/new_relic.rb

Instance Attribute Summary

Attributes inherited from Base

#app, #options

Instance Method Summary collapse

Methods inherited from Base

#initialize, #service

Constructor Details

This class inherits a constructor from Rester::Service::Middleware::Base

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
# File 'lib/rester/service/middleware/new_relic.rb', line 11

def call(env)
  request = Service::Request.new(env)
  name = identify_method(request)
  ::NewRelic::Agent.set_transaction_name(name, category: :controller)
  super
end

#identify_method(request) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rester/service/middleware/new_relic.rb', line 18

def identify_method(request)
  object_chain = request.object_chain

  if object_chain.length.odd?
    resource_name = object_chain.last
  else
    resource_name = object_chain[-2]
  end

  method = _determine_method(request)

  "#{service.class.name}::#{request.version.to_s.upcase}::"\
    "#{resource_name.singularize.camelcase}/#{method}"
end