Class: Datadog::ContextFlush::Partial

Inherits:
Object
  • Object
show all
Defined in:
lib/ddtrace/context_flush.rb

Overview

Performs partial trace flushing to avoid large traces residing in memory for too long

Constant Summary collapse

DEFAULT_MIN_SPANS_FOR_PARTIAL_FLUSH =

Start flushing partial trace after this many active spans in one trace

500

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Partial

Returns a new instance of Partial.



22
23
24
# File 'lib/ddtrace/context_flush.rb', line 22

def initialize(options = {})
  @min_spans_for_partial = options.fetch(:min_spans_before_partial_flush, DEFAULT_MIN_SPANS_FOR_PARTIAL_FLUSH)
end

Instance Method Details

#consume!(context) ⇒ Array<Span>

Consumes and returns completed or partially completed traces from the provided context, if any.

Partially completed traces, where not all spans have finished, will only be returned if there are at least @min_spans_for_partial finished spans.

Any spans consumed are removed from context as a side effect.

Returns:

  • (Array<Span>)

    partial or complete trace to be flushed, or nil if no spans are finished



36
37
38
39
40
41
42
43
# File 'lib/ddtrace/context_flush.rb', line 36

def consume!(context)
  trace, sampled = context.get

  return nil unless sampled
  return trace if trace && !trace.empty?

  partial_trace(context)
end