Sha256: bb6f07e01adc45024a661a80442e9eecbb10a3c77aea483f89a52da8e3702c2d
Contents?: true
Size: 1.33 KB
Versions: 13
Compression:
Stored size: 1.33 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 dropped, # otherwise the span is kept. # # @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
13 entries across 13 versions & 1 rubygems