Class: Appdash::Client

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

Constant Summary collapse

DEFAULTS =

Client defaults

{
  host: 'localhost',
  port: 7701,
  max_buffer_size: 0,
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Initializes a new client

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :host (String)

    the hostname, defaults to localhost

  • :port (Integer)

    the port, defaults to 7701

  • :max_buffer_size (Integer)

    maximum buffer size in bytes, defaults to 0 (= no buffering, flushes on every span)



20
21
22
23
24
25
# File 'lib/appdash/client.rb', line 20

def initialize(opts = {})
  @config = DEFAULTS.merge(opts)
  @buffer = Buffer.new
  @mutex  = Mutex.new
  reconnect!
end

Instance Method Details

#closeObject

Close flushes any remaining buffered packets and closes the connection



55
56
57
58
# File 'lib/appdash/client.rb', line 55

def close
  flush_buffer!
  @sock.close
end

#span(&block) ⇒ Object

Traces a new span with a series of associated events. Accepts an optional block. If no block is given you must flush to send data to the collector.

Examples:

manual flush


span = client.span
span.name "Request"
span.message "A simple message"
span.flush

with block


client.span do |span|
  span.name "Request"
  span.message "A simple message"
end


43
44
45
46
47
48
49
50
51
52
# File 'lib/appdash/client.rb', line 43

def span(&block)
  span = Appdash::Span.new(self)
  return span unless block

  begin
    block.call(span)
  ensure
    span.flush
  end
end