Class: Instana::Processor
- Inherits:
-
Object
- Object
- Instana::Processor
- Defined in:
- lib/instana/tracing/processor.rb
Instance Method Summary collapse
-
#add_span(span) ⇒ Object
Adds a span to the span queue.
-
#add_spans(spans) ⇒ Object
Adds a Set of spans to the queue.
-
#clear! ⇒ Object
Removes all traces from the @queue.
-
#initialize ⇒ Processor
constructor
A new instance of Processor.
-
#queued_spans ⇒ Array
Retrieves all of the traces in @queue and returns the sum of their raw spans.
-
#send ⇒ Object
send.
Constructor Details
#initialize ⇒ Processor
Returns a new instance of Processor.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/instana/tracing/processor.rb', line 5 def initialize # The main queue before being reported to the # host agent. Spans in this queue are complete # and ready to be sent. @queue = Queue.new # This is the maximum number of spans we send to the host # agent at once. @batch_size = 3000 end |
Instance Method Details
#add_span(span) ⇒ Object
Adds a span to the span queue
26 27 28 29 30 31 32 33 34 |
# File 'lib/instana/tracing/processor.rb', line 26 def add_span(span) # Occasionally, do a checkup on our background thread. if rand(10) > 8 if ::Instana.agent.collect_thread.nil? || !::Instana.agent.collect_thread.alive? ::Instana.agent.spawn_background_thread end end @queue.push(span) end |
#add_spans(spans) ⇒ Object
Adds a Set of spans to the queue
19 20 21 |
# File 'lib/instana/tracing/processor.rb', line 19 def add_spans(spans) spans.each { |span| @queue.push(span)} end |
#clear! ⇒ Object
Removes all traces from the @queue. Used in the test suite to reset state.
85 86 87 88 89 90 |
# File 'lib/instana/tracing/processor.rb', line 85 def clear! until @queue.empty? do # Non-blocking pop; ignore exception @queue.pop(true) rescue nil end end |
#queued_spans ⇒ Array
Retrieves all of the traces in @queue and returns the sum of their raw spans. This is used by Processor::send and in the test suite. Note that traces retrieved with this method are removed entirely from the queue.
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/instana/tracing/processor.rb', line 68 def queued_spans return [] if @queue.empty? spans = [] until @queue.empty? do # Non-blocking pop; ignore exception span = @queue.pop(true) rescue nil if span spans << span.raw end end spans end |
#send ⇒ Object
send
Sends all traces in @queue to the host agent
FIXME: Add limits checking here in regards to:
- Max HTTP Post size
- Out of control/growing queue
- Prevent another run of the timer while this is running
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/instana/tracing/processor.rb', line 46 def send return if @queue.empty? || ENV.key?('INSTANA_TEST') # Retrieve all spans for queued traces spans = queued_spans # Report spans in batches batch = spans.shift(@batch_size) while !batch.empty? do ::Instana.agent.report_spans(batch) batch = spans.shift(@batch_size) end end |