Sha256: 1ea58dbc6cb36d120ebfda8be1932bd987d5a47d9e05b03e6c62c40c05b76c33

Contents?: true

Size: 989 Bytes

Versions: 7

Compression:

Stored size: 989 Bytes

Contents

module Datadog
  module Pipeline
    # SpanFilter implements a processor that filters entire span subtrees
    class SpanFilter
      def initialize(filter = nil, &block)
        callable = filter || block

        raise(ArgumentError) unless callable.respond_to?(:call)

        @criteria = filter || block
      end

      # NOTE: this SpanFilter implementation only handles traces in which child spans appear
      # after parent spans in the trace array. If in the future child spans can be before
      # parent spans, then the code below will need to be updated.
      def call(trace)
        deleted = Set.new

        trace.delete_if do |span|
          if deleted.include?(span.parent)
            deleted << span
            true
          else
            drop = drop_it?(span)
            deleted << span if drop
            drop
          end
        end
      end

      private

      def drop_it?(span)
        @criteria.call(span) rescue false
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ddtrace-0.51.1 lib/ddtrace/pipeline/span_filter.rb
ddtrace-0.51.0 lib/ddtrace/pipeline/span_filter.rb
ddtrace-0.50.0 lib/ddtrace/pipeline/span_filter.rb
ddtrace-0.49.0 lib/ddtrace/pipeline/span_filter.rb
ddtrace-0.48.0 lib/ddtrace/pipeline/span_filter.rb
ddtrace-0.47.0 lib/ddtrace/pipeline/span_filter.rb
ddtrace-0.46.0 lib/ddtrace/pipeline/span_filter.rb