Class: Datadog::Tracing::Transport::IO::Client
- Inherits:
-
Object
- Object
- Datadog::Tracing::Transport::IO::Client
- Includes:
- Traces::Client, Statistics
- Defined in:
- lib/datadog/tracing/transport/io/client.rb
Overview
Encodes and writes tracer data to IO
Constant Summary
Constants included from Traces::Encoder
Instance Attribute Summary collapse
-
#encoder ⇒ Object
readonly
Returns the value of attribute encoder.
-
#out ⇒ Object
readonly
Returns the value of attribute out.
Instance Method Summary collapse
- #build_response(_request, _data, result) ⇒ Object
-
#initialize(out, encoder, options = {}) ⇒ Client
constructor
A new instance of Client.
- #send_request(request) ⇒ Object
- #write_data(out, data) ⇒ Object
Methods included from Traces::Client
Methods included from Traces::Encoder
Methods included from Statistics
#metrics_for_exception, #metrics_for_response, #stats, #update_stats_from_exception!, #update_stats_from_response!
Constructor Details
#initialize(out, encoder, options = {}) ⇒ Client
Returns a new instance of Client.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/datadog/tracing/transport/io/client.rb', line 18 def initialize(out, encoder, = {}) @out = out @encoder = encoder # Note: The :encode option was previously supported but is no longer used. # Data is now expected to be pre-encoded in the Parcel before reaching this client, # matching the behavior of other transports (e.g., HTTP transport). # If provided, the :encode option will be silently ignored for backwards compatibility. @request_block = .fetch(:request, method(:send_default_request)) @write_block = .fetch(:write, method(:write_data)) @response_block = .fetch(:response, method(:build_response)) end |
Instance Attribute Details
#encoder ⇒ Object (readonly)
Returns the value of attribute encoder.
14 15 16 |
# File 'lib/datadog/tracing/transport/io/client.rb', line 14 def encoder @encoder end |
#out ⇒ Object (readonly)
Returns the value of attribute out.
14 15 16 |
# File 'lib/datadog/tracing/transport/io/client.rb', line 14 def out @out end |
Instance Method Details
#build_response(_request, _data, result) ⇒ Object
68 69 70 |
# File 'lib/datadog/tracing/transport/io/client.rb', line 68 def build_response(_request, _data, result) IO::Response.new(result) end |
#send_request(request) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/datadog/tracing/transport/io/client.rb', line 31 def send_request(request) # Write data to IO # If block is given, allow it to handle writing # Otherwise do a standard encode/write/response. response = if block_given? yield(out, request) else @request_block.call(out, request) end # Update statistics update_stats_from_response!(response) response rescue => e = "Internal error during IO transport request. Cause: #{e.class.name}: #{e.} " \ "Location: #{Array(e.backtrace).first}" # Log error if stats.consecutive_errors > 0 Datadog.logger.debug() else # Not to report telemetry logs Datadog.logger.error() end # Update statistics update_stats_from_exception!(e) InternalErrorResponse.new(e) end |
#write_data(out, data) ⇒ Object
64 65 66 |
# File 'lib/datadog/tracing/transport/io/client.rb', line 64 def write_data(out, data) out.puts(data) end |