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.

Constant Summary

Constants included from Emitter

Emitter::DAEMON_ADDRESS_KEY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger, logger, logger=

Constructor Details

#initializeDefaultEmitter

Returns a new instance of DefaultEmitter.



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

def initialize
  @socket = UDPSocket.new
  @address = ENV[DAEMON_ADDRESS_KEY] || '127.0.0.1:2000'
  configure_socket(@address)
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



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

def address
  @address
end

Instance Method Details

#daemon_address=(v) ⇒ Object



35
36
37
38
39
# File 'lib/aws-xray-sdk/emitter/default_emitter.rb', line 35

def daemon_address=(v)
  v = ENV[DAEMON_ADDRESS_KEY] || v
  @address = v
  configure_socket(v)
end

#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