class XRay::DefaultEmitter

The default emitter the X-Ray recorder uses to send segments/subsegments to the X-Ray daemon over UDP using a non-blocking socket.

Attributes

daemon_config[R]

Public Class Methods

new(daemon_config: DaemonConfig.new) click to toggle source
# File lib/aws-xray-sdk/emitter/default_emitter.rb, line 16
def initialize(daemon_config: DaemonConfig.new)
  @socket = UDPSocket.new
  self.daemon_config = daemon_config
end

Public Instance Methods

daemon_config=(v) click to toggle source
# File lib/aws-xray-sdk/emitter/default_emitter.rb, line 35
def daemon_config=(v)
  @address = %(#{v.udp_ip}:#{v.udp_port})
  @socket.connect(v.udp_ip, v.udp_port)
rescue StandardError
  raise InvalidDaemonAddressError, %(Invalid X-Ray daemon address specified: #{v}.)
end
send_entity(entity:) click to toggle source

Serializes a segment/subsegment and sends it to the X-Ray daemon over UDP. It is no-op for non-sampled entity. @param [Entity] entity The entity to send

# File lib/aws-xray-sdk/emitter/default_emitter.rb, line 24
def send_entity(entity:)
  return nil unless entity.sampled
  begin
    payload = %(#{@@protocol_header}#{@@protocol_delimiter}#{entity.to_json})
    logger.debug %(sending payload #{payload} to daemon at #{@address}.)
    @socket.send payload, 0
  rescue StandardError => e
    logger.warn %(failed to send payload due to #{e.message})
  end
end