Class: Datadog::Transport::Traces::Transport
- Inherits:
-
Object
- Object
- Datadog::Transport::Traces::Transport
- Defined in:
- lib/ddtrace/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
-
#apis ⇒ Object
readonly
Returns the value of attribute apis.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#current_api_id ⇒ Object
readonly
Returns the value of attribute current_api_id.
-
#default_api ⇒ Object
readonly
Returns the value of attribute default_api.
Instance Method Summary collapse
- #current_api ⇒ Object
-
#initialize(apis, default_api) ⇒ Transport
constructor
A new instance of Transport.
- #send_traces(traces) ⇒ Object
- #stats ⇒ Object
Constructor Details
#initialize(apis, default_api) ⇒ Transport
Returns a new instance of Transport.
117 118 119 120 121 122 |
# File 'lib/ddtrace/transport/traces.rb', line 117 def initialize(apis, default_api) @apis = apis @default_api = default_api change_api!(default_api) end |
Instance Attribute Details
#apis ⇒ Object (readonly)
Returns the value of attribute apis.
115 116 117 |
# File 'lib/ddtrace/transport/traces.rb', line 115 def apis @apis end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
115 116 117 |
# File 'lib/ddtrace/transport/traces.rb', line 115 def client @client end |
#current_api_id ⇒ Object (readonly)
Returns the value of attribute current_api_id.
115 116 117 |
# File 'lib/ddtrace/transport/traces.rb', line 115 def current_api_id @current_api_id end |
#default_api ⇒ Object (readonly)
Returns the value of attribute default_api.
115 116 117 |
# File 'lib/ddtrace/transport/traces.rb', line 115 def default_api @default_api end |
Instance Method Details
#current_api ⇒ Object
162 163 164 |
# File 'lib/ddtrace/transport/traces.rb', line 162 def current_api apis[@current_api_id] end |
#send_traces(traces) ⇒ Object
124 125 126 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 |
# File 'lib/ddtrace/transport/traces.rb', line 124 def send_traces(traces) encoder = current_api.encoder chunker = Datadog::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 |
#stats ⇒ Object
158 159 160 |
# File 'lib/ddtrace/transport/traces.rb', line 158 def stats @client.stats end |