class XRay::DefaultStreamer

The default streamer use subsegment count as the threshold for performance reasons and it streams out subtrees where all the nodes in it are completed.

Attributes

stream_threshold[RW]

@return [Integer] The maximum number of subsegments a segment

can hold before streaming.

Public Class Methods

new() click to toggle source
# File lib/aws-xray-sdk/streaming/default_streamer.rb, line 12
def initialize
  @stream_threshold = 50
end

Public Instance Methods

eligible?(segment:) click to toggle source

@param [Segment] segment Check if the provided segment exceeds

the threshold to stream.
# File lib/aws-xray-sdk/streaming/default_streamer.rb, line 18
def eligible?(segment:)
  # only get subsegments to stream from sampled segments.
  segment && segment.sampled && segment.subsegment_size >= stream_threshold
end
stream_subsegments(root:, emitter:) click to toggle source

@param [Segment] root The target segment to stream subsegments from. @param [Emitter] emitter The emitter employed to send data to the daemon.

# File lib/aws-xray-sdk/streaming/default_streamer.rb, line 25
def stream_subsegments(root:, emitter:)
  children = root.subsegments
  children_ready = []

  unless children.empty?
    # Collect ready subtrees from root.
    children.each do |child|
      children_ready << child if stream_subsegments root: child, emitter: emitter
    end
  end

  # If this subtree is ready, go back to the root's parent
  # to try to find a bigger subtree
  return true if children_ready.length == children.length && root.closed?
  # Otherwise this subtree has at least one non-ready node.
  # Only stream its ready child subtrees.
  children_ready.each do |child|
    root.remove_subsegment subsegment: child
    emitter.send_entity entity: child
  end
  # Return false so this node won't be added to its parent's ready children.
  false
end