Sha256: 95003240bf201e0eed0bb36b333650e0424689d4c7a2fea15bfc9ed3cb302ad8

Contents?: true

Size: 989 Bytes

Versions: 9

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

9 entries across 9 versions & 2 rubygems

Version Path
ddtrace-0.45.0 lib/ddtrace/pipeline/span_filter.rb
ddtrace-0.44.0 lib/ddtrace/pipeline/span_filter.rb
ddtrace-0.43.0 lib/ddtrace/pipeline/span_filter.rb
ddtrace-0.42.0 lib/ddtrace/pipeline/span_filter.rb
ddtrace-0.41.0 lib/ddtrace/pipeline/span_filter.rb
ls-trace-0.2.0 lib/ddtrace/pipeline/span_filter.rb
ddtrace-0.40.0 lib/ddtrace/pipeline/span_filter.rb
ddtrace-0.39.0 lib/ddtrace/pipeline/span_filter.rb
ddtrace-0.38.0 lib/ddtrace/pipeline/span_filter.rb