Class: XRay::DefaultEmitter

Inherits:
Object
  • Object
show all
Includes:
Emitter, Logging
Defined in:
lib/aws-xray-sdk/emitter/default_emitter.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger, logger, logger=

Constructor Details

#initialize(daemon_config: DaemonConfig.new) ⇒ DefaultEmitter

Returns a new instance of DefaultEmitter.



16
17
18
19
# 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

Instance Attribute Details

#daemon_configObject

Returns the value of attribute daemon_config.



14
15
16
# File 'lib/aws-xray-sdk/emitter/default_emitter.rb', line 14

def daemon_config
  @daemon_config
end

Instance Method Details

#send_entity(entity:) ⇒ Object

Serializes a segment/subsegment and sends it to the X-Ray daemon over UDP. It is no-op for non-sampled entity.

Parameters:

  • entity (Entity)

    The entity to send



24
25
26
27
28
29
30
31
32
33
# 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