Class: Datadog::Tracing::Transport::Traces::Transport

Inherits:
Core::Transport::Transport show all
Defined in:
lib/datadog/tracing/transport/traces.rb

Overview

Sends traces based on transport API configuration.

This class initializes the HTTP client, breaks down large batches of traces into smaller chunks and handles API version downgrade handshake.

Instance Attribute Summary

Attributes inherited from Core::Transport::Transport

#apis, #client, #current_api_id, #default_api, #logger

Instance Method Summary collapse

Methods inherited from Core::Transport::Transport

#current_api, #initialize

Constructor Details

This class inherits a constructor from Datadog::Core::Transport::Transport

Instance Method Details

#send_traces(traces) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/datadog/tracing/transport/traces.rb', line 129

def send_traces(traces)
  encoder = current_api.encoder
  chunker = Datadog::Tracing::Transport::Traces::Chunker.new(
    encoder,
    logger: logger,
    native_events_supported: native_events_supported?
  )

  responses = chunker.encode_in_chunks(traces.lazy).map do |encoded_traces, trace_count|
    request = Request.new(EncodedParcel.new(encoded_traces, trace_count))

    client.send_request(:traces, request).tap do |response|
      if downgrade?(response)
        downgrade!
        return send_traces(traces)
      end
    end
  end

  # Force resolution of lazy enumerator.
  #
  # The "correct" method to call here would be `#force`,
  # as this method was created to force the eager loading
  # of a lazy enumerator.
  #
  # Unfortunately, JRuby < 9.2.9.0 erroneously eagerly loads
  # the lazy Enumerator during intermediate steps.
  # This forces us to use `#to_a`, as this method works for both
  # lazy and regular Enumerators.
  # Using `#to_a` can mask the fact that we expect a lazy
  # Enumerator.
  responses = responses.to_a

  Datadog.health_metrics.transport_chunked(responses.size)

  responses
end

#statsObject



167
168
169
# File 'lib/datadog/tracing/transport/traces.rb', line 167

def stats
  client.stats
end