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.
107 108 109 110 111 112 |
# File 'lib/ddtrace/transport/traces.rb', line 107 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.
105 106 107 |
# File 'lib/ddtrace/transport/traces.rb', line 105 def apis @apis end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
105 106 107 |
# File 'lib/ddtrace/transport/traces.rb', line 105 def client @client end |
#current_api_id ⇒ Object (readonly)
Returns the value of attribute current_api_id.
105 106 107 |
# File 'lib/ddtrace/transport/traces.rb', line 105 def current_api_id @current_api_id end |
#default_api ⇒ Object (readonly)
Returns the value of attribute default_api.
105 106 107 |
# File 'lib/ddtrace/transport/traces.rb', line 105 def default_api @default_api end |
Instance Method Details
#current_api ⇒ Object
152 153 154 |
# File 'lib/ddtrace/transport/traces.rb', line 152 def current_api apis[@current_api_id] end |
#send_traces(traces) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/ddtrace/transport/traces.rb', line 114 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_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
148 149 150 |
# File 'lib/ddtrace/transport/traces.rb', line 148 def stats @client.stats end |