Sha256: de2df7e58346ae365547459a84204f9a334705ce54461537f99e7dd99caf8728

Contents?: true

Size: 1.58 KB

Versions: 5

Compression:

Stored size: 1.58 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.

module NewRelic
  module Agent
    module Instrumentation
      module Sinatra
        module Ignorer

          def self.should_ignore?(app, type)
            return false if !app.settings.respond_to?(:newrelic_ignores)

            app.settings.newrelic_ignores[type].any? do |pattern|
              pattern.match(app.request.path_info)
            end
          end

          def newrelic_ignore(*routes)
            set_newrelic_ignore(:routes, *routes)
          end

          def newrelic_ignore_apdex(*routes)
            set_newrelic_ignore(:apdex, *routes)
          end

          def newrelic_ignore_enduser(*routes)
            set_newrelic_ignore(:enduser, *routes)
          end

          private

          def set_newrelic_ignore(type, *routes)
            # Important to default this in the context of the actual app
            # If it's done at register time, ignores end up shared between apps.
            set :newrelic_ignores, Hash.new([]) if !respond_to?(:newrelic_ignores)

            # If we call an ignore without a route, it applies to the whole app
            routes = ["*"] if routes.empty?

            settings.newrelic_ignores[type] += routes.map do |r|
              # Ugly sending to private Base#compile, but we want to mimic
              # exactly Sinatra's mapping of route text to regex
              Array(send(:compile, r)).first
            end
          end

        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
newrelic_rpm-6.15.0 lib/new_relic/agent/instrumentation/sinatra/ignorer.rb
newrelic_rpm-6.14.0 lib/new_relic/agent/instrumentation/sinatra/ignorer.rb
newrelic_rpm-6.13.1 lib/new_relic/agent/instrumentation/sinatra/ignorer.rb
newrelic_rpm-6.13.0 lib/new_relic/agent/instrumentation/sinatra/ignorer.rb
newrelic_rpm-6.12.0.367 lib/new_relic/agent/instrumentation/sinatra/ignorer.rb