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

Direct Known Subclasses

Datadog::CI::ContextFlush::Partial

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.



29
30
31
# File 'lib/ddtrace/context_flush.rb', line 29

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



43
44
45
46
47
48
49
50
# File 'lib/ddtrace/context_flush.rb', line 43

def consume!(context)
  trace, sampled = get_trace(context)

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

  partial_trace(context)
end