Sha256: 2630358d74147e19557a1c6211c0a85f74572f12e2940fac483af6d06de5ebf5

Contents?: true

Size: 1.35 KB

Versions: 27

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

require 'set'
require_relative 'span_processor'

module Datadog
  module Tracing
    module Pipeline
      # SpanFilter implements a processor that filters entire span subtrees
      # This processor executes the configured `operation` for each {Datadog::Tracing::Span}
      # in a {Datadog::Tracing::TraceSegment}.
      #
      # If `operation` returns a truthy value for a span, that span is kept,
      # otherwise the span is removed from the trace.
      #
      # @public_api
      class SpanFilter < SpanProcessor
        # NOTE: This SpanFilter implementation only handles traces in which child spans appear
        # before parent spans in the trace array. If in the future child spans can be after
        # parent spans, then the code below will need to be updated.
        # @!visibility private
        def call(trace)
          deleted = Set.new

          span_count = trace.spans.length
          trace.spans.reverse_each.with_index do |span, i|
            should_delete = deleted.include?(span.parent_id) || drop_it?(span)

            if should_delete
              deleted << span.id
              trace.spans.delete_at(span_count - 1 - i)
            end
          end

          trace
        end

        private

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

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
datadog-2.2.0 lib/datadog/tracing/pipeline/span_filter.rb
ddtrace-1.23.3 lib/datadog/tracing/pipeline/span_filter.rb
ddtrace-1.23.2 lib/datadog/tracing/pipeline/span_filter.rb
datadog-2.1.0 lib/datadog/tracing/pipeline/span_filter.rb
datadog-2.0.0 lib/datadog/tracing/pipeline/span_filter.rb
ddtrace-1.23.1 lib/datadog/tracing/pipeline/span_filter.rb
datadog-2.0.0.beta2 lib/datadog/tracing/pipeline/span_filter.rb
ddtrace-1.22.0 lib/datadog/tracing/pipeline/span_filter.rb
datadog-2.0.0.beta1 lib/datadog/tracing/pipeline/span_filter.rb
ddtrace-1.21.1 lib/datadog/tracing/pipeline/span_filter.rb
ddtrace-1.21.0 lib/datadog/tracing/pipeline/span_filter.rb
ddtrace-1.20.0 lib/datadog/tracing/pipeline/span_filter.rb
ddtrace-1.19.0 lib/datadog/tracing/pipeline/span_filter.rb
ddtrace-1.18.0 lib/datadog/tracing/pipeline/span_filter.rb
ddtrace-1.17.0 lib/datadog/tracing/pipeline/span_filter.rb
ddtrace-1.16.2 lib/datadog/tracing/pipeline/span_filter.rb
ddtrace-1.16.1 lib/datadog/tracing/pipeline/span_filter.rb
ddtrace-1.16.0 lib/datadog/tracing/pipeline/span_filter.rb
ddtrace-1.15.0 lib/datadog/tracing/pipeline/span_filter.rb
ddtrace-1.14.0 lib/datadog/tracing/pipeline/span_filter.rb