Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single pass SpanFilter #1071

Merged
merged 3 commits into from
Jul 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions lib/ddtrace/pipeline/span_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ def initialize(filter = nil, &block)
@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)
black_list = trace.select(&method(:drop_it?))

clean_trace(black_list, trace) while black_list.any?

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

def clean_trace(black_list, trace)
current = black_list.shift

trace.delete(current)

trace.each do |span|
black_list << span if span.parent == current
end
end
end
end
end