Sha256: 7d1382460274e1e695a3c1244f8e161b76cf15394b2071e4ed114b3cd556b82a

Contents?: true

Size: 1.3 KB

Versions: 16

Compression:

Stored size: 1.3 KB

Contents

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

module NewRelic::Agent::Instrumentation
  module Roda
    module Ignorer
      def self.should_ignore?(app, type)
        return false unless app.opts.include?(:newrelic_ignores)

        app.opts[:newrelic_ignores][type].any? do |pattern|
          pattern === 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)
        # Create a newrelic_ignores hash if one doesn't exist
        opts[:newrelic_ignores] = Hash.new([]) if !opts.include?(:newrelic_ignores)

        if routes.empty?
          opts[:newrelic_ignores][type] += [Regexp.new('.*')]
        else
          opts[:newrelic_ignores][type] += routes.map do |r|
            # Roda adds leading slashes to routes, so we need to do the same
            "#{'/' unless r.start_with?('/')}#{r}"
          end
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
newrelic_rpm-9.17.0 lib/new_relic/agent/instrumentation/roda/ignorer.rb
newrelic_rpm-9.16.1 lib/new_relic/agent/instrumentation/roda/ignorer.rb
newrelic_rpm-9.16.0 lib/new_relic/agent/instrumentation/roda/ignorer.rb
newrelic_rpm-9.15.0 lib/new_relic/agent/instrumentation/roda/ignorer.rb
newrelic_rpm-9.14.0 lib/new_relic/agent/instrumentation/roda/ignorer.rb
newrelic_rpm-9.13.0 lib/new_relic/agent/instrumentation/roda/ignorer.rb
newrelic_rpm-9.12.0 lib/new_relic/agent/instrumentation/roda/ignorer.rb
newrelic_rpm-9.11.0 lib/new_relic/agent/instrumentation/roda/ignorer.rb
newrelic_rpm-9.10.2 lib/new_relic/agent/instrumentation/roda/ignorer.rb
newrelic_rpm-9.10.1 lib/new_relic/agent/instrumentation/roda/ignorer.rb
newrelic_rpm-9.10.0 lib/new_relic/agent/instrumentation/roda/ignorer.rb
newrelic_rpm-9.9.0 lib/new_relic/agent/instrumentation/roda/ignorer.rb
newrelic_rpm-9.8.0 lib/new_relic/agent/instrumentation/roda/ignorer.rb
newrelic_rpm-9.7.1 lib/new_relic/agent/instrumentation/roda/ignorer.rb
newrelic_rpm-9.7.0 lib/new_relic/agent/instrumentation/roda/ignorer.rb
newrelic_rpm-9.6.0 lib/new_relic/agent/instrumentation/roda/ignorer.rb