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
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
- #encode_data(encoder, request) ⇒ 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 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 |
# File 'lib/datadog/tracing/transport/io/client.rb', line 18 def initialize(out, encoder, = {}) @out = out @encoder = encoder @request_block = .fetch(:request, method(:send_default_request)) @encode_block = .fetch(:encode, method(:encode_data)) @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
70 71 72 |
# File 'lib/datadog/tracing/transport/io/client.rb', line 70 def build_response(_request, _data, result) IO::Response.new(result) end |
#encode_data(encoder, request) ⇒ Object
62 63 64 |
# File 'lib/datadog/tracing/transport/io/client.rb', line 62 def encode_data(encoder, request) request.parcel.encode_with(encoder) end |
#send_request(request) ⇒ Object
28 29 30 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 |
# File 'lib/datadog/tracing/transport/io/client.rb', line 28 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) # Return response response rescue StandardError => 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
66 67 68 |
# File 'lib/datadog/tracing/transport/io/client.rb', line 66 def write_data(out, data) out.puts(data) end |