Sha256: afae0f52beda4240d316add7fff857cd04441aa74d0ddd0ff2f66a43ed731958

Contents?: true

Size: 1003 Bytes

Versions: 5

Compression:

Stored size: 1003 Bytes

Contents

# typed: true
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

5 entries across 5 versions & 1 rubygems

Version Path
ddtrace-0.54.2 lib/ddtrace/pipeline/span_filter.rb
ddtrace-0.54.1 lib/ddtrace/pipeline/span_filter.rb
ddtrace-0.54.0 lib/ddtrace/pipeline/span_filter.rb
ddtrace-0.53.0 lib/ddtrace/pipeline/span_filter.rb
ddtrace-0.52.0 lib/ddtrace/pipeline/span_filter.rb