Class: LightStep::Transport::HTTPJSON

Inherits:
Base
  • Object
show all
Defined in:
lib/lightstep/transport/http_json.rb

Overview

HTTPJSON is a transport that sends reports via HTTP in JSON format. It is thread-safe, however it is not fork-safe. When forking, all items in the queue will be copied and sent in duplicate.

When forking, you should first disable the tracer, then enable it from within the fork (and in the parent post-fork). See examples/fork_children/main.rb for an example.

Defined Under Namespace

Classes: QueueFullError

Constant Summary collapse

LIGHTSTEP_HOST =
"collector.lightstep.com"
LIGHTSTEP_PORT =
443
QUEUE_SIZE =
16
ENCRYPTION_TLS =
'tls'
ENCRYPTION_NONE =
'none'

Instance Method Summary collapse

Constructor Details

#initialize(host: LIGHTSTEP_HOST, port: LIGHTSTEP_PORT, verbose: 0, encryption: ENCRYPTION_TLS, access_token:) ⇒ HTTPJSON

Initialize the transport

Parameters:

  • host (String) (defaults to: LIGHTSTEP_HOST)

    host of the domain to the endpoind to push data

  • port (Numeric) (defaults to: LIGHTSTEP_PORT)

    port on which to connect

  • verbose (Numeric) (defaults to: 0)

    verbosity level. Right now 0-3 are supported

  • secure (Boolean)
  • access_token (String)

    access token for LightStep server

Raises:

  • (ConfigurationError)


30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/lightstep/transport/http_json.rb', line 30

def initialize(host: LIGHTSTEP_HOST, port: LIGHTSTEP_PORT, verbose: 0, encryption: ENCRYPTION_TLS, access_token:)
  @host = host
  @port = port
  @verbose = verbose
  @encryption = encryption

  raise ConfigurationError, "access_token must be a string" unless String === access_token
  raise ConfigurationError, "access_token cannot be blank"  if access_token.empty?
  @access_token = access_token

  start_queue
end

Instance Method Details

#clearObject

Clear the current queue, deleting pending items



68
69
70
# File 'lib/lightstep/transport/http_json.rb', line 68

def clear
  @queue.clear
end

#closeObject

Close the transport. No further data can be sent!



73
74
75
76
# File 'lib/lightstep/transport/http_json.rb', line 73

def close
  @queue.close
  @thread.join
end

#flushObject

Flush the current queue



62
63
64
65
# File 'lib/lightstep/transport/http_json.rb', line 62

def flush
  close
  start_queue
end

#report(report) ⇒ Object

Queue a report for sending



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/lightstep/transport/http_json.rb', line 44

def report(report)
  p report if @verbose >= 3
  # TODO([email protected]): the queue could be full here if we're
  # lagging, which would cause this to block!
  @queue.push({
    host: @host,
    port: @port,
    encryption: @encryption,
    access_token: @access_token,
    content: report,
    verbose: @verbose
  }, true)
  nil
rescue ThreadError
  raise QueueFullError
end