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

Inherits:
Object
  • Object
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.

Defined Under Namespace

Classes: NoDowngradeAvailableError, UnknownApiVersionError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(apis, default_api) ⇒ Transport

Returns a new instance of Transport.



120
121
122
123
124
125
# File 'lib/datadog/tracing/transport/traces.rb', line 120

def initialize(apis, default_api)
  @apis = apis
  @default_api = default_api

  change_api!(default_api)
end

Instance Attribute Details

#apisObject (readonly)

Returns the value of attribute apis.



118
119
120
# File 'lib/datadog/tracing/transport/traces.rb', line 118

def apis
  @apis
end

#clientObject (readonly)

Returns the value of attribute client.



118
119
120
# File 'lib/datadog/tracing/transport/traces.rb', line 118

def client
  @client
end

#current_api_idObject (readonly)

Returns the value of attribute current_api_id.



118
119
120
# File 'lib/datadog/tracing/transport/traces.rb', line 118

def current_api_id
  @current_api_id
end

#default_apiObject (readonly)

Returns the value of attribute default_api.



118
119
120
# File 'lib/datadog/tracing/transport/traces.rb', line 118

def default_api
  @default_api
end

Instance Method Details

#current_apiObject



165
166
167
# File 'lib/datadog/tracing/transport/traces.rb', line 165

def current_api
  apis[@current_api_id]
end

#send_traces(traces) ⇒ Object



127
128
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
# File 'lib/datadog/tracing/transport/traces.rb', line 127

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

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

    client.send_traces_payload(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



161
162
163
# File 'lib/datadog/tracing/transport/traces.rb', line 161

def stats
  @client.stats
end