class Bigcommerce::Lightstep::Transport
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.
Constants
- DEFAULT_KEEPALIVE_TIMEOUT
- DEFAULT_OPEN_TIMEOUT
- DEFAULT_READ_TIMEOUT
- DEFAULT_SSL_PORT
- ENCRYPTION_NONE
- ENCRYPTION_TLS
- HEADER_ACCESS_TOKEN
- LIGHTSTEP_HOST
- LIGHTSTEP_PORT
- REPORTS_API_ENDPOINT
Public Class Methods
new( 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 )
click to toggle source
Initialize the transport @param host [String] host of the domain to the endpoind to push data @param port [Numeric] port on which to connect @param verbose [Numeric] verbosity level. Right now 0-3 are supported @param encryption [ENCRYPTION_TLS, ENCRYPTION_NONE
] kind of encryption to use @param ssl_verify_peer [Boolean] @param access_token [String] access token for LightStep server @return [Transport]
Calls superclass method
# 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
Public Instance Methods
report(report)
click to toggle source
Queue a report for sending
@param [Hash] report @return [NilClass]
# 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
Private Instance Methods
build_request(report)
click to toggle source
@param [Hash] report @return [Net::HTTP::Post]
# File lib/bigcommerce/lightstep/transport.rb, line 116 def build_request(report) req = Net::HTTP::Post.new(REPORTS_API_ENDPOINT) req[HEADER_ACCESS_TOKEN] = @access_token unless @access_token.to_s.empty? req['Content-Type'] = 'application/json' req['Connection'] = 'keep-alive' req.body = report.to_json req end
connection()
click to toggle source
@return [Net::HTTP]
# File lib/bigcommerce/lightstep/transport.rb, line 128 def connection unless @connection @connection = ::Net::HTTP.new(@host, @port) if @port == @ssl_port @connection.use_ssl = @encryption == ENCRYPTION_TLS @connection.verify_mode = ::OpenSSL::SSL::VERIFY_NONE unless @ssl_verify_peer end @connection.open_timeout = @open_timeout @connection.read_timeout = @read_timeout @connection.continue_timeout = @continue_timeout @connection.keep_alive_timeout = @keep_alive_timeout end @connection end