Class: Bigcommerce::Lightstep::Transport

Inherits:
LightStep::Transport::Base
  • Object
show all
Defined in:
lib/bigcommerce/lightstep/transport.rb

Overview

This 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.

Defined Under Namespace

Classes: InvalidAccessTokenError

Constant Summary collapse

ENCRYPTION_TLS =
'tls'.freeze
ENCRYPTION_NONE =
'none'.freeze
HEADER_ACCESS_TOKEN =
'LightStep-Access-Token'.freeze
LIGHTSTEP_HOST =
'collector.lightstep.com'.freeze
LIGHTSTEP_PORT =
443
REPORTS_API_ENDPOINT =
'/api/v0/reports'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(access_token:, host: LIGHTSTEP_HOST, port: LIGHTSTEP_PORT, verbose: 0, encryption: ENCRYPTION_TLS, ssl_verify_peer: true, open_timeout: 2, read_timeout: 2, continue_timeout: nil, keep_alive_timeout: 2, logger: nil) ⇒ Transport

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

  • encryption (ENCRYPTION_TLS, ENCRYPTION_NONE) (defaults to: ENCRYPTION_TLS)

    kind of encryption to use

  • ssl_verify_peer (Boolean) (defaults to: true)
  • access_token (String)

    access token for LightStep server

Raises:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/bigcommerce/lightstep/transport.rb', line 43

def initialize(
  access_token:,
  host: LIGHTSTEP_HOST,
  port: LIGHTSTEP_PORT,
  verbose: 0,
  encryption: ENCRYPTION_TLS,
  ssl_verify_peer: true,
  open_timeout: 2,
  read_timeout: 2,
  continue_timeout: nil,
  keep_alive_timeout: 2,
  logger: nil
)
  @host = host
  @port = port
  @verbose = verbose
  @encryption = encryption
  @ssl_verify_peer = ssl_verify_peer
  @open_timeout = open_timeout.to_i
  @read_timeout = read_timeout.to_i
  @continue_timeout = continue_timeout
  @keep_alive_timeout = keep_alive_timeout.to_i

  raise ::Bigcommerce::Lightstep::Errors::InvalidAccessToken, 'access_token must be a string' unless access_token.is_a?(String)

  raise ::Bigcommerce::Lightstep::Errors::InvalidAccessToken, 'access_token cannot be blank'  if access_token.empty?

  @access_token = access_token.to_s
  @logger = logger || ::Logger.new(STDOUT)
end

Instance Method Details

#report(report) ⇒ NilClass

Queue a report for sending

Parameters:

  • report (Hash)

Returns:

  • (NilClass)


80
81
82
83
84
85
86
87
88
89
# File 'lib/bigcommerce/lightstep/transport.rb', line 80

def report(report)
  @logger.info report if @verbose >= 3

  req = build_request(report)
  res = connection.request(req)

  @logger.info res.to_s if @verbose >= 3

  nil
end