Sha256: 883c0cbaab70c0e341cec226adb8bf725ba31e2b4be035e65074b475a6eb88a9

Contents?: true

Size: 1.92 KB

Versions: 25

Compression:

Stored size: 1.92 KB

Contents

require 'new_relic/agent/instrumentation/controller_instrumentation'

DependencyDetection.defer do
  depends_on do
    defined?(::Sinatra) && defined?(::Sinatra::Base)
  end

  executes do
    NewRelic::Agent.logger.debug 'Installing Sinatra instrumentation'
  end

  executes do
    ::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


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 off leading ^ and / chars and trailing $ and /
          name.gsub!(%r{^[/^]*(.*?)[/\$\?]*$}, '\1')
          name = 'root' if name.empty?
          name = @request.request_method + ' ' + name if @request && @request.respond_to?(:request_method)
          perform_action_with_newrelic_trace(:category => :sinatra, :name => name, :params => @request.params) do
            route_eval_without_newrelic(&block_arg)
          end
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
dolores_rpm-3.2.0.6 lib/new_relic/agent/instrumentation/sinatra.rb
dolores_rpm-3.2.0.5 lib/new_relic/agent/instrumentation/sinatra.rb
dolores_rpm-3.2.0.4 lib/new_relic/agent/instrumentation/sinatra.rb
dolores_rpm-3.2.0.3 lib/new_relic/agent/instrumentation/sinatra.rb
dolores_rpm-3.2.0.2 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-3.3.2.1 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-3.3.2 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-3.3.2.beta2 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-3.3.2.beta1 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-3.3.1 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-3.3.1.beta2 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-3.3.1.beta1 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-3.3.0 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-3.3.0.beta1 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-3.2.0.1 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-3.2.0 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-3.2.0.beta2 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-3.2.0.beta1 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-3.1.2 lib/new_relic/agent/instrumentation/sinatra.rb
newrelic_rpm-3.1.2.beta2 lib/new_relic/agent/instrumentation/sinatra.rb