Module: NewRelic::Agent::Instrumentation::Sinatra::NewRelic

Extended by:
NewRelic
Included in:
NewRelic
Defined in:
lib/new_relic/agent/instrumentation/sinatra.rb

Instance Method Summary collapse

Instance Method Details

#http_verb(request) ⇒ Object



74
75
76
# File 'lib/new_relic/agent/instrumentation/sinatra.rb', line 74

def http_verb(request)
  request.request_method if request.respond_to?(:request_method)
end

#transaction_name(routes, request) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/new_relic/agent/instrumentation/sinatra.rb', line 78

def transaction_name(routes, request)
  name = '(unknown)'
  verb = http_verb(request)

  Array(routes[verb]).each do |pattern, keys, conditions, block|
    if route = yield(pattern, keys, conditions)
      name = route
      # it's important we short circuit here.  Otherwise we risk
      # applying conditions from lower priority routes which can
      # break the action.
      break
    end
  end

  name.gsub!(%r{^[/^]*(.*?)[/\$\?]*$}, '\1')
  if verb
    name = verb + ' ' + name
  end

  name
rescue => e
  ::NewRelic::Agent.logger.debug("#{e.class} : #{e.message} - Error encountered trying to identify Sinatra transaction name")
  '(unknown)'
end