Class: Datadog::Pipeline::SpanFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/ddtrace/pipeline/span_filter.rb

Overview

SpanFilter implements a processor that filters entire span subtrees

Instance Method Summary collapse

Constructor Details

#initialize(filter = nil, &block) ⇒ SpanFilter

Returns a new instance of SpanFilter.

Raises:

  • (ArgumentError)

5
6
7
8
9
10
11
# File 'lib/ddtrace/pipeline/span_filter.rb', line 5

def initialize(filter = nil, &block)
  callable = filter || block

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

  @criteria = filter || block
end

Instance Method Details

#call(trace) ⇒ Object

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.


16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ddtrace/pipeline/span_filter.rb', line 16

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