Class: Datadog::Tracing::Transport::Traces::Transport
- Inherits:
-
Object
- Object
- Datadog::Tracing::Transport::Traces::Transport
- 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
-
#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.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #current_api ⇒ Object
-
#initialize(apis, default_api, logger: Datadog.logger) ⇒ Transport
constructor
A new instance of Transport.
- #send_traces(traces) ⇒ Object
- #stats ⇒ Object
Constructor Details
#initialize(apis, default_api, logger: Datadog.logger) ⇒ Transport
Returns a new instance of Transport.
129 130 131 132 133 134 135 |
# File 'lib/datadog/tracing/transport/traces.rb', line 129 def initialize(apis, default_api, logger: Datadog.logger) @apis = apis @default_api = default_api @logger = logger change_api!(default_api) end |
Instance Attribute Details
#apis ⇒ Object (readonly)
Returns the value of attribute apis.
127 128 129 |
# File 'lib/datadog/tracing/transport/traces.rb', line 127 def apis @apis end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
127 128 129 |
# File 'lib/datadog/tracing/transport/traces.rb', line 127 def client @client end |
#current_api_id ⇒ Object (readonly)
Returns the value of attribute current_api_id.
127 128 129 |
# File 'lib/datadog/tracing/transport/traces.rb', line 127 def current_api_id @current_api_id end |
#default_api ⇒ Object (readonly)
Returns the value of attribute default_api.
127 128 129 |
# File 'lib/datadog/tracing/transport/traces.rb', line 127 def default_api @default_api end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
127 128 129 |
# File 'lib/datadog/tracing/transport/traces.rb', line 127 def logger @logger end |
Instance Method Details
#current_api ⇒ Object
179 180 181 |
# File 'lib/datadog/tracing/transport/traces.rb', line 179 def current_api apis[@current_api_id] end |
#send_traces(traces) ⇒ Object
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 166 167 168 169 170 171 172 173 |
# File 'lib/datadog/tracing/transport/traces.rb', line 137 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_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
175 176 177 |
# File 'lib/datadog/tracing/transport/traces.rb', line 175 def stats @client.stats end |