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, Verbosity

Constant Summary collapse

ENCRYPTION_TLS =
'tls'
ENCRYPTION_NONE =
'none'
HEADER_ACCESS_TOKEN =
'LightStep-Access-Token'
LIGHTSTEP_HOST =
'collector.lightstep.com'
LIGHTSTEP_PORT =
443
REPORTS_API_ENDPOINT =
'/api/v0/reports'
DEFAULT_OPEN_TIMEOUT =
20
DEFAULT_READ_TIMEOUT =
20
DEFAULT_KEEPALIVE_TIMEOUT =
2
DEFAULT_SSL_PORT =
443

Instance Method Summary collapse

Constructor Details

#initialize(access_token:, host: nil, port: nil, verbose: nil, encryption: nil, ssl_verify_peer: true, ssl_port: nil, open_timeout: nil, read_timeout: nil, continue_timeout: nil, keep_alive_timeout: nil, logger: nil) ⇒ Transport

Initialize the transport

Parameters:

  • host (String) (defaults to: nil)

    host of the domain to the endpoind to push data

  • port (Numeric) (defaults to: nil)

    port on which to connect

  • verbose (Numeric) (defaults to: nil)

    verbosity level. Right now 0-3 are supported

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

    kind of encryption to use

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

    access token for LightStep server



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/bigcommerce/lightstep/transport.rb', line 61

def initialize(
  access_token:,
  host: nil,
  port: nil,
  verbose: nil,
  encryption: nil,
  ssl_verify_peer: true,
  ssl_port: nil,
  open_timeout: nil,
  read_timeout: nil,
  continue_timeout: nil,
  keep_alive_timeout: nil,
  logger: nil
)
  @host = host || LIGHTSTEP_HOST
  @port = port || LIGHTSTEP_PORT
  @verbose = verbose || Verbosity::FATAL
  @encryption = encryption || ENCRYPTION_TLS
  @ssl_verify_peer = ssl_verify_peer
  @ssl_port = (ssl_port || DEFAULT_SSL_PORT).to_i
  @open_timeout = (open_timeout || DEFAULT_OPEN_TIMEOUT).to_i
  @read_timeout = (read_timeout || DEFAULT_READ_TIMEOUT).to_i
  @continue_timeout = continue_timeout
  @keep_alive_timeout = (keep_alive_timeout || DEFAULT_KEEPALIVE_TIMEOUT).to_i
  @access_token = access_token.to_s

  default_logger = ::Logger.new($stdout)
  default_logger.level = ::Logger::INFO
  @logger = logger || default_logger
  super()
end

Instance Method Details

#report(report) ⇒ NilClass

Queue a report for sending

Parameters:

  • report (Hash)

Returns:

  • (NilClass)


99
100
101
102
103
104
105
106
107
108
# File 'lib/bigcommerce/lightstep/transport.rb', line 99

def report(report)
  @logger.info report if @verbose >= Verbosity::INFO

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

  @logger.info res.to_s if @verbose >= Verbosity::INFO

  nil
end