Class: SplunkTracing::Transport::HTTPJSON

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

Overview

HTTPJSON is a transport that sends reports via HTTP in JSON format. It is thread-safe.

Constant Summary collapse

SPLUNK_HEC_HOST =
'localhost'.freeze
SPLUNK_HEC_PORT =
8088
ENCRYPTION_TLS =
'tls'.freeze
ENCRYPTION_NONE =
'none'.freeze
REPORTS_API_ENDPOINT =
'/services/collector'.freeze
HEADER_ACCESS_TOKEN =
'Authorization'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(host: SPLUNK_HEC_HOST, port: SPLUNK_HEC_PORT, verbose: 0, encryption: ENCRYPTION_TLS, access_token:, ssl_verify_peer: false, open_timeout: 20, read_timeout: 20, continue_timeout: nil, keep_alive_timeout: 2, logger: nil) ⇒ HTTPJSON

Initialize the transport

Parameters:

  • host (String) (defaults to: SPLUNK_HEC_HOST)

    host of the domain to the endpoint to push data

  • port (Numeric) (defaults to: SPLUNK_HEC_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

  • access_token (String)

    access token for SplunkTracing server

  • ssl_verify_peer (Boolean) (defaults to: false)
  • open_timeout (Integer) (defaults to: 20)
  • read_timeout (Integer) (defaults to: 20)
  • continue_timeout (Integer) (defaults to: nil)
  • keep_alive_timeout (Integer) (defaults to: 2)
  • logger (Logger) (defaults to: nil)

Raises:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/splunktracing/transport/http_json.rb', line 35

def initialize(
  host: SPLUNK_HEC_HOST,
  port: SPLUNK_HEC_PORT,
  verbose: 0,
  encryption: ENCRYPTION_TLS,
  access_token:,
  ssl_verify_peer: false,
  open_timeout: 20,
  read_timeout: 20,
  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 Tracer::ConfigurationError, 'access_token must be a string' unless access_token.is_a?(String)
  raise Tracer::ConfigurationError, 'access_token cannot be blank'  if access_token.empty?
  @access_token = access_token
  @logger = logger || SplunkTracing.logger
end

Instance Method Details

#report(report) ⇒ Object

Queue a report for sending



67
68
69
70
71
72
73
74
75
76
# File 'lib/splunktracing/transport/http_json.rb', line 67

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