Class: Aws::Xray::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/xray/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(host: nil, port: nil, sock: nil) ⇒ Client

sock is for test

XXX: keep options for implmenting copying later.



9
10
11
12
# File 'lib/aws/xray/client.rb', line 9

def initialize(host: nil, port: nil, sock: nil)
  @host, @port = host, port
  @sock = sock || UDPSocket.new
end

Instance Method Details

#closeObject



25
26
27
# File 'lib/aws/xray/client.rb', line 25

def close
  @sock.close
end

#send_segment(segment) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/aws/xray/client.rb', line 15

def send_segment(segment)
  segment.finish
  payload = %!{"format": "json", "version": 1}\n#{segment.to_json}\n!
  len = @sock.send(payload, 0, @host, @port)
  # TODO: retry
  if payload.size != len
    $stderr.puts("Can not send all bytes: #{len} sent")
  end
end