Class: XRay::DefaultStreamer

Inherits:
Object
  • Object
show all
Includes:
Logging, Streamer
Defined in:
lib/aws-xray-sdk/streaming/default_streamer.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger, logger, logger=

Methods included from Streamer

#subsegments_to_stream

Constructor Details

#initializeDefaultStreamer

Returns a new instance of DefaultStreamer.



12
13
14
# File 'lib/aws-xray-sdk/streaming/default_streamer.rb', line 12

def initialize
  @stream_threshold = 50
end

Instance Attribute Details

#stream_thresholdInteger

Returns The maximum number of subsegments a segment can hold before streaming.

Returns:

  • (Integer)

    The maximum number of subsegments a segment can hold before streaming.



51
52
53
# File 'lib/aws-xray-sdk/streaming/default_streamer.rb', line 51

def stream_threshold
  @stream_threshold
end

Instance Method Details

#eligible?(segment:) ⇒ Boolean

Parameters:

  • segment (Segment)

    Check if the provided segment exceeds the threshold to stream.

Returns:

  • (Boolean)


18
19
20
21
# 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:) ⇒ Object

Parameters:

  • root (Segment)

    The target segment to stream subsegments from.

  • emitter (Emitter)

    The emitter employed to send data to the daemon.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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