Class: Raygun::Apm::Tracer

Inherits:
Object
  • Object
show all
Defined in:
lib/raygun/apm/tracer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env = ENV) ⇒ Tracer

Returns a new instance of Tracer.



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/raygun/apm/tracer.rb', line 30

def initialize(env=ENV)
  configure(env)
  initialize_blacklist
  register_known_library_paths
  run_agent_connectivity_diagnostics
  require_hooks
  ObjectSpace.define_finalizer(self, proc{ disable_tracepoints })
# Any fails here is kamikaze for the tracer
rescue => e
  # XXX works for the middleware wrapped case, not for standalone - revisit
  raise Raygun::Apm::FatalError, "Raygun APM tracer could not be initialized: #{e.message} #{e.backtrace.join("\n")}"
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



28
29
30
# File 'lib/raygun/apm/tracer.rb', line 28

def config
  @config
end

Class Method Details

.instanceObject



15
16
17
# File 'lib/raygun/apm/tracer.rb', line 15

def instance
  @__pids[Process.pid]
end

.instance=(tracer) ⇒ Object



19
20
21
# File 'lib/raygun/apm/tracer.rb', line 19

def instance=(tracer)
  @__pids[Process.pid] = tracer
end

.patch(concern, hook) ⇒ Object



23
24
25
# File 'lib/raygun/apm/tracer.rb', line 23

def patch(concern, hook)
  concern.prepend(hook) unless concern.ancestors.include?(hook)
end

.synchronize(&block) ⇒ Object



11
12
13
# File 'lib/raygun/apm/tracer.rb', line 11

def synchronize(&block)
  @__mutex.synchronize { block.call }
end

Instance Method Details

#enable_sink!Object



68
69
70
71
72
73
74
# File 'lib/raygun/apm/tracer.rb', line 68

def enable_sink!
  if config.proton_network_mode == "Udp"
    udp_sink!
  elsif config.proton_network_mode == "Tcp"
    tcp_sink!
  end
end

#tcp_sink!Object



58
59
60
61
62
63
64
65
66
# File 'lib/raygun/apm/tracer.rb', line 58

def tcp_sink!
  self.tcp_sink(
    host: config.proton_tcp_host,
    port: config.proton_tcp_port
  )
rescue => e
  # XXX works for the middleware wrapped case, not for standalone - revisit
  raise Raygun::Apm::FatalError, "Raygun APM TCP sink could not be initialized: #{e.message} #{e.backtrace.join("\n")}"
end

#udp_sink!Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/raygun/apm/tracer.rb', line 43

def udp_sink!
  sock = UDPSocket.new
  # For UDP sockets, SO_SNDBUF is the max packet size and NOT send buffer as with a connection oriented transport
  sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF, Tracer::BATCH_PACKET_SIZE)
  self.udp_sink(
    socket: sock,
    host: config.proton_udp_host,
    port: config.proton_udp_port,
    receive_buffer_size: sock.getsockopt(Socket::SOL_SOCKET, Socket::SO_RCVBUF).int
  )
rescue => e
  # XXX works for the middleware wrapped case, not for standalone - revisit
  raise Raygun::Apm::FatalError, "Raygun APM UDP sink could not be initialized: #{e.message} #{e.backtrace.join("\n")}"
end