Module: ScoutApm::Instruments::SinatraInstruments

Defined in:
lib/scout_apm/instruments/sinatra.rb

Instance Method Summary collapse

Instance Method Details

#dispatch_with_scout_instruments!Object



31
32
33
34
35
36
# File 'lib/scout_apm/instruments/sinatra.rb', line 31

def dispatch_with_scout_instruments!
  scout_controller_action = "Controller/Sinatra/#{scout_sinatra_controller_name(@request)}"
  self.class.scout_apm_trace(scout_controller_action, :uri => @request.path_info, :ip => @request.ip) do
    dispatch_without_scout_instruments!
  end
end

#scout_sinatra_controller_name(request) ⇒ Object

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).



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/scout_apm/instruments/sinatra.rb', line 44

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