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

Inherits:
Object
  • Object
show all
Includes:
Statistics
Defined in:
lib/ddtrace/transport/io/client.rb

Overview

Encodes and writes tracer data to IO

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Statistics

#metrics_for_exception, #metrics_for_response, #stats, #update_stats_from_exception!, #update_stats_from_response!

Constructor Details

#initialize(out, encoder) ⇒ Client

Returns a new instance of Client.



15
16
17
18
# File 'lib/ddtrace/transport/io/client.rb', line 15

def initialize(out, encoder)
  @out = out
  @encoder = encoder
end

Instance Attribute Details

#encoderObject (readonly)

Returns the value of attribute encoder.



11
12
13
# File 'lib/ddtrace/transport/io/client.rb', line 11

def encoder
  @encoder
end

#outObject (readonly)

Returns the value of attribute out.



11
12
13
# File 'lib/ddtrace/transport/io/client.rb', line 11

def out
  @out
end

Instance Method Details

#send_request(request) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ddtrace/transport/io/client.rb', line 20

def send_request(request)
  # Write data to IO
  # If block is given, allow it to handle writing
  # Otherwise use default encoding.
  response = if block_given?
               yield(out, request)
             else
               send_default_request(out, request)
             end

  # Update statistics
  update_stats_from_response!(response)

  # Return response
  response
rescue StandardError => e
  message = "Internal error during IO transport request. Cause: #{e.message} Location: #{e.backtrace.first}"

  # Log error
  if stats.consecutive_errors > 0
    Datadog::Logger.log.debug(message)
  else
    Datadog::Logger.log.error(message)
  end

  # Update statistics
  update_stats_from_exception!(e)

  InternalErrorResponse.new(e)
end