Sha256: 156155e724aac3c38b6322cc70a04ee72e18fa0ebd5feb5ec5107c85d12d0549

Contents?: true

Size: 1.4 KB

Versions: 42

Compression:

Stored size: 1.4 KB

Contents

# encoding: utf-8

module OneApm
  module Agent
    module Instrumentation
      module Sinatra
        module Ignorer

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

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

          def oneapm_ignore(*routes)
            set_oneapm_ignore(:routes, *routes)
          end

          def oneapm_ignore_apdex(*routes)
            set_oneapm_ignore(:apdex, *routes)
          end

          def oneapm_ignore_enduser(*routes)
            set_oneapm_ignore(:enduser, *routes)
          end

          private

          def set_oneapm_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 :oneapm_ignores, Hash.new([]) if !respond_to?(:oneapm_ignores)

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

            settings.oneapm_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
              send(:compile, r).first
            end
          end

        end
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
oneapm_rpm-1.4.2 lib/one_apm/inst/framework/sinatra/ignorer.rb
oneapm_rpm-1.4.1 lib/one_apm/inst/framework/sinatra/ignorer.rb
oneapm_rpm-1.4.0 lib/one_apm/inst/framework/sinatra/ignorer.rb
oneapm_rpm-1.3.7 lib/one_apm/inst/framework/sinatra/ignorer.rb
oneapm_rpm-1.3.7.rc1 lib/one_apm/inst/framework/sinatra/ignorer.rb
oneapm_rpm-1.3.6 lib/one_apm/inst/framework/sinatra/ignorer.rb
oneapm_rpm-1.3.6.rc1 lib/one_apm/inst/framework/sinatra/ignorer.rb
oneapm_rpm-1.3.5 lib/one_apm/inst/framework/sinatra/ignorer.rb
oneapm_rpm-1.3.5.rc1 lib/one_apm/inst/framework/sinatra/ignorer.rb
oneapm_rpm-1.3.4 lib/one_apm/inst/framework/sinatra/ignorer.rb
oneapm_rpm-1.3.4.rc1 lib/one_apm/inst/framework/sinatra/ignorer.rb
oneapm_rpm-1.3.3 lib/one_apm/inst/framework/sinatra/ignorer.rb
oneapm_rpm-1.3.3.rc1 lib/one_apm/inst/framework/sinatra/ignorer.rb
oneapm_rpm-1.3.2 lib/one_apm/inst/framework/sinatra/ignorer.rb
oneapm_rpm-1.3.2.rc1 lib/one_apm/inst/framework/sinatra/ignorer.rb
oneapm_rpm-1.3.1 lib/one_apm/inst/framework/sinatra/ignorer.rb
oneapm_rpm-1.3.1.rc1 lib/one_apm/inst/framework/sinatra/ignorer.rb
oneapm_rpm-1.3.0 lib/one_apm/inst/framework/sinatra/ignorer.rb
oneapm_rpm-1.3.0.rc1 lib/one_apm/inst/framework/sinatra/ignorer.rb
oneapm_rpm-1.2.9 lib/one_apm/inst/framework/sinatra/ignorer.rb