Sha256: cec8b1ea15f7fc96a315b5daa5c870a354f0fe35deae3780a49f01cf49db5693

Contents?: true

Size: 1.67 KB

Versions: 31

Compression:

Stored size: 1.67 KB

Contents

module Datadog
  module Sampling
    # Checks if a span conforms to a matching criteria.
    class Matcher
      # Returns `true` if the span should conforms to this rule, `false` otherwise
      #
      # @abstract
      # @param [Span] span
      # @return [Boolean]
      def match?(span)
        raise NotImplementedError
      end
    end

    # A \Matcher that supports matching a span by
    # operation name and/or service name.
    class SimpleMatcher < Matcher
      # Returns `true` for case equality (===) with any object
      MATCH_ALL = Class.new do
        # DEV: A class that implements `#===` is ~20% faster than
        # DEV: a `Proc` that always returns `true`.
        def ===(other)
          true
        end
      end.new

      attr_reader :name, :service

      # @param name [String,Regexp,Proc] Matcher for case equality (===) with the span name, defaults to always match
      # @param service [String,Regexp,Proc] Matcher for case equality (===) with the service name, defaults to always match
      def initialize(name: MATCH_ALL, service: MATCH_ALL)
        @name = name
        @service = service
      end

      def match?(span)
        name === span.name && service === span.service
      end
    end

    # A \Matcher that allows for arbitrary span matching
    # based on the return value of a provided block.
    class ProcMatcher < Matcher
      attr_reader :block

      # @yield [name, service] Provides span name and service to the block
      # @yieldreturn [Boolean] Whether the span conforms to this matcher
      def initialize(&block)
        @block = block
      end

      def match?(span)
        block.call(span.name, span.service)
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
ddtrace-0.51.1 lib/ddtrace/sampling/matcher.rb
ddtrace-0.51.0 lib/ddtrace/sampling/matcher.rb
ddtrace-0.50.0 lib/ddtrace/sampling/matcher.rb
ddtrace-0.49.0 lib/ddtrace/sampling/matcher.rb
ddtrace-0.48.0 lib/ddtrace/sampling/matcher.rb
ddtrace-0.47.0 lib/ddtrace/sampling/matcher.rb
ddtrace-0.46.0 lib/ddtrace/sampling/matcher.rb
ddtrace-0.45.0 lib/ddtrace/sampling/matcher.rb
ddtrace-0.44.0 lib/ddtrace/sampling/matcher.rb
ddtrace-0.43.0 lib/ddtrace/sampling/matcher.rb
ddtrace-0.42.0 lib/ddtrace/sampling/matcher.rb
ddtrace-0.41.0 lib/ddtrace/sampling/matcher.rb
ls-trace-0.2.0 lib/ddtrace/sampling/matcher.rb
ddtrace-0.40.0 lib/ddtrace/sampling/matcher.rb
ddtrace-0.39.0 lib/ddtrace/sampling/matcher.rb
ddtrace-0.38.0 lib/ddtrace/sampling/matcher.rb
ddtrace-0.37.0 lib/ddtrace/sampling/matcher.rb
ddtrace-0.36.0 lib/ddtrace/sampling/matcher.rb
ddtrace-0.35.2 lib/ddtrace/sampling/matcher.rb
ddtrace-0.35.1 lib/ddtrace/sampling/matcher.rb