Module: NewRelic::Agent::Instrumentation::Sinatra::TransactionNamer
- Extended by:
- TransactionNamer
- Included in:
- TransactionNamer
- Defined in:
- lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb
Instance Method Summary collapse
- #http_verb(request) ⇒ Object
- #initial_transaction_name(request) ⇒ Object
-
#route_for_sinatra(env) ⇒ Object
For bare Sinatra, our override on process_route captures the last route into the environment for us to use later on.
-
#route_name_for_padrino(request) ⇒ Object
For Padrino, the request object has a copy of the matched route on it when we go to evaluating, so we can just retrieve that.
- #transaction_name(route_text, request) ⇒ Object
- #transaction_name_for_route(env, request) ⇒ Object
Instance Method Details
#http_verb(request) ⇒ Object
35 36 37 |
# File 'lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb', line 35 def http_verb(request) request.request_method if request.respond_to?(:request_method) end |
#initial_transaction_name(request) ⇒ Object
19 20 21 |
# File 'lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb', line 19 def initial_transaction_name(request) transaction_name(::NewRelic::Agent::UNKNOWN_METRIC, request) end |
#route_for_sinatra(env) ⇒ Object
For bare Sinatra, our override on process_route captures the last route into the environment for us to use later on
41 42 43 |
# File 'lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb', line 41 def route_for_sinatra(env) env["newrelic.last_route"] end |
#route_name_for_padrino(request) ⇒ Object
For Padrino, the request object has a copy of the matched route on it when we go to evaluating, so we can just retrieve that
47 48 49 50 51 |
# File 'lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb', line 47 def route_name_for_padrino(request) request.route_obj.original_path rescue => e nil end |
#transaction_name(route_text, request) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb', line 23 def transaction_name(route_text, request) verb = http_verb(request) route_text = route_text.source if route_text.is_a?(Regexp) name = route_text.gsub(%r{^[/^\\A]*(.*?)[/\$\?\\z]*$}, '\1') name = "#{verb} #{name}" unless verb.nil? name rescue => e ::NewRelic::Agent.logger.debug("#{e.class} : #{e.} - Error encountered trying to identify Sinatra transaction name") ::NewRelic::Agent::UNKNOWN_METRIC end |
#transaction_name_for_route(env, request) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb', line 12 def transaction_name_for_route(env, request) name = route_for_sinatra(env) name = route_name_for_padrino(request) if name.nil? transaction_name(name, request) unless name.nil? end |