Class: Datadog::Tracing::Transport::IO::Client

Inherits:
Object
  • Object
show all
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

Traces::Encoder::ENCODED_IDS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Traces::Client

#send_traces

Methods included from Traces::Encoder

#encode_traces

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, options = {})
  @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 = options.fetch(:request, method(:send_default_request))
  @write_block = options.fetch(:write, method(:write_data))
  @response_block = options.fetch(:response, method(:build_response))
end

Instance Attribute Details

#encoderObject (readonly)

Returns the value of attribute encoder.



14
15
16
# File 'lib/datadog/tracing/transport/io/client.rb', line 14

def encoder
  @encoder
end

#outObject (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
  message =
    "Internal error during IO transport request. Cause: #{e.class.name}: #{e.message} " \
      "Location: #{Array(e.backtrace).first}"

  # Log error
  if stats.consecutive_errors > 0
    Datadog.logger.debug(message)
  else
    # Not to report telemetry logs
    Datadog.logger.error(message)
  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