module ScoutApm::Instruments::SinatraInstruments
Public Instance Methods
dispatch_with_scout_instruments!()
click to toggle source
# File lib/scout_apm/instruments/sinatra.rb, line 34 def dispatch_with_scout_instruments! scout_controller_action = "Sinatra/#{scout_sinatra_controller_name(@request)}" req = ScoutApm::RequestManager.lookup req.annotate_request(:uri => @request.path_info) req.context.add_user(:ip => @request.ip) # req.set_headers(env) # TODO: Parse headers with name HTTP_* req.start_layer( ScoutApm::Layer.new("Controller", scout_controller_action) ) begin dispatch_without_scout_instruments! rescue req.error! raise ensure req.stop_layer end end
scout_sinatra_controller_name(request)
click to toggle source
Iterates through the app's routes, returning the matched route that the request should be grouped under for the metric name.
If not found, “unknown” is returned. This prevents a metric explosion.
Nice to have: substitute the param pattern (([^/?#]+)) w/the named key (the key
param of the block).
# File lib/scout_apm/instruments/sinatra.rb, line 59 def scout_sinatra_controller_name(request) name = 'unknown' verb = request.request_method if request && request.respond_to?(:request_method) Array(self.class.routes[verb]).each do |pattern, keys, conditions, block| if pattern = process_route(pattern, keys, conditions) { pattern.source } name = pattern end end name.gsub!(%r{^[/^]*(.*?)[/\$\?]*$}, '\1') if verb name = [verb,name].join(' ') end name end