Class: Datadog::Transport::Traces::Chunker

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

Overview

Traces chunker

Constant Summary collapse

DEFAULT_MAX_PAYLOAD_SIZE =

Trace agent limit payload size of 10 MiB (since agent v5.11.0): https://github.com/DataDog/datadog-agent/blob/6.14.1/pkg/trace/api/api.go#L46

We set the value to a conservative 5 MiB, in case network speed is slow.

5 * 1024 * 1024

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(encoder, max_size: DEFAULT_MAX_PAYLOAD_SIZE) ⇒ Chunker

Single traces larger than +max_size+ will be discarded.

Parameters:

  • encoder (Datadog::Encoding::Encoder)
  • max_size (String) (defaults to: DEFAULT_MAX_PAYLOAD_SIZE)

    maximum acceptable payload size



49
50
51
52
# File 'lib/ddtrace/transport/traces.rb', line 49

def initialize(encoder, max_size: DEFAULT_MAX_PAYLOAD_SIZE)
  @encoder = encoder
  @max_size = max_size
end

Instance Attribute Details

#encoderObject (readonly)

Returns the value of attribute encoder.



42
43
44
# File 'lib/ddtrace/transport/traces.rb', line 42

def encoder
  @encoder
end

#max_sizeObject (readonly)

Returns the value of attribute max_size.



42
43
44
# File 'lib/ddtrace/transport/traces.rb', line 42

def max_size
  @max_size
end

Instance Method Details

#encode_in_chunks(traces) ⇒ Enumerable[Array[Bytes,Integer]]

Encodes a list of traces in chunks. Before serializing, all traces are normalized. Trace nesting is not changed.

Parameters:

  • traces (Enumerable<Trace>)

    list of traces

Returns:

  • (Enumerable[Array[Bytes,Integer]])

    list of encoded chunks: each containing a byte array and number of traces



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ddtrace/transport/traces.rb', line 60

def encode_in_chunks(traces)
  encoded_traces = if traces.respond_to?(:filter_map)
                     # DEV Supported since Ruby 2.7, saves an intermediate object creation
                     traces.filter_map { |t| encode_one(t) }
                   else
                     traces.map { |t| encode_one(t) }.reject(&:nil?)
                   end

  Datadog::Chunker.chunk_by_size(encoded_traces, max_size).map do |chunk|
    [encoder.join(chunk), chunk.size]
  end
end