module Datadog::Transport::IO::Traces::Encoder

Encoder for IO-specific trace encoding API compliant when used with {JSONEncoder}.

Constants

ENCODED_IDS

Public Instance Methods

encode_traces(encoder, traces) click to toggle source

Encodes a list of traces

# File lib/ddtrace/transport/io/traces.rb, line 57
def encode_traces(encoder, traces)
  trace_hashes = traces.map do |trace|
    encode_trace(trace)
  end

  # Wrap traces & encode them
  encoder.encode(traces: trace_hashes)
end

Private Instance Methods

encode_trace(trace) click to toggle source
# File lib/ddtrace/transport/io/traces.rb, line 68
def encode_trace(trace)
  # Convert each trace to hash
  trace.map(&:to_hash).tap do |spans|
    # Convert IDs to hexadecimal
    spans.each do |span|
      ENCODED_IDS.each do |id|
        span[id] = span[id].to_s(16) if span.key?(id)
      end
    end
  end
end