Class: LightStep::Transport::HTTPJSON
- 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.
Constant Summary collapse
- LIGHTSTEP_HOST =
"collector.lightstep.com"- LIGHTSTEP_PORT =
443- ENCRYPTION_TLS =
'tls'- ENCRYPTION_NONE =
'none'
Instance Method Summary collapse
-
#initialize(host: LIGHTSTEP_HOST, port: LIGHTSTEP_PORT, verbose: 0, encryption: ENCRYPTION_TLS, access_token:) ⇒ HTTPJSON
constructor
Initialize the transport.
-
#report(report) ⇒ Object
Queue a report for sending.
Constructor Details
#initialize(host: LIGHTSTEP_HOST, port: LIGHTSTEP_PORT, verbose: 0, encryption: ENCRYPTION_TLS, access_token:) ⇒ HTTPJSON
Initialize the transport
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/lightstep/transport/http_json.rb', line 27 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 end |
Instance Method Details
#report(report) ⇒ Object
Queue a report for sending
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/lightstep/transport/http_json.rb', line 39 def report(report) p report if @verbose >= 3 https = Net::HTTP.new(@host, @port) https.use_ssl = @encryption == ENCRYPTION_TLS req = Net::HTTP::Post.new('/api/v0/reports') req['LightStep-Access-Token'] = @access_token req['Content-Type'] = 'application/json' req['Connection'] = 'keep-alive' req.body = report.to_json res = https.request(req) puts res.to_s if @verbose >= 3 nil end |