Sha256: 6f6e0172c17d58dffdac04dd372f99ec037a146ece6331cbc1b51cd2c5ee769d

Contents?: true

Size: 1.72 KB

Versions: 23

Compression:

Stored size: 1.72 KB

Contents

if defined?(Sinatra::Base)
  require 'new_relic/agent/instrumentation/controller_instrumentation'
  module NewRelic
    module Agent
      module Instrumentation
        # 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.
        module Sinatra
          
          include NewRelic::Agent::Instrumentation::ControllerInstrumentation
          
          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
        end
        
        ::Sinatra::Base.class_eval do
          include NewRelic::Agent::Instrumentation::Sinatra
          alias route_eval_without_newrelic route_eval
          alias route_eval route_eval_with_newrelic
        end
        
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
onyx_newrelic_rpm-2.12.5 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-2.13.0.beta5 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-2.13.0.beta4 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-2.13.0.beta3 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-2.12.3 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-2.12.2 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-2.12.2.beta2 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-2.12.2.beta lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-2.12.1 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-2.12.1.alpha lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-2.12.0 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-2.11.3 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-2.11.2 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-2.11.2.beta2 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-2.11.2.beta lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-2.11.1 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-2.11.0.beta2 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-2.11.0.beta lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-2.10.8 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-2.10.6 lib/new_relic/agent/instrumentation/sinatra.rb