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

Includes:
ControllerInstrumentation
Defined in:
lib/new_relic/agent/instrumentation/sinatra.rb

Overview

NewRelic instrumentation for Sinatra applications. Sinatra actions will appear in the UI similar to controller actions, and have breakdown charts and transaction traces.

The actions in the UI will correspond to the pattern expression used to match them. HTTP operations are not distinguished. Multiple matches will all be tracked as separate actions.

Instance Method Summary collapse

Methods included from ControllerInstrumentation

included, #newrelic_metric_path, #perform_action_with_newrelic_trace

Instance Method Details

#route_eval_with_newrelic(&block_arg) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/new_relic/agent/instrumentation/sinatra.rb', line 17

def route_eval_with_newrelic(&block_arg)
  path = unescape(@request.path_info)
  name = path
  # Go through each route and look for a match
  if routes = self.class.routes[@request.request_method]
    routes.detect do |pattern, keys, conditions, block|
      if block_arg.equal? block
        name = pattern.source
      end
    end
  end
  # strip of leading ^ and / chars and trailing $ and /
  name.gsub!(%r{^[/^]*(.*?)[/\$]*$}, '\1')
  name = 'root' if name.empty?
  perform_action_with_newrelic_trace(:category => :sinatra, :name => name) do
    route_eval_without_newrelic(&block_arg)
  end
end